:root {
  --bg: #f5f5f4; --surface: #fff; --sunken: #f0efed; --line: #e4e3e0; --text: #1c1b19; --muted: #6b6a66;
  --primary: #c8372d; --on-primary: #fff; --ok: #1f7a4d; --warn: #9a5b00; --auto: #2d5fa8; --mcp: #6b4bb0;
  --radius: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211; --surface: #1c1c1a; --sunken: #252523; --line: #2f2f2c; --text: #f2f1ee; --muted: #a3a29d;
    --primary: #e0675c; --on-primary: #fff; --ok: #5cc28d; --warn: #e2a64f; --auto: #7aa7e8; --mcp: #b29ae8;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--sunken); padding: 1px 5px; border-radius: 5px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; min-height: 34px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, tr:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea { min-height: 70px; resize: vertical; }
button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; min-height: 32px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
button.danger { color: var(--primary); }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--primary); }
button.seg { border-radius: 999px; }
button.seg.on { background: var(--text); color: var(--bg); border-color: var(--text); }
button:disabled { opacity: .45; cursor: default; }
input.box, .check input { width: 18px; min-height: 18px; height: 18px; accent-color: var(--primary); margin: 0; }

/* Khung: thanh bên trái trên máy tính, thanh ngang trên điện thoại */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
aside { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.brand span { margin-left: 6px; font-weight: 600; font-size: 12px; color: var(--primary); text-transform: uppercase; letter-spacing: .06em; }
.brand.big { font-size: 22px; margin-bottom: 4px; }
nav { display: grid; gap: 14px; }
.glabel { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 0 10px 4px; }
nav a { display: block; color: var(--text); padding: 7px 10px; border-radius: 8px; }
nav a:hover { background: var(--sunken); text-decoration: none; }
nav a.on { background: var(--sunken); font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
aside .me { margin-top: auto; display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; padding: 0 10px; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  aside { position: sticky; z-index: 5; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  nav { display: flex; gap: 2px; overflow-x: auto; order: 3; width: 100%; }
  .glabel { display: none; }
  .group { display: contents; }
  nav a { white-space: nowrap; }
  nav a.on { box-shadow: inset 0 -2px 0 var(--primary); }
  aside .me { margin: 0 0 0 auto; gap: 10px; padding: 0; }
}

main { padding: 28px 32px 60px; max-width: 1280px; width: 100%; }
@media (max-width: 900px) { main { padding: 18px 16px 48px; } }
h1 { font-size: 24px; letter-spacing: -.01em; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 28px 0 10px; }
.card h2 { margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 120px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; margin-top: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; overflow-wrap: anywhere; }
.stat { color: var(--muted); }
.stat b { color: var(--text); }
.stat.todo { border-color: var(--primary); }
.stat.todo b { color: var(--primary); }
a.stat:hover { text-decoration: none; border-color: var(--muted); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.chart svg { width: 100%; height: 70px; display: block; margin: 6px 0 2px; }
.chart rect { fill: var(--primary); opacity: .85; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.ok { background: var(--ok); }
pre.report { white-space: pre-wrap; font: 13px/1.55 inherit; font-family: inherit; background: var(--sunken); border-radius: 8px; padding: 12px; margin: 0 0 6px; }
.feed { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.meter { width: 120px; height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--primary); }

table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.plain { border: 0; background: none; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.plain td { padding: 6px 4px; }
th { font-weight: 600; color: var(--muted); font-size: 12px; background: var(--sunken); }
tbody tr:last-child td { border-bottom: 0; }
tr.sel td { background: var(--sunken); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--sunken); }
tr.undone td { opacity: .55; }
td.wrap { max-width: 440px; overflow-wrap: anywhere; }
@media (max-width: 700px) { table { display: block; overflow-x: auto; } }

.split { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.list { max-height: calc(100vh - 200px); overflow: auto; border-radius: var(--radius); }
#map { height: 360px; border-radius: 10px; border: 1px solid var(--line); }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.form .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form { grid-template-columns: 1fr; } }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; }
.center { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 16px; }
.login { max-width: 360px; padding: 28px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--sunken); font-size: 12px; white-space: nowrap; }
.pill.bad { color: var(--primary); }
.pill.good { color: var(--ok); }
.pill.auto { color: var(--auto); }
.pill.mcp { color: var(--mcp); }
.pill.human { color: var(--text); }
