:root {
  --bg: #f4f6f5; --panel: #ffffff; --panel-2: #f8faf9; --line: #e3e8e6; --text: #15201d; --muted: #66756f;
  --brand: #0f766e; --brand-2: #0d9488; --brand-soft: #e6f4f2;
  --ok: #15803d; --ok-soft: #e8f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --bad: #b91c1c; --bad-soft: #fdecec;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .05);
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412; --panel: #151d1a; --panel-2: #1a2420; --line: #26332e; --text: #e6eeeb; --muted: #93a39d;
    --brand: #2dd4bf; --brand-2: #14b8a6; --brand-soft: #123330;
    --ok: #4ade80; --ok-soft: #12291b; --warn: #fbbf24; --warn-soft: #2b2312; --bad: #f87171; --bad-soft: #2d1616;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .grow { flex: 1; } .right { margin-left: auto; }
.stack > * + * { margin-top: 14px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px 18px; font-weight: 700; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: 18px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--text); text-decoration: none; cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.nav:hover { background: var(--panel-2); }
.nav.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .ic { width: 20px; text-align: center; }
.badge { background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; margin-left: auto; font-weight: 700; }
.side .foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); }
.main { min-width: 0; overflow-x: hidden; }
.top { display: flex; align-items: center; gap: 10px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.page { padding: 22px 24px 90px; max-width: 1180px; }

.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 99px; padding: 3px 10px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ok.solid { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h2 { margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; }
.kpi { background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.kpi .l { font-size: 12.5px; color: var(--muted); } .kpi .v { font-size: clamp(16px, 1.45vw, 21px); font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .s { font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12.5px; background: var(--panel-2); position: sticky; top: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.tbl table td:first-child, .tbl table th:first-child { padding-left: 14px; }

.check { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.check:last-child { border: 0; }
.dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; flex: none; }
.dot.ok { background: var(--ok-soft); color: var(--ok); } .dot.no { background: var(--warn-soft); color: var(--warn); }

/* ---------- Form ---------- */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-weight: 500; font-size: 13.5px; margin-bottom: 4px; }
label.f > small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=time], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 70px; }
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; margin-bottom: 12px; }
.toggle input { display: none; }
.toggle i { width: 40px; height: 23px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: .2s; }
.toggle i::after { content: ''; position: absolute; width: 17px; height: 17px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + i { background: var(--brand); }
.toggle input:checked + i::after { left: 20px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 4px; margin: 0 0 12px; }
legend { font-weight: 600; font-size: 13.5px; padding: 0 6px; }
.note { background: var(--panel-2); border-left: 3px solid var(--brand); padding: 10px 12px; border-radius: 6px; font-size: 13.5px; color: var(--muted); margin-bottom: 12px; }
.note.warn { border-color: var(--warn); }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: 13px; }
.days input { display: none; }
.days label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

details.sec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); }
details.sec > summary { list-style: none; cursor: pointer; padding: 15px 18px; display: flex; align-items: center; gap: 10px; font-weight: 600; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after { content: '›'; margin-left: auto; font-size: 20px; color: var(--muted); transition: .2s; }
details.sec[open] > summary::after { transform: rotate(90deg); }
details.sec > .body { padding: 0 18px 18px; }
.step { width: 26px; height: 26px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; }
.step.done { background: var(--ok-soft); color: var(--ok); }
pre.out { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 12px; overflow: auto; max-height: 360px; white-space: pre-wrap; font: 12.5px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 10px 0 0; }

/* ---------- Chat ---------- */
.chatwrap { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 14px; height: calc(100vh - 140px); }
.chatlist { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; padding: 8px; }
.chatlist .it { padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; display: flex; gap: 6px; }
.chatlist .it:hover { background: var(--panel-2); } .chatlist .it.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.chatlist .it span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.msgs { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 860px; min-width: 0; overflow-wrap: anywhere; }
.msg pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; padding: 10px 14px; border-radius: 14px 14px 4px 14px; max-width: 75%; white-space: pre-wrap; }
.msg.system { align-self: center; background: var(--panel-2); border: 1px dashed var(--line); padding: 8px 12px; border-radius: 10px; font-size: 13px; color: var(--muted); max-width: 90%; white-space: pre-wrap; max-height: 140px; overflow: auto; }
.msg.assistant .md { line-height: 1.6; }
.msg.err .md { color: var(--bad); }
.md table { margin: 8px 0; display: block; overflow: auto; } .md p { margin: 0 0 8px; } .md h1, .md h2, .md h3 { margin: 12px 0 6px; font-size: 16px; }
.md pre { background: var(--panel-2); padding: 10px; border-radius: 8px; overflow: auto; white-space: pre-wrap; } .md code { font-size: 12.5px; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.tool { font-size: 12.5px; border: 1px solid var(--line); background: var(--panel-2); border-radius: 99px; padding: 3px 10px; cursor: pointer; color: var(--muted); }
.tool:hover { border-color: var(--brand); color: var(--brand); }
.typing { color: var(--muted); font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.typing::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.composer { border-top: 1px solid var(--line); padding: 12px; }
.composer textarea { min-height: 46px; max-height: 180px; border-radius: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--panel-2); border-radius: 99px; padding: 4px 11px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--brand); color: var(--brand); }

.ap { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 12px; padding: 14px; }
.ap.done { border-color: var(--line); background: var(--panel-2); }
.ap h3 { margin-bottom: 6px; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 400px; }
#toast { position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast div { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); max-width: 90vw; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal .card { width: 100%; max-width: 900px; max-height: 88vh; overflow: auto; }
.burger { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 20; justify-content: space-around; gap: 0; }
  .side .brand, .side .foot, .side .nav.more { display: none; }
  .nav { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; text-align: center; position: relative; }
  .nav .ic { font-size: 19px; }
  .nav .badge { position: absolute; top: 0; right: 8px; margin: 0; }
  .top { padding: 10px 14px; }
  .page { padding: 14px 12px 100px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .chatwrap { grid-template-columns: 1fr; height: calc(100vh - 190px); }
  .chatlist { display: none; } .chatlist.show { display: block; position: fixed; inset: 60px 10px 80px; z-index: 30; }
  .burger { display: inline-flex; }
  .msg.user { max-width: 88%; }
  .hide-m { display: none; }
}

/* Tab nền tảng trong Cài đặt */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.tab:hover { background: var(--panel-2); }
.tab.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.tab .dot { width: 18px; height: 18px; font-size: 11px; }
.pf-chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
@media (max-width: 640px) { .tab { flex: 1 1 calc(50% - 6px); justify-content: center; padding: 8px 6px; font-size: 13px; } }
