:root {
  --bg: #f5f0e6;
  --surface: #ffffff;
  --surface-2: #faf5e8;
  --fg: #1a2238;
  --fg-dim: #58605b;
  --muted: #8a877f;
  --border: #e4ddc9;
  --border-strong: #c4bca3;
  --accent: #ff9900;
  --accent-soft: #fff2d4;
  --accent-ink: #c47000;
  --nav-bg: #1a2238;
  --nav-fg: #e8e2d0;
  --nav-fg-dim: #8a8e9e;
  --nav-active-bg: #2a3350;
  --nav-active-ink: #ff9900;
  --good: #2b8f5a;
  --good-soft: #e4f3ea;
  --warn: #d88a1a;
  --warn-soft: #fdf3df;
  --bad: #c2443d;
  --bad-soft: #fbe9e7;
  --hot: #a855e8;
  --hot-soft: #f3e8fb;
  --info: #3b7fb8;
  --info-soft: #e4f0f8;
  --shadow: 0 1px 2px rgba(26,34,56,.04), 0 2px 8px rgba(26,34,56,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131c; --surface: #1a2032; --surface-2: #141827;
    --fg: #e8e6df; --fg-dim: #a8aab2; --muted: #6a6d78;
    --border: #2a3043; --border-strong: #3f485d;
    --accent: #ffa733; --accent-soft: #3a2d0e; --accent-ink: #ffa733;
    --nav-bg: #0a0e18; --nav-fg: #d4d2cb; --nav-fg-dim: #6c7284;
    --nav-active-bg: #182039; --nav-active-ink: #ffa733;
    --good: #4ab877; --good-soft: #16301f;
    --warn: #e6a24f; --warn-soft: #3d2d10;
    --bad: #e06560; --bad-soft: #3d1a18;
    --hot: #c278e8; --hot-soft: #2d1a3d;
    --info: #5fa0d0; --info-soft: #15283a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font-family: 'Rubik', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 15px; direction: rtl; text-align: right;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.sidebar {
  background: var(--nav-bg); color: var(--nav-fg);
  padding: 24px 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: env(safe-area-inset-top, 0px);
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 4px 10px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 14px;
  color: var(--nav-fg);
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  color: #1a2238; font-weight: 800; font-size: 17px;
}
.brand-text { font-weight: 700; font-size: 15px; letter-spacing: 0.02em; }
.brand-text small { display: block; color: var(--nav-fg-dim); font-weight: 400; font-size: 10.5px; letter-spacing: 0.1em; margin-top: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 13px; border-radius: 8px;
  color: var(--nav-fg); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background 0.1s;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: var(--nav-active-bg); color: var(--nav-active-ink); font-weight: 600; }
.nav-item.muted { color: var(--nav-fg-dim); cursor: not-allowed; }
.nav-item.muted:hover { background: transparent; }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-sep { height: 1px; background: rgba(255,255,255,.06); margin: 14px 10px; }
.nav-footer { margin-top: auto; padding-top: 14px; }
.user-chip {
  display: flex; align-items: center; gap: 11px;
  padding: 11px; border-radius: 8px; background: rgba(255,255,255,.04);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
  color: #1a2238; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-chip .name { font-size: 13.5px; font-weight: 500; }
.user-chip .role { color: var(--nav-fg-dim); font-size: 11.5px; }

.main {
  padding: 0 24px 40px 24px;
  min-width: 0;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 0 16px; gap: 16px;
  position: sticky; top: env(safe-area-inset-top, 0px);
  background: var(--bg); z-index: 5;
}
.topbar h1 { font-size: 24px; font-weight: 700; }
.topbar .crumb { color: var(--muted); font-size: 13px; margin-bottom: 2px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
  padding: 10px 16px; border-radius: 9px;
  font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 7px;
  transition: all 0.1s;
}
.btn:hover { border-color: var(--border-strong); }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #1a2238; font-weight: 600;
}
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-dim); }
.btn.ghost:hover { background: var(--surface); color: var(--fg); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 7px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 13px; padding: 20px;
  box-shadow: var(--shadow);
}
.card .title {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card .title h3 { font-size: 16px; font-weight: 600; }

.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 5px;
}
.kpi .label { color: var(--muted); font-size: 12px; letter-spacing: 0.03em; text-transform: uppercase; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .delta { font-size: 12px; font-weight: 500; }
.kpi .delta.up { color: var(--good); }
.kpi .delta.down { color: var(--bad); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad  { background: var(--bad-soft);  color: var(--bad);  }
.pill.hot  { background: var(--hot-soft);  color: var(--hot);  }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.neutral { background: var(--surface-2); color: var(--fg-dim); border: 1px solid var(--border); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
.data th {
  text-align: right; padding: 13px 14px;
  background: var(--surface-2); color: var(--fg-dim);
  font-size: 12px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.data td { padding: 14px; border-bottom: 1px solid var(--border); }
.data tr:last-child td { border-bottom: none; }
.data tr.link-row { cursor: pointer; }
.data tr.link-row:hover td { background: var(--surface-2); }
.data td.mono { font-family: 'SFMono-Regular', 'Menlo', monospace; font-size: 13px; }
.data td.right { text-align: left; }

.progress {
  position: relative; width: 100%; max-width: 200px;
  height: 11px; background: var(--surface-2); border-radius: 999px; overflow: hidden;
  border: 1px solid var(--border);
}
.progress .fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s; }
.progress .fill.good { background: var(--good); }
.progress .fill.warn { background: var(--warn); }
.progress .fill.bad  { background: var(--bad);  }
.progress .fill.hot  { background: var(--hot);  }
.progress-label { font-size: 13px; font-weight: 500; margin-bottom: 5px; display: flex; justify-content: space-between; }

.bal.positive { color: var(--good); font-weight: 500; }
.bal.negative { color: var(--bad); font-weight: 500; }
.bal.zero { color: var(--muted); }
.bench { font-size: 12.5px; color: var(--fg-dim); }
.bench strong { color: var(--fg); }

.menu-btn {
  display: none;
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); color: var(--fg);
  align-items: center; justify-content: center; cursor: pointer;
}
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }
.scrim.visible { display: block; }

.icon { stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.empty-state {
  background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: 13px; padding: 50px 30px; text-align: center;
}
.empty-state h3 { margin-bottom: 8px; font-size: 17px; }
.empty-state p { color: var(--fg-dim); margin-bottom: 20px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 0; width: 270px;
    height: 100vh; transform: translateX(100%); transition: transform 0.25s;
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .main { padding: 0 16px 32px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
