/* ===== Design tokens (semantic). Light and dark are each tuned, not inverted. ===== */
/* Visual language: warm neutral canvas, very round white cards, charcoal active pill, one yellow accent, mint highlight. */
:root {
  color-scheme: light;
  --bg: #eeece7;
  --surface: #ffffff;
  --surface-2: #f6f4ef;
  --surface-hover: #f1eee7;
  --border: #e8e4da;
  --border-strong: #d8d3c6;
  --text: #17171a;
  --text-2: #5e5d63;
  --text-3: #92908f;
  --accent: #17171a;            /* charcoal: primary actions, active nav */
  --accent-fg: #f7c52b;         /* yellow on charcoal */
  --accent-soft: #f4efe0;
  --accent-contrast: #ffffff;
  --highlight: #f7c52b;
  --mint: #dce9de;
  --ok: #17734f;      --ok-soft: #e1f1e7;
  --warn: #9a5b00;    --warn-soft: #fbefcf;
  --bad: #bb3a2d;     --bad-soft: #fbe7e4;
  --muted-soft: #efece4;
  --chart-1: #17171a;
  --chart-2: #3f9b7a;
  --chart-grid: #ece8de;
  --shadow: 0 1px 2px rgba(40, 34, 20, .04), 0 8px 24px rgba(40, 34, 20, .04);
  --focus: 0 0 0 3px rgba(247, 197, 43, .55);
  --skeleton-a: #efece4;
  --skeleton-b: #f7f5f0;

  --radius: 24px;
  --radius-sm: 14px;
  --sidebar-w: 236px;
  --font: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1013;
  --surface: #181a1f;
  --surface-2: #1f2127;
  --surface-hover: #252831;
  --border: #272a32;
  --border-strong: #363a45;
  --text: #ecebe7;
  --text-2: #a3a29f;
  --text-3: #74747a;
  --accent: #f5c542;            /* yellow becomes the active surface in dark */
  --accent-fg: #17171a;
  --accent-soft: rgba(245, 197, 66, .12);
  --accent-contrast: #17171a;
  --highlight: #f5c542;
  --mint: #1d2b26;
  --ok: #54d6a0;      --ok-soft: rgba(84, 214, 160, .13);
  --warn: #f2b84b;    --warn-soft: rgba(242, 184, 75, .13);
  --bad: #ff8a80;     --bad-soft: rgba(255, 138, 128, .14);
  --muted-soft: rgba(163, 162, 159, .11);
  --chart-1: #f5c542;
  --chart-2: #5fd3b0;
  --chart-grid: #262932;
  --shadow: none;
  --focus: 0 0 0 3px rgba(245, 197, 66, .4);
  --skeleton-a: #1f2127;
  --skeleton-b: #272a32;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14px/1.6 var(--font); -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--focus); }
h1, h2, h3, p { margin: 0; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ===== Shell ===== */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px; background: var(--surface); border-inline-end: 1px solid var(--border); border-start-start-radius: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-fg);
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--text-3); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 99px;
  color: var(--text-2); text-decoration: none; font-weight: 500; position: relative;
}
.nav a:hover { background: var(--surface-hover); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sidebar-note { font-size: 12px; color: var(--text-3); padding: 0 10px; }

.main { padding: 28px 32px 48px; max-width: 1400px; width: 100%; margin-inline: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.page-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.head-actions { display: flex; align-items: center; gap: 8px; }

/* ===== Controls ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 18px; border-radius: 99px !important;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-weight: 500; color: var(--text);
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn.icon-only { width: 40px; padding: 0; justify-content: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn[disabled] { opacity: .55; cursor: default; }
.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }
.live-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; font-size: 12.5px;
  color: var(--text-2); border: 1px solid var(--border); border-radius: 99px; background: var(--surface);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

/* ===== Cards ===== */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.row-2 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); margin-bottom: 16px; }
.row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 650; }
.card-meta { font-size: 12px; color: var(--text-3); }

