:root {
  --bg: #f1ede6;
  --ink: #23252f;
  --muted: #666a78;
  --panel: #ffffff;
  --panel-2: #f8f6f2;
  --line: #e0dbd1;
  --warn-bg: #fff4d6;
  --warn-line: #f0d58a;
  --warn-ink: #6a5200;
  --err-bg: #fff3f3;
  --err-line: #e6a3a3;
  --err-ink: #8a2020;
  --shadow: rgba(40,30,10,.14);
  --dept: #4a8fd9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1b1d24; --ink: #eceae5; --muted: #a3a6b3; --panel: #262932; --panel-2: #20232b;
    --line: #3a3e4a; --warn-bg: #3a3218; --warn-line: #6b5a24; --warn-ink: #f3dc93;
    --err-bg: #3a2224; --err-line: #7a3a3e; --err-ink: #f4b4b4; --shadow: rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1d24; --ink: #eceae5; --muted: #a3a6b3; --panel: #262932; --panel-2: #20232b;
  --line: #3a3e4a; --warn-bg: #3a3218; --warn-line: #6b5a24; --warn-ink: #f3dc93;
  --err-bg: #3a2224; --err-line: #7a3a3e; --err-ink: #f4b4b4; --shadow: rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 "Be Vietnam Pro", system-ui, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; overflow: hidden;
}

.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; flex-wrap: wrap;
}
.hud-title { display: flex; flex-direction: column; }
.hud-title strong { font-size: 17px; }
.hud-title span { color: var(--muted); font-size: 12px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--panel); color: var(--ink); font-size: 11px; }
#hud-depts { display: flex; gap: 8px; flex-wrap: wrap; }
#hud-depts button {
  border: 0; border-radius: 999px; padding: 7px 14px; cursor: pointer;
  background: var(--dept); color: #fff; font-weight: 600; font-size: 13px;
}
#hud-depts button:hover { filter: brightness(1.08); }

.banner {
  margin: 0 16px 6px; padding: 6px 12px; border-radius: 8px;
  background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); font-size: 12.5px;
}

.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 16px 16px; }
#map { border-radius: 12px; box-shadow: 0 6px 24px var(--shadow); max-width: 100%; touch-action: none; }

/* ── Chat ─────────────────────────────────────────────────────────────── */
.chat {
  position: fixed; top: 12px; right: 12px; bottom: 12px; width: min(400px, calc(100vw - 24px));
  background: var(--panel); border-radius: 14px; box-shadow: 0 10px 40px var(--shadow); color: var(--ink);
  display: flex; flex-direction: column; overflow: hidden; z-index: 10;
}
.chat[hidden] { display: none; }
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  background: var(--dept); color: #fff;
}
.chat-head > div { flex: 1; min-width: 0; }
.chat-title { font-weight: 700; font-size: 15px; }
.chat-sub { font-size: 12px; opacity: .9; }
.chat-head button {
  border: 0; background: rgba(255,255,255,.18); color: #fff; width: 30px; height: 30px;
  border-radius: 8px; cursor: pointer; font-size: 15px;
}
.chat-head button:hover { background: rgba(255,255,255,.3); }

.chat-list { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--panel-2); }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--dept); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.intro { color: var(--muted); }
.msg.error { border-color: var(--err-line); background: var(--err-bg); color: var(--err-ink); }
.msg.typing:empty::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.mode-note { margin-top: 6px; font-size: 11px; color: var(--muted); }

.chips { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.chips button {
  border: 1px solid var(--dept); color: var(--ink); background: var(--panel); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: 13px; text-align: left;
}
.chips button:hover { background: var(--dept); color: #fff; }

.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  font: inherit; color: var(--ink); background: var(--panel);
}
.chat-form textarea:focus { outline: 2px solid var(--dept); outline-offset: -1px; }
.chat-form button {
  border: 0; border-radius: 10px; padding: 0 16px; background: var(--dept); color: #fff;
  font-weight: 600; cursor: pointer;
}
.chat-form button:disabled { opacity: .5; cursor: default; }

@media (max-width: 700px) {
  .hud-title span { display: none; }
  .chat { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 72vh; }
}

button:focus-visible, textarea:focus-visible { outline: 2px solid var(--dept); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .msg.typing:empty::after { animation: none; } }

.hud-admin { color: var(--muted); font-size: 12.5px; text-decoration: none; }
.hud-admin:hover { color: var(--ink); text-decoration: underline; }

/* ── Hỏi chung ─────────────────────────────────────────────────────────── */
#hud-depts .hud-auto { background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 1.5px #3d6fb4; }
.fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 9; display: flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 12px 18px; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 14px; line-height: 1;
  background: #3d6fb4; color: #fff; box-shadow: 0 8px 24px var(--shadow);
}
.fab:hover { filter: brightness(1.08); }
.fab[hidden] { display: none; }
@media (max-width: 700px) { .fab span { display: none; } .fab { padding: 14px; font-size: 18px; } }

.route-tag { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; font-size: 12px; white-space: normal; }
.route-tag span { background: var(--dept); color: #fff; font-weight: 600; border-radius: 999px; padding: 1px 9px; }
.route-tag button { border: 0; background: none; color: var(--dept); font-family: inherit; font-weight: 600; font-size: 12px; cursor: pointer; padding: 2px 0; }
.route-tag button:hover { text-decoration: underline; }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; white-space: normal; }
.source {
  font-size: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; color: var(--ink);
  background: var(--panel-2); text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
a.source:hover { border-color: var(--dept); color: var(--dept); }

/* 👍/👎 */
.feedback { display: flex; align-items: center; gap: 4px; margin-top: 6px; white-space: normal; }
.feedback button { border: 1px solid transparent; background: none; border-radius: 6px; padding: 1px 5px; cursor: pointer; font-size: 13px; opacity: .55; filter: grayscale(1); }
.feedback button:hover, .feedback button[aria-pressed="true"] { opacity: 1; filter: none; border-color: var(--line); background: var(--panel-2); }
.fb-thanks { font-size: 11.5px; color: var(--muted); margin-left: 4px; }
.privacy-note { font-size: 11px; color: var(--muted); padding: 0 12px 8px; }
.privacy-note[hidden] { display: none; }
