:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #8a93a3;
  --line: #e3e6ec;
  --brand: #0f1f3a;
  --brand-2: #1d3461;
  --gold: #b8913a;
  --gold-soft: #f6efdf;
  --ok: #157a4a;
  --ok-soft: #e3f4ea;
  --warn: #a8630b;
  --warn-soft: #fbf0dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info: #1d4ed8;
  --info-soft: #e5edff;
  --wa: #d9fdd3;
  --wa-bg: #efeae2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #121b2e; --surface-2: #18233a; --ink: #e8ecf3; --ink-2: #b4bdcc; --ink-3: #7f8aa0;
    --line: #243049; --brand: #0a1628; --brand-2: #1d3461; --gold: #d4ae5c; --gold-soft: #2c2616;
    --ok: #4ade80; --ok-soft: #12301f; --warn: #fbbf24; --warn-soft: #33270c; --bad: #f87171; --bad-soft: #3a1513;
    --info: #93b4ff; --info-soft: #172548; --wa: #144d37; --wa-bg: #0d1418; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #121b2e; --surface-2: #18233a; --ink: #e8ecf3; --ink-2: #b4bdcc; --ink-3: #7f8aa0;
  --line: #243049; --brand: #0a1628; --brand-2: #1d3461; --gold: #d4ae5c; --gold-soft: #2c2616;
  --ok: #4ade80; --ok-soft: #12301f; --warn: #fbbf24; --warn-soft: #33270c; --bad: #f87171; --bad-soft: #3a1513;
  --info: #93b4ff; --info-soft: #172548; --wa: #144d37; --wa-bg: #0d1418; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.65;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--info); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); font-size: 13px; }

/* ---------- splash & auth ---------- */
.splash { min-height: 100vh; display: grid; place-items: center; background: var(--brand); }
.logo-mark { width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--gold); position: relative; }
.logo-mark::after { content: ""; position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--gold);
  top: -7px; left: 50%; transform: translateX(-50%); }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 80% -10%, #24447a 0%, var(--brand) 60%); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px; padding: 28px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.auth-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-card .brand .logo-mark { width: 40px; height: 40px; }
