/* Tokens from apps/checklist/DESIGN.md. Status = strong colour + soft tint + text label, never colour alone. */
:root {
  --bg: #f4f5f7; --surface: #fff; --surface-2: #f8f9fb; --ink: #14171f; --muted: #5d6575; --line: #e1e4ea;
  --accent: #2f5bea; --on-accent: #fff; --shadow: 0 10px 30px rgba(20, 23, 31, .14);
  --pass: #0e7c4a; --pass-soft: #e2f4ea; --fail: #c2261c; --fail-soft: #fce6e4;
  --waiting_input: #a35a00; --waiting_input-soft: #fff1da; --waiting_verify: #1f5fbf; --waiting_verify-soft: #e3edfc;
  --in_progress: #6b3fc4; --in_progress-soft: #eee7fb; --todo: #5d6575; --todo-soft: #edeff3; --na: #4a5263; --na-soft: #f1f2f4;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117; --surface: #161b24; --surface-2: #1c2230; --ink: #e8ecf3; --muted: #9aa3b4; --line: #2a3242;
    --accent: #7b9bff; --on-accent: #0e1117; --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --pass: #4fd394; --pass-soft: #12301f; --fail: #ff7b70; --fail-soft: #3a1714; --waiting_input: #f3b65b; --waiting_input-soft: #33250f;
    --waiting_verify: #82adff; --waiting_verify-soft: #15243d; --in_progress: #b99bff; --in_progress-soft: #241b3b;
    --todo: #a3abba; --todo-soft: #232a37; --na: #aab2c0; --na-soft: #1f2530; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono, code { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.pad { padding: 24px 0; }
.shell { max-width: 1200px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right)) 80px max(16px, env(safe-area-inset-left)); }
.shell:focus { outline: none; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
  padding: 10px max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--on-accent); font-size: 15px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a.active, .nav a:hover { background: var(--surface-2); color: var(--ink); }
.me { margin-left: auto; color: var(--muted); display: flex; gap: 8px; align-items: center; }

/* Buttons and forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--fail); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=url], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
textarea { min-height: 72px; resize: vertical; }
.field { margin-bottom: 12px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.error { color: var(--fail); font-weight: 600; min-height: 1.2em; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; gap: 6px; align-items: center; font-weight: 500; color: var(--ink); font-size: 13px; margin: 0; }

/* Cards and headings */
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: space-between; margin: 4px 0 18px; }
.page-head h1 { font-size: 24px; line-height: 1.2; margin: 0; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.stack > * + * { margin-top: 16px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .03em; }
.badge.demo { background: var(--waiting_input-soft); color: var(--waiting_input); }
.badge.code { background: var(--ink); color: var(--surface); font-family: var(--mono); }
.tag { display: inline-block; padding: 2px 8px; margin: 2px 4px 2px 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; border: 1px dashed var(--line); border-radius: 14px; }

/* Status chips */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.pass { background: var(--pass-soft); color: var(--pass); } .chip.fail { background: var(--fail-soft); color: var(--fail); }
.chip.waiting_input { background: var(--waiting_input-soft); color: var(--waiting_input); }
.chip.waiting_verify { background: var(--waiting_verify-soft); color: var(--waiting_verify); }
.chip.in_progress { background: var(--in_progress-soft); color: var(--in_progress); }
.chip.todo { background: var(--todo-soft); color: var(--todo); } .chip.na { background: var(--na-soft); color: var(--na); }
.chip.na.pending { outline: 1px dashed var(--na); }

/* Progress */
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--todo-soft); }
.bar span { display: block; height: 100%; }
.bar .pass { background: var(--pass); } .bar .waiting_verify { background: var(--waiting_verify); } .bar .in_progress { background: var(--in_progress); }
.bar .waiting_input { background: var(--waiting_input); } .bar .fail { background: var(--fail); }
.progress-line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.progress-line strong { font-size: 15px; }
.counters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.counter { display: inline-flex; gap: 6px; align-items: baseline; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }
.counter b { font-size: 14px; }
.counter.alert { border-color: var(--fail); color: var(--fail); }

