:root {
  --bg: #F4F0EB;
  --card: #FFFFFF;
  --card-2: #FAF7F3;
  --line: #ECE5DD;
  --text: #1D1A19;
  --muted: #6E6865;
  --faint: #A39C97;
  --brand: #7E1E2B;          /* button maroon from the existing app */
  --brand-ink: #FFFFFF;
  --brand-soft: #F6E9EA;
  --logo-maroon: #971F21;
  --orange: #EE6924;
  --crit: #9F1D24;  --crit-bg: #FBE7E7;
  --high: #D9581C;  --high-bg: #FDEDE3;
  --med:  #B68900;  --med-bg:  #FBF3D9;
  --low:  #3C8A3C;  --low-bg:  #E6F2E5;
  --info-bg: #EEF0F3;
  --shadow: 0 1px 2px rgba(40, 20, 10, .05), 0 4px 16px rgba(40, 20, 10, .04);
  --radius: 18px;
  --logo-bg: transparent;
  --logo-pad: 0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151312; --card: #1F1C1B; --card-2: #262221; --line: #34302E;
    --text: #F2EEEA; --muted: #ABA4A0; --faint: #7A736F;
    --brand: #B8384A; --brand-soft: #3A2226;
    --crit: #F07A7F; --crit-bg: #3D1F21; --high: #F59A62; --high-bg: #3B2618;
    --med: #E3BE4A; --med-bg: #35301A; --low: #7CC27C; --low-bg: #1F3220; --info-bg: #2A2A2D;
    --shadow: none; --logo-bg: #FFFFFF; --logo-pad: 5px 9px; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151312; --card: #1F1C1B; --card-2: #262221; --line: #34302E;
  --text: #F2EEEA; --muted: #ABA4A0; --faint: #7A736F;
  --brand: #B8384A; --brand-soft: #3A2226;
  --crit: #F07A7F; --crit-bg: #3D1F21; --high: #F59A62; --high-bg: #3B2618;
  --med: #E3BE4A; --med-bg: #35301A; --low: #7CC27C; --low-bg: #1F3220; --info-bg: #2A2A2D;
  --shadow: none; --logo-bg: #FFFFFF; --logo-pad: 5px 9px; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.shell { max-width: 620px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: var(--bg);
  display: flex; flex-direction: column; }
@media (min-width: 700px) {
  body { padding: 24px 0; }
  .shell { border-radius: 28px; overflow: hidden; box-shadow: 0 6px 40px rgba(0,0,0,.08); min-height: calc(100vh - 48px);
    border: 1px solid var(--line); }
}
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.logo { height: 40px; display: block; background: var(--logo-bg); padding: var(--logo-pad); border-radius: 10px; box-sizing: content-box; }
.logo-dark { display: none; }
.brandtext { display: flex; flex-direction: column; line-height: 1.1; }
.brandtext b { color: var(--logo-maroon); font-size: 19px; letter-spacing: -.2px; }
.brandtext span { font-size: 10px; letter-spacing: 2.6px; color: var(--muted); }
.iconbtn { width: 42px; height: 42px; border: 0; background: transparent; border-radius: 12px; display: grid; place-items: center; cursor: pointer; }
.iconbtn:hover { background: var(--card-2); }
.iconbtn svg { width: 24px; height: 24px; }
main { flex: 1; padding: 20px 16px 110px; }
@media (min-width: 420px) { main { padding-left: 20px; padding-right: 20px; } }