.qr { background: #fff; padding: 10px; border-radius: 12px; display: grid; place-items: center; margin: 12px 0; }
.qr svg { width: 200px; height: 200px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; direction: ltr; font-family: ui-monospace, monospace; }
.codes span { background: var(--surface-2); border-radius: 8px; padding: 6px; text-align: center; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--ink-2); margin: 12px 0 6px; }
input, select, textarea { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
textarea { min-height: 90px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 10px;
  padding: 11px 16px; font-weight: 600; cursor: pointer; background: var(--surface-2); color: var(--ink);
  min-height: 44px; transition: transform .05s ease, filter .15s ease; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand-2); color: #fff; }
.btn.gold { background: var(--gold); color: #1a1406; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.error { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 1em; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #dfe6f3; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.side .brand .logo-mark { width: 30px; height: 30px; border-width: 2px; }
.side .brand .logo-mark::after { width: 8px; height: 8px; top: -5px; }
.side a { color: #c9d3e6; padding: 10px 12px; border-radius: 10px; display: flex; align-items: center; gap: 10px; }
.side a.on { background: rgba(255, 255, 255, .1); color: #fff; }
.side a .badge { margin-inline-start: auto; }
.side .sep { height: 1px; background: rgba(255, 255, 255, .1); margin: 8px 4px; }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); padding: 12px 24px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; flex: 1; }
.content { padding: 20px 24px 40px; max-width: 1180px; }
.tabbar { display: none; }
.ico { width: 20px; height: 20px; flex: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar { padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .content { padding: 14px 16px calc(90px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; bottom: 0; inset-inline: 0; z-index: 10;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px;
    color: var(--ink-3); position: relative; }
  .tabbar a.on { color: var(--brand-2); }
  :root[data-theme="dark"] .tabbar a.on, .tabbar a.on { color: var(--gold); }
  .tabbar .badge { position: absolute; top: 4px; inset-inline-start: calc(50% + 6px); }
}

/* ---------- components ---------- */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); min-width: 0; }
.card.tap { cursor: pointer; transition: border-color .15s; } .card.tap:hover { border-color: var(--gold); }
.card h3 { margin-bottom: 6px; }
.section { margin-top: 22px; }
.section > .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 10px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.info { background: var(--info-soft); color: var(--info); }
.badge.gold { background: var(--gold-soft); color: var(--gold); } .badge.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.count { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px;
  cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.empty { text-align: center; color: var(--ink-3); padding: 28px 12px; }
.list > .item { padding: 12px 0; border-bottom: 1px solid var(--line); } .list > .item:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; }

/* status hero */
.hero { background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); color: #fff; border: 0; }
.hero .faint { color: #aab6cc; }
.hero .state { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74, 222, 128, .6);
  animation: pulse 2s infinite; }
.pulse.off { background: #f87171; animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }
.bigbtn { min-height: 52px; font-size: 16px; padding: 12px 22px; }

/* meters */
.meter { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.hero .meter { background: rgba(255, 255, 255, .15); }
.meter > i { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.meter > i.hot { background: var(--bad); }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .t { font-size: 13px; color: var(--ink-2); min-height: 2.6em; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; direction: ltr; }
.bars > i { flex: 1; background: var(--gold); border-radius: 3px 3px 0 0; min-height: 2px; }

/* figures & labels */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-3); font-weight: 600; font-size: 12px; }
.tablewrap { overflow-x: auto; }
.lbl-verified { background: var(--ok-soft); color: var(--ok); } .lbl-estimated { background: var(--warn-soft); color: var(--warn); }
.lbl-assumption { background: var(--surface-2); color: var(--ink-2); }

/* markdown */
.md { overflow-wrap: anywhere; } .md h1, .md h2, .md h3 { margin: 16px 0 6px; } .md p { margin: 8px 0; }
.md ul, .md ol { padding-inline-start: 22px; margin: 6px 0; } .md table { margin: 10px 0; display: block; overflow-x: auto; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md blockquote { margin: 8px 0; padding: 6px 12px; border-inline-start: 3px solid var(--gold); background: var(--gold-soft); border-radius: 6px; }

/* decision page */
.verdict { font-size: 18px; font-weight: 700; }
.actionbar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px;
  margin: 18px -16px -16px; border-radius: 0 0 var(--radius) var(--radius); }
@media (max-width: 860px) { .actionbar { bottom: calc(62px + env(safe-area-inset-bottom)); } }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--info-soft); color: var(--info); font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

/* whatsapp */
.wa { background: var(--wa-bg); border-radius: var(--radius); border: 1px solid var(--line); display: flex; flex-direction: column;
  height: calc(100vh - 170px); min-height: 420px; overflow: hidden; }
@media (max-width: 860px) { .wa { height: calc(100vh - 175px - env(safe-area-inset-bottom)); border-radius: 12px; } }
.wa-head { background: var(--brand-2); color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.wa-head .av { width: 36px; height: 36px; border-radius: 50%; background: var(--gold); display: grid; place-items: center; color: #1a1406; font-weight: 700; }
.wa-body { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 82%; padding: 7px 10px 5px; border-radius: 10px; background: var(--surface); box-shadow: 0 1px .5px rgba(0, 0, 0, .13);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; align-self: flex-start; }
.bubble.me { background: var(--wa); align-self: flex-end; }
.bubble .meta { font-size: 11px; color: var(--ink-3); text-align: end; margin-top: 2px; }
.bubble .from { font-size: 12px; font-weight: 600; color: var(--gold); margin-bottom: 2px; }
.bubble .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 8px -10px -5px; border-top: 1px solid var(--line); }
.bubble .btns button { background: transparent; border: 0; padding: 10px; color: var(--info); font-weight: 600; cursor: pointer; }
.bubble .btns button + button { border-inline-start: 1px solid var(--line); }
.wa-day { align-self: center; background: var(--surface); color: var(--ink-2); font-size: 12px; padding: 3px 10px; border-radius: 8px; }
.wa-input { display: flex; gap: 8px; padding: 8px; background: var(--surface-2); }
.wa-input textarea { min-height: 44px; max-height: 120px; border-radius: 22px; padding: 10px 16px; }
.wa-input .btn { border-radius: 50%; width: 46px; padding: 0; background: #00a884; color: #fff; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: end center; z-index: 50; }
@media (min-width: 861px) { .modal { place-items: center; } }
.modal .sheet { background: var(--surface); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 20px 18px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; }
@media (min-width: 861px) { .modal .sheet { border-radius: 18px; } }
#toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 10px; opacity: 0; transition: all .25s; z-index: 60; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.org { display: grid; gap: 10px; }
.org .lvl { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.org .node { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13px; text-align: center; min-width: 130px; }
.org .node.top { background: var(--brand-2); color: #fff; border: 0; }
.org .node .st { font-size: 11px; color: var(--ink-3); }
.org .node.top .st { color: #aab6cc; }

[hidden] { display: none !important; }
a.card, a.item { color: inherit; display: block; }
a.card.row { display: flex; }
[dir="rtl"] .wa-input .ico { transform: scaleX(-1); }
.org a.node { color: var(--ink); }
.org a.node.top { color: #fff; }
@media (max-width: 860px) { .org .node { min-width: 0; flex: 1 1 40%; } }

/* Touch targets: at least 44px on phones (Apple's Human Interface Guidelines). */
@media (pointer: coarse), (max-width: 860px) {
  .chip { min-height: 44px; display: inline-flex; align-items: center; padding: 8px 14px; }
  .btn.sm { min-height: 44px; padding: 8px 14px; }
  details > summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
  .bubble .btns button { min-height: 46px; }
}
.wa-input .btn { flex: none; height: 46px; }
details > summary { cursor: pointer; }
.kpi .unit { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.btn.on { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.topbar .back { flex: none; width: 44px; height: 44px; margin-inline-start: -10px; display: inline-flex; align-items: center;
  justify-content: center; border: 0; border-radius: 10px; background: transparent; color: var(--ink); cursor: pointer; }
.topbar .back[hidden] { display: none; }
.topbar .back:active { background: var(--surface-2); }
.bubble .tick { letter-spacing: -3px; margin-inline-start: 4px; }
.bubble .tick.read { color: #34b7f1; }
.bubble .tick.failed { color: var(--bad); letter-spacing: 0; }

/* assistant: chat and voice */
.as .bubble { white-space: normal; }
.as .bubble.me { white-space: pre-wrap; }
.as .bubble .md > :first-child { margin-top: 0; } .as .bubble .md > :last-child { margin-bottom: 0; }
.as .bubble.err { background: var(--bad-soft); color: var(--bad); }
.as .wa-head .av { flex: none; }
.as .hbtn { flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.as .hbtn:active { background: rgba(255, 255, 255, .15); }
.as .wa-input .btn.talk { background: var(--gold); color: #1a1406; }
.as-hello { margin: auto; text-align: center; max-width: 520px; padding: 12px; }
.as-hello .av.big { width: 56px; height: 56px; border-radius: 50%; background: var(--gold); color: #1a1406; display: grid;
  place-items: center; margin: 0 auto 8px; }
.as-hello .chip { cursor: pointer; font: inherit; color: var(--ink); }
.bubble.typing { color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.voice { position: fixed; inset: 0; z-index: 55; background: radial-gradient(900px 600px at 50% 30%, #24447a 0%, var(--brand) 65%);
  color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); text-align: center; }
.voice .chip { position: absolute; top: calc(16px + env(safe-area-inset-top)); cursor: pointer; font: inherit; }
.voice .orb { width: 168px; height: 168px; border-radius: 50%; border: 0; cursor: pointer; background: var(--gold); color: #1a1406;
  display: grid; place-items: center; box-shadow: 0 0 0 0 rgba(212, 174, 92, .5); transition: transform .2s, background .2s; }
.voice .orb .ico { width: 56px; height: 56px; }
.voice[data-phase="listening"] .orb { animation: listen 1.4s infinite; transform: scale(calc(1 + var(--lvl, 0) * .3)); transition: transform .08s; }
.voice[data-phase="thinking"] .orb { background: #93b4ff; animation: think 1.6s ease-in-out infinite; }
.voice[data-phase="speaking"] .orb { background: #4ade80; animation: talk .8s ease-in-out infinite alternate; }
.voice[data-phase="idle"] .orb { background: rgba(255, 255, 255, .2); color: #fff; }
@keyframes listen { 70% { box-shadow: 0 0 0 28px rgba(212, 174, 92, 0); } 100% { box-shadow: 0 0 0 0 rgba(212, 174, 92, 0); } }
@keyframes think { 50% { transform: scale(.92); } }
@keyframes talk { to { transform: scale(1.07); } }
.voice-state { font-size: 18px; font-weight: 600; max-width: 520px; min-height: 1.6em; }
.voice-said { max-width: 560px; max-height: 30vh; overflow-y: auto; color: #c9d3e6; font-size: 15px; white-space: pre-wrap; }
.voice .btn.ghost { color: #fff; border-color: rgba(255, 255, 255, .35); min-height: 48px; }
@media (prefers-reduced-motion: reduce) { .voice .orb, .dots i { animation: none !important; } }
.as .bubble .say { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; min-height: 32px;
  margin-top: 4px; border: 1px solid var(--line); border-radius: 999px; background: transparent; cursor: pointer; font-size: 14px; }
.as .bubble .say.on { background: var(--gold-soft); border-color: var(--gold); }
