/* ─── IEC Optimization System — Design System ──────────────────────────────── */

:root {
  --iec-orange: #E8600A;
  --iec-orange-light: #FF7520;
  --iec-orange-pale: #FFF0E8;
  --iec-navy: #1A3A6B;
  --iec-navy-dark: #0F2548;
  --white: #ffffff;
  --gray-50: #F8F9FB;
  --gray-100: #F0F2F5;
  --gray-200: #E2E6ED;
  --gray-300: #C8D0DC;
  --gray-400: #9AA5B5;
  --gray-500: #6B7A8D;
  --gray-600: #4A5568;
  --gray-700: #2D3748;
  --gray-900: #1A202C;
  --sidebar-width: 240px;
  --header-height: 64px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 16px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
  --transition: 150ms ease;

  /* Status colors */
  --status-planned: #3B82F6;
  --status-approved: #8B5CF6;
  --status-in-progress: #F59E0B;
  --status-completed: #10B981;
  --status-cancelled: #6B7A8D;
  --status-overdue: #EF4444;
  --status-emergency: #EF4444;
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; overflow-x: hidden; }
body {
  font-family: 'Segoe UI', 'Arial', sans-serif;
  background: var(--gray-50);
  color: var(--gray-700);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}
[dir="rtl"] body { font-family: 'Segoe UI', 'Arial Hebrew', 'Arial', sans-serif; }
a { color: var(--iec-orange); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { cursor: pointer; border: none; background: none; font: inherit; }

/* ─── App Shell ────────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--iec-navy-dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0;
  z-index: 100;
  box-shadow: 2px 0 12px rgba(0,0,0,.18);
  transition: width var(--transition);
}
[dir="rtl"] .sidebar { left: auto; right: 0; }
[dir="ltr"] .sidebar { left: 0; right: auto; }

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  background: var(--iec-navy);
  border-bottom: 1px solid rgba(255,255,255,.10);
}
.sidebar-logo {
  width: 130px;
  height: 90px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 4px rgba(0,0,0,.3));
}
.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.sidebar-brand-name {
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}
.sidebar-brand-sub {
  color: var(--iec-orange-light);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .4px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-section-label {
  color: var(--gray-400);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 16px 20px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: rgba(255,255,255,.65);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
  text-decoration: none;
}
.nav-item:hover { color: var(--white); background: rgba(255,255,255,.06); text-decoration: none; }
.nav-item.active {
  color: var(--white);
  background: rgba(232,96,10,.18);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 3px;
  background: var(--iec-orange);
  border-radius: 0 3px 3px 0;
}
[dir="rtl"] .nav-item.active::before { left: auto; right: 0; border-radius: 3px 0 0 3px; }
[dir="ltr"] .nav-item.active::before { left: 0; }

.nav-icon {
  width: 20px;
  height: 20px;
  opacity: .8;
  flex-shrink: 0;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius);
}
.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--iec-orange);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { color: var(--white); font-size: 13px; font-weight: 600; truncate: true; }
.sidebar-user-role { color: var(--gray-400); font-size: 11px; }
.sidebar-logout { color: var(--gray-400); font-size: 13px; padding: 4px 8px; border-radius: 4px; }
.sidebar-logout:hover { color: var(--white); background: rgba(255,255,255,.06); }

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
[dir="rtl"] .main-content { margin-right: var(--sidebar-width); margin-left: 0; }
[dir="ltr"] .main-content { margin-left: var(--sidebar-width); margin-right: 0; }

/* ─── Top Header ───────────────────────────────────────────────────────────── */
.top-header {
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.header-title { font-size: 20px; font-weight: 700; color: var(--gray-900); flex: 1; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.lang-switcher {
  display: flex;
  align-items: center;
  background: var(--gray-100);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
}
.lang-btn {
  padding: 4px 12px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  transition: all var(--transition);
  cursor: pointer;
  border: none;
  background: none;
}
.lang-btn.active {
  background: var(--iec-orange);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}

/* ─── Page Body ────────────────────────────────────────────────────────────── */
.page-body { padding: 28px; flex: 1; }

/* ─── Page Header ──────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-size: 24px; font-weight: 700; color: var(--gray-900); }
.page-header .subtitle { color: var(--gray-500); font-size: 14px; margin-top: 2px; }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}
.card-body { padding: 24px; }
.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h2 { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.card-footer { padding: 14px 24px; border-top: 1px solid var(--gray-100); background: var(--gray-50); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ─── KPI Grid ─────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.kpi-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  transition: box-shadow var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow); }
.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 24px; height: 24px; }
.kpi-icon.orange { background: var(--iec-orange-pale); color: var(--iec-orange); }
.kpi-icon.blue { background: #EEF2FF; color: #4F46E5; }
.kpi-icon.green { background: #ECFDF5; color: #059669; }
.kpi-icon.red { background: #FEF2F2; color: #DC2626; }
.kpi-value { font-size: 32px; font-weight: 800; color: var(--gray-900); line-height: 1; }
.kpi-label { color: var(--gray-500); font-size: 13px; margin-top: 4px; }

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--gray-50); }
th {
  padding: 12px 16px;
  text-align: start;
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-500);
  letter-spacing: .5px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
td {
  padding: 14px 16px;
  font-size: 14px;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

/* ─── Badges / Status ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-planned { background: #EFF6FF; color: var(--status-planned); }
.badge-approved { background: #F5F3FF; color: var(--status-approved); }
.badge-in_progress { background: #FFFBEB; color: var(--status-in-progress); }
.badge-completed { background: #ECFDF5; color: var(--status-completed); }
.badge-cancelled { background: var(--gray-100); color: var(--gray-500); }
.badge-overdue { background: #FEF2F2; color: var(--status-overdue); }
.badge-emergency { background: #FEF2F2; color: var(--status-emergency); }
.badge-active { background: #ECFDF5; color: #059669; }
.badge-offline { background: #FEF2F2; color: #DC2626; }
.badge-maintenance { background: #FFFBEB; color: #D97706; }

.criticality-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.criticality-dot::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.crit-1::before { background: #10B981; }
.crit-2::before { background: #6EE7B7; }
.crit-3::before { background: #F59E0B; }
.crit-4::before { background: #F97316; }
.crit-5::before { background: #EF4444; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  cursor: pointer;
  border: 1.5px solid transparent;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--iec-orange);
  color: var(--white);
  border-color: var(--iec-orange);
}
.btn-primary:hover { background: var(--iec-orange-light); border-color: var(--iec-orange-light); }
.btn-secondary {
  background: var(--white);
  color: var(--gray-700);
  border-color: var(--gray-200);
}
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-300); }
.btn-danger {
  background: #FEF2F2;
  color: #DC2626;
  border-color: #FECACA;
}
.btn-danger:hover { background: #DC2626; color: var(--white); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; }
.btn svg { width: 16px; height: 16px; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--iec-orange);
  box-shadow: 0 0 0 3px rgba(232,96,10,.1);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 90px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ─── Filters Bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.search-input-wrap { position: relative; flex: 1; min-width: 200px; }
.search-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--gray-400);
  pointer-events: none;
}
[dir="rtl"] .search-icon { right: 12px; }
[dir="ltr"] .search-icon { left: 12px; }
.search-input {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--white);
  transition: border-color var(--transition);
}
[dir="rtl"] .search-input { padding-right: 36px; }
[dir="ltr"] .search-input { padding-left: 36px; }
.search-input:focus { outline: none; border-color: var(--iec-orange); }
.filter-select {
  padding: 9px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--white);
  color: var(--gray-700);
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--iec-orange); }

/* ─── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--gray-400);
}
.empty-icon { width: 56px; height: 56px; margin-bottom: 16px; opacity: .4; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; }
.empty-sub { font-size: 14px; }

/* ─── Gantt ────────────────────────────────────────────────────────────────── */
.gantt-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
.gantt-table { border-collapse: collapse; min-width: 100%; }
.gantt-row-label {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
  border-bottom: 1px solid var(--gray-100);
  background: var(--white);
  min-width: 180px;
  position: sticky;
}
[dir="rtl"] .gantt-row-label { right: 0; }
[dir="ltr"] .gantt-row-label { left: 0; }
.gantt-cell {
  border-bottom: 1px solid var(--gray-100);
  border-right: 1px solid var(--gray-100);
  height: 44px;
  min-width: 40px;
  position: relative;
}
.gantt-bar {
  position: absolute;
  top: 8px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
}
.gantt-bar-planned { background: var(--status-planned); }
.gantt-bar-emergency { background: var(--status-overdue); }
.gantt-bar-completed { background: var(--status-completed); }
.gantt-bar-maintenance { background: var(--status-in-progress); }

/* ─── Toggle Switch ────────────────────────────────────────────────────────── */
.toggle-switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 42px;
  height: 24px;
  background: var(--gray-200);
  border-radius: 12px;
  transition: background var(--transition);
  position: relative;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.toggle-switch input:checked + .toggle-track { background: var(--iec-orange); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(18px); }

/* ─── Alert / Flash ────────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 16px;
}
.alert-error { background: #FEF2F2; color: #DC2626; border: 1px solid #FECACA; }
.alert-success { background: #ECFDF5; color: #059669; border: 1px solid #A7F3D0; }
.alert-warning { background: #FFFBEB; color: #D97706; border: 1px solid #FDE68A; }

/* ─── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  background: linear-gradient(135deg, var(--iec-navy-dark) 0%, var(--iec-navy) 60%, #1e4d8c 100%);
}
.login-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 60px;
  position: relative;
  overflow: hidden;
}
.login-left::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.login-hero-logo { width: 220px; margin-bottom: 32px; filter: drop-shadow(0 4px 16px rgba(0,0,0,.3)); }
.login-hero-title {
  color: var(--white);
  font-size: 36px;
  font-weight: 800;
  text-align: center;
  line-height: 1.25;
  margin-bottom: 12px;
}
.login-hero-sub {
  color: rgba(255,255,255,.6);
  font-size: 16px;
  text-align: center;
  max-width: 380px;
}
.login-features {
  margin-top: 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 340px;
}
.login-feature {
  display: flex;
  align-items: center;
  gap: 14px;
  color: rgba(255,255,255,.75);
  font-size: 14px;
}
.login-feature-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--iec-orange-light);
}

.login-right {
  width: 480px;
  background: var(--white);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 60px 56px;
}
.login-card-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--gray-900);
  margin-bottom: 6px;
}
.login-card-sub { color: var(--gray-500); font-size: 14px; margin-bottom: 36px; }
.login-divider {
  height: 1px;
  background: var(--gray-100);
  margin: 28px 0;
}
.login-footer-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}
.login-lang { display: flex; gap: 8px; }
.login-lang-btn {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-400);
  background: none;
  border: 1.5px solid var(--gray-200);
  cursor: pointer;
  transition: all var(--transition);
}
.login-lang-btn.active,
.login-lang-btn:hover { border-color: var(--iec-orange); color: var(--iec-orange); }

/* ─── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--gray-100);
  padding: 3px;
  border-radius: var(--radius);
  margin-bottom: 24px;
}
.tab-btn {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  background: none;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}
.tab-btn.active { background: var(--white); color: var(--gray-900); box-shadow: var(--shadow-sm); }
.tab-btn:hover:not(.active) { color: var(--gray-700); }

/* ─── Shift Calendar ───────────────────────────────────────────────────────── */
.shift-grid { display: grid; grid-template-columns: 160px repeat(7, 1fr); gap: 1px; background: var(--gray-200); border-radius: var(--radius-lg); overflow: hidden; }
.shift-cell { background: var(--white); padding: 10px; min-height: 56px; }
.shift-header { background: var(--gray-50); font-size: 12px; font-weight: 700; color: var(--gray-500); text-transform: uppercase; padding: 10px 12px; }
.shift-label { background: var(--gray-50); font-size: 13px; font-weight: 600; color: var(--gray-700); }
.shift-slot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.shift-pill {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.shift-available { background: #ECFDF5; color: #059669; }
.shift-assigned { background: var(--iec-orange-pale); color: var(--iec-orange); }
.shift-off { background: var(--gray-100); color: var(--gray-400); }

/* ─── Rule Builder ─────────────────────────────────────────────────────────── */
.rule-type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.rule-type-card {
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--white);
}
.rule-type-card:hover { border-color: var(--iec-orange); }
.rule-type-card.selected { border-color: var(--iec-orange); background: var(--iec-orange-pale); }
.rule-type-icon { font-size: 24px; margin-bottom: 8px; }
.rule-type-name { font-size: 13px; font-weight: 700; color: var(--gray-700); }
.rule-type-desc { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-20px);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 18px; font-weight: 700; color: var(--gray-900); }
.modal-close { color: var(--gray-400); padding: 4px; border-radius: 4px; }
.modal-close:hover { background: var(--gray-100); color: var(--gray-700); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-100); display: flex; justify-content: flex-end; gap: 10px; }

/* ─── Modal Box (display:none/flex toggled via JS) ─────────────────────────── */
.modal-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

/* ─── Shared Popup Modal ──────────────────────────────────────────────────── */
.popup-modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px; max-width: 96vw; max-height: 90vh;
  overflow-y: auto;
}
.popup-modal-wide { width: 660px; }
.popup-modal-sm   { width: 420px; }
.popup-header {
  background: linear-gradient(135deg, var(--iec-navy-dark) 0%, var(--iec-navy) 100%);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.popup-header-title { color: var(--white); font-size: 16px; font-weight: 700; }
.popup-header-sub   { color: rgba(255,255,255,.6); font-size: 12px; margin-top: 3px; }
.popup-header-close {
  background: rgba(255,255,255,.15); border: none;
  color: rgba(255,255,255,.8); width: 30px; height: 30px;
  border-radius: 8px; cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.popup-header-close:hover { background: rgba(255,255,255,.28); color: var(--white); }
.popup-body    { padding: 24px; }
.popup-footer  { padding: 16px 24px; border-top: 1px solid var(--gray-100); display: flex; justify-content: flex-end; gap: 10px; }
.popup-section { margin-bottom: 20px; }
.popup-section:last-child { margin-bottom: 0; }
.popup-section-label { font-size: 11px; font-weight: 700; color: var(--gray-400); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.popup-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ─── Mobile hamburger ───────────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: 1.5px solid var(--gray-200); border-radius: 8px;
  background: var(--white); cursor: pointer; color: var(--gray-600);
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 149;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Layout */
  .mobile-menu-btn { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    position: fixed; z-index: 150; height: 100%;
    transition: transform .25s ease;
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .app-shell.nav-open .sidebar { transform: translateX(0) !important; }
  .app-shell.nav-open .sidebar-backdrop { display: block; }
  [dir="ltr"] .main-content, [dir="rtl"] .main-content { margin: 0; }

  /* Contain horizontal overflow at the layout level */
  .main-content { min-width: 0; overflow-x: hidden; max-width: 100vw; }
  .page-body    { min-width: 0; overflow-x: hidden; }

  /* Header */
  .top-header { gap: 8px; padding: 0 16px; }
  .header-title { font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-actions { gap: 6px; flex-shrink: 0; }
  .lang-switcher { gap: 4px; }

  /* Content */
  .page-body { padding: 12px; }

  /* Login — branded top banner on mobile */
  .login-page { flex-direction: column; }
  .login-left {
    flex: unset;
    padding: 36px 28px 28px;
    align-items: flex-start;
    min-height: unset;
  }
  .login-hero-logo { width: 90px; margin-bottom: 10px; }
  .login-hero-title { font-size: 22px; text-align: start; margin-bottom: 4px; }
  .login-hero-sub { font-size: 13px; text-align: start; max-width: 100%; }
  .login-features { display: none; }
  .login-right {
    width: 100%;
    flex: 1;
    border-radius: 20px 20px 0 0;
    margin-top: -20px;
    padding: 32px 24px 40px;
    box-shadow: 0 -8px 32px rgba(0,0,0,.15);
  }

  /* Grids */
  .form-row, .form-row-3, .popup-form-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }

  /* Tables: scroll within their container */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card-body  { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Only set min-width inside explicit scroll containers */
  .table-wrap table, .card-body table { min-width: 540px; }

  /* Cards: reduce padding */
  .card { border-radius: 10px; overflow: hidden; }
  .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }

  /* Modals: sheet from bottom */
  .popup-modal, .popup-modal-wide, .popup-modal-sm {
    width: 100%; max-width: 100%; border-radius: 20px 20px 0 0; max-height: 88vh;
  }
  .modal-overlay { align-items: flex-end; }

  /* Inventory category grid */
  .inv-category-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ─── Rule Engine 3-Panel ──────────────────────────────────────────────────── */
.rule-engine-grid {
  display: grid;
  grid-template-columns: 200px 1fr 300px;
  gap: 16px;
  min-height: 480px;
  align-items: start;
}
.rule-type-sidebar {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.rule-type-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; width: 100%; text-align: start;
  border-bottom: 1px solid var(--gray-100); cursor: pointer;
  transition: all var(--transition); background: var(--white);
  font-size: 13px; font-weight: 500; color: var(--gray-700);
}
.rule-type-btn:last-child { border-bottom: none; }
.rule-type-btn:hover { background: var(--gray-50); }
.rule-type-btn.active {
  background: var(--iec-orange-pale);
  color: var(--iec-orange);
  border-left: 3px solid var(--iec-orange);
}
[dir="rtl"] .rule-type-btn.active { border-left: none; border-right: 3px solid var(--iec-orange); }

/* ─── Optimizer Terminal ───────────────────────────────────────────────────── */
.optimizer-terminal {
  font-family: 'Courier New', 'Courier', monospace;
  background: #0d1117;
  color: #7ee787;
  padding: 16px;
  border-radius: 8px;
  height: 220px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
}
.optimizer-terminal .log-error { color: #f97316; }
.optimizer-terminal .log-warn { color: #fbbf24; }
.optimizer-terminal .log-success { color: #34d399; }
.optimizer-terminal .log-info { color: #60a5fa; }
.optimizer-terminal .log-dim { color: #8b949e; }

/* ─── Asset Card Grid ──────────────────────────────────────────────────────── */
.asset-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.asset-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: box-shadow var(--transition), border-color var(--transition);
  display: flex; flex-direction: column; gap: 12px;
}
.asset-card:hover { box-shadow: var(--shadow); border-color: var(--gray-300); }

/* Criticality bar segments */
.crit-bar { display: flex; gap: 3px; }
.crit-seg { height: 6px; flex: 1; border-radius: 2px; background: var(--gray-200); }
.crit-seg.lit-1 { background: #10B981; }
.crit-seg.lit-2 { background: #6EE7B7; }
.crit-seg.lit-3 { background: #F59E0B; }
.crit-seg.lit-4 { background: #F97316; }
.crit-seg.lit-5 { background: #EF4444; }

/* ─── KPI Card Trend ───────────────────────────────────────────────────────── */
.kpi-trend { display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; margin-top: 6px; }
.trend-up { color: #059669; }
.trend-down { color: #DC2626; }

/* ─── Responsive Rule Engine ───────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .rule-engine-grid, .re-grid { grid-template-columns: 1fr; }
  .re-right { flex-direction: row; flex-wrap: wrap; }
}

/* ─── Map Report — Full-Width Redesign ─────────────────────────────────────── */
.map-page-wrap { display: flex; flex-direction: column; gap: 0; }
.map-container-outer { position: relative; border-radius: 12px 12px 0 0; overflow: hidden; }
#asset-map { height: calc(100vh - 220px); min-height: 500px; width: 100%; border-radius: 12px 12px 0 0; }

.map-controls-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  background: white;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  min-width: 230px;
  font-size: 13px;
}
.map-controls-overlay label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  color: var(--gray-700);
  font-weight: 500;
}
.map-controls-overlay label:hover { color: var(--iec-orange); }
.map-controls-overlay .ctrl-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-400);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--gray-200);
}
.map-route-info {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--gray-200);
  display: none;
}
.map-route-info .dist-val { font-size: 20px; font-weight: 700; color: var(--iec-orange); }
.map-route-info .eta-val { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.map-bottom-panel {
  background: var(--white);
  border-radius: 0 0 12px 12px;
  border: 1px solid var(--gray-200);
  border-top: 3px solid var(--iec-orange);
}
.map-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 16px;
  background: var(--gray-50);
  border-radius: 0;
}
.map-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.map-tab:hover { color: var(--gray-800); }
.map-tab.active { color: var(--iec-orange); border-bottom-color: var(--iec-orange); background: none; }
.map-tab-content { display: none; padding: 0; }
.map-tab-content.active { display: block; }
.map-bottom-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.map-bottom-table thead th {
  padding: 10px 14px;
  text-align: start;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-400);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
.map-bottom-table tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
.map-bottom-table tbody tr:last-child td { border-bottom: none; }
.map-bottom-table tbody tr:hover { background: var(--gray-50); }
.map-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-active    { background: #dcfce7; color: #166534; }
.badge-maintenance { background: #fef3c7; color: #92400e; }
.badge-offline   { background: #f1f5f9; color: #475569; }
.badge-decommissioned { background: #fee2e2; color: #991b1b; }
.badge-en-route  { background: #dbeafe; color: #1d4ed8; }
.badge-loading   { background: #fef9c3; color: #854d0e; }
.badge-on-site   { background: #dcfce7; color: #166534; }
.badge-in-transit { background: #dbeafe; color: #1d4ed8; }
.badge-in-storage { background: #f1f5f9; color: #475569; }
.map-navigate-btn {
  background: none;
  border: 1px solid var(--iec-orange);
  color: var(--iec-orange);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.map-navigate-btn:hover { background: var(--iec-orange); color: #fff; }
.map-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 13px;
}
.map-pin-popup input, .map-pin-popup select {
  width: 100%;
  margin-bottom: 6px;
  padding: 5px 8px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
}
.map-pin-popup textarea {
  width: 100%;
  margin-bottom: 6px;
  padding: 5px 8px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 12px;
  resize: vertical;
  min-height: 48px;
}
.map-pin-popup button {
  background: var(--iec-orange);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.map-pin-popup button:hover { background: #c54d00; }
.depot-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--iec-navy);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}
.map-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--gray-500);
}
.map-legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 3px; }
.dot-active { background: #22c55e; }
.dot-maintenance { background: #f59e0b; }
.dot-offline { background: #94a3b8; }
.dot-decommissioned { background: #ef4444; }
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.map-filter-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