.eyebrow { color: var(--brand); font-size: 12px; font-weight: 700; letter-spacing: .9px; text-transform: uppercase; margin: 0 0 4px; }
h1 { font-size: 26px; line-height: 1.15; margin: 0 0 4px; letter-spacing: -.4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 26px 0 10px; font-weight: 700; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.4px; margin-top: 2px; white-space: nowrap; }
.kpi .v small { font-size: 12px; font-weight: 600; color: var(--muted); margin-right: 3px; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { grid-column: 1 / -1; background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.kpi.hero .l, .kpi.hero .s, .kpi.hero .v small { color: rgba(255,255,255,.82); }
.kpi.hero .v { font-size: 30px; }
.up { color: var(--low); } .down { color: var(--crit); }
.kpi.hero .up, .kpi.hero .down { color: #fff; font-weight: 700; }

/* ---------- chips / tags ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; margin: 0 0 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); padding: 7px 13px; border-radius: 999px;
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.tag.Critical { background: var(--crit-bg); color: var(--crit); }
.tag.High { background: var(--high-bg); color: var(--high); }
.tag.Medium { background: var(--med-bg); color: var(--med); }
.tag.Low { background: var(--low-bg); color: var(--low); }
.tag.grey { background: var(--info-bg); color: var(--muted); }
.tag.brand { background: var(--brand-soft); color: var(--brand); }

/* ---------- lists ---------- */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--line); width: 100%;
  background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; cursor: pointer; }
.row:first-child { border-top: 0; }
a.row:hover, button.row:hover { background: var(--card-2); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .m { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r { text-align: right; flex: none; }
.row .r .a { font-weight: 700; }
.row .r .m { margin-top: 2px; }
.row.static { cursor: default; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--brand); font-weight: 700; font-size: 12.5px; cursor: pointer; text-decoration: underline; }
.more { display: block; width: 100%; padding: 13px; border: 0; border-top: 1px solid var(--line); background: var(--card-2);
  color: var(--brand); font-weight: 700; cursor: pointer; }

/* ---------- bars ---------- */
.stack { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--info-bg); gap: 2px; }
.stack span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: 0; }
.bar-row { display: grid; grid-template-columns: 92px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 13.5px; }
.bar-row .track { height: 10px; background: var(--info-bg); border-radius: 999px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--brand); border-radius: 999px; min-width: 2px; }
.bar-row .fill.past { background: var(--high); }
.bar-row .val { font-weight: 600; min-width: 64px; text-align: right; }
.bar-row .lbl { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 8px; background: var(--info-bg); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.meter span { display: block; height: 100%; background: var(--low); }

/* ---------- alert card ---------- */
.alert { display: flex; align-items: center; gap: 14px; background: var(--brand-soft); border: 1px solid transparent;
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; cursor: pointer; }
.alert .ic { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.alert .ic svg { width: 22px; height: 22px; }
.alert b { display: block; color: var(--brand); }
.alert span { font-size: 13px; color: var(--muted); }
.alert .go { margin-left: auto; color: var(--brand); }

/* ---------- forms & buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px;
  padding: 14px 18px; font-weight: 700; cursor: pointer; background: var(--brand); color: var(--brand-ink); font-size: 15.5px; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn.danger { background: var(--crit-bg); color: var(--crit); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input { width: 100%; border: 1px solid var(--line); background: var(--card-2); border-radius: 12px; padding: 12px 13px; outline: none; }
.input:focus { border-color: var(--brand); background: var(--card); }
textarea.input { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.err { background: var(--crit-bg); color: var(--crit); padding: 10px 12px; border-radius: 12px; font-size: 13.5px; margin-bottom: 12px; }
.ok { background: var(--low-bg); color: var(--low); padding: 10px 12px; border-radius: 12px; font-size: 13.5px; margin-bottom: 12px; }
.warn { background: var(--med-bg); color: var(--med); padding: 10px 12px; border-radius: 12px; font-size: 13.5px; margin-bottom: 12px; }
.note { font-size: 12.5px; color: var(--muted); }
.drop { border: 2px dashed var(--line); border-radius: 16px; padding: 28px 16px; text-align: center; cursor: pointer; background: var(--card-2); }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop b { display: block; margin-bottom: 4px; }
.picker-results { border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; max-height: 230px; overflow: auto; }
.picker-results button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-top: 1px solid var(--line); background: var(--card); cursor: pointer; }
.picker-results button:first-child { border-top: 0; }
.picker-results button:hover { background: var(--card-2); }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 14px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: none; padding: 9px 8px; border-radius: 10px; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; color: var(--muted); }
.seg button.on { background: var(--text); color: var(--bg); }
.seg .n { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 11px; margin-left: 4px; }
.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.monthnav b { font-size: 17px; }
.searchbox { position: relative; margin-bottom: 12px; }
.searchbox svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); }
.searchbox .input { padding-left: 40px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-weight: 600; }

/* ---------- cheque card ---------- */
.cheque { padding: 14px 16px; border-top: 1px solid var(--line); }
.cheque:first-child { border-top: 0; }
.cheque .top { display: flex; justify-content: space-between; gap: 12px; }
.cheque .amt { font-size: 18px; font-weight: 700; white-space: nowrap; }
.cheque .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.cheque .btns { margin-top: 10px; }

/* ---------- nav ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; pointer-events: none; }
.tabbar nav { pointer-events: auto; width: 100%; max-width: 620px; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .tabbar { bottom: 24px; } .tabbar nav { border-radius: 0 0 28px 28px; border: 1px solid var(--line); } }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; font-weight: 600; color: var(--muted); border-radius: 12px; position: relative; }
.tabbar a.on { color: var(--brand); }
.tabbar svg { width: 23px; height: 23px; }
.badge { position: absolute; top: 1px; left: 50%; margin-left: 5px; background: var(--orange); color: #fff; font-size: 10.5px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }

.drawer-bg, .sheet-bg { position: fixed; inset: 0; background: rgba(20, 10, 5, .38); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer-bg.open, .sheet-bg.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 86vw); background: var(--card); z-index: 41; transform: translateX(100%); transition: transform .22s; padding: calc(20px + env(safe-area-inset-top)) 16px 20px; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer .who { padding: 4px 8px 16px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.drawer .who b { display: block; font-size: 17px; }
.drawer a, .drawer button.link { display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: 12px; font-weight: 600; border: 0; background: none; width: 100%; text-align: left; cursor: pointer; }
.drawer a:hover, .drawer button.link:hover { background: var(--card-2); }
.drawer svg { width: 20px; height: 20px; color: var(--muted); }

.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 42; background: var(--card); border-radius: 24px 24px 0 0; max-height: 92vh; overflow: auto;
  transform: translateY(100%); transition: transform .24s; padding: 8px 18px calc(22px + env(safe-area-inset-bottom)); max-width: 620px; margin: 0 auto; }
.sheet.open { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { font-size: 20px; margin: 0 0 14px; }
@media (min-width: 700px) {
  .sheet { top: 50%; bottom: auto; left: 50%; right: auto; width: 520px; border-radius: 22px; transform: translate(-50%, -45%); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; pointer-events: auto; }
  .sheet .grab { display: none; }
}
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 60; opacity: 0; transition: .2s; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 400px; padding: 28px 22px; }
.login .logo { height: 54px; margin: 0 auto 18px; }
.login h1 { text-align: center; font-size: 24px; }
.login .sub { text-align: center; }
.demo-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.demo-box .btns .btn { flex: 1; }

.spin { display: grid; place-items: center; padding: 60px 0; color: var(--muted); }
.spin::before { content: ""; width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: r .8s linear infinite; }
@keyframes r { to { transform: rotate(360deg); } }
.demo-ribbon { background: var(--med-bg); color: var(--med); text-align: center; font-size: 12px; font-weight: 700; padding: 6px 12px; }
svg.chart { width: 100%; height: auto; display: block; }
.mt { margin-top: 14px; } .mb0 { margin-bottom: 0; }
.right { text-align: right; }
.hide { display: none !important; }
