:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --line: #e7eaf3;
  --line-2: #d9deea;
  --text: #0f1729;
  --muted: #667085;
  --faint: #98a2b3;
  --navy: #0f1b3d;
  --navy-2: #172650;
  --primary: #2f6bff;
  --primary-2: #1f55e0;
  --primary-soft: #eaf0ff;
  --green: #12a150;
  --green-soft: #e7f7ee;
  --red: #e5484d;
  --red-soft: #fdecec;
  --amber: #e08a00;
  --amber-soft: #fff4e0;
  --milk: #2f6bff;
  --ice: #12b5cb;
  --gas: #f26b1d;
  --other: #8b5cf6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
  --shadow-lg: 0 24px 60px rgba(15, 27, 61, .22);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.num, .kpi-val, td.r, .money { font-variant-numeric: tabular-nums; }
.ic { flex: none; display: block; }
.muted { color: var(--muted); }
.r { text-align: right; }
.red { color: var(--red); }
.green { color: var(--green); }
.hidden { display: none !important; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(47, 107, 255, .28); }
.btn.primary:hover { background: var(--primary-2); }
.btn.ghost { background: var(--surface); border-color: var(--line-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.danger:hover { background: #fbd9da; }
.btn.green { background: var(--green); color: #fff; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 10px;
  border: 0; background: transparent; cursor: pointer; color: inherit;
}
.icon-btn:hover { background: rgba(127, 127, 127, .12); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  height: 42px; width: 100%; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 11px;
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 70px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(47, 107, 255, .12); }
.input.sm { height: 34px; border-radius: 9px; padding: 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
}
.login-art {
  position: relative; overflow: hidden; color: #fff; padding: 48px;
  background: radial-gradient(1200px 600px at -10% -10%, #2f6bff 0%, transparent 55%),
              radial-gradient(800px 500px at 110% 110%, #12b5cb 0%, transparent 50%),
              linear-gradient(160deg, #0f1b3d, #0a1430);
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-art .brand { color: #fff; padding: 0; }
.login-art h2 { font-size: 40px; line-height: 1.1; letter-spacing: -.03em; margin: 0 0 14px; max-width: 460px; position: relative; z-index: 1; }
@media (max-height: 720px) { .login-float { display: none; } }
.login-art p { color: rgba(255, 255, 255, .72); max-width: 420px; font-size: 15px; margin: 0; }
.login-chips { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 28px; }
.login-chips span {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .16); font-weight: 500; font-size: 13px;
  backdrop-filter: blur(6px);
}
.login-float {
  position: absolute; right: -40px; top: 90px; width: 280px; padding: 20px; border-radius: 20px;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .16); backdrop-filter: blur(12px);
  transform: rotate(-6deg);
}
.login-float small { color: rgba(255, 255, 255, .6); }
.login-float b { display: block; font-size: 26px; margin: 2px 0 14px; letter-spacing: -.02em; }
.login-bars { display: flex; align-items: flex-end; gap: 8px; height: 70px; }
.login-bars i { flex: 1; border-radius: 6px 6px 3px 3px; background: linear-gradient(#7fa6ff, #2f6bff); }
.login-form-wrap { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.login-form { width: 100%; max-width: 380px; }
.login-form h1 { font-size: 28px; letter-spacing: -.02em; margin: 0 0 6px; }
.login-form .sub { color: var(--muted); margin: 0 0 28px; }
.input-ic { position: relative; }
.input-ic .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.input-ic .input { padding-left: 40px; }
.login-err { background: var(--red-soft); color: var(--red); padding: 10px 12px; border-radius: 10px; font-weight: 500; font-size: 13px; }
.hint { background: var(--primary-soft); color: var(--primary-2); padding: 10px 12px; border-radius: 10px; font-size: 13px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.side {
  background: var(--navy); color: #cdd5ea; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; color: #fff; }
.brand b { display: block; font-size: 15.5px; letter-spacing: -.01em; line-height: 1.2; }
.brand small { color: rgba(255, 255, 255, .55); font-size: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none;
  background: linear-gradient(135deg, #4f86ff, #2f6bff 55%, #1d4fd6); box-shadow: 0 8px 20px rgba(47, 107, 255, .4);
}
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side nav .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: rgba(255, 255, 255, .35); padding: 14px 12px 6px; font-weight: 600; }
.side nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px; font-weight: 500;
  color: #b9c3dd; transition: background .15s, color .15s;
}
.side nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side nav a.on { background: rgba(47, 107, 255, .18); color: #fff; box-shadow: inset 3px 0 0 var(--primary); }
.side nav a.on .ic { color: #7fa6ff; }
.side-foot { display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .08); }
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.me b { display: block; color: #fff; font-size: 13.5px; }
.me small { color: rgba(255, 255, 255, .5); font-size: 12px; }
.av {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, #12b5cb, #2f6bff); color: #fff; flex: none; text-transform: uppercase;
}
.main { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 18px 28px; background: rgba(244, 246, 251, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
}
.top h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { margin-left: auto; display: flex; gap: 10px; }
.menu-btn { display: none; }
.view { padding: 8px 28px 40px; }
.scrim { display: none; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card-h h3 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.card-h .muted { font-size: 12.5px; }
.card-b { padding: 16px 18px 18px; }
.grid-dash { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; }
.c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c7 { grid-column: span 7; } .c8 { grid-column: span 8; } .c6 { grid-column: span 6; } .c12 { grid-column: span 12; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 18px; }
.kpi { padding: 18px; position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 500; font-size: 13px; }
.kpi-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
.kpi-val { font-size: 27px; font-weight: 800; letter-spacing: -.03em; margin: 12px 0 4px; }
.kpi-foot { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi.hero { background: linear-gradient(140deg, #1d4fd6, #2f6bff 60%, #4f86ff); color: #fff; border: 0; box-shadow: 0 14px 30px rgba(47, 107, 255, .3); }
.kpi.hero .kpi-top, .kpi.hero .kpi-foot { color: rgba(255, 255, 255, .8); }
.kpi.hero .kpi-ic { background: rgba(255, 255, 255, .18); color: #fff; }
.kpi.hero::after { content: ""; position: absolute; right: -30px; top: -30px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.tone-blue { background: var(--primary-soft); color: var(--primary); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.tone-cyan { background: #e3f8fb; color: var(--ice); }
.tone-orange { background: #fff0e6; color: var(--gas); }
.tone-violet { background: #f1ebff; color: var(--other); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.pill.up { background: var(--green-soft); color: var(--green); }
.pill.down { background: var(--red-soft); color: var(--red); }
.kpi.hero .pill { background: rgba(255, 255, 255, .2); color: #fff; }

.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid line { stroke: var(--line); }
.chart .axis text { fill: var(--faint); font-size: 11px; }
.chart .ba { fill: var(--primary); }
.chart .bb { fill: #9fe0c0; }
.chart .bar:hover { opacity: .8; }

.donut-wrap { display: flex; align-items: center; gap: 20px; }
.donut { position: relative; width: 150px; height: 150px; flex: none; }
.donut svg { transform: rotate(-90deg); }
.donut .ctr { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut .ctr b { display: block; font-size: 18px; letter-spacing: -.02em; }
.donut .ctr small { color: var(--muted); font-size: 11.5px; }
.cat-list { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cat-row { display: flex; align-items: center; gap: 10px; }
.cat-row .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cat-row .nm { flex: 1; font-weight: 500; }
.cat-row .v { font-weight: 700; }
.cat-row small { color: var(--muted); width: 38px; text-align: right; }

.insights { display: flex; flex-direction: column; gap: 10px; }
.insight { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.insight .kpi-ic { width: 32px; height: 32px; }
.insight b { display: block; font-size: 13.5px; }
.insight p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.insight a.lnk { color: var(--primary); font-weight: 600; }

.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.li:first-child { border-top: 0; }
.li .nm { flex: 1; min-width: 0; }
.li .nm b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .nm small { color: var(--muted); font-size: 12.5px; }
.li.click { cursor: pointer; border-radius: 10px; }
.li.click:hover { background: var(--surface-2); }
.avs { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .ic { margin: 0 auto 10px; color: var(--faint); }

/* ---------- Tables ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .input { width: auto; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search .input { padding-left: 38px; width: 100%; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #fafbfe; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.actions { display: flex; gap: 2px; justify-content: flex-end; }
.actions .icon-btn { width: 32px; height: 32px; color: var(--muted); }
.actions .icon-btn:hover { color: var(--text); }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line-2); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--navy); color: #fff; }

/* ---------- Customers grid ---------- */
.cust-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.cust { padding: 16px; cursor: pointer; transition: transform .12s, box-shadow .15s; }
.cust:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(16, 24, 40, .09); }
.cust-h { display: flex; align-items: center; gap: 12px; }
.cust-h b { display: block; font-size: 15px; }
.cust-h small { color: var(--muted); }
.cust-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.cust-stats div { background: var(--surface-2); border-radius: 10px; padding: 9px 11px; }
.cust-stats small { display: block; color: var(--muted); font-size: 11.5px; }
.cust-stats b { font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-weight: 500; }

/* ---------- Daily entry ---------- */
.daily-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; }
.daily-sum { display: flex; gap: 22px; margin-left: auto; flex-wrap: wrap; }
.daily-sum small { display: block; color: var(--muted); font-size: 12px; }
.daily-sum b { font-size: 18px; letter-spacing: -.02em; }
.drow { display: grid; grid-template-columns: 34px minmax(160px, 1.1fr) 2.6fr 110px 120px; gap: 14px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.drow.head { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); border-top: 0; border-radius: var(--radius) var(--radius) 0 0; }
.drow.done { background: #f6fbf8; }
.drow .cn b { display: block; }
.drow .cn small { color: var(--muted); font-size: 12px; }
.qitems { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.qchip { display: inline-flex; align-items: center; gap: 0; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; background: var(--surface); }
.qchip span { padding: 0 10px; font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; border-right: 1px solid var(--line); height: 32px; display: flex; align-items: center; background: var(--surface-2); }
.qchip input { width: 56px; height: 32px; border: 0; outline: none; text-align: center; font-weight: 700; background: transparent; }
.qchip input:focus { background: var(--primary-soft); }
.addsel { height: 32px; border: 1px dashed var(--line-2); border-radius: 10px; background: transparent; color: var(--muted); padding: 0 8px; font-size: 12.5px; cursor: pointer; max-width: 120px; }
.drow .tot { font-weight: 700; text-align: right; }
.check { width: 22px; height: 22px; accent-color: var(--green); cursor: pointer; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 6px; }

/* ---------- Ledger / detail ---------- */
.detail-h { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.detail-h .avs { width: 52px; height: 52px; font-size: 18px; border-radius: 15px; }
.due-box { margin-left: auto; text-align: right; }
.due-box small { color: var(--muted); display: block; font-size: 12px; }
.due-box b { font-size: 26px; letter-spacing: -.03em; }
.mini-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.mini-kpis div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.mini-kpis small { display: block; color: var(--muted); font-size: 11.5px; }
.mini-kpis b { font-size: 16px; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 41, .45); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px); overflow: hidden; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); animation: pop .18s ease;
}
.modal.wide { max-width: 880px; }
.modal-h { display: flex; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-h h3 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.modal-b { padding: 20px; overflow-y: auto; }
.modal-f { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.lines { display: flex; flex-direction: column; gap: 8px; }
.line { display: grid; grid-template-columns: 1fr 80px 90px 90px 32px; gap: 8px; align-items: center; }
.line .lt { text-align: right; font-weight: 600; }
.line-h { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.total-box { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-radius: 12px; background: var(--navy); color: #fff; }
.total-box b { font-size: 22px; letter-spacing: -.02em; }
.total-box small { color: rgba(255, 255, 255, .65); }

/* ---------- Toast ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 12px; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: pop .2s ease; }
.toast .ic { color: #6ee7a8; }

/* ---------- Settings ---------- */
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .c4, .c5, .c7, .c8, .c6 { grid-column: span 12; }
}
@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 28px 22px; min-height: 260px; }
  .login-art h2 { font-size: 28px; }
  .login-float { display: none; }
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 60; transform: translateX(-100%); transition: transform .22s ease; }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 41, .45); }
  .menu-btn { display: inline-grid; margin-left: -6px; }
  .top { padding: 12px 16px; }
  .top h1 { font-size: 18px; }
  .top p { display: none; }
  .top-actions .btn span { display: none; }
  .top-actions .btn { padding: 0 11px; }
  .view { padding: 6px 16px 32px; }
  .set-grid, .grid3 { grid-template-columns: 1fr; }
  .drow.head { display: none; }
  .drow { grid-template-columns: 30px 1fr auto; grid-template-areas: "ck cn tot" "it it it" "pd pd pd"; gap: 10px; }
  .drow > :nth-child(1) { grid-area: ck; }
  .drow > :nth-child(2) { grid-area: cn; }
  .drow > :nth-child(3) { grid-area: it; }
  .drow > :nth-child(4) { grid-area: tot; }
  .drow > :nth-child(5) { grid-area: pd; }
  .daily-sum { margin-left: 0; width: 100%; }
  .card-h { flex-wrap: wrap; }
}
@media (max-width: 560px) {
  .kpis { gap: 12px; }
  .kpi { padding: 14px; }
  .kpi-val { font-size: 21px; }
  .grid2 { grid-template-columns: 1fr; }
  .mini-kpis { grid-template-columns: 1fr 1fr; }
  .line { grid-template-columns: 1fr 64px 76px 28px; }
  .line .lt { display: none; }
  .line-h span:nth-child(4) { display: none; }
  .donut-wrap { flex-direction: column; align-items: stretch; }
  .donut { margin: 0 auto; }
  .modal-bg { padding: 0; place-items: end center; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92vh; }
  .tbl th, .tbl td { padding: 10px 12px; }
  .due-box { margin-left: 0; text-align: left; width: 100%; }
}

/* ---------- Online sync & roles ---------- */
.role-staff .admin-only { display: none !important; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 11px;
  border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; font-size: 13px; color: var(--muted);
  cursor: pointer; white-space: nowrap;
}
.sync-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.sync-pill.ok { color: var(--green); }
.sync-pill.busy i { background: var(--primary); animation: pulse 1s ease-in-out infinite; }
.sync-pill.busy { color: var(--primary); }
.sync-pill.off i { background: var(--amber); }
.sync-pill.off { color: var(--amber); background: var(--amber-soft); border-color: transparent; }
.sync-pill.err i { background: var(--red); }
.sync-pill.err { color: var(--red); background: var(--red-soft); border-color: transparent; }
.sync-pill.stale { color: #fff; background: var(--primary); border-color: transparent; }
.sync-pill.stale i { background: #fff; }
@keyframes pulse { 50% { opacity: .3; } }
@media (max-width: 900px) {
  .sync-pill { padding: 0 11px; }
  .sync-pill.ok span, .sync-pill.busy span { display: none; }
}

/* ---------- Distributors & money flow ---------- */
.kpi.hero-orange { background: linear-gradient(140deg, #d9480f, #f26b1d 60%, #ff9248); box-shadow: 0 14px 30px rgba(242, 107, 29, .28); }
.total-box.total-orange { background: linear-gradient(120deg, #7a2e0b, #b8420f); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.money-flow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.money-flow > div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.money-flow > div.hl { background: var(--green-soft); border-color: transparent; }
.money-flow small { color: var(--muted); font-size: 12px; }
.money-flow b { font-size: 18px; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; }
.money-flow .kpi-foot { font-size: 11.5px; flex-wrap: wrap; }
.net-bar { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 12px; border-radius: 12px; overflow: hidden; background: var(--navy); color: #fff; }
.net-bar > div { padding: 12px; border-left: 1px solid rgba(255, 255, 255, .1); }
.net-bar > div:first-child { border-left: 0; }
.net-bar small { display: block; color: rgba(255, 255, 255, .6); font-size: 11.5px; }
.net-bar b { font-size: 16px; }
.net-bar .green { color: #6ee7a8; } .net-bar .red { color: #ff9b9e; }
.money-strip { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 16px 20px; margin-bottom: 18px; }
.money-strip > div { display: flex; flex-direction: column; }
.money-strip small { color: var(--muted); font-size: 12px; }
.money-strip b { font-size: 20px; letter-spacing: -.02em; }
.money-strip .op { font-size: 22px; color: var(--faint); font-weight: 300; }
.money-strip .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 6px; }
.kpi.click { cursor: pointer; transition: transform .12s, box-shadow .15s; }
.kpi.click:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(16, 24, 40, .09); }

/* ---------- Install as app ---------- */
.install-banner { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 18px; border-radius: var(--radius); background: linear-gradient(120deg, #0f1b3d, #1d3a8a); color: #fff; box-shadow: var(--shadow); }
.install-banner img { border-radius: 11px; flex: none; }
.install-banner div { flex: 1; min-width: 0; }
.install-banner p { margin: 2px 0 0; color: rgba(255, 255, 255, .7); font-size: 12.5px; }
.install-banner .icon-btn { color: rgba(255, 255, 255, .7); }
.install-steps { display: flex; flex-direction: column; gap: 14px; }
.install-steps .step { display: flex; gap: 14px; align-items: flex-start; }
.install-steps .n { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex: none; }
.install-steps p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.install-steps .key { display: inline-flex; vertical-align: middle; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--primary); margin-left: 4px; font-weight: 700; }

/* ---------- App shell on every screen size ---------- */
.tabbar { display: none; }
.view { max-width: 1680px; margin: 0 auto; width: 100%; }
.side { padding-top: max(18px, env(safe-area-inset-top)); padding-left: max(14px, env(safe-area-inset-left)); padding-bottom: max(18px, env(safe-area-inset-bottom)); }

/* Large desktops */
@media (min-width: 1700px) {
  body { font-size: 15px; }
  .kpi-val { font-size: 30px; }
}

/* Small laptops & landscape tablets: icon-only sidebar */
@media (min-width: 901px) and (max-width: 1100px) {
  .layout { grid-template-columns: 76px 1fr; }
  .side { padding-left: 12px; padding-right: 12px; }
  .side .brand > div:last-child, .side nav a span, .side nav .lbl, .side-foot .me > div { display: none; }
  .side .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .side nav a { justify-content: center; padding: 12px 0; }
  .side nav .lbl { display: block; height: 10px; padding: 0; font-size: 0; }
  .side-foot { flex-direction: column; padding-left: 0; padding-right: 0; }
  .side-foot .me { flex: none; }
  .top { padding: 16px 20px; }
  .view { padding: 8px 20px 40px; }
}

/* Phones & portrait tablets */
@media (max-width: 900px) {
  .input, select.input, textarea.input, .qchip input, .addsel { font-size: 16px; } /* stops iOS zooming into fields */
  .input.sm { height: 38px; }
  .top { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .view { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, .94); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border: 0; background: none;
    color: var(--faint); font-size: 11px; font-weight: 600; cursor: pointer; border-radius: 12px; -webkit-tap-highlight-color: transparent;
  }
  .tabbar a.on { color: var(--primary); }
  .tabbar a.on .ic { filter: drop-shadow(0 4px 8px rgba(47, 107, 255, .35)); }
  #toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .toolbar .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .toolbar .seg::-webkit-scrollbar { display: none; }
  .toolbar .seg button { white-space: nowrap; }
  .money-strip { gap: 12px; }
  .money-strip .sep { display: none; }
  .modal-f { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .grid-auto { grid-template-columns: 1fr 1fr; }
}

/* Phones */
@media (max-width: 640px) {
  .top-actions .btn.ghost { display: none; } /* Receive Payment lives in each screen's toolbar */
  .toolbar > .btn span { display: none; }
  .toolbar > .btn { padding: 0 12px; }
  /* tables become stacked cards */
  .tbl-cards thead { display: none; }
  .tbl-cards, .tbl-cards tbody { display: block; }
  .tbl-cards tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); position: relative; }
  .tbl-cards tbody tr:hover { background: none; }
  .tbl-cards td { display: block; padding: 0; border: 0; text-align: left !important; min-width: 0; }
  .tbl-cards td[data-l]::before { content: attr(data-l); display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; margin-bottom: 1px; }
  .tbl-cards td:nth-child(2), .tbl-cards td:nth-child(3) { grid-column: 1 / -1; }
  .tbl-cards td:first-child { grid-column: 1 / -1; font-weight: 600; }
  .tbl-cards td:first-child::before { display: none; }
  .tbl-cards td:last-child { position: absolute; top: 8px; right: 8px; }
  .tbl-cards td[colspan] { grid-column: 1 / -1; }
  .money-flow { grid-template-columns: 1fr; }
  .money-flow > div { flex-direction: row; align-items: baseline; flex-wrap: wrap; gap: 8px; }
  .money-flow small { width: 90px; }
  .net-bar b { font-size: 14px; }
  .install-banner { flex-wrap: wrap; }
  .install-banner div { flex-basis: calc(100% - 100px); }
  .install-banner .btn { margin-left: 58px; }
  .install-banner .icon-btn { position: absolute; right: 22px; }
  .install-banner { position: relative; }
  .kpi-top { font-size: 12px; }
  .kpi-ic { width: 30px; height: 30px; }
}

/* Very small phones */
@media (max-width: 360px) {
  .kpis { grid-template-columns: 1fr; }
  .grid-auto { grid-template-columns: 1fr; }
}

/* Installed app (standalone): no browser chrome, so respect the status bar */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; overscroll-behavior-y: none; }
  input, textarea, .tbl td, .li .nm { -webkit-user-select: text; user-select: text; }
}
