:root {
  --navy: #0D2B4E;
  --navy-dark: #091E38;
  --primary: #1D4ED8;
  --primary-hover: #1E40AF;
  --amber: #D97706;
  --green: #15803D;
  --red: #DC2626;
  --bg: #F1F5F9;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow-x: clip;
  max-width: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12.5px; }

/* ── Lucide Icons ── */
svg.lucide, .lu {
  width: 17px;
  height: 17px;
  stroke-width: 2;
  vertical-align: middle;
  flex-shrink: 0;
}
.lu-sm { width: 14px !important; height: 14px !important; }
.nav-item .ico, .nav-item svg.lucide { width: 18px; height: 18px; }
.icon-heading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.kpi-label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.meta-strip span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Login ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #091E38 0%, #153E75 60%, #1D4ED8 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: white;
  border-radius: 18px;
  padding: 34px 30px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.25);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand img { width: 68px; height: 68px; object-fit: contain; margin-bottom: 10px; }
.login-brand h1 { margin: 0 0 6px; font-size: 22px; color: var(--navy); }
.login-brand h1 span { color: var(--primary); }
.login-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.login-footer { text-align: center; margin-top: 18px; }
.login-footer a { color: var(--primary); text-decoration: none; font-weight: 500; }

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

.sidebar {
  width: 265px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-brand img {
  width: 44px;
  height: 44px;
  background: white;
  border-radius: 12px;
  padding: 4px;
  object-fit: contain;
}
.sidebar-brand strong { display: block; font-size: 16px; }
.sidebar-brand small { color: #93C5FD; font-size: 11.5px; }

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: #CBD5E1;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: right;
  transition: all 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: white; }
.nav-item.active { background: var(--primary); color: white; font-weight: 600; }
.nav-item .ico { font-size: 16px; }
.nav-badge {
  margin-right: auto;
  background: #EF4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.admin-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.07);
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 10px;
}
.admin-pill .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.admin-pill strong { display: block; font-size: 13px; }
.admin-pill small { color: #93C5FD; font-size: 11px; }
.sidebar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ── Workspace ── */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 16px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 19px; color: var(--navy); }
.topbar p { margin: 2px 0 0; }
.topbar-actions { display: flex; gap: 10px; }

.content-area { padding: 22px 26px; flex: 1; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: white;
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-right: 4px solid var(--primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.kpi-card.green { border-right-color: var(--green); }
.kpi-card.amber { border-right-color: var(--amber); }
.kpi-card.red { border-right-color: var(--red); }
.kpi-card.navy { border-right-color: var(--navy); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 700; margin: 6px 0 4px; color: var(--text); }
.kpi-sub { font-size: 11.5px; color: var(--muted); }

/* ── Cards & Grids ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.03);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
  flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 15.5px; color: var(--navy); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.topbar-title-wrap { display: flex; align-items: center; gap: 12px; }
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
  color: var(--navy);
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 900;
}

@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .sidebar { width: 225px; }
}

@media (max-width: 820px) {
  .mobile-menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 270px;
    max-width: 82vw;
    height: 100vh;
    z-index: 950;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.25);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 14px 16px; }
  .topbar h2 { font-size: 16.5px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; padding: 8px 10px; font-size: 12.5px; }
  .content-area { padding: 14px; }
  .card { padding: 14px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .filters { flex-direction: column; width: 100%; }
  .filters input, .filters select { max-width: 100%; width: 100%; }
  .toolbar .btn { width: 100%; }
  .modal-card { padding: 16px; }
  .modal-actions { flex-direction: column; }
  .modal-actions .btn { width: 100%; }
}

@media (max-width: 440px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ── Charts ── */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 175px;
  padding: 12px 4px 0;
  border-bottom: 1px solid var(--border);
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  min-width: 20px;
}
.bar-num { font-size: 11px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.bar-fill {
  width: 100%;
  max-width: 30px;
  background: linear-gradient(180deg, #3B82F6, #1D4ED8);
  border-radius: 6px 6px 0 0;
  min-height: 4px;
  transition: height 0.25s;
}
.bar-lbl { font-size: 10px; color: var(--muted); margin-top: 6px; white-space: nowrap; }

.breakdown-list { display: flex; flex-direction: column; gap: 12px; }
.breakdown-row { display: flex; flex-direction: column; gap: 5px; }
.breakdown-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.breakdown-track { height: 10px; background: #E2E8F0; border-radius: 999px; overflow: hidden; }
.breakdown-bar { height: 100%; background: var(--primary); border-radius: 999px; }

/* ── Forms & Inputs ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-stack { display: flex; flex-direction: column; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: #334155; }
input[type="text"], input[type="password"], input[type="url"], input[type="date"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13.5px;
  background: #FFFFFF;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}
.input-copy { display: flex; gap: 8px; }
.input-copy input { flex: 1; }
.radio-group { display: flex; gap: 12px; flex-wrap: wrap; }
.radio-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #CBD5E1;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  background: #F8FAFC;
}
.checkbox-row label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: 0.15s;
}
.btn-block { width: 100%; padding: 12px; font-size: 14px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-amber { background: var(--amber); color: white; }
.btn-amber:hover { background: #B45309; }
.btn-green { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #B91C1C; }
.btn-outline { background: white; border-color: #CBD5E1; color: var(--text); }
.btn-outline:hover { background: #F8FAFC; }
.btn-ghost { background: rgba(255, 255, 255, 0.12); color: white; }
.btn-link { background: none; border: 0; color: var(--primary); font-family: inherit; font-weight: 600; cursor: pointer; }

/* ── Tables & Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filters { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; }
.filters input { max-width: 300px; }
.filters select { max-width: 185px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #F8FAFC; color: #475569; font-weight: 700; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: #F8FAFC; }
.mono { font-family: Consolas, monospace; direction: ltr; display: inline-block; font-size: 12px; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-green { background: #DCFCE7; color: #166534; }
.badge-amber { background: #FEF3C7; color: #92400E; }
.badge-red { background: #FEE2E2; color: #991B1B; }
.badge-blue { background: #DBEAFE; color: #1E40AF; }
.badge-gray { background: #E2E8F0; color: #334155; }

/* ── Progress Bar ── */
.progress-bar { height: 10px; background: #E2E8F0; border-radius: 999px; overflow: hidden; margin-bottom: 4px; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.2s; }

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.55); }
.modal-card {
  position: relative;
  z-index: 2;
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 580px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.modal-card.modal-lg { max-width: 760px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; color: var(--navy); }
.modal-close {
  border: 0;
  background: #F1F5F9;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: #F8FAFC;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 12px;
}
.text-box {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
  line-height: 1.6;
}
.code-box {
  background: #0F172A;
  color: #E2E8F0;
  padding: 12px;
  border-radius: 8px;
  direction: ltr;
  text-align: left;
  font-size: 12px;
  overflow-x: auto;
  margin: 0;
}
.log-box { max-height: 200px; overflow-y: auto; }
.report-img { max-width: 100%; max-height: 320px; border-radius: 8px; border: 1px solid var(--border); }

.alert-error {
  background: #FEE2E2;
  color: #991B1B;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 22px;
  background: #0F172A;
  color: white;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: 2000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
