:root {
  --navy: #16202A; --navy-2: #24313d; --teal: #4F9D8F; --teal-2: #3d8073; --teal-bg: #D3E8E5; --amber: #E3A33B;
  --bg: #f4f6f7; --card: #ffffff; --text: #1c2630; --muted: #5b6670; --line: #e1e6ea;
  --ok: #1f7a4d; --ok-bg: #e3f4ea; --warn: #8a5a00; --warn-bg: #fff3d6; --bad: #b3261e; --bad-bg: #fde7e6;
  --info: #1d4f91; --info-bg: #e5eefb; --input: #fffbe0;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
a { color: var(--teal-2); }
.muted { color: var(--muted); }
.small, small { font-size: 12px; }
.strong { font-weight: 600; }
.block { display: block; }
.loading { color: var(--muted); }
.loading.boot { padding: 24px; }
.empty { color: var(--muted); padding: 12px 0; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 230px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; }
.brand img { height: 28px; background: #fff; border-radius: 4px; padding: 2px 6px; }
.spacer { flex: 1; }
.who { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.who small { color: #b8c4cf; }
.viewing { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #b8c4cf; }
.viewing select { background: var(--navy-2); color: #fff; border: 1px solid #3a4856; border-radius: 6px; padding: 5px 8px; max-width: 220px; }
.topbar .btn.ghost { color: #fff; border-color: #3a4856; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; }
.menu-btn span { display: block; width: 20px; height: 2px; background: #fff; margin: 4px 0; }
.sidenav { background: #fff; border-right: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto; }
.sidenav a { display: block; padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.sidenav a:hover { background: var(--bg); }
.sidenav a.active { background: var(--teal-bg); color: var(--navy); font-weight: 600; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 12px; }
main { padding: 22px 26px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { background: var(--teal-bg); color: var(--navy); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; }

/* ---------- cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
.grid2.wide-left { grid-template-columns: 3fr 2fr; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row.end { justify-content: flex-end; }
.stack { display: grid; gap: 10px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.inline { display: inline-flex; gap: 8px; align-items: center; }

/* ---------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.tile-value { font-size: 24px; font-weight: 700; color: var(--navy); margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--muted); }
.tile.hero { background: var(--navy); border-color: var(--navy); }
.tile.hero .tile-label, .tile.hero .tile-sub { color: #b8c4cf; }
.tile.hero .tile-value { color: #fff; }
.tile.warn { border-color: #f0c36b; background: var(--warn-bg); }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.wrap { min-width: 180px; max-width: 360px; }
tfoot td, tfoot th { font-weight: 600; background: #fafbfc; }
tr.strong th, tr.strong td { font-weight: 700; }
tr.hl th, tr.hl td { background: var(--teal-bg); font-weight: 600; }
tr.total td { font-size: 16px; font-weight: 700; background: var(--teal-bg); }
table.kv td:first-child { color: var(--muted); }
table.matrix tbody th { font-weight: 500; min-width: 200px; }
table.kpi td.kcell { text-align: right; white-space: nowrap; min-width: 92px; }
table.kpi td.kcell small { display: block; color: var(--muted); }
table.kpi td.kcell.good { background: #eef8f2; }
table.kpi td.kcell.mid { background: #fff8e8; }
table.kpi td.kcell.low { background: #fdf1f0; }
table.kpi td.kcell.na { color: var(--muted); }
.actual { font-weight: 600; font-size: 15px; }
.cell-input { width: 86px; text-align: right; background: var(--input); border: 1px solid #e6d77a; border-radius: 6px; padding: 4px 6px; font: inherit; }
table.grid-edit td { padding: 4px; }
table.grid-edit input[type=text], table.grid-edit input[type=number], table.grid-edit select { width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; min-width: 70px; }

/* ---------- badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f3; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.alert { padding: 10px 14px; border-radius: 8px; background: var(--info-bg); color: var(--info); margin-bottom: 14px; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field.check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 8px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .help { color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); }
.field input:not([type=checkbox]), .field select, .field textarea, .partner-edit select, .partner-edit textarea, .row select {
  padding: 8px 10px; border: 1px solid #cfd6dc; border-radius: 8px; background: #fff; width: 100%; }
.row select { width: auto; }
.field input:focus, .field select:focus, .field textarea:focus, .cell-input:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
.form-error { color: var(--bad); min-height: 18px; margin-top: 8px; font-weight: 500; }
.btn { background: var(--teal); color: #fff; border: 1px solid var(--teal); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--teal-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--navy); border-color: var(--navy); }
.btn.ghost { background: transparent; color: var(--text); border-color: #cfd6dc; }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost.danger { background: transparent; color: var(--bad); border-color: #f0c2be; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.link { background: none; border: 0; color: var(--teal-2); cursor: pointer; padding: 6px 0; font: inherit; text-decoration: underline; }

/* ---------- chart */
.chart-box { width: 100%; }
.chart { width: 100%; height: auto; }
.chart .grid { stroke: var(--line); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .s1, .legend .s1 { fill: var(--navy); background: var(--navy); }
.chart .s2, .legend .s2 { fill: var(--teal); background: var(--teal); }
.chart .s3, .legend .s3 { fill: var(--amber); background: var(--amber); }
.legend { display: flex; gap: 16px; justify-content: center; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

/* ---------- partners */
.partners { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.partners .card { margin: 0; display: flex; flex-direction: column; }
.partner-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.partner-head h2 { margin: 0 6px 0 0; }
dl { margin: 8px 0; }
dt { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 8px; }
dd { margin: 2px 0 0; }
details summary { cursor: pointer; color: var(--teal-2); font-weight: 600; margin: 8px 0; }
.partner-edit { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.partner-edit label { font-size: 12px; font-weight: 600; color: var(--muted); }
dl.guide dt { font-size: 13px; color: var(--navy); }
dl.guide dd { margin-bottom: 6px; }
ol.rules li, ol.steps li { margin: 6px 0; }

/* ---------- auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-brand { background: var(--navy); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: center; }
.auth-brand img { width: 180px; background: #fff; border-radius: 8px; padding: 8px 12px; margin-bottom: 24px; }
.auth-brand h1 { font-size: 28px; }
.auth-brand p { color: #b8c4cf; }
.auth-box { display: flex; flex-direction: column; justify-content: center; padding: 48px; max-width: 520px; width: 100%; }
.auth-box .form-grid { grid-template-columns: 1fr; }
.auth-box .btn[type=submit] { width: 100%; padding: 10px; }
.qr { display: flex; justify-content: center; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; min-height: 224px; align-items: center; }
.secret code { display: block; font-size: 16px; letter-spacing: .08em; background: var(--bg); padding: 10px; border-radius: 6px; word-break: break-all; }

/* ---------- dialogs / toast */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.dialog { background: #fff; border-radius: 12px; padding: 20px; max-width: 420px; width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.2); max-height: 90vh; overflow: auto; }
.dialog.wide { max-width: 860px; }
.dialog input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid #cfd6dc; border-radius: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); opacity: 0; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; transition: all .25s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--bad); }

/* ---------- statement */
.statement-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 8px; }
.statement-head .right { text-align: right; }

/* ---------- responsive */
@media (max-width: 960px) {
  .grid2, .grid2.wide-left { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 28px 16px; }
  .auth-box { padding: 24px 16px; max-width: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .sidenav { position: fixed; top: 56px; left: 0; bottom: 0; width: 260px; height: auto; transform: translateX(-100%); transition: transform .2s; z-index: 30; box-shadow: 0 0 20px rgba(0,0,0,.15); }
  body.nav-open .sidenav { transform: none; }
  main { padding: 16px 16px 60px; }
  .who { display: none; }
  .brand span { display: none; }
  .viewing select { max-width: 140px; }
  .tile-value { font-size: 20px; }
  .partners { grid-template-columns: 1fr; }
}

@media print {
  .topbar, .sidenav, .no-print, .page-head .chip { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}
