:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #eef2ff; --text: #0f172a; --muted: #5b6475;
  --border: #dfe4ee; --brand: #1d4ed8; --brand-2: #7c3aed; --brand-ink: #ffffff;
  --ok: #047857; --warn: #b45309; --bad: #b91c1c;
  --radius: 14px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 6px 20px rgba(15,23,42,.06);
  --grad: linear-gradient(135deg, #0b1530 0%, #1d4ed8 55%, #7c3aed 100%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #121a2e; --surface-2: #1a2440; --text: #e6eaf5; --muted: #9aa5bd;
    --border: #26304a; --brand: #6d8cff; --brand-2: #a78bfa; --ok: #34d399; --warn: #fbbf24; --bad: #f87171;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
button, input, textarea, select { font: inherit; color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; } h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }

/* Layout: sidebar on PC, bottom bar on phones */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--grad); color: #fff; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; scrollbar-width: thin; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; }
.brand img { width: 38px; height: 38px; border-radius: 10px; background: #fff; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: #e8ecff; text-decoration: none; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.16); color: #fff; }
.nav .badge { margin-left: auto; background: #fff; color: #1d4ed8; border-radius: 999px; padding: 0 8px; font-size: .75rem; font-weight: 700; }
.side .foot { margin-top: auto; font-size: .8rem; opacity: .9; padding: 8px; }
main { padding: 24px clamp(16px, 3vw, 40px) 96px; max-width: 1100px; width: 100%; min-width: 0; }
.bottom { display: none; }
.topbar { display: none; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 700; }
.topbar img { width: 32px; height: 32px; border-radius: 8px; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .bottom { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
  .bottom a { text-align: center; padding: 8px 2px; font-size: .72rem; color: var(--muted); text-decoration: none; }
  .bottom a .i { display: block; font-size: 1.25rem; }
  .bottom a.active { color: var(--brand); font-weight: 600; }
  .bottom .badge { display: none; }
  .topbar { display: flex; }
  table th:nth-child(3), table td:nth-child(3) { display: none; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.stack > * + * { margin-top: 14px; }
.kpi .n { font-size: 1.8rem; font-weight: 700; } .kpi .l { color: var(--muted); font-size: .9rem; }
.banner { border-radius: var(--radius); padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border); }
.banner.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 10px; padding: 10px 16px;
  background: var(--brand); color: var(--brand-ink); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.err { color: var(--bad); } .ok { color: var(--ok); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.pill { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--grad); }
.auth .card { width: min(440px, 100%); }
.auth .logo { width: 120px; display: block; margin: 0 auto 10px; border-radius: 18px; background: #fff; }

/* Assistant */
.chat { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; }
.msgs { flex: 1; overflow-y: auto; padding: 8px 2px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.composer { display: flex; gap: 8px; padding-top: 10px; }
.composer textarea { resize: none; height: 48px; }
.ad-slot { margin: 14px 0; min-height: 60px; text-align: center; }
.ad-label { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.install { display: none; }
.install.show { display: inline-flex; }

/* Copy / read-aloud tools under each AI reply */
.msgtools { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.mini { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 8px; padding: 2px 9px; cursor: pointer; font-size: .8rem; }
.mic.on { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.composer .paste { padding: 10px 12px; }

/* Floating assistant on every page */
#fab { position: fixed; right: 18px; bottom: 18px; z-index: 20; }
[dir="rtl"] #fab { right: auto; left: 18px; }
.fabbtn { border-radius: 999px; box-shadow: 0 8px 24px rgba(29,78,216,.35); padding: 12px 18px; }
.fabpanel { width: min(400px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px)); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 12px 40px rgba(15,23,42,.25); display: flex; flex-direction: column; padding: 12px; }
.fabpanel .msgs { flex: 1; }
.fabpanel .msg { max-width: 92%; font-size: .92rem; }
.fabpanel .composer textarea { height: 44px; }
.fabpanel .composer .btn { padding: 8px 10px; }
@media (max-width: 820px) { #fab { bottom: calc(70px + env(safe-area-inset-bottom)); right: 10px; } [dir="rtl"] #fab { left: 10px; } }
@media print { #fab { display: none; } }

/* All systems */
.modcard { text-decoration: none; color: inherit; transition: transform .12s; }
.modcard:hover { transform: translateY(-2px); border-color: var(--brand); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a { padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: .9rem; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; overflow-wrap: anywhere; }
.trk { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; text-decoration: none; color: inherit; }
.trk .pill { margin-inline-start: auto; }
.bar { display: grid; grid-template-columns: minmax(140px, 40%) 1fr 40px; gap: 10px; align-items: center; padding: 4px 0; font-size: .88rem; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar .track span { display: block; height: 100%; background: var(--grad); }
.pill.st-approved, .pill.st-delivered, .pill.st-done, .pill.st-paid, .pill.st-completed, .pill.st-won, .pill.st-active, .pill.st-cleared { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); }
.pill.st-rejected, .pill.st-failed, .pill.st-exception, .pill.st-lost, .pill.st-cancelled { background: color-mix(in srgb, var(--bad) 16%, var(--surface)); }
.pill.st-draft, .pill.st-requested, .pill.st-unpaid, .pill.st-submitted { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); }
@media (max-width: 820px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } .bar { grid-template-columns: 1fr 60px 34px; } }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.toolbar .topbar { margin-bottom: 0; }
.toolbar select { width: auto; max-width: 11rem; }
.bell { position: relative; text-decoration: none; font-size: 1.25rem; line-height: 1; }
.bell .badge { position: absolute; top: -6px; right: -10px; }

/* Systems side menu, breadcrumbs and the Ctrl+K search box */
.navsys { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,.18); }
.navsys .navh { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; opacity: .75; margin: 10px 12px 2px; }
.navsys details summary { cursor: pointer; padding: 7px 12px; border-radius: 10px; color: #e8ecff; font-weight: 600; font-size: .9rem; list-style: none; }
.navsys details summary::-webkit-details-marker { display: none; }
.navsys details summary::before { content: "▸"; display: inline-block; width: 1em; transition: transform .15s; }
.navsys details[open] summary::before { transform: rotate(90deg); }
.navsys details summary:hover { background: rgba(255,255,255,.12); }
.navsys a { padding: 6px 12px 6px 22px; font-size: .9rem; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted, #64748b); }
.crumbs .sep { opacity: .6; }
.crumbs span:last-child { color: inherit; font-weight: 600; }
.srch { display: inline-flex; align-items: center; gap: 6px; }
.srch kbd { font: inherit; font-size: .72rem; border: 1px solid var(--border, #cbd5e1); border-radius: 6px; padding: 0 5px; opacity: .8; }
@media (max-width: 720px) { .srch .srchl, .srch kbd { display: none; } }
.palette { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1000; display: flex; justify-content: center; align-items: flex-start; padding: 10vh 12px 12px; }
.palette .pal { width: min(640px, 100%); max-height: 75vh; display: flex; flex-direction: column; gap: 6px; }
.palette .palr { overflow-y: auto; }
.palette .palh { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted, #64748b); margin: 8px 4px 2px; }
.palette .palitem { display: grid; grid-template-columns: 1.6em minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; color: inherit; text-decoration: none; }
.palette .palitem.on, .palette .palitem:hover { background: rgba(37,99,235,.12); }
@media (max-width: 720px) { .toolbar { gap: 6px; } .toolbar select { max-width: 7.5rem; } .toolbar .topbar { min-width: 0; } }
