:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #5d6b7c;
  --line: #e2e6ec;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --brand-soft: #e8f0f8;
  --ok: #1e7a4c;
  --ok-soft: #e4f4ec;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: 'Be Vietnam Pro', -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1a2029; --ink: #e6eaf0; --muted: #9aa6b5; --line: #2a323e;
    --brand: #5b9bd5; --brand-ink: #0d1520; --brand-soft: #1d2b3a;
    --ok: #5cc493; --ok-soft: #173326; --warn: #f0b356; --warn-soft: #34290f; --bad: #f08a80; --bad-soft: #3a1c1a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Bố cục */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 700; line-height: 1.2; padding: 0 8px 18px; }
#nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
#nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
#nav a:hover { background: var(--bg); }
#nav a.active { background: var(--brand-soft); color: var(--brand); }
#nav .group { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 14px 10px 4px; }
.count { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; min-width: 20px; text-align: center; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 8px 0; }
.guide-link { display: block; font-size: 13px; font-weight: 600; text-decoration: none; margin-bottom: 8px; }
.me { font-size: 13px; margin-bottom: 8px; }
.main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* Thành phần */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.alert b { color: var(--bad); }

.btn { appearance: none; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.active { color: var(--brand); border-color: var(--brand); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.verified, .badge.approved, .badge.executed, .badge.active, .badge.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.draft, .badge.proposed, .badge.pending, .badge.open { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.outdated, .badge.rejected, .badge.failed, .badge.revoked, .badge.superseded { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

/* Hỏi đáp */
.ask-box { display: flex; gap: 8px; }
.ask-box textarea { min-height: 56px; }
.answer { white-space: normal; }
.answer p { margin: 0 0 8px; }
.answer ul { margin: 0 0 8px 18px; padding: 0; }
.cite { display: inline-block; font-size: 11px; font-weight: 700; color: var(--brand); background: var(--brand-soft); border-radius: 5px; padding: 0 5px; margin: 0 1px; cursor: pointer; vertical-align: 1px; }
.sources { display: grid; gap: 8px; margin-top: 12px; }
.source { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.source:hover { border-color: var(--brand); }
.source .t { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 10px; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }
.pre { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 12px; max-height: 50vh; overflow: auto; font-size: 14px; }

/* Đăng nhập */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; }

/* Hộp thoại và thông báo */
.modal { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-box { background: var(--panel); border-radius: 12px; width: 100%; max-width: 760px; max-height: 90vh; overflow: auto; padding: 22px; position: relative; }
.modal-x { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 26px; color: var(--muted); cursor: pointer; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: 90vw; }
.toast.error { background: var(--bad); color: #fff; }


/* Hội thoại */
.chat { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.conv-side { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; padding: 14px; }
.conv-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.conv { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv:hover { background: var(--bg); }
.conv.active { background: var(--brand-soft); color: var(--brand); }
.conv-del { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; opacity: 0; }
.conv:hover .conv-del, .conv.active .conv-del { opacity: 1; }
.btn.ghost.on { background: var(--brand-soft); }
details.sources summary, details.version summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
details.version { border-bottom: 1px solid var(--line); padding: 10px 0; }
textarea.tall { min-height: 340px; }
#me { cursor: pointer; }
#me:hover b { text-decoration: underline; }

/* Kéo thả file */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 8px; }
.drop.over, .drop:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* Biểu đồ cột */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 8px; overflow-x: auto; }
.bar-col { flex: 1 0 22px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar { width: 100%; max-width: 28px; min-height: 2px; background: var(--brand); border-radius: 4px 4px 0 0; }
.bar-col span { font-size: 10px; color: var(--muted); }

.code-wrap { margin-bottom: 12px; }
.code-wrap .pre { margin: 0 0 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; word-break: break-all; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.main { min-width: 0; }
@media (max-width: 860px) {
  .chat { grid-template-columns: minmax(0, 1fr); }
  .conv-side { position: static; max-height: 220px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; padding: 12px 16px; }
  .brand { padding-bottom: 10px; }
  #nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
  #nav a { white-space: nowrap; }
  #nav .group { display: none; }
  .side-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; margin-top: 8px; }
  .me { margin: 0; }
  .main { padding: 18px 16px 40px; }
  .grid.two { grid-template-columns: 1fr; }
}