.kpi { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--text-2); font-weight: 500; }
.kpi-ico { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.kpi-ico.ok { background: var(--ok-soft); color: var(--ok); }
.kpi-ico.warn { background: var(--warn-soft); color: var(--warn); }
.kpi-ico.bad { background: var(--bad-soft); color: var(--bad); }
.kpi-value { direction: ltr; text-align: end; font-size: 40px; font-weight: 500; letter-spacing: -.03em; line-height: 1.05; }
.kpi.mint { background: var(--mint); border-color: transparent; }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--highlight); color: #17171a; vertical-align: middle; margin-inline-start: 8px; }
.kpi-value small { font-size: 15px; font-weight: 600; color: var(--text-3); margin-inline-start: 4px; }
.kpi-sub { font-size: 12.5px; color: var(--text-3); display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 6px; border-radius: 99px; background: var(--muted-soft); overflow: hidden; direction: ltr; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--chart-1); transition: width .4s ease; }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }
.spark { width: 100%; height: 28px; direction: ltr; display: block; }
.spark path { fill: none; stroke: var(--chart-1); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }

/* ===== Chart ===== */
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-wrap { position: relative; direction: ltr; }
.chart { width: 100%; height: 220px; display: block; }
.chart .grid-line { stroke: var(--chart-grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .axis-text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .l1 { stroke: var(--chart-1); } .chart .l2 { stroke: var(--chart-2); }
.chart .a1 { fill: var(--chart-1); opacity: .09; }
.chart .cursor { stroke: var(--border-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tip {
  position: absolute; top: 0; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.12); white-space: nowrap; z-index: 2;
}
.tip b { font-weight: 600; }
.chart-foot { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; color: var(--text-3); }

/* ===== Lists / pills ===== */
.list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list li:last-child { padding-bottom: 0; }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-sub { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--muted-soft); color: var(--text-2);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--text); }
.scroll { max-height: 330px; overflow: auto; margin-inline: -4px; padding-inline: 4px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: start; font-weight: 500; color: var(--text-3); font-size: 12px; padding: 0 0 8px; }
.table td { padding: 9px 0; border-top: 1px solid var(--border); }

/* ===== States ===== */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 28px 12px; color: var(--text-2); }
.state .state-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--muted-soft); color: var(--text-3); }
.state.ok .state-ico { background: var(--ok-soft); color: var(--ok); }
.state.bad .state-ico { background: var(--bad-soft); color: var(--bad); }
.state-title { font-weight: 600; color: var(--text); }
.state-text { font-size: 12.5px; max-width: 30ch; }
.skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--skeleton-a), var(--skeleton-b), var(--skeleton-a)); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-line { height: 12px; margin: 10px 0; }

/* ===== Login ===== */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 18px; padding: 28px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.input { height: 44px; padding: 0 16px; border: 1px solid var(--border-strong); border-radius: 99px; background: var(--surface-2); }
.input:focus { outline: none; border-color: var(--highlight); box-shadow: var(--focus); }
.form-error { color: var(--bad); font-size: 12.5px; min-height: 18px; }

/* ===== Responsive ===== */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-2 { grid-template-columns: minmax(0, 1fr); }
  .row-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 10; inset: auto 0 0 0; height: auto; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-inline-end: 0; border-top: 1px solid var(--border);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-between; gap: 2px; }
  .nav a { flex: 1; flex-direction: column; gap: 3px; padding: 7px 2px; font-size: 11px; min-width: 0; text-align: center; }
  .nav a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .nav a[aria-current="page"]::before { display: none; }
  .main { padding: 18px 16px 96px; }
  .page-title { font-size: 19px; }
  .live-chip .live-text { display: none; }
  .live-chip { padding: 0 11px; }
}
@media (max-width: 560px) {
  .kpis, .row-3 { grid-template-columns: minmax(0, 1fr); }
  .kpis { gap: 12px; }
  .kpi-value { font-size: 26px; }
  .chart { height: 180px; }
  .card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ===== Sun/Moon toggle pill (reference 1) ===== */
.theme-toggle { display: inline-flex; padding: 4px; gap: 2px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); }
.theme-toggle button { width: 32px; height: 32px; border-radius: 50%; border: 0; background: transparent; color: var(--text-3); display: grid; place-items: center; }
.theme-toggle button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.theme-toggle svg.icon { width: 17px; height: 17px; }
.tip { border-radius: 14px; }
.state .state-ico { border-radius: 50%; }
