/* plant-demo — control-room stylesheet (brief §4). One typeface, self-hosted; one accent; amber only for abnormal. */
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/IBMPlexSans-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
}

:root {
  --bg: #E9ECEF;
  --panel: #F7F8FA;
  --ink: #1B2430;
  --muted: #5C6674;
  --accent: #123E8A;
  --fill: #7FC4E8;
  --warn: #C8641E;
  --header-h: 40px;
  --ruler-h: 64px;
  --gap: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px; line-height: 1.35;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
h1, h2, h3 { font-weight: 600; margin: 0; }
h1 { font-size: 15px; }
h2 { font-size: 13px; margin-bottom: 4px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.secondary, .muted { color: var(--muted); }
.small { font-size: 11px; }
.tag-id { font-size: 10px; color: var(--muted); margin-left: 4px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.warn { color: var(--warn); }

button, .btn {
  font: inherit; font-weight: 600; padding: 4px 10px; cursor: pointer;
  color: var(--ink); background: var(--panel); border: 1px solid var(--muted); border-radius: 2px;
}
button:hover, .btn:hover { border-color: var(--ink); }
button.primary, button[aria-pressed="true"] { color: #fff; background: var(--accent); border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input, select {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--muted); border-radius: 2px; padding: 4px 6px;
}
label { color: var(--muted); }

/* ---------- login / simple pages ---------- */
.login-body { display: grid; place-items: center; overflow: auto; }
.login-card { background: var(--panel); border: 1px solid var(--muted); padding: 24px 28px; width: 360px; max-width: 92vw; }
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card label { display: block; margin: 12px 0 4px; }
.login-card input { width: 100%; padding: 7px 9px; }
.login-card button { width: 100%; margin-top: 16px; padding: 7px 14px; }
.form-error { color: var(--warn); margin: 12px 0 0; }

/* ---------- app frame ---------- */
.app { display: grid; grid-template-rows: var(--header-h) var(--ruler-h) 1fr; height: 100vh; gap: var(--gap); padding: var(--gap); }
.app-header {
  display: flex; align-items: center; gap: 16px; padding: 0 12px;
  background: var(--panel); border: 1px solid var(--muted);
}
.app-header .case { color: var(--muted); }
.app-header .cursor-time { margin-left: auto; font-weight: 600; font-size: 14px; }
.app-header .who { color: var(--muted); }
.app-header form { margin: 0; }
.app-header nav { display: flex; align-items: center; gap: 12px; }

/* ---------- ruler ---------- */
.ruler { display: flex; align-items: stretch; gap: 12px; padding: 6px 12px; background: var(--panel); border: 1px solid var(--muted); }
.ruler .controls { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.ruler .controls .speeds { display: flex; gap: 0; }
.ruler .controls .speeds button { border-radius: 0; margin-left: -1px; padding: 4px 8px; font-weight: 400; }
.ruler .controls .speeds button:first-child { border-radius: 2px 0 0 2px; margin-left: 0; }
.ruler .controls .speeds button:last-child { border-radius: 0 2px 2px 0; }
.ruler .controls .speeds button[aria-pressed="true"] { font-weight: 600; }
.ruler .controls .play { min-width: 64px; }
.ruler .axis { flex: 1 1 auto; position: relative; touch-action: none; cursor: ew-resize; user-select: none; }
.ruler .axis svg { width: 100%; height: 100%; display: block; }
.ruler .axis text { font-size: 11px; fill: var(--muted); }
.ruler .axis .track { stroke: var(--muted); stroke-width: 1; }
.ruler .axis .tick { stroke: var(--muted); stroke-width: 1; }
.ruler .axis .tick.minor { stroke-width: 0.5; }
.ruler .axis .cursor { stroke: var(--accent); stroke-width: 2; }
.ruler .axis .handle { fill: var(--accent); }
.ruler .axis .hit { fill: transparent; }

/* ---------- main ---------- */
.main { display: grid; grid-template-columns: 62fr 38fr; gap: var(--gap); min-height: 0; }
.schematic { background: var(--panel); border: 1px solid var(--muted); overflow: auto; min-height: 0; padding: 4px; }
.schematic svg { width: 100%; height: 100%; display: block; }
.period { background: var(--panel); border: 1px solid var(--muted); overflow: auto; min-height: 0; padding: 8px 12px; font-size: 12.5px; }

/* ---------- schematic SVG ---------- */
.schematic text { font-family: inherit; fill: var(--ink); font-size: 10px; }
.schematic .area-label { font-weight: 600; font-size: 11px; }
.schematic .area-ref { font-size: 8.5px; fill: var(--muted); }
.schematic .area-box { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.schematic .unit-box { fill: var(--panel); stroke: var(--ink); stroke-width: 1; }
.schematic .unit-title { font-weight: 600; font-size: 10px; }
.schematic .unit-code, .schematic .t-id { font-size: 8px; fill: var(--muted); }
.schematic .row-label { fill: var(--ink); font-size: 9px; }
.schematic .row-value { font-size: 9.5px; text-anchor: end; }
.schematic .row-sub { font-size: 8.5px; fill: var(--muted); text-anchor: end; }
.schematic .level-fill { fill: var(--fill); }
.schematic .level-line { stroke: var(--accent); stroke-width: 1.5; }
.schematic .flow { stroke: var(--muted); stroke-width: 1.2; fill: none; marker-end: url(#arrow); }
.schematic .flow.thin { stroke-width: 0.8; }
.schematic .badge-box { fill: var(--panel); stroke: var(--muted); stroke-width: 0.6; }
.schematic .badge-name { font-size: 8.5px; }
.schematic .badge-value { font-size: 9.5px; font-weight: 600; }
.schematic .badge-sub { font-size: 8.5px; fill: var(--muted); }
.schematic .flag { font-size: 8px; font-weight: 600; fill: var(--warn); }
.schematic .abnormal .badge-box, .schematic .abnormal .unit-box { stroke: var(--warn); stroke-width: 1.2; }
.schematic .abnormal .row-value, .schematic .abnormal .badge-value { fill: var(--warn); }
.schematic .clickable { cursor: pointer; }
.schematic .clickable:hover .badge-box, .schematic .clickable:hover .row-hit { stroke: var(--accent); }
.schematic .row-hit { fill: transparent; stroke: none; }
.schematic .clickable:hover .row-hit { fill: var(--bg); }
.schematic .note { font-size: 8.5px; fill: var(--muted); }
.schematic .truck { fill: var(--panel); stroke: var(--ink); stroke-width: 1; }
.schematic .stub { fill: var(--bg); stroke: var(--muted); stroke-width: 0.8; }
.schematic .level-fill, .schematic .level-line { transition: y 150ms ease-out, height 150ms ease-out, y1 150ms ease-out, y2 150ms ease-out; }

/* ---------- period panel ---------- */
.period h2 { display: flex; align-items: baseline; gap: 8px; }
.period .day-head { margin-bottom: 6px; }
.period .day-head .big { font-size: 15px; font-weight: 600; }
.period table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.period th { text-align: left; font-weight: 400; color: var(--muted); font-size: 11px; padding: 2px 4px; border-bottom: 1px solid var(--muted); }
.period th.num { text-align: right; }
.period td { padding: 1px 4px; border-bottom: 1px solid var(--bg); vertical-align: baseline; white-space: nowrap; }
.period th { white-space: nowrap; }
.period td.num { font-weight: 600; }
.period tr.total td { border-top: 1px solid var(--muted); }
.period tr.clickable { cursor: pointer; }
.period tr.clickable:hover td { background: var(--bg); }
.period .unit { color: var(--muted); font-weight: 400; margin-left: 3px; }
.period .planned td { color: var(--muted); font-weight: 400; }
.period .balance-line { display: flex; justify-content: space-between; padding: 2px 4px; border-bottom: 1px solid var(--bg); }
.period .balance-line.residual { font-weight: 600; color: var(--warn); border-top: 1px solid var(--muted); }
.period .approx { color: var(--muted); font-size: 11px; margin: 0 0 4px; }

/* ---------- trend chart ---------- */
.trend-backdrop { position: fixed; inset: 0; background: rgba(27, 36, 48, 0.25); display: grid; place-items: center; z-index: 10; }
.trend-backdrop[hidden] { display: none; }
.trend { background: var(--panel); border: 1px solid var(--ink); padding: 12px 14px; width: 720px; max-width: 96vw; }
.trend header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.trend header h2 { margin: 0; }
.trend header .close { margin-left: auto; }
.trend canvas { display: block; width: 100%; height: 280px; cursor: crosshair; }
.trend .legend { color: var(--muted); font-size: 11px; margin-top: 6px; display: flex; gap: 16px; }
.trend .legend .sw { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 4px; background: var(--ink); }
.trend .legend .sw.warn { background: var(--warn); }
.trend .legend .sw.accent { background: var(--accent); }

/* ---------- users page ---------- */
.users-page { display: grid; grid-template-rows: var(--header-h) 1fr; height: 100vh; gap: var(--gap); padding: var(--gap); }
.users-body { background: var(--panel); border: 1px solid var(--muted); padding: 16px 20px; overflow: auto; }
.users-body table { border-collapse: collapse; margin: 12px 0 20px; min-width: 620px; }
.users-body th { text-align: left; font-weight: 400; color: var(--muted); font-size: 11px; padding: 4px 8px; border-bottom: 1px solid var(--muted); }
.users-body td { padding: 5px 8px; border-bottom: 1px solid var(--bg); }
.users-body td .actions { display: flex; gap: 6px; align-items: center; }
.users-body form.inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.users-body form.inline label { display: flex; flex-direction: column; gap: 3px; }
.users-body .msg { margin-top: 10px; min-height: 18px; }
.users-body .msg.error { color: var(--warn); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
