/* Layout: sticky header with tabs, one working view at a time; department cards in a wrapping grid; details open in a dialog. */
:root {
  --bg: #eef1f0; --surface: #ffffff; --surface-2: #f5f7f6; --fg: #1b2422; --muted: #5b6965; --line: #d4dbd8; --grid: #e6ebe9;
  --accent: #1f6b4f; --accent-fg: #ffffff; --accent-soft: #dcece5;
  --crit: #b3261e; --crit-soft: #f8e1df; --warn: #9a5b00; --warn-soft: #fbecd2; --ok: #2d6a2f; --ok-soft: #e0efdc; --info: #285a8c; --info-soft: #e0eaf5;
  /* department series (validated categorical palette) */
  --d1: #2a78d6; --d2: #eb6834; --d3: #1baf7a; --d4: #eda100; --d5: #e87ba4; --d6: #008300; --d7: #6250d6; --d8: #e34948;
  --font-display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --r: 6px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #121816; --surface: #1a2220; --surface-2: #202a27; --fg: #e3eae7; --muted: #95a39e; --line: #2f3b37; --grid: #26302d;
  --accent: #5fbf95; --accent-fg: #0c1a14; --accent-soft: #1d3a2e;
  --crit: #f08a80; --crit-soft: #3d1d1a; --warn: #e8b05c; --warn-soft: #3a2b12; --ok: #8fcf8c; --ok-soft: #1d3320; --info: #8bb6e6; --info-soft: #1b2a3c;
  --d1: #3987e5; --d2: #d95926; --d3: #199e70; --d4: #c98500; --d5: #d55181; --d6: #008300; --d7: #9085e9; --d8: #e66767;
  color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #121816; --surface: #1a2220; --surface-2: #202a27; --fg: #e3eae7; --muted: #95a39e; --line: #2f3b37; --grid: #26302d;
  --accent: #5fbf95; --accent-fg: #0c1a14; --accent-soft: #1d3a2e;
  --crit: #f08a80; --crit-soft: #3d1d1a; --warn: #e8b05c; --warn-soft: #3a2b12; --ok: #8fcf8c; --ok-soft: #1d3320; --info: #8bb6e6; --info-soft: #1b2a3c;
  --d1: #3987e5; --d2: #d95926; --d3: #199e70; --d4: #c98500; --d5: #d55181; --d6: #008300; --d7: #9085e9; --d8: #e66767;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
[hidden] { display: none !important; }
img { max-width: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
a { color: var(--accent); }
.wrap { max-width: 1180px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
header { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.top { display: flex; align-items: center; gap: 12px; padding-block: 12px 4px; flex-wrap: wrap; }
.brand { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; line-height: 1; }
.brand small { display: block; font-family: var(--font-body); font-size: 12px; font-weight: 500; letter-spacing: .08em; color: var(--muted); margin-top: 3px; }
.top .spacer { flex: 1; }
.who { font-size: 13px; color: var(--muted); }
.who b { color: var(--fg); }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav.tabs a { padding: 10px 12px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 3px solid transparent; white-space: nowrap; }
nav.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }
nav.tabs a .n { font-family: var(--font-mono); font-size: 12px; background: var(--surface-2); border-radius: 10px; padding: 1px 6px; margin-left: 4px; }
nav.tabs a .n.alert { background: var(--crit-soft); color: var(--crit); }
main { padding-block: 20px 60px; display: grid; gap: 20px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; margin: 0; text-wrap: balance; line-height: 1.1; }
h1 { font-size: 30px; } h2 { font-size: 21px; } h3 { font-size: 17px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.stack { display: grid; gap: 10px; min-width: 0; }
button { font: inherit; font-weight: 600; font-size: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: var(--r); padding: 8px 14px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger { color: var(--crit); }
button.small { padding: 4px 10px; font-size: 13px; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select, input, textarea { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; width: 100%; min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 13px; font-weight: 600; padding: 5px 11px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.depts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.dept { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 10px; cursor: pointer; border-top: 4px solid var(--dc); text-align: left; font-weight: 400; }
.dept:hover { border-color: var(--muted); border-top-color: var(--dc); }
.dept h3 { font-size: 20px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 13px; color: var(--muted); }
.kv b { font-family: var(--font-mono); color: var(--fg); font-weight: 500; text-align: right; }
.kv b.crit { color: var(--crit); } .kv b.warn { color: var(--warn); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.item { display: grid; grid-template-columns: 6px 1fr auto; gap: 0 12px; padding: 12px 14px 12px 0; border-top: 1px solid var(--line); cursor: pointer; align-items: start; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); }
.item .stripe { align-self: stretch; background: var(--sc, transparent); }
.item .main { min-width: 0; display: grid; gap: 4px; }
.item .title { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; gap: 4px 12px; flex-wrap: wrap; }
.item .side { display: grid; gap: 6px; justify-items: end; text-align: right; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; letter-spacing: .02em; }
.p-crit { background: var(--crit-soft); color: var(--crit); } .p-warn { background: var(--warn-soft); color: var(--warn); }
.p-ok { background: var(--ok-soft); color: var(--ok); } .p-info { background: var(--info-soft); color: var(--info); }
.p-neutral { background: var(--surface-2); color: var(--muted); }
.dtag { font-size: 12px; font-weight: 600; color: var(--fg); }
.dtag::before, .sw { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; background: var(--dc); margin-right: 5px; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.group-h { padding: 10px 14px; background: var(--surface-2); font-family: var(--font-display); font-size: 16px; text-transform: uppercase; letter-spacing: .04em; border-top: 1px solid var(--line); display: flex; justify-content: space-between; }
.group-h:first-child { border-top: 0; }
.notice { padding: 10px 14px; border-radius: var(--r); background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { display: grid; gap: 2px; } .stat b { font-family: var(--font-display); font-size: 30px; line-height: 1; } .stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }
tfoot td { font-weight: 600; border-bottom: 0; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-family: var(--font-body); font-size: 11px; }
.legend { display: flex; gap: 6px 14px; flex-wrap: wrap; font-size: 13px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 14px rgb(0 0 0 / .15); min-width: 170px; z-index: 3; }
.tip .kv { font-size: 12px; }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--fg); padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: grid; gap: 14px; padding: 20px; }
.sect { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 10px; }
.lines { display: grid; gap: 6px; font-size: 14px; }
.line { display: flex; gap: 8px 12px; align-items: center; flex-wrap: wrap; padding: 6px 10px; background: var(--surface-2); border-radius: var(--r); }
.line .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.addrow { display: grid; grid-template-columns: 1.2fr .7fr 2fr auto; gap: 8px; align-items: end; }
.addrow.parts { grid-template-columns: 2fr .7fr auto; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photo { position: relative; width: 104px; height: 104px; border-radius: var(--r); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo button { position: absolute; top: 4px; right: 4px; padding: 0 6px; font-size: 12px; background: var(--surface); }
.photo .ph { display: grid; place-items: center; height: 100%; font-size: 11px; color: var(--muted); text-align: center; padding: 6px; }
.upl { display: grid; place-items: center; width: 104px; height: 104px; border: 1px dashed var(--muted); border-radius: var(--r); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; text-align: center; }
.upl input { display: none; }
#zoom { position: fixed; inset: 0; background: rgb(0 0 0 / .85); display: grid; place-items: center; z-index: 30; padding: 20px; }
#zoom img { max-width: 100%; max-height: 100%; }
.log { display: grid; gap: 8px; font-size: 13px; }
.log div { padding: 8px 10px; background: var(--surface-2); border-radius: var(--r); }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: var(--r); font-weight: 600; font-size: 14px; z-index: 40; }
@media (prefers-reduced-motion: no-preference) { .toast { animation: up .2s ease-out; } @keyframes up { from { transform: translate(-50%, 8px); opacity: 0; } } }
@media (max-width: 640px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .addrow, .addrow.parts { grid-template-columns: 1fr 1fr; }
  .addrow > :last-child { grid-column: 1 / -1; }
  .item { grid-template-columns: 6px 1fr; } .item .side { grid-column: 2; justify-items: start; text-align: left; display: flex; flex-wrap: wrap; }
  h1 { font-size: 26px; }
}

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 24px; display: grid; gap: 14px; }
.login .err { color: var(--crit); font-size: 14px; min-height: 1em; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 6px 20px rgb(0 0 0 / .15); display: grid; min-width: 190px; z-index: 8; }
.menu-pop button { border: 0; border-radius: 0; text-align: left; font-weight: 500; }
.menu-pop button:hover { background: var(--surface-2); }
