:root {
  --bg: #f5f6fd; --side: #f1f2fb; --surface: #ffffff; --surface-2: #eef0fa; --line: #e3e5f1;
  --text: #14142b; --muted: #7b7f95;
  --brand: #4b3fa0; --brand-ink: #ffffff; --brand-soft: #e9e6fb;
  --coral: #ff7a59; --teal: #14c8a8; --blue: #1e90ff; --amber: #f5a623;
  --ok: #0f9d7a; --ok-soft: #dcf7ef; --low: #c26a00; --low-soft: #fff0d6; --out: #e5172f; --out-soft: #ffe3e6;
  --g-purple: linear-gradient(135deg, #e7b5f3 0%, #cfc4fb 45%, #cdd6ff 100%);
  --g-sun: linear-gradient(135deg, #fdf3a4 0%, #fcd9c4 55%, #f9c7dc 100%);
  --g-green: radial-gradient(circle at 88% 8%, #9cf58a 0 22%, transparent 23%), radial-gradient(circle at 70% 55%, #c2f8b6 0 46%, transparent 47%), linear-gradient(135deg, #d9fbd0, #c8f7c0);
  --g-help: linear-gradient(160deg, #efd9f6 0%, #cfc8fa 60%, #b9b4f4 100%);
  --hero-ink: #14142b;
  --radius: 18px; --shadow: 0 1px 2px rgba(20,20,43,.04), 0 10px 30px rgba(75,63,160,.07);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1020; --side: #13142a; --surface: #1a1b33; --surface-2: #24264a; --line: #2c2e52;
  --text: #f1f1fb; --muted: #9a9dbb;
  --brand: #9d92f5; --brand-ink: #0f1020; --brand-soft: #2a2756;
  --ok: #3ddbb6; --ok-soft: #123a33; --low: #ffb84d; --low-soft: #3d2c0e; --out: #ff6b7d; --out-soft: #45161d;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 800; } h2 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); } .small { font-size: .78rem; }
.error { color: var(--out); font-size: .9rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); min-height: 44px; }
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
label { display: grid; gap: 6px; font-size: .85rem; font-weight: 600; }
label input, label textarea, label select { font-weight: 400; }
.logo-mark { border-radius: 10px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 18px; min-height: 44px; font-weight: 700; font-size: .88rem; cursor: pointer; white-space: nowrap; transition: background .15s, transform .1s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 16px rgba(75,63,160,.25); }
.btn.primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn.danger { color: var(--out); }
.btn.small { min-height: 34px; padding: 6px 14px; font-size: .8rem; border-radius: 10px; }
.btn.link { border: 0; background: none; color: var(--muted); min-height: 32px; padding: 4px 6px; font-weight: 600; box-shadow: none; }
.btn.link:hover { color: var(--brand); }
.btn[disabled] { opacity: .55; cursor: progress; }

/* ---- auth ---- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 15% 10%, #ecd3f7 0, transparent 40%), radial-gradient(circle at 90% 90%, #d2f6cb 0, transparent 38%), var(--bg); }
.auth-card { width: 100%; max-width: 390px; display: grid; gap: 14px; background: var(--surface); padding: 32px 28px; border-radius: 24px; box-shadow: var(--shadow); }
[data-theme="dark"] .auth { background: var(--bg); }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); padding: 26px 18px 20px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100dvh; }
.logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.logo div { display: grid; min-width: 0; }
.logo strong { font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; }
.logo span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-title { font-weight: 700; font-size: .92rem; padding: 0 8px 8px; }
.tabs { display: grid; gap: 2px; }
.tabs button { position: relative; border: 0; background: none; padding: 11px 10px; border-radius: 12px; display: flex; align-items: center; gap: 12px; color: var(--muted); font-weight: 500; font-size: .95rem; cursor: pointer; text-align: left; min-height: 44px; }
.tabs button > span { flex: 1; }
.tabs svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--brand); background: var(--surface); font-weight: 700; box-shadow: var(--shadow); }
.chev { width: 7px; height: 7px; border-right: 2px solid currentColor; border-top: 2px solid currentColor; transform: rotate(45deg); opacity: .7; }
.badge { background: var(--out); color: #fff; border-radius: 999px; font-size: .68rem; font-style: normal; min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; font-weight: 700; }
.side-card { margin-top: auto; background: var(--g-help); color: #14142b; border-radius: 20px; padding: 34px 16px 16px; text-align: center; display: grid; gap: 6px; position: relative; }
.side-card .dot { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); width: 44px; height: 44px; border-radius: 50%; background: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(20,20,43,.12); }
.side-card .dot i { width: 22px; height: 22px; border-radius: 50%; background: var(--teal); display: block; }
.side-card .dot.off i { background: var(--coral); }
.side-card b { font-size: .98rem; }
.side-card p { font-size: .76rem; color: #4a4a68; }
.side-card .btn { background: #fff; border: 0; color: #14142b; margin-top: 8px; min-height: 38px; font-size: .78rem; }

.main { min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 26px 34px 6px; }
.search { position: relative; display: block; width: min(340px, 100%); }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.search input { padding-left: 44px; border: 0; background: var(--surface); box-shadow: var(--shadow); min-height: 48px; border-radius: 6px; }
.top-right { display: flex; align-items: center; gap: 18px; min-width: 0; }
.sync { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me { display: flex; align-items: center; gap: 10px; border: 0; background: none; font-weight: 700; cursor: pointer; padding: 0; white-space: nowrap; }
.avatar { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #ff9d6c, #e0522f); color: #fff; display: grid; place-items: center; font-weight: 800; text-transform: uppercase; }
.banner { margin: 12px 34px 0; background: var(--low-soft); color: var(--low); padding: 10px 16px; font-size: .88rem; font-weight: 600; border-radius: 12px; }
.view { padding: 22px 34px 48px; display: grid; gap: 22px; max-width: 1240px; }
.stack { display: grid; gap: 16px; align-content: start; }

/* ---- hero gradient cards ---- */
.hero { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.hcard { border: 0; text-align: left; cursor: pointer; border-radius: 6px; padding: 18px 20px; min-height: 172px; display: flex; flex-direction: column; justify-content: space-between; color: var(--hero-ink); box-shadow: 0 14px 30px rgba(120,100,200,.14); transition: transform .15s; }
.hcard:hover { transform: translateY(-2px); }
.hcard.purple { background: var(--g-purple); } .hcard.sun { background: var(--g-sun); } .hcard.green { background: var(--g-green); }
.hcard .cap { display: flex; justify-content: space-between; gap: 10px; font-size: .8rem; font-weight: 700; }
.hcard .cap u { font-weight: 500; opacity: .75; text-underline-offset: 3px; }
.hcard .big { font-size: 2.3rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hcard .big small { font-size: .85rem; font-weight: 700; letter-spacing: 0; margin-left: 6px; }
.hcard .mid { display: flex; align-items: center; gap: 14px; }
.hcard .orb { width: 50px; height: 50px; border-radius: 50%; background: #ffa9e0; display: grid; place-items: center; flex: none; }
.hcard .orb svg { width: 22px; height: 22px; fill: #ff3d6e; }
.hcard .pct { font-size: 1.15rem; font-weight: 800; color: #e5172f; }
.hcard .sub { font-size: .8rem; font-weight: 600; }
.hcard .name { font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.hcard .pair { display: flex; gap: 28px; }
.hcard .pair div { display: grid; }
.hcard .pair span { font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; opacity: .7; }
.hcard .pair b { font-size: .98rem; }

/* ---- stat row with mini bars ---- */
.statrow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; padding: 22px 0; border-top: 2px solid var(--line); border-bottom: 2px solid var(--line); }
.stat3 { display: flex; justify-content: space-between; align-items: end; gap: 12px; }
.stat3 .lab { font-size: .8rem; font-weight: 700; }
.stat3 .num { display: flex; align-items: center; gap: 10px; margin: 2px 0; }
.stat3 .num b { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat3 .delta { font-size: .72rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.stat3.coral .num b { color: var(--out); } .stat3.coral .delta { background: var(--ok-soft); color: var(--ok); }
.stat3.indigo .num b { color: var(--brand); } .stat3.indigo .delta { background: var(--brand-soft); color: var(--brand); }
.stat3.teal .num b { color: var(--teal); } .stat3.teal .delta { background: var(--ok-soft); color: var(--ok); }
.bars { display: flex; align-items: end; gap: 5px; height: 70px; }
.bars i { width: 16px; border-radius: 4px; background: var(--surface-2); min-height: 8px; display: block; }
:root:not([data-theme="dark"]) .bars i { background: #e4e9f5; }
.stat3.coral .bars i.hi { background: var(--coral); box-shadow: 0 14px 18px -4px rgba(255,122,89,.45); }
.stat3.indigo .bars i.hi { background: var(--brand); box-shadow: 0 14px 18px -4px rgba(75,63,160,.4); }
.stat3.teal .bars i.hi { background: var(--teal); box-shadow: 0 14px 18px -4px rgba(20,200,168,.45); }

/* ---- panels + rows ---- */
.cols { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); gap: 26px; align-items: start; }
.cols.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.panel { background: var(--surface); border-radius: var(--radius); padding: 22px; display: grid; gap: 14px; box-shadow: var(--shadow); min-width: 0; }
.panel.bare { background: none; box-shadow: none; padding: 20px 0 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.panel-head select { width: auto; min-height: 36px; padding: 6px 12px; font-size: .82rem; border-radius: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips button { border: 0; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 7px 14px; font-size: .8rem; font-weight: 700; cursor: pointer; white-space: nowrap; min-height: 34px; }
.chips button.on { background: var(--brand); color: var(--brand-ink); }
.rows { display: grid; }
.group-label { font-size: .78rem; color: var(--muted); padding: 10px 0 4px; }
.item, .line { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 9px 6px; border-radius: 12px; }
.item { cursor: pointer; }
.item:hover { background: var(--surface-2); }
.line { grid-template-columns: minmax(0, 1fr) auto; padding: 11px 0; border-radius: 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.ico { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); color: var(--text); display: grid; place-items: center; flex: none; font-weight: 800; font-size: .9rem; }
.ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.solid { color: #fff; }
.ico.c-out { background: #e9345a; } .ico.c-now { background: var(--amber); } .ico.c-soon { background: var(--blue); } .ico.c-brand { background: var(--brand); }
.main-col, .item .main, .line .main { min-width: 0; display: grid; gap: 1px; }
.name, .line .main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line .main b { white-space: normal; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty, .right { text-align: right; display: grid; gap: 2px; justify-items: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.qty b { font-size: 1.02rem; font-weight: 700; }
.item.low .qty b { color: var(--low); } .item.out .qty b { color: var(--out); }
.amt { font-weight: 800; font-variant-numeric: tabular-nums; }
.amt.red { color: var(--out); }
.pill { font-size: .66rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.low { background: var(--low-soft); color: var(--low); } .pill.out { background: var(--out-soft); color: var(--out); } .pill.ok { background: var(--ok-soft); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.up { color: var(--ok); font-weight: 800; } .down { color: var(--out); font-weight: 800; }

.tag { font-size: .62rem; background: var(--brand-soft); color: var(--brand); padding: 3px 8px; border-radius: 6px; vertical-align: middle; letter-spacing: .06em; }
.panel.ai { background: var(--g-purple); color: #14142b; }
.panel.ai .muted { color: #4a4a68; }
.panel.ai .btn { background: #fff; border: 0; color: #14142b; }
.panel.ai .tag { background: #fff; color: #4b3fa0; }
.briefing { margin: 0; white-space: pre-wrap; font: inherit; line-height: 1.6; }
.formula summary { cursor: pointer; font-weight: 700; }
.formula p { font-size: .88rem; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > input { flex: 1; min-width: 160px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .92rem; }
.switch input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }

/* ---- priority cards ---- */
.prio { background: var(--surface); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.prio-head { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.rank { width: 40px; height: 40px; border-radius: 10px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; }
.prio.now .rank { background: var(--amber); } .prio.out .rank { background: #e9345a; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 9px 12px; display: grid; }
.stat span { font-size: .68rem; color: var(--muted); font-weight: 700; }
.stat b { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---- scanner ---- */
.scanner { position: relative; aspect-ratio: 4 / 3; max-height: 46vh; width: 100%; background: #14142b; border-radius: 14px; overflow: hidden; display: grid; place-items: center; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.reticle { position: absolute; inset: 22% 12%; border: 2px solid rgba(255,255,255,.85); border-radius: 14px; pointer-events: none; }
.scan-msg { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; color: #fff; font-size: .85rem; text-shadow: 0 1px 3px #000; }

/* ---- sheet ---- */
.sheet { border: 0; border-radius: 24px; padding: 0; width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(20,20,43,.3); }
.sheet::backdrop { background: rgba(20,20,43,.45); backdrop-filter: blur(3px); }
.sheet-body { padding: 24px; display: grid; gap: 16px; }
.sheet-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.sheet-head h2 { font-size: 1.25rem; overflow-wrap: anywhere; }
.x { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1rem; flex: none; }
.inset { background: var(--surface-2); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.bigqty { display: grid; grid-template-columns: 56px 1fr 56px; gap: 10px; align-items: center; }
.bigqty button { height: 56px; border-radius: 14px; border: 0; background: var(--surface); font-size: 1.6rem; font-weight: 700; cursor: pointer; box-shadow: var(--shadow); }
.bigqty input { text-align: center; font-size: 1.8rem; font-weight: 800; height: 56px; font-variant-numeric: tabular-nums; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--coral); }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-weight: 700; font-size: .88rem; z-index: 50; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 12px 30px rgba(20,20,43,.25); }
.toast.bad { background: var(--out); color: #fff; }
@media (prefers-reduced-motion: no-preference) { .toast { animation: rise .2s ease-out; } @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } } }

.token-box summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.token-box { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.token-box code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.token-form { display: grid; grid-template-columns: 1fr 1.6fr 1fr auto; gap: 12px; align-items: end; margin-top: 10px; }
@media (max-width: 1080px) { .token-form { grid-template-columns: 1fr; } }

.batch { background: var(--surface-2); border-radius: 16px; padding: 14px; display: grid; gap: 10px; }
.batch-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.batch-total { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.batch .line { border-color: var(--line); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--surface); font-weight: 800; font-size: 1.1rem; cursor: pointer; }
.stepper b { min-width: 34px; text-align: center; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.flash { animation: flash .5s ease-out; }
@keyframes flash { from { background: var(--ok-soft); } }

.scanner-only { display: none; }
body.role-scanner .scanner-only { display: grid; }
body.role-scanner .admin-only, body.role-scanner .tabs button:not([data-tab="scan"]), body.role-scanner .side-card, body.role-scanner .search, body.role-scanner .nav-title { display: none; }
body.role-scanner .top { justify-content: flex-end; }
.batch input.n { width: 64px; min-height: 36px; padding: 4px 6px; text-align: center; font-weight: 800; font-size: 1.05rem; }
.users-role { width: auto; min-height: 34px; padding: 4px 10px; font-size: .8rem; border-radius: 10px; }

/* ---- sales dashboard ---- */
.sales-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.crumbs button { border: 0; background: none; padding: 4px 0; font-weight: 600; color: var(--muted); cursor: pointer; font-size: 1.05rem; }
.crumbs button.here { color: var(--text); font-weight: 800; font-size: 1.25rem; letter-spacing: -.02em; cursor: default; }
.crumbs i { width: 7px; height: 7px; border-right: 2px solid var(--muted); border-top: 2px solid var(--muted); transform: rotate(45deg); }
.seg { display: inline-flex; background: var(--surface); border-radius: 12px; padding: 4px; box-shadow: var(--shadow); }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font-weight: 700; font-size: .8rem; color: var(--muted); cursor: pointer; min-height: 34px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.hcard .sub .delta, .delta.pos, .delta.neg { font-weight: 800; margin-right: 6px; }
.delta.pos { color: #0a7d5f; } .delta.neg { color: #d0142a; }
div.hcard { cursor: default; } div.hcard:hover { transform: none; }
.chart { display: flex; align-items: stretch; gap: 10px; height: 230px; padding-top: 6px; }
.chart.dense { gap: 4px; }
.chart .col { flex: 1; min-width: 0; border: 0; background: none; padding: 0; display: grid; grid-template-rows: auto 1fr auto; gap: 6px; cursor: pointer; align-items: end; justify-items: center; }
.chart .col i { width: min(100%, 46px); border-radius: 8px; background: #e4e9f5; display: block; align-self: end; transition: background .15s; }
.chart .col:hover i, .chart .col.sel i { background: var(--brand); box-shadow: 0 14px 18px -4px rgba(75,63,160,.4); }
.chart .col.dim { opacity: .45; }
.chart .v { font-size: .68rem; font-weight: 700; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart .d { font-size: .68rem; color: var(--muted); white-space: nowrap; text-transform: capitalize; }
[data-theme="dark"] .chart .col i { background: var(--surface-2); }
.meter { display: block; height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 4px 0 2px; }
.meter i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }

/* ---- AI findings ---- */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.fact { background: var(--surface-2); border-radius: 14px; padding: 14px 16px; display: grid; gap: 4px; border-left: 4px solid var(--brand); }
.fact.bueno { border-left-color: var(--teal); } .fact.alerta { border-left-color: var(--coral); }
.fact p { font-size: .88rem; color: var(--muted); }
.amt.up { color: var(--ok); }
div.col { cursor: default; }

/* ---- floating AI chat ---- */
.fab { position: fixed; right: 22px; bottom: 22px; z-index: 20; width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer; background: linear-gradient(135deg, #7c5cf0, #4b3fa0); box-shadow: 0 12px 28px rgba(75,63,160,.45); display: grid; place-items: center; transition: transform .15s; }
.fab:hover { transform: scale(1.06); }
.fab svg { width: 28px; height: 28px; fill: #fff; }
.chat { position: fixed; right: 22px; bottom: 22px; z-index: 21; width: min(400px, calc(100vw - 24px)); height: min(600px, calc(100dvh - 44px)); background: var(--surface); border-radius: 22px; box-shadow: 0 24px 70px rgba(20,20,43,.32); display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.chat header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; background: var(--g-purple); color: #14142b; }
.chat header div:first-child { display: grid; }
.chat header .muted { color: #4a4a68; }
.chat header .btn { background: #fff; border: 0; color: #14142b; }
.chat header .x { background: rgba(255,255,255,.7); color: #14142b; }
.chat-log { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: grid; gap: 3px; max-width: 88%; }
.msg.user { align-self: flex-end; justify-items: end; }
.bubble { padding: 10px 14px; border-radius: 16px; background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .92rem; line-height: 1.5; }
.msg.user .bubble { background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 5px; }
.msg.assistant .bubble { border-bottom-left-radius: 5px; }
.bubble.typing { color: var(--muted); font-style: italic; }
.chat-empty { margin: auto 0; display: grid; gap: 8px; text-align: center; justify-items: center; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: .82rem; font-weight: 600; cursor: pointer; color: var(--text); }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chat form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); align-items: end; }
.chat textarea { resize: none; max-height: 120px; min-height: 44px; }
body.role-scanner .fab, body.role-scanner .chat { display: none; }

.chat-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; margin-top: 8px; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--brand); background: var(--surface); color: var(--brand); font-weight: 700; font-size: .84rem; cursor: pointer; text-align: left; white-space: normal; }
.chat-link::after { content: '→'; }
.chat-link:hover { background: var(--brand); color: var(--brand-ink); }

/* ---- tablet ---- */
@media (max-width: 1080px) {
  .hero, .statrow { gap: 16px; }
  .cols, .cols.even { grid-template-columns: minmax(0, 1fr); }
  .panel.bare { padding-top: 0; }
}
/* ---- phone: sidebar becomes a bottom tab bar ---- */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: auto 0 0 0; height: auto; z-index: 6; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); background: var(--surface); }
  .logo, .nav-title, .side-card, .chev { display: none; }
  .tabs { display: flex; justify-content: space-around; gap: 0; }
  .tabs button { flex: 1; flex-direction: column; gap: 2px; font-size: .66rem; padding: 6px 2px; box-shadow: none !important; background: none !important; }
  .tabs button > span { flex: none; }
  .tabs .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
  .top { padding: calc(14px + env(safe-area-inset-top)) 16px 4px; }
  .sync, #hello { display: none; }
  .banner { margin: 10px 16px 0; }
  .view { padding: 16px 16px calc(100px + env(safe-area-inset-bottom)); gap: 18px; }
  .hero { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .hcard { min-height: 140px; border-radius: 14px; }
  .statrow { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 18px 0; }
  .grid3 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 18px 16px; }
  .chart { height: 180px; gap: 4px; }
  .chart .v { visibility: hidden; height: 0; overflow: hidden; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
  .fab { right: 14px; bottom: calc(84px + env(safe-area-inset-bottom)); width: 52px; height: 52px; }
  .chat { right: 0; bottom: 0; width: 100vw; height: min(86dvh, 720px); border-radius: 22px 22px 0 0; }
  .tabs button { font-size: .6rem; }
}
