/* ============================================================================
   app.css — Q-Optimization

   A work tool that building operators read on office screens, so LIGHT is
   the default and dark is opt-in. The palette is the Quwa family: the cyan
   brand (#0b7592 on light, #19c8e8 on dark), the green arrow of the mark for
   "good", amber for "waiting", coral for "needs attention". Every colour is
   a token; nothing below hard-codes a hex.
   ========================================================================== */

:root {
  --bg: #f4f6f8;
  --bg-1: #ffffff;
  --bg-2: #eef2f5;
  --bg-3: #e2e8ee;
  --line: #d6dee6;
  --line-2: #b9c6d2;
  --ink: #10202b;
  --ink-2: #3b4d5b;
  --ink-3: #5d6f7d;
  --ink-4: #7c8c99;
  --brand: #0b7592;
  --brand-2: #0e8fb2;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3f8;
  --ok: #17845f;
  --ok-soft: #e1f4ec;
  --warn: #a8620a;
  --warn-soft: #fbf0dd;
  --bad: #c2412a;
  --bad-soft: #fbe6e1;
  --info: #5a4fcf;
  --info-soft: #ecebfb;
  --shadow: 0 1px 2px rgba(16, 32, 43, .06), 0 8px 24px -12px rgba(16, 32, 43, .18);
  --radius: 10px;
  --radius-sm: 6px;
  --top-bg: rgba(255, 255, 255, .92);
  --focus: 0 0 0 3px rgba(11, 117, 146, .35);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b0f16;
  --bg-1: #121825;
  --bg-2: #18202f;
  --bg-3: #1f2939;
  --line: rgba(150, 175, 205, .16);
  --line-2: rgba(150, 175, 205, .30);
  --ink: #f2f6fb;
  --ink-2: #c3cfdd;
  --ink-3: #93a3b6;
  --ink-4: #72839a;
  --brand: #19c8e8;
  --brand-2: #4fdcf6;
  --brand-ink: #04222b;
  --brand-soft: rgba(25, 200, 232, .12);
  --ok: #2fd3a7;
  --ok-soft: rgba(47, 211, 167, .12);
  --warn: #f0a23c;
  --warn-soft: rgba(240, 162, 60, .13);
  --bad: #f2684a;
  --bad-soft: rgba(242, 104, 74, .13);
  --info: #a79cff;
  --info-soft: rgba(142, 123, 255, .14);
  --shadow: 0 2px 6px rgba(0, 0, 0, .3), 0 22px 60px -22px rgba(0, 0, 0, .65);
  --top-bg: rgba(11, 15, 22, .9);
  --focus: 0 0 0 3px rgba(25, 200, 232, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75em; }
small, .small { font-size: .86rem; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: .88em; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 8px; z-index: 99; background: var(--bg-1); padding: 6px 10px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

/* ---------------------------------------------------------------- top bar -- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--top-bg); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1280px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; letter-spacing: .01em; }
.brand img { width: 28px; height: 28px; }
.brand span small { display: block; font-weight: 400; color: var(--ink-3); font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; }
.top nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.top nav a { color: var(--ink-2); padding: 6px 10px; border-radius: var(--radius-sm); }
.top nav a.on, .top nav a:hover { background: var(--bg-2); color: var(--ink); text-decoration: none; }
.top .me { display: flex; align-items: center; gap: 8px; }
.bell { position: relative; }
.bell .dot { position: absolute; top: -4px; right: -6px; background: var(--bad); color: #fff; font-size: .7rem; border-radius: 99px; padding: 0 5px; min-width: 18px; text-align: center; }

main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 80px; outline: none; }
.loading { color: var(--ink-3); padding: 40px 0; }

/* ------------------------------------------------------------ primitives -- */
.card { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card.flat { box-shadow: none; }
.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)); }
@media (max-width: 900px) { .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.crumbs { color: var(--ink-3); font-size: .88rem; margin-bottom: 6px; }
.crumbs a { color: var(--ink-3); }
.page-head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 0 0 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

button, .btn {
  font: inherit; cursor: pointer; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--bg-1); color: var(--ink);
  padding: 7px 14px; display: inline-flex; align-items: center; gap: 6px; line-height: 1.3;
}
button:hover, .btn:hover { background: var(--bg-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.primary:hover { background: var(--brand-2); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.small, .btn.small { padding: 4px 9px; font-size: .86rem; }
button:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: .88rem; color: var(--ink-2); margin-bottom: 4px; }
label .hint { font-weight: 400; color: var(--ink-3); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg-1);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 7px 10px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; }
.field { margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; color: var(--ink); }
.check input { margin-top: 4px; }
.form-error { color: var(--bad); background: var(--bad-soft); border-radius: var(--radius-sm); padding: 8px 12px; margin: 8px 0; }
.form-ok { color: var(--ok); background: var(--ok-soft); border-radius: var(--radius-sm); padding: 8px 12px; margin: 8px 0; }
.notice { background: var(--warn-soft); color: var(--ink); border-left: 3px solid var(--warn); border-radius: var(--radius-sm); padding: 10px 14px; margin: 10px 0; }
.notice.info { background: var(--brand-soft); border-left-color: var(--brand); }
.notice.bad { background: var(--bad-soft); border-left-color: var(--bad); }

/* ----------------------------------------------------------------- badges -- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; border-radius: 99px; padding: 2px 9px; background: var(--bg-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.pill-sev-critical { background: var(--bad); color: #fff; }
.pill-sev-high { background: var(--bad-soft); color: var(--bad); }
.pill-sev-medium { background: var(--warn-soft); color: var(--warn); }
.pill-sev-low { background: var(--bg-2); color: var(--ink-3); }

/* ------------------------------------------------------------------ table -- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-3); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; background: var(--bg-2); }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--bg-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- step rail -- */
.rail { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; margin: 6px 0 18px; }
.rail .st { position: relative; background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 9px 9px; min-height: 76px; cursor: pointer; }
.rail .st:hover { border-color: var(--line-2); }
.rail .st .n { font-size: .72rem; font-weight: 700; color: var(--ink-4); letter-spacing: .05em; }
.rail .st .t { font-size: .82rem; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.rail .st .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; border-radius: 0 0 var(--radius-sm) var(--radius-sm); background: var(--bg-3); }
.rail .st.in_progress .bar { background: var(--warn); }
.rail .st.done .bar { background: var(--ok); }
.rail .st.done .n::after { content: " \2713"; color: var(--ok); }
.rail .st.sel { border-color: var(--brand); box-shadow: var(--focus); }
.rail.mini { grid-template-columns: repeat(10, 1fr); gap: 3px; margin: 8px 0 0; }
.rail.mini span { height: 7px; border-radius: 2px; background: var(--bg-3); }
.rail.mini span.in_progress { background: var(--warn); }
.rail.mini span.done { background: var(--ok); }
@media (max-width: 900px) {
  .rail { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.progress-line { display: flex; gap: 14px; flex-wrap: wrap; color: var(--ink-3); font-size: .9rem; }
.progress-line b { color: var(--ink); }

.evidence { list-style: none; padding: 0; margin: 0; }
.evidence li { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: .92rem; }
.evidence li:last-child { border-bottom: 0; }
.evidence .mark { width: 18px; flex: 0 0 18px; text-align: center; font-weight: 700; }
.evidence .mark.ok { color: var(--ok); }
.evidence .mark.no { color: var(--warn); }
.evidence .mark.na { color: var(--ink-4); }
.evidence .v { margin-left: auto; color: var(--ink-2); text-align: right; }

/* ------------------------------------------------------------- AOB items -- */
.item { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-1); margin-bottom: 14px; box-shadow: var(--shadow); scroll-margin-top: 80px; }
.item.target { border-color: var(--brand); box-shadow: var(--focus); }
.item-head { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2); border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap; }
.item-head .seq { font-weight: 800; font-size: 1.05rem; min-width: 30px; }
.item-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.item-body > div { padding: 14px 16px; }
.item-body > div + div { border-left: 1px solid var(--line); }
@media (max-width: 900px) { .item-body { grid-template-columns: minmax(0, 1fr); } .item-body > div + div { border-left: 0; border-top: 1px solid var(--line); } }
.side-title { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin-bottom: 8px; }
dl.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 5px 12px; margin: 0; font-size: .93rem; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
@media (max-width: 600px) { dl.kv { grid-template-columns: minmax(0, 1fr); } dl.kv dt { margin-top: 6px; } }
.item-foot { border-top: 1px solid var(--line); padding: 10px 16px; }

.decisions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.decisions label { display: flex; gap: 8px; align-items: center; margin: 0; border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; font-weight: 600; color: var(--ink); }
.decisions label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.decisions input { margin: 0; }

.thread { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 8px; }
.msg { padding: 7px 10px; border-radius: var(--radius-sm); background: var(--bg-2); margin: 6px 0; font-size: .92rem; }
.msg.staff { background: var(--brand-soft); }
.msg .who { font-size: .8rem; color: var(--ink-3); margin-bottom: 2px; }

.history { font-size: .86rem; color: var(--ink-3); margin-top: 8px; }
.history li { margin: 3px 0; }

/* ---------------------------------------------------------------- charts -- */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }

/* ---------------------------------------------------------------- dialog -- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-1); color: var(--ink); padding: 0; width: min(720px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(8, 14, 20, .45); }
dialog .dh { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
dialog .dh h2 { margin: 0; font-size: 1.1rem; flex: 1; }
dialog .db { padding: 16px 18px; max-height: 70vh; overflow: auto; }
dialog .df { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: var(--bg-1); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------------------------------------------------------------- login -- */
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth .brand { justify-content: center; margin-bottom: 18px; font-size: 1.2rem; }
.auth .brand img { width: 40px; height: 40px; }

.stat { display: flex; flex-direction: column; }
.stat .big { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--ink-3); font-size: .86rem; }

.empty { color: var(--ink-3); padding: 18px; text-align: center; border: 1px dashed var(--line-2); border-radius: var(--radius); }

/* ---------------------------------------------------------------- report -- */
.report { max-width: 980px; }
.report h2 { margin-top: 26px; border-bottom: 2px solid var(--brand); padding-bottom: 4px; }
@media print {
  .top, .no-print, #toasts, .tabs, .crumbs { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main { padding: 0; max-width: none; }
  .card, .item { box-shadow: none; break-inside: avoid; }
  a { color: #000; }
  .report h2 { break-after: avoid; }
}
