:root {
  color-scheme: light;
  --bg: #f3f5f8; --paper: #fff; --paper2: #f8fafc; --ink: #162436; --muted: #5f6f84; --line: #e1e7ee;
  --accent: #157a6e; --accent-ink: #fff; --soft: #e5f4f0; --red: #b23a3e; --red-soft: #fdecec;
  --orange: #9a6513; --orange-soft: #fff5e3; --blue: #3d6f99; --blue-soft: #e8f0f8;
  --head: #101c2b; --head-ink: #fff; --head-muted: #a9b7c9;
  --shadow: 0 2px 10px #1c2b4010; --radius: 12px;
  --chart-main: #157a6e; --chart-alt: #c0612f; --chart-buffer: #c58b3a; --chart-grid: #e3e8ee;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1721; --paper: #18232f; --paper2: #1d2a38; --ink: #e5ecf4; --muted: #9eadbf; --line: #2c3a4b;
    --accent: #5cc4ae; --accent-ink: #082420; --soft: #1d3936; --red: #f08b8e; --red-soft: #3b2226;
    --orange: #e6b56b; --orange-soft: #3a2f1f; --blue: #8fb9e0; --blue-soft: #1f3044;
    --head: #0a121b; --shadow: none; --chart-main: #5cc4ae; --chart-alt: #f0a070; --chart-grid: #2c3a4b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1721; --paper: #18232f; --paper2: #1d2a38; --ink: #e5ecf4; --muted: #9eadbf; --line: #2c3a4b;
  --accent: #5cc4ae; --accent-ink: #082420; --soft: #1d3936; --red: #f08b8e; --red-soft: #3b2226;
  --orange: #e6b56b; --orange-soft: #3a2f1f; --blue: #8fb9e0; --blue-soft: #1f3044;
  --head: #0a121b; --shadow: none; --chart-main: #5cc4ae; --chart-alt: #f0a070; --chart-grid: #2c3a4b;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.good { color: var(--accent); }
.bad { color: var(--red); }
.warn { color: var(--orange); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* header & nav */
.topbar { background: var(--head); color: var(--head-ink); padding: 14px max(16px, calc((100vw - 1240px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #1aa08f, #157a6e); display: grid; place-items: center; font-weight: 800; color: #fff; }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -.5px; }
.topbar .sub { margin: 0; color: var(--head-muted); font-size: 12px; }
.topactions { display: flex; gap: 8px; align-items: center; }
.topbar .ghost { color: var(--head-ink); border-color: #ffffff30; }
.nav { display: flex; gap: 4px; overflow-x: auto; padding: 10px max(16px, calc((100vw - 1240px) / 2)); background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; scrollbar-width: thin; }
.nav a { white-space: nowrap; text-decoration: none; color: var(--muted); padding: 7px 11px; border-radius: 8px; font-weight: 600; font-size: 14px; position: relative; }
.nav a:hover { background: var(--paper2); color: var(--ink); }
.nav a.active { background: var(--soft); color: var(--accent); }
.nav .badge { margin-left: 5px; }
main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 18px 16px 40px; outline: none; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 14px 16px 22px; }

/* controls */
button { cursor: pointer; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); padding: 8px 13px; font-weight: 600; line-height: 1.2; }
button:hover { filter: brightness(.97); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.small { font-size: 12px; padding: 5px 9px; }
button.danger { color: var(--red); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; }
button.seg { border-radius: 0; margin-left: -1px; }
.segs { display: inline-flex; max-width: 100%; overflow-x: auto; padding: 2px; scrollbar-width: thin; }
.segs button { white-space: nowrap; flex: 0 0 auto; }
.segs button:first-child { border-radius: 8px 0 0 8px; }
.segs button:last-child { border-radius: 0 8px 8px 0; }
.segs button.on { background: var(--soft); color: var(--accent); border-color: var(--accent); position: relative; z-index: 1; }
input, select, textarea { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"] { width: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }

/* layout */
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead h2 { margin: 0; font-size: 22px; letter-spacing: -.4px; }
.pagehead p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar label.field { flex-direction: row; align-items: center; gap: 6px; }
.toolbar input, .toolbar select { width: auto; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols2 { grid-template-columns: 1.4fr 1fr; }
.cols2e { grid-template-columns: 1fr 1fr; }
.cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack > * + * { margin-top: 12px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel h3 { margin: 0 0 10px; font-size: 16px; letter-spacing: -.2px; }
.panelhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.panelhead h3 { margin: 0; }
.kpi small { color: var(--muted); font-size: 12px; display: block; }
.kpi strong { display: block; font-size: clamp(19px, 2.4vw, 27px); letter-spacing: -.8px; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi em { font-style: normal; color: var(--muted); font-size: 12px; }
.kpi.alert { border-color: var(--red); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .meta { color: var(--muted); font-size: 12px; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }

/* alerts & tags */
.alerts { display: grid; gap: 8px; margin-bottom: 12px; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 14px; border: 1px solid; display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; }
.alert.red { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.alert.orange { background: var(--orange-soft); color: var(--orange); border-color: color-mix(in srgb, var(--orange) 30%, transparent); }
.alert.blue { background: var(--blue-soft); color: var(--blue); border-color: color-mix(in srgb, var(--blue) 30%, transparent); }
.alert.green { background: var(--soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--paper2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.tag.green { background: var(--soft); color: var(--accent); border-color: transparent; }
.tag.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.tag.orange { background: var(--orange-soft); color: var(--orange); border-color: transparent; }
.tag.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: var(--paper2); }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 4px; }
.txname { font-weight: 600; }
.txsub { color: var(--muted); font-size: 12px; }
tr.shortage td { background: var(--red-soft); }
tr.overdue td:first-child { color: var(--orange); }

/* charts & bars */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart .zero { stroke: var(--red); stroke-width: 1; opacity: .5; }
.chart .buffer { stroke: var(--chart-buffer); stroke-dasharray: 5 5; stroke-width: 1.5; }
.chart .line { fill: none; stroke: var(--chart-main); stroke-width: 2.5; stroke-linejoin: round; }
.chart .line.alt { stroke: var(--chart-alt); stroke-dasharray: 6 4; }
.chart .area { fill: var(--chart-main); opacity: .08; }
.chart .short { fill: var(--red); opacity: .10; }
.chart .dot { fill: var(--chart-main); }
.chart .lowdot { fill: var(--red); }
.chart .bar-in { fill: var(--chart-main); }
.chart .bar-out { fill: var(--chart-alt); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
.legend .l-main { background: var(--chart-main); }
.legend .l-alt { background: var(--chart-alt); }
.legend .l-buf { background: var(--chart-buffer); }
.legend .l-short { background: var(--red); opacity: .5; }
svg.bar { width: 100%; height: 10px; display: block; margin: 7px 0; border-radius: 5px; overflow: hidden; }
svg.bar .bg { fill: var(--line); }
svg.bar .spent { fill: var(--accent); }
svg.bar .committed { fill: var(--blue); opacity: .7; }
svg.bar .over { fill: var(--red); }

/* modal */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(620px, calc(100% - 20px)); max-height: calc(100vh - 30px); background: var(--paper); color: var(--ink); box-shadow: 0 20px 70px #0004; }
dialog::backdrop { background: #08111d99; }
dialog form { padding: 18px; display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
#modalBody { overflow-y: auto; padding: 2px; }
.modalhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.modalhead h2 { margin: 0; font-size: 18px; }
.modalactions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.formgrid .wide { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

/* login */
.login { max-width: 380px; margin: 8vh auto; }
.login h2 { margin-top: 0; }
.login form { display: grid; gap: 12px; }

/* toasts */
.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 50; pointer-events: none; }
.toast { pointer-events: auto; background: var(--head); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 30px #0004; max-width: 440px; font-size: 14px; border-left: 4px solid var(--accent); }
.toast.error { border-left-color: #f08b8e; }
.toast.warn { border-left-color: #e6b56b; }

.split-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.empty { padding: 22px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; }
.verdict { font-size: 20px; font-weight: 700; }
.logo-img { width: 22px; height: 22px; object-fit: contain; vertical-align: middle; margin-right: 6px; border-radius: 4px; background: #fff; }
.aspsp { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.aspsp:last-child { border-bottom: 0; }
.scrollbox { max-height: 360px; overflow-y: auto; }
details > summary { cursor: pointer; font-weight: 600; margin: 6px 0; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols2, .cols2e { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  main { padding: 12px 10px 30px; }
  .panel { padding: 12px; }
  .formgrid { grid-template-columns: 1fr; }
  .topbar .sub { display: none; }
  .topbar h1 { font-size: 18px; }
  .kpi strong { font-size: 20px; }
  th, td { padding: 8px 5px; }
  .hide-sm { display: none; }
  .split-row { grid-template-columns: 1fr 1fr; }
}