/* Dashboard */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select, .filters select { width: auto; max-width: 100%; }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
@media (max-width: 400px) { .apps { grid-template-columns: 1fr; } }
.app-card { display: flex; flex-direction: column; gap: 12px; color: inherit; text-decoration: none; }
.app-card:hover { border-color: var(--accent); }
.app-top { display: flex; gap: 10px; align-items: center; }
.app-top h3 { margin: 0; font-size: 16px; line-height: 1.25; }
.app-meta { font-size: 12px; color: var(--muted); }
.ready { display: inline-flex; gap: 6px; align-items: center; font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 8px; }
.ready.yes { background: var(--pass-soft); color: var(--pass); } .ready.no { background: var(--surface-2); color: var(--muted); }
.ready.approved { background: var(--pass); color: var(--surface); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.table tr.clickable { cursor: pointer; } .table tr.clickable:hover td { background: var(--surface-2); }
.scroll-x { overflow-x: auto; }

/* Build page */
.summary { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 14px; }
@media (max-width: 860px) { .summary { grid-template-columns: 1fr; } }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 16px; margin-top: 14px; font-size: 13px; }
.facts dt { color: var(--muted); font-size: 12px; } .facts dd { margin: 0; overflow-wrap: anywhere; }
.handover h2 { display: flex; gap: 8px; align-items: center; }
.handover ul { margin: 6px 0 12px; padding-left: 18px; }
.filters { position: sticky; top: 52px; z-index: 10; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0; background: var(--bg); }
.filters input[type=search] { max-width: 260px; }
.filters select { width: auto; }
.status-filter { display: flex; flex-wrap: wrap; gap: 4px; }
.status-filter button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.status-filter button[aria-pressed=true] { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.group { margin-top: 14px; }
.group summary { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; cursor: pointer; list-style: none; padding: 10px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; font-weight: 700; }
.group summary::-webkit-details-marker { display: none; }
.group summary::before { content: "▸"; color: var(--muted); }
.group[open] summary::before { content: "▾"; }
.group .group-count { margin-left: auto; font-weight: 500; font-size: 12px; color: var(--muted); }
.items { margin-top: 6px; display: grid; gap: 6px; }
.item { display: grid; grid-template-columns: 140px minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.item:hover { border-color: var(--accent); }
.item .title { font-weight: 600; }
.item .sub { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.item .right { display: flex; gap: 6px; align-items: center; }
.item.optional .title::after { content: " · tùy chọn"; color: var(--muted); font-weight: 400; font-size: 12px; }
@media (max-width: 640px) { .item { grid-template-columns: 1fr; } .item .sub { grid-column: 1; } }
.dots { display: inline-flex; gap: 3px; }
.dot { width: 10px; height: 10px; border-radius: 3px; background: var(--todo-soft); border: 1px solid var(--line); }
.dot.pass { background: var(--pass); border-color: var(--pass); } .dot.fail { background: var(--fail); border-color: var(--fail); }
.dot.waiting_input { background: var(--waiting_input); border-color: var(--waiting_input); } .dot.waiting_verify { background: var(--waiting_verify); border-color: var(--waiting_verify); }
.dot.in_progress { background: var(--in_progress); border-color: var(--in_progress); } .dot.na { background: transparent; border-style: dashed; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 18, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(580px, 100vw); z-index: 41; background: var(--surface); box-shadow: var(--shadow);
  display: flex; flex-direction: column; }
.drawer-head { display: flex; gap: 10px; align-items: start; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 17px; margin: 4px 0; }
.drawer-head .close { margin-left: auto; }
.drawer-body { overflow-y: auto; padding: 16px; flex: 1; }
.drawer section + section { margin-top: 22px; }
.drawer h3 { font-size: 14px; margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.rule { font-size: 12px; padding: 8px 10px; border-radius: 8px; background: var(--waiting_verify-soft); color: var(--ink); margin-bottom: 10px; }
.steps { display: grid; gap: 6px; }
.step { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface-2); }
.step:hover { border-color: var(--accent); }
.evidence { display: grid; gap: 8px; }
.evidence-item { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
.evidence-item img { display: block; max-width: 100%; max-height: 220px; margin-top: 6px; border-radius: 6px; border: 1px solid var(--line); }
.evidence-item pre { white-space: pre-wrap; max-height: 160px; overflow: auto; background: var(--surface-2); padding: 6px; border-radius: 6px; margin: 6px 0 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.tabs button[aria-selected=true] { background: var(--ink); color: var(--surface); }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; font-size: 13px; }
.timeline li { border-left: 3px solid var(--line); padding-left: 10px; }
.timeline .who { font-weight: 600; } .timeline .agent { color: var(--in_progress); font-size: 11px; font-weight: 700; }
.diff { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }

/* Login */
.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { font-size: 22px; margin: 0 0 4px; }

/* Agent guide */
.copy-box { position: relative; }
.copy-box pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; margin: 0; }
.copy-box .btn { position: absolute; top: 8px; right: 8px; }
.steps-list { padding-left: 20px; } .steps-list li { margin-bottom: 6px; }
.secret-once { padding: 12px; border-radius: 10px; background: var(--waiting_input-soft); border: 1px solid var(--waiting_input); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; z-index: 60;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 600; transition: .18s; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--fail); color: #fff; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
