:root {
  --navy: #07316A; --navy-2: #0b3f86; --navy-ink: #0a2550; --gold: #F2B71C; --gold-soft: #fdf3d6;
  --bg: #f4f6fa; --card: #fff; --ink: #14213d; --muted: #5b6475; --line: #dfe4ec; --line-2: #eef1f6;
  --ok: #1f7a4d; --ok-bg: #e5f4ec; --warn: #9a6200; --warn-bg: #fdf1d8; --bad: #b3261e; --bad-bg: #fbe7e5; --info-bg: #e7eef9;
  --radius: 10px; --shadow: 0 1px 2px rgba(10,37,80,.06), 0 2px 8px rgba(10,37,80,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--navy-2); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ----- shell ----- */
.topbar { background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px 20px; position: sticky; top: 0; z-index: 20; }
.topbar .brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.topbar .brand img { height: 38px; width: auto; display: block; }
.topbar .app-name { color: var(--navy); font-weight: 700; font-size: 15px; border-left: 2px solid var(--gold); padding-left: 12px; letter-spacing: .02em; }
.topbar .spacer { flex: 1; }
.topbar .who { text-align: right; line-height: 1.2; }
.topbar .who b { display: block; font-size: 13px; }
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 59px); }
.side { background: var(--navy); color: #cfd9ea; padding: 14px 10px; }
.side a { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #dfe7f4; text-decoration: none; padding: 9px 12px; border-radius: 8px; margin: 2px 0; font-weight: 500; border-left: 3px solid transparent; }
.side a:hover { background: rgba(255,255,255,.07); }
.side a.on { background: rgba(255,255,255,.12); color: #fff; border-left-color: var(--gold); }
.side .sect { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8fa3c4; margin: 16px 12px 4px; }
.side .count { background: var(--gold); color: var(--navy-ink); font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; }
main { padding: 22px 26px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.crumb { font-size: 12px; margin-bottom: 4px; }
.crumb a { text-decoration: none; }

/* ----- cards & grid ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 14px 18px 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; }
.stat .v { font-size: 26px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }
a.stat:hover { border-color: var(--navy-2); }
.stat.hot { border-color: var(--gold); background: var(--gold-soft); }

/* ----- tables ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #fafbfd; font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #f8fafd; }
tr.click { cursor: pointer; }
td .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ----- pills ----- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--navy-2); }
.pill.gold { background: var(--gold); color: var(--navy-ink); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; color: var(--navy); border: 1px solid #c9d5ea; border-radius: 5px; padding: 0 5px; }

/* ----- forms ----- */
label { display: block; font-weight: 600; font-size: 12.5px; margin: 0 0 4px; color: #33405a; }
.field { margin-bottom: 12px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 3px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid #cdd5e1; border-radius: 8px; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,63,134,.25); border-color: var(--navy-2); }
input[type=checkbox] { width: auto; margin: 0 6px 0 0; vertical-align: -2px; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: flex-start; gap: 4px; font-weight: 500; font-size: 13.5px; margin: 6px 0; }
.check small { display: block; color: var(--muted); font-weight: 400; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0,1fr)); }
.row3 { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0,1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 140px; padding: 7px 9px; }
.filters input[type=search] { min-width: 220px; }
.filters input[type=checkbox] { min-width: 0; }
.filters .check { margin: 0 6px; white-space: nowrap; }
.inline-add { display: flex; gap: 8px; }

/* ----- buttons ----- */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; border: 1px solid #c3cddc; background: #fff; color: var(--navy); border-radius: 8px; padding: 8px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--navy-2); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--navy-ink); }
.btn.danger { color: var(--bad); border-color: #e7b4b0; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--navy); border-bottom-color: var(--gold); }

/* ----- detail ----- */
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 500; }
.meter { height: 8px; border-radius: 6px; background: var(--line-2); overflow: hidden; display: flex; margin: 8px 0 6px; }
.meter span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--navy-2); }
.timeline .when { color: var(--muted); font-size: 12px; }
.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; background: var(--info-bg); color: var(--navy-ink); }
.notice.warn { background: var(--warn-bg); color: #6b4500; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }

/* ----- modal, toast ----- */
.modal-back { position: fixed; inset: 0; background: rgba(8,22,48,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h2 { margin: 0; flex: 1; }
.modal header button { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal .body { padding: 16px 20px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.modal .err { color: var(--bad); margin-right: auto; align-self: center; font-weight: 600; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--navy-ink); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; font-weight: 500; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); }

/* ----- login ----- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(180deg, #fff 0, #fff 45%, var(--bg) 45%); }
.login .box { width: 100%; max-width: 400px; }
.login .logo { text-align: center; margin-bottom: 18px; }
.login .logo img { max-width: 100%; height: auto; width: 360px; }
.login .card { padding: 24px; border-top: 4px solid var(--navy); }
.login h1 { font-size: 18px; margin-bottom: 4px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; gap: 4px; padding: 8px; position: sticky; top: 55px; z-index: 15; }
  .side .sect { display: none; }
  .side a { white-space: nowrap; margin: 0; border-left: 0; border-bottom: 3px solid transparent; border-radius: 6px; }
  .side a.on { border-bottom-color: var(--gold); }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .g2 { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .topbar { padding: 8px 16px; }
  .topbar .brand img { height: 28px; }
  .topbar .app-name { display: none; }
  .topbar .who .muted { display: none; }
}
@media (max-width: 560px) {
  .row, .row3 { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { margin-top: 6px; }
  .filters input, .filters select, .filters input[type=search] { min-width: 0; flex: 1 1 140px; }
}
@media (max-width: 700px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
  table.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: 0; padding: 3px 0; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  table.stack td:first-child { display: block; text-align: left; padding-bottom: 4px; }
  table.stack td:first-child::before, table.stack td.empty::before { content: none; }
  table.stack td:empty, table.stack td[data-label=""]:not(:has(*)) { display: none; }
  table.stack td.act { justify-content: flex-end; padding-top: 6px; }
  table.stack td.act::before { content: none; }
  table.stack td.empty { display: block; text-align: center; }
}
@media print {
  .topbar, .side, .actions, .filters, .btn { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; }
}
