:root {
  --bg: #f3f6fb; --card: #fff; --text: #101a2c; --muted: #5a6680; --line: #dde4ef;
  --brand: #0a5bc4; --brand-2: #e8f0fc; --gold: #f2b01e; --navy: #041a3a; --navy-2: #0a3d8f; --warn: #b54708; --warn-bg: #fff4e5; --bad: #b42318; --bad-bg: #fee4e2;
  --ok: #067647; --ok-bg: #dcfae6; --me: #0a4fae; --me-text: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #08111f; --card: #111c30; --text: #e6ecf5; --muted: #98a6bf; --line: #24324b; --brand: #5ea0ff; --brand-2: #16264a; --warn-bg: #3a2712; --bad-bg: #3b1513; --ok-bg: #12301f; --me: #0a4fae; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; }
button.primary { background: #0a5bc4; color: #fff; border-color: #0a5bc4; }

button.danger { color: var(--bad); border-color: var(--bad); }
button.small { padding: 4px 10px; font-size: 14px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 11px; }
textarea { resize: vertical; }
label { display: block; font-size: 14px; color: var(--muted); margin: 8px 0; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
.hidden { display: none !important; }
.err { color: var(--bad); min-height: 1.2em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.login { background: radial-gradient(ellipse at 50% 30%, #0a2f6e 0%, var(--navy) 65%); min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); text-align: center; }
.login form label { text-align: left; }
.login form.card { background: rgba(4,20,48,.75); color: #fff; border: 1px solid rgba(242,176,30,.35); box-shadow: 0 10px 40px rgba(0,0,0,.45); }
.login .logo { width: 100%; max-width: 320px; }
.login h1 { font-size: 22px; margin: 6px 0 16px; color: var(--gold); letter-spacing: .5px; }
.login input { background: #fff; color: #101a2c; border-color: #cfd8e6; }
.login label { color: #b9c9e6; }
.login button { width: 100%; margin-top: 8px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: linear-gradient(90deg, var(--navy) 0%, var(--navy-2) 100%); border-bottom: 3px solid var(--gold); color: #fff; }
.brand { flex: none; display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .5px; color: #fff; }
.brand em { font-style: normal; color: var(--gold); }
.brand img { margin: -4px 0; }
.status { flex: 1; min-width: 0; font-size: 13px; color: #b9c9e6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop { flex: none; background: var(--bad); color: #fff; border: none; font-weight: 700; padding: 8px 12px; }
.stopped { background: var(--bad-bg); color: var(--bad); padding: 10px 16px; font-weight: 600; display: flex; gap: 10px; align-items: center; }

main { max-width: 860px; margin: 0 auto; padding: 16px 16px 96px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs button { flex: 1; border: none; border-radius: 0; background: none; padding: 8px 2px 10px; font-size: 12px; color: var(--muted); position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button.on { color: var(--brand); font-weight: 600; box-shadow: inset 0 3px 0 var(--gold); }
.tabs .ic { font-size: 20px; line-height: 1; }
.badge { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; font-style: normal; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }
h2 { font-size: 19px; margin: 4px 0 12px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--brand-2); color: var(--brand); white-space: nowrap; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.grey { background: var(--line); color: var(--muted); }
.subtabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.subtabs button { white-space: nowrap; border-radius: 20px; }
.subtabs button.on { background: #0a5bc4; color: #fff; border-color: #0a5bc4; }

.pre { white-space: pre-wrap; word-break: break-word; }
.table { width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* Trò chuyện */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 130px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-text); border-color: var(--me); }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.me .who { color: #cfe0ff; }
.msg.sys { align-self: center; background: var(--warn-bg); color: var(--warn); border: none; font-size: 14px; }
.msg a.ref { display: inline-block; margin-top: 6px; font-size: 14px; color: var(--brand); }
.composer { position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); background: var(--bg); padding: 8px 16px; z-index: 4; }
.composer .box { max-width: 828px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 46px; max-height: 160px; border-radius: 22px; padding: 11px 16px; }
.composer button { border-radius: 50%; width: 46px; height: 46px; padding: 0; flex: none; font-size: 20px; }
.composer .mic.on { background: var(--bad); color: #fff; border-color: var(--bad); }
.typing { color: var(--muted); font-size: 14px; }
.hint { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; max-width: 828px; margin: 0 auto 6px; }
.composer .hint button { flex: none; width: auto; height: auto; white-space: nowrap; font-size: 13px; border-radius: 16px; padding: 4px 10px; }

.approval .amount { font-size: 20px; font-weight: 700; }
.approval .actions { display: flex; gap: 8px; margin-top: 10px; }
.approval .actions button { flex: 1; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100% - 32px); }
.list-item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.list-item:last-child { border-bottom: none; }
details summary { cursor: pointer; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); }
.switch input { width: auto; }
.md { white-space: normal; }
.md .md-h { font-weight: 700; margin: 8px 0 2px; }
.md .md-li { padding-left: 16px; position: relative; }
.md .md-li::before { content: "•"; position: absolute; left: 4px; }
.md .md-li.sub { padding-left: 32px; }
.md .md-li.sub::before { left: 20px; }
.md .md-gap { height: 8px; }
.md .table { margin: 6px 0; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }
.md code { background: var(--brand-2); padding: 0 4px; border-radius: 4px; }
.hint::-webkit-scrollbar { display: none; }
