:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --grid: #e8e7e3;
  --accent: #2a78d6;
  --pos: #008300;
  --neg: #d03b3a;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --grid: #2a2a27;
    --accent: #3987e5; --pos: #3fb950; --neg: #f07070;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --grid: #2a2a27;
  --accent: #3987e5; --pos: #3fb950; --neg: #f07070;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, "Noto Sans Arabic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
button, select, input { font: inherit; color: inherit; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 22l5-6 4 3 7-9' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.login-card button { padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.error { color: var(--neg); margin: 0; }
.loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.tabs button:hover { background: var(--surface-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); outline: 1px solid var(--border); }
.controls { display: flex; align-items: center; gap: 8px; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 10px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
select, input[type="search"] { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 10px; }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-2); cursor: pointer; }
.icon-btn:hover { color: var(--text); }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { margin: 16px 24px 0; padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, var(--s4) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--s4) 40%, transparent); }

main { padding: 20px 24px 8px; max-width: 1400px; margin: 0 auto; }
.tab-panel { display: grid; gap: 16px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* Cards */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card > header { margin-bottom: 12px; }
.card > header p { margin: 2px 0 0; font-size: 12.5px; }
.card > header.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chart { position: relative; height: 260px; }
.chart.tall { height: 340px; }

/* Allocation bars */
.alloc { display: grid; gap: 12px; }
.alloc-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: baseline; }
.alloc-row .name { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.alloc-row .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.alloc-row .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.alloc-row .bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.alloc-row .bar span { display: block; height: 100%; border-radius: 4px; }
.alloc-row .pct { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }

/* Tables */
.table-wrap { max-height: 420px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 500; font-size: 12.5px; cursor: pointer; user-select: none; }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; }
tr:hover td { background: var(--surface-2); }
tfoot td { font-weight: 600; border-bottom: 0; }
[dir="auto"] { unicode-bidi: plaintext; }

.foot { text-align: center; padding: 16px 24px 28px; font-size: 12.5px; }

@media (max-width: 960px) {
  .g-2, .g-2-1, .g-1-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .tabs { order: 3; flex-basis: 100%; }
  .controls { margin-left: auto; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  main { padding: 16px 16px 8px; }
  .banner { margin: 12px 16px 0; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 20px; }
  .chart, .chart.tall { height: 240px; }
}
