:root {
  --navy: #0B1F4D;
  --navy-2: #13306E;
  --blue: #2563B8;
  --blue-soft: #EAF1FB;
  --orange: #E2701E;
  --orange-soft: #FDF0E5;
  --ground: #F3F5F9;
  --card: #FFFFFF;
  --line: #E1E6EE;
  --line-strong: #C9D1DD;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #5B6474;
  --ok: #15703F;
  --ok-soft: #E5F5EC;
  --warn: #8A5300;
  --warn-soft: #FFF4DE;
  --bad: #B42318;
  --bad-soft: #FDECEA;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 16px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; padding-bottom: 92px; font-feature-settings: "tnum" 1; }
a { color: var(--blue); }
h1 { font-size: 24px; line-height: 30px; margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 12px; letter-spacing: .9px; text-transform: uppercase; color: var(--muted); margin: 0; font-weight: 700; }
.wrap { max-width: 680px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

/* header */
.topbar { background: linear-gradient(180deg, var(--navy), var(--navy-2)); color: #fff; padding: 12px 16px 14px; position: sticky; top: 0; z-index: 5; }
.topbar .in { max-width: 680px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar a { color: #fff; text-decoration: none; }
.brandlink { display: flex; align-items: center; gap: 10px; }
.brandlink .chip { width: 40px; height: 40px; border-radius: 12px; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.brandlink .chip img { width: 28px; height: 28px; object-fit: contain; }
.brand { font-weight: 700; font-size: 17px; line-height: 20px; }
.sub { font-size: 12px; color: #B9C6E3; }
.avatar { width: 40px; height: 40px; border-radius: 20px; background: rgba(255,255,255,.14); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; }

/* bottom nav */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.97); backdrop-filter: blur(8px); border-top: 1px solid var(--line); z-index: 5; padding-bottom: env(safe-area-inset-bottom); }
.tabbar .in { max-width: 680px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px 10px; font-size: 11.5px; color: var(--muted); text-decoration: none; min-height: 60px; justify-content: center; }
.tabbar a.on { color: var(--blue); font-weight: 700; }
.tabbar a.on svg { stroke-width: 2.4; }
.tabbar svg { width: 23px; height: 23px; }
.tabbar .new { color: #fff; }
.tabbar .new .plus { width: 44px; height: 44px; border-radius: 14px; background: var(--orange); display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(226,112,30,.35); margin-top: -18px; }
.tabbar .new span.l { color: var(--muted); }
.nb { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.card.tight { gap: 6px; }
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap-row { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.warn-text { color: var(--warn); }

/* forms */
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 5px; font-weight: 500; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; min-height: 48px; border: 1px solid var(--line-strong); border-radius: 12px; background: #fff; color: var(--ink); }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(37,99,184,.22); border-color: var(--blue); }
.field { min-width: 0; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1.5px solid var(--blue); background: var(--blue); color: #fff; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center; line-height: 1.2; }
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: #fff; color: var(--blue); }
.btn.quiet { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.btn.orange { background: var(--orange); border-color: var(--orange); }
.btn.green { background: var(--ok); border-color: var(--ok); }
.btn.danger { background: #fff; color: var(--bad); border-color: #E7B4AE; }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; font-size: 17px; border-radius: 14px; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
form.inline { display: contents; }

.seg { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.seg.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { margin: 0; display: flex; align-items: center; justify-content: center; min-height: 48px; border: 1.5px solid var(--line-strong); border-radius: 12px; font-size: 15px; font-weight: 600; color: var(--ink); background: #fff; cursor: pointer; text-align: center; padding: 0 4px; }
.seg input:checked + label { background: var(--blue); border-color: var(--blue); color: #fff; }
.seg input:focus-visible + label { outline: 3px solid rgba(37,99,184,.35); outline-offset: 2px; }

.item { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: #FAFBFD; }
.item .grid3 { display: grid; grid-template-columns: 0.8fr 1fr 1.3fr; gap: 8px; }
.item .amt { font-weight: 700; text-align: right; }
.icon-btn { min-width: 44px; min-height: 44px; border: none; background: transparent; color: var(--muted); border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: #EEF1F5; }

.totals { background: linear-gradient(160deg, var(--navy), var(--navy-2)); color: #fff; border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.totals .row { justify-content: space-between; }
.totals .lbl { color: #B9C6E3; }
.totals .grand { font-size: 26px; font-weight: 800; letter-spacing: -0.3px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.doc { display: flex; justify-content: space-between; gap: 12px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 14px; color: inherit; text-decoration: none; box-shadow: var(--shadow); }
.doc:hover { border-color: var(--line-strong); }
.doc .no { font-weight: 700; }
.doc .co { font-size: 14px; color: var(--ink-2); }
.doc .meta { font-size: 13px; color: var(--muted); }
.doc .right { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.doc .amt { font-weight: 700; }
.lrow { display: flex; justify-content: space-between; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.lrow:first-child { border-top: none; }
.lrow:hover { background: #FAFBFD; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.type-Q { background: var(--blue-soft); color: #1D4F8C; }
.type-IN { background: var(--orange-soft); color: #8A3D08; }
.st-draft { background: #EEF0F3; color: #444B57; }
.st-sent { background: var(--blue-soft); color: #1D4F8C; }
.st-approved { background: #E8E6FB; color: #4433A8; }
.st-paid { background: var(--ok-soft); color: var(--ok); }
.st-partial { background: var(--warn-soft); color: var(--warn); }
.st-late { background: var(--bad-soft); color: var(--bad); }
.st-cancelled { background: var(--bad-soft); color: var(--bad); }
.st-superseded { background: #F3EFE6; color: #6B5B2E; }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters a { flex-shrink: 0; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; font-size: 14px; min-height: 40px; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.filters a.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.filters .cnt { background: rgba(0,0,0,.08); border-radius: 999px; padding: 0 7px; font-size: 12px; }
.filters a.on .cnt { background: rgba(255,255,255,.2); }

.flash { padding: 12px 14px; border-radius: 12px; font-size: 15px; }
.flash.ok { background: var(--ok-soft); color: #0F4F2C; }
.flash.err { background: var(--bad-soft); color: #7A1A12; }
.flash.info { background: var(--warn-soft); color: #6B4100; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 0; font-size: 15px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; padding-left: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.kv .total-row { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 2px; font-weight: 800; color: var(--ink); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.stat .n { font-size: 22px; font-weight: 800; line-height: 1.15; letter-spacing: -0.3px; }
.stat .l { font-size: 13px; color: var(--muted); }
.stat.hl { background: var(--navy); border-color: var(--navy); color: #fff; }
.stat.hl .l { color: #B9C6E3; }
.stat.bad { background: var(--bad-soft); border-color: #F5C7C2; }
.stat.bad .n { color: var(--bad); }

/* todo strip */
.todo { display: flex; flex-direction: column; gap: 8px; }
.todo a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; text-decoration: none; color: var(--ink); background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.todo .ic { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.todo .ic svg { width: 20px; height: 20px; }
.todo .t { font-weight: 600; font-size: 15px; }
.todo .d { font-size: 13px; color: var(--muted); }
.todo .go { margin-left: auto; color: var(--muted); }
.ic.red { background: var(--bad-soft); color: var(--bad); }
.ic.amber { background: var(--warn-soft); color: var(--warn); }
.ic.blue { background: var(--blue-soft); color: var(--blue); }
.ic.grey { background: #EEF0F3; color: #444B57; }
.allclear { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--ok-soft); color: #0F4F2C; font-weight: 600; }

/* pipeline */
.pipe { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.pipe .st { background: #F7F9FC; border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px; text-align: center; }
.pipe .st .c { font-size: 20px; font-weight: 800; }
.pipe .st .v { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pipe .st .k { font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 2px; }

/* aging bar */
.agebar { display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: #EEF1F5; }
.agebar div { height: 100%; }
.ag-0 { background: #9DB8DE; } .ag-1 { background: #F2B66B; } .ag-2 { background: #E8893A; } .ag-3 { background: #D2582A; } .ag-4 { background: #A8231A; }
.agelist { display: flex; flex-direction: column; gap: 6px; }
.agelist div { display: flex; justify-content: space-between; font-size: 14px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: middle; }

/* month bars */
.mbars { display: flex; flex-direction: column; gap: 10px; }
.mrow { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; font-size: 13px; }
.mtracks { display: flex; flex-direction: column; gap: 3px; }
.mtrack { height: 10px; background: #EEF1F5; border-radius: 5px; overflow: hidden; }
.mtrack div { height: 100%; border-radius: 5px; }
.m-inv { background: #4F81BD; } .m-rec { background: #2F9E62; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td, table.simple th { padding: 9px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.simple th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.simple td.r, table.simple th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.simple tr:last-child td { border-bottom: none; }

.progress { height: 10px; border-radius: 5px; background: #EEF1F5; overflow: hidden; display: flex; }
.progress .p-rec { background: #2F9E62; } .progress .p-wht { background: #8CCBA6; }

.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.steps div { text-align: center; font-size: 11.5px; color: var(--muted); padding-top: 8px; border-top: 4px solid var(--line); font-weight: 600; }
.steps div.done { border-color: var(--ok); color: var(--ok); }
.steps div.now { border-color: var(--blue); color: var(--blue); }

.events { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.events > div { display: flex; justify-content: space-between; gap: 10px; }

details summary { cursor: pointer; color: var(--blue); font-weight: 600; min-height: 44px; display: flex; align-items: center; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: '+'; display: inline-flex; width: 22px; height: 22px; border-radius: 6px; background: var(--blue-soft); align-items: center; justify-content: center; margin-right: 8px; font-weight: 700; }
details[open] summary::before { content: '−'; }

.login { max-width: 380px; margin: 10vh auto 0; padding: 16px; }
.login img { width: 200px; display: block; margin: 0 auto 20px; }
.empty { text-align: center; padding: 24px 12px; color: var(--muted); }

@media (min-width: 560px) {
  .stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
