:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1a2230; --muted: #5d6878; --line: #dfe3ea;
  --accent: #0b5cad; --accent-ink: #ffffff; --code-bg: #0f1722; --code-ink: #e6edf5;
  --low: #1f7a4d; --low-bg: #e3f4ea; --med: #8a5a00; --med-bg: #fdf1d6; --high: #b3261e; --high-bg: #fde7e5;
  --warn-bg: #fff6e0; --warn-line: #e5b84a; --sel: #e7f0fb;
  --font: "Leelawadee UI", "Noto Sans Thai", "Segoe UI", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --panel: #19212b; --ink: #e7ecf2; --muted: #9aa6b5; --line: #2b3643;
    --accent: #6cb0f5; --accent-ink: #0b1622; --code-bg: #0b1017; --code-ink: #dbe5f0;
    --low: #6fd3a0; --low-bg: #163526; --med: #f0c264; --med-bg: #3a2f12; --high: #ff9a92; --high-bg: #43201d;
    --warn-bg: #33290f; --warn-line: #8a6d1f; --sel: #1f3147;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.6 var(--font); color: var(--ink); background: var(--bg); }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* lock screen */
.lock { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.lock-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: grid; gap: 10px; }
.lock-card h1 { margin: 0; font-size: 26px; }
.lock-card p { margin: 0; color: var(--muted); }
.lock-card label { margin-top: 10px; font-weight: 600; }
.lock-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-family: var(--mono); letter-spacing: 1px; }
.lock-card button { padding: 10px 12px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.lock-card button:disabled { opacity: .6; cursor: progress; }
.lock-msg { min-height: 1.5em; color: var(--high) !important; }
.fine { font-size: 13px; }

/* shell */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; }
.top select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); max-width: 100%; }
.top nav { margin-left: auto; display: flex; gap: 6px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.ghost:hover { background: var(--sel); }
.layout { display: grid; grid-template-columns: 400px minmax(0, 1fr); height: calc(100vh - 53px); }
.side { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.search { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.search textarea { width: 100%; resize: vertical; min-height: 40px; max-height: 220px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters select { flex: 1 1 100px; min-width: 0; padding: 5px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 13px; }
.count { font-size: 13px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.list li { border-bottom: 1px solid var(--line); }
.list button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 10px 12px; }
.list button:hover { background: var(--bg); }
.list button.on { background: var(--sel); }
.list .rid { font-family: var(--mono); font-weight: 700; margin-right: 6px; }
.list .ttl { display: block; font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.list .miss { padding: 10px 12px; color: var(--high); font-size: 14px; overflow-wrap: anywhere; }
.tags { display: inline-flex; gap: 4px; flex-wrap: wrap; vertical-align: middle; }
.tag { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.low { color: var(--low); background: var(--low-bg); border-color: transparent; }
.tag.med { color: var(--med); background: var(--med-bg); border-color: transparent; }
.tag.high { color: var(--high); background: var(--high-bg); border-color: transparent; }

/* detail */
.detail { overflow: auto; padding: 22px 28px 60px; min-width: 0; }
.detail .empty { color: var(--muted); max-width: 60ch; }
.detail h1 { font-size: 21px; line-height: 1.4; margin: 6px 0 10px; overflow-wrap: anywhere; }
.detail h2 { font-size: 16px; margin: 26px 0 8px; display: flex; align-items: center; gap: 8px; }
.detail h2 .n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; }
.crumb { color: var(--muted); font-size: 13px; }
.back { display: none; margin-bottom: 10px; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 12px 0; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.box { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); margin: 10px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.box.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.box b { display: block; margin-bottom: 2px; }
.steps { margin: 0; padding-left: 22px; }
.steps li { margin: 8px 0; overflow-wrap: anywhere; }
.cmd { position: relative; margin: 6px 0 2px; }
.cmd pre { margin: 0; padding: 10px 64px 10px 12px; background: var(--code-bg); color: var(--code-ink); border-radius: 8px; font: 13px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.cmd button { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid #3a4656; background: #1c2734; color: #dbe5f0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.tabs button { padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); text-align: left; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tabs small { display: block; font-size: 12px; opacity: .85; }
details { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin: 8px 0; }
details summary { padding: 9px 14px; cursor: pointer; font-weight: 600; }
details .body { padding: 0 14px 12px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.others { display: flex; gap: 6px; flex-wrap: wrap; }
.others button { font-size: 13px; }
.actions { display: flex; gap: 6px; margin: 4px 0 0; }
.note { color: var(--muted); font-size: 13px; }

.guide { width: min(760px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 22px 26px; }
.guide::backdrop { background: rgba(0, 0, 0, .45); }
.guide h2 { margin-top: 0; }
.guide li { margin: 6px 0; }
.guide .close { float: right; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 7px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .15s; font-size: 14px; }
.toast.on { opacity: 1; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { border-right: 0; }
  .list { max-height: none; }
  body.viewing .side { display: none; }
  body:not(.viewing) .detail { display: none; }
  .back { display: inline-block; }
  .detail { padding: 16px 16px 60px; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { margin-top: 6px; }
}
@media print {
  .top, .side, .actions, .cmd button, .back, .tabs { display: none !important; }
  .layout { display: block; height: auto; }
  .detail { overflow: visible; padding: 0; }
  .cmd pre { background: #fff; color: #000; border: 1px solid #999; }
  details { break-inside: avoid; }
  .plan { display: block !important; }
}

/* references */
.refs ul { margin: 2px 0 10px; padding-left: 22px; }
.refs li { margin: 5px 0; overflow-wrap: anywhere; }
.refs a { color: var(--accent); }
.refs .url { font-size: 12px; color: var(--muted); }
@media print { .refs a::after { content: " (" attr(href) ")"; font-size: 11px; } .refs .url { display: none; } }
