/* T&T AI HUB – giao diện 1.7
   Ý tưởng: bảng điều hành bến cảng. Nền xám thép sáng, thanh điều hướng xanh cảng đêm,
   một điểm nhấn duy nhất là vàng tín hiệu (vạch kẻ bãi container). Số liệu lớn dùng chữ hẹp
   kiểu biển báo (Barlow Condensed), còn lại là Be Vietnam Pro – kiểu chữ vẽ riêng cho tiếng Việt. */

:root {
  --harbor: #102a43;      /* xanh cảng đêm: thanh bên, bảng số */
  --harbor-2: #1b3a5a;
  --harbor-ink: #c9d6e3;
  --quay: #eef1f4;        /* nền */
  --panel: #ffffff;
  --ink: #17212b;
  --steel: #56636f;       /* chữ phụ */
  --line: #d9dfe5;
  --line-soft: #e9edf1;
  --signal: #f5b700;      /* vàng tín hiệu – chỉ dùng cho điểm nhấn */
  --action: #1c5fd0;      /* nút, liên kết */
  --action-soft: #e8effb;
  --ok: #1e7f4f;  --ok-soft: #e4f3ea;
  --warn: #a86b00; --warn-soft: #fff3d1;
  --bad: #c0392b; --bad-soft: #fcebe8;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --font: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --display: "Barlow Condensed", "Be Vietnam Pro", "Arial Narrow", sans-serif;
  font-family: var(--font);
  color: var(--ink); background: var(--quay);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-size: 15px; line-height: 1.55; font-feature-settings: "tnum" 1; }
.hidden { display: none !important; }
.sprite { position: absolute; }
.ic { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--steel); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; }
.mt { margin-top: 20px; }
a { color: var(--action); }
button { font: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
input, select, textarea { font: inherit; color: inherit; background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--action); box-shadow: 0 0 0 3px var(--action-soft); }
label { display: grid; gap: 5px; font-size: 13.5px; font-weight: 500; color: var(--steel); }
label input, label select, label textarea { color: var(--ink); }
h1 { font-family: var(--display); font-weight: 700; font-size: 32px; line-height: 1.1; letter-spacing: .2px; margin: 0 0 6px; }
h2 { font-size: 15.5px; font-weight: 600; margin: 0 0 12px; }
.error { color: var(--bad); margin: 0; }
.ok-text { color: var(--ok); margin: 0; }
.ok, .pos { color: var(--ok); font-weight: 600; }
.bad, .neg { color: var(--bad); font-weight: 600; }
.up { color: var(--ok); font-weight: 600; }
.down { color: var(--bad); font-weight: 600; }

/* Nút */
button[type=submit], .primary, #ai-save { background: var(--action); color: #fff; border: 0; border-radius: var(--r-sm);
  padding: 10px 18px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button[type=submit]:hover, #ai-save:hover { background: #154fb2; }
button[type=submit]:disabled { opacity: .6; cursor: wait; }
.btn { background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 14px;
  font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--action); color: var(--action); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn .ic { width: 16px; height: 16px; }
.link { background: none; border: 0; padding: 0; color: var(--harbor-ink); }
.link:hover { color: #fff; }
.link-dark { background: none; border: 0; padding: 0; color: var(--action); font-size: 14px; text-align: left; }
.link-dark:hover { text-decoration: underline; }
.danger { color: var(--bad); }
.badge { display: inline-block; min-width: 19px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 19px; text-align: center; }
.role-tag { font-family: var(--font); font-size: 12px; font-weight: 600; background: var(--action-soft); color: var(--action);
  border-radius: 20px; padding: 3px 10px; margin-left: 10px; vertical-align: middle; letter-spacing: 0; }

/* ===== Khung chính ===== */
.layout { display: grid; grid-template-columns: 236px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.rail { background: var(--harbor); color: #fff; display: flex; flex-direction: column; min-height: 0; padding: 18px 12px 14px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px 18px; }
.brand b { display: block; font-family: var(--display); font-size: 22px; line-height: 1; letter-spacing: .5px; }
.brand small { display: block; font-size: 11.5px; color: var(--harbor-ink); margin-top: 3px; }
.logo { background: var(--signal); color: var(--harbor); font-family: var(--display); font-weight: 700; font-size: 17px;
  border-radius: 4px; padding: 5px 7px; line-height: 1; }
.rail-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; min-height: 0; }
.rail-group { margin: 14px 10px 4px; font-size: 12px; color: #8ea4ba; font-weight: 500; }
.rail-group:first-child { margin-top: 0; }
.rail .nav { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; background: none; border: 0;
  color: var(--harbor-ink); padding: 9px 10px; border-radius: var(--r-sm); position: relative; font-size: 14.5px; }
.rail .nav:hover { background: rgba(255,255,255,.06); color: #fff; }
.rail .nav.active { background: var(--harbor-2); color: #fff; font-weight: 600; }
.rail .nav.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px;
  background: var(--signal); border-radius: 0 3px 3px 0; }
.rail .nav span:not(.badge) { flex: 1; }
.install-btn { margin: 10px 0 0; background: var(--signal); color: var(--harbor); border: 0; border-radius: var(--r-sm);
  padding: 9px 12px; font-weight: 700; }
.rail-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid rgba(255,255,255,.12);
  padding: 12px 6px 0; margin-top: 10px; font-size: 13px; }
.rail-foot .link { white-space: nowrap; }
.user-name { color: #fff; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 28px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.only-mobile { display: none !important; }
.ask { flex: 1; max-width: 640px; display: flex; align-items: center; gap: 10px; background: var(--quay); border: 1px solid transparent;
  border-radius: 22px; padding: 0 14px; height: 40px; color: var(--steel); }
.ask:focus-within { background: #fff; border-color: var(--action); box-shadow: 0 0 0 3px var(--action-soft); }
.ask input { flex: 1; border: 0; background: none; padding: 0; height: 100%; min-width: 0; color: var(--ink); }
.ask input:focus { box-shadow: none; }
.ask kbd { font: 12px var(--font); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; color: var(--steel); background: #fff; }
.icon-btn { background: none; border: 0; width: 42px; height: 42px; border-radius: 50%; display: inline-flex; align-items: center;
  justify-content: center; position: relative; padding: 0; color: var(--steel); margin-left: auto; }
.icon-btn:hover { background: var(--quay); color: var(--ink); }
.icon-btn .badge { position: absolute; top: 3px; right: 1px; }
.icon-btn.ghost { margin-left: 0; }
.main { flex: 1; overflow-y: auto; padding: 28px 32px 40px; min-height: 0; }
.view > .muted:first-of-type, .view > p.muted { max-width: 760px; margin: 0 0 16px; }
.drawer-backdrop, .tabbar { display: none; }

/* ===== Khối nội dung ===== */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; overflow-x: auto; }
.panel.narrow { max-width: 480px; margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; margin: 18px 0;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.card { background: var(--panel); padding: 14px 16px; position: relative; }
.card small { display: block; color: var(--steel); font-size: 13px; }
.card b { display: block; font-family: var(--display); font-size: 30px; font-weight: 600; line-height: 1.15; }
.card .sub { display: block; font-size: 12.5px; color: var(--steel); }
.card .line { display: block; }
.card.warn::after, .card.alarm::after { content: ""; position: absolute; left: 0; top: 0; right: 0; height: 3px; background: var(--signal); }
.card.alarm::after { background: var(--bad); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--steel); font-weight: 500; font-size: 13px; border-bottom: 1px solid var(--line); padding: 7px 10px; white-space: nowrap; }
td { border-bottom: 1px solid var(--line-soft); padding: 9px 10px; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.actions { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--harbor); color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 14px; z-index: 60; }

/* ===== Hôm nay ===== */
.today-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.today-head h1 { margin: 0; }
.today-head p { margin: 4px 0 0; }
/* Bảng số kiểu bảng giờ tàu: điểm nhấn duy nhất của giao diện */
.board { display: flex; flex-wrap: wrap; background: var(--harbor);
  border-radius: var(--r); overflow: hidden; margin-bottom: 18px; }
.board .card { flex: 1 1 165px; background: none; color: #fff; padding: 14px 18px 16px; border-right: 1px solid rgba(255,255,255,.08);
  border-bottom: 1px solid rgba(255,255,255,.08); }
.board .card small { color: #9fb3c8; font-size: 12.5px; }
.board .card b { font-size: 40px; font-weight: 600; color: #fff; letter-spacing: .3px; margin: 2px 0 1px; }
.board .card .sub { color: #9fb3c8; }
.board .card.warn b { color: var(--signal); }
.board .card.alarm b { color: #ff8f7f; }
.board .card.warn::after, .board .card.alarm::after { display: none; }
.board .up { color: #6fd39b; } .board .down { color: #ff8f7f; }
.today-split { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 16px; margin-bottom: 16px; }
.today-split .panel { margin: 0; }
#view-today > .panel, #view-today .grid2 { margin-bottom: 16px; }
.action-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }
.action-list button { width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 11px 14px 11px 16px; position: relative; display: block; }
.action-list button::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 2px 2px 0; background: var(--action); }
.action-list .danger, .action-list .warning { color: var(--ink); }
.action-list .warning::before { background: var(--signal); }
.action-list .danger::before { background: var(--bad); }
.action-list button:hover { border-color: var(--action); background: #fbfcfe; }
.action-list small { display: block; color: var(--action); font-size: 12.5px; margin-top: 2px; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.report-grid button { text-align: left; background: var(--quay); border: 1px solid transparent; border-radius: var(--r); padding: 10px 12px; }
.report-grid button:hover { background: #fff; border-color: var(--action); }
.report-grid b { display: block; font-size: 14px; font-weight: 600; }
.report-grid span { font-size: 12.5px; color: var(--steel); }

/* ===== Hỏi AI ===== */
#view-chat:not(.hidden) { height: calc(100% + 68px); margin: -28px -32px -40px; }
.chat-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); height: 100%; }
.history { border-right: 1px solid var(--line); background: #f6f8fa; display: flex; flex-direction: column; min-height: 0; }
.history-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 14px 10px; }
.small-btn { padding: 5px 10px; font-size: 13px; }
.conv-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; min-height: 0; }
.conv-list li { display: flex; border-radius: var(--r-sm); }
.conv-list li:hover { background: #e9eef3; }
.conv-list li.active { background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.conv { flex: 1; text-align: left; background: none; border: 0; padding: 8px 10px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-size: 14px; color: var(--ink); }
.del { background: none; border: 0; color: var(--steel); padding: 0 10px; font-size: 17px; visibility: hidden; }
.conv-list li:hover .del { visibility: visible; }
.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; padding: 14px 28px 18px; }
.chat-top { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-top h1 { font-family: var(--font); font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 120px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#history-toggle { display: none; }
.chat-opts { display: flex; align-items: center; gap: 6px 16px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; font-size: 13.5px; color: var(--ink); cursor: pointer; grid: none; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--action); }
.check.disabled { opacity: .5; cursor: not-allowed; }
.mode { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.mode select { padding: 5px 8px; }
.opts-toggle { display: none; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 18px 0 12px; }
.messages > * { width: 100%; max-width: 860px; margin-left: auto; margin-right: auto; }
.empty { color: var(--steel); }
.msg { border-radius: var(--r-lg); padding: 11px 15px; }
.msg.user { background: var(--harbor); color: #fff; max-width: min(78%, 680px); margin-right: max(0px, calc((100% - 860px) / 2)); align-self: flex-end; width: auto; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); }
.msg.error-msg { border-color: #f0bdb5; background: var(--bad-soft); }
.msg.review { border-left: 4px solid var(--signal); background: #fffcf2; }
.msg.waiting .body { color: var(--steel); font-style: italic; }
.meta { font-size: 12px; color: var(--steel); margin-bottom: 4px; }
.msg.user .meta { color: #9fb3c8; display: flex; justify-content: space-between; gap: 12px; }
.text { white-space: pre-wrap; word-wrap: break-word; }
.status:empty { display: none; }
.status { margin-bottom: 4px; font-style: italic; }
.note { align-self: center; margin: 0; }
.pin { background: none; border: 0; color: #9fb3c8; font-size: 12px; padding: 0; visibility: hidden; }
.msg.user:hover .pin { visibility: visible; }
.pins { display: inline-flex; gap: 10px; }
.speak-btn { margin-top: 6px; background: none; border: 1px solid var(--line); border-radius: 14px; color: var(--action); font-size: 12px; padding: 2px 10px; }
pre { background: #0f1b28; color: #e6edf3; padding: 10px 12px; border-radius: var(--r-sm); overflow-x: auto; font-size: 13px; }
.quick-bar { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; width: 100%; max-width: 860px; margin: 0 auto; }
.quick-bar::-webkit-scrollbar { display: none; }
.quick-bar:empty { display: none; }
.chip { flex: 0 0 auto; background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 18px; padding: 6px 13px; font-size: 13.5px; white-space: nowrap; }
.chip:hover { border-color: var(--action); color: var(--action); }
.chip.mine { border-color: var(--signal); background: #fffbeb; }
.composer { display: flex; gap: 8px; align-items: flex-end; background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 8px 8px 8px 14px; width: 100%; max-width: 860px; margin: 0 auto; }
.composer:focus-within { border-color: var(--action); box-shadow: 0 0 0 3px var(--action-soft); }
.composer textarea { flex: 1; border: 0; resize: none; min-height: 44px; max-height: 220px; padding: 10px 0; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer button[type=submit] { border-radius: var(--r); padding: 10px 14px; }
.composer button[type=submit] .ic { width: 18px; height: 18px; }
.mic { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--action);
  display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.mic.on { background: var(--bad); border-color: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(192,57,43,.45); } 70% { box-shadow: 0 0 0 12px rgba(192,57,43,0); } 100% { box-shadow: 0 0 0 0 rgba(192,57,43,0); } }
.voice-status { margin: 6px auto 0; font-size: 13px; color: var(--action); max-width: 860px; width: 100%; }
.tools-used { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; font-size: 12px; color: var(--steel);
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tool-chip { background: var(--ok-soft); color: var(--ok); border-radius: 12px; padding: 1px 9px; font-weight: 500; }
.cite { background: var(--action-soft); color: var(--action); border-radius: 4px; padding: 0 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sources { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; font-size: 13px; }
.sources summary { cursor: pointer; color: var(--action); font-weight: 500; }
.sources ol { margin: 6px 0 0; padding-left: 20px; }
.export-btn { margin: 8px 8px 0 0; background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe0cb; border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 600; padding: 4px 12px; }
.export-btn:disabled { opacity: .6; }

/* Markdown trong câu trả lời */
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h2, .md h3, .md h4, .md h5, .md h6 { margin: 14px 0 6px; font-size: 15.5px; font-weight: 600; }
.md h2 { font-size: 17px; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { background: var(--quay); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.md pre code { background: none; padding: 0; color: inherit; }
.md blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--steel); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.table-wrap { overflow-x: auto; margin: 6px 0 10px; }
.md table { border: 1px solid var(--line); width: auto; min-width: 50%; font-size: 13.5px; }
.md th { background: var(--quay); color: var(--ink); font-weight: 600; border: 1px solid var(--line); white-space: normal; }
.md td { border: 1px solid var(--line); }

/* Biểu đồ */
.chart { margin: 10px 0; padding: 12px 14px 8px; background: #fff; border: 1px solid var(--line); border-radius: var(--r); max-width: 780px; }
.panel .chart { border: 0; padding: 0; margin: 0; }
.chart figcaption { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.chart-svg { width: 100%; height: auto; display: block; font-family: var(--font); }
.chart-svg .grid { stroke: #edf0f3; stroke-width: 1; }
.chart-svg .axis { stroke: #9aa5b1; stroke-width: 1; }
.chart-svg .tick { font-size: 15px; fill: var(--steel); }
.chart-svg .lab { font-size: 15px; fill: #36404c; }
.chart-svg .val { font-size: 14px; fill: #36404c; }
.chart-svg rect:hover, .chart-svg circle:hover { opacity: .8; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--steel); margin-top: 4px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.msg.assistant:has(figure.chart) { width: 100%; }
.chart-box { margin: 10px 0; padding: 14px; border: 1px dashed var(--line); border-radius: var(--r); color: var(--steel); font-size: 13px; }
.chart-box::before { content: "Đang vẽ biểu đồ…"; }
.chart-box.chart-error::before { content: attr(data-msg); color: var(--bad); }
.chart-src { display: none; }

/* ===== Chi hộ ===== */
.chiho-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 4px 0 6px; }
.chiho-bar label { min-width: 150px; }
#view-chiho .cards { margin: 14px 0; }
#view-chiho .panel { margin-bottom: 16px; }
#ch-ai summary { cursor: pointer; }
#ch-ai-body { margin-top: 10px; max-width: 900px; }
.chiho-table td { font-size: 13.5px; }
.chiho-table .msg-text { max-width: 260px; color: var(--steel); font-size: 13px; }
.chiho-table .notes { margin: 0; padding-left: 16px; font-size: 13px; }
.chiho-table tr td:first-child { box-shadow: inset 3px 0 0 transparent; }
.chiho-table tr.m-danger td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.chiho-table tr.m-warning td:first-child { box-shadow: inset 3px 0 0 var(--signal); }
.chiho-table tr.m-info td:first-child, .chiho-table tr.m-ok td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.chiho-table tr.st-bo_qua { opacity: .5; }
.chiho-table .acts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chiho-table .acts button { font-size: 12.5px; padding: 3px 9px; }
.st { font-size: 12px; font-weight: 600; border-radius: 12px; padding: 2px 9px; background: var(--quay); white-space: nowrap; }
.st.da_duyet { background: var(--ok-soft); color: var(--ok); }
.st.da_nhap { background: var(--action-soft); color: var(--action); }
.st.cho_duyet { background: var(--warn-soft); color: var(--warn); }

/* ===== Cảnh báo ===== */
.alert-list { display: grid; gap: 10px; margin-top: 12px; max-width: 1100px; }
.alert-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 13px 18px; position: relative; }
.alert-card::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 2px 2px 0; background: #8aa4c4; }
.alert-card.sev-warning::before { background: var(--signal); }
.alert-card.sev-danger::before { background: var(--bad); }
.alert-card.unread { border-color: #a9c3ea; }
.alert-card summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; list-style: none; }
.alert-card summary::-webkit-details-marker { display: none; }
.alert-card summary b { font-weight: 600; }
.alert-card .badge { background: var(--action); }
.alert-card .md { margin-top: 12px; }
.alert-card .export-btn { margin-top: 10px; }

/* ===== Ghi nhớ, Kho tài liệu, Người dùng, Tài khoản ===== */
.mem-form, .kb-form { display: flex; gap: 10px; align-items: flex-end; margin: 14px 0; flex-wrap: wrap; }
.mem-form textarea { flex: 2; min-width: 240px; resize: vertical; }
.kb-form input[type=text], .kb-form input[type=file] { flex: 1; min-width: 200px; }
.mem-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; max-width: 900px; }
.mem-list li { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 10px 14px; }
.mem-list li.off .mem-text { color: var(--steel); text-decoration: line-through; }
.mem-list li.mem-head { background: none; border: 0; padding: 14px 2px 2px; font-weight: 600; color: var(--harbor); }
.mem-text { flex: 1; white-space: pre-wrap; }
.row-actions { display: inline-flex; gap: 12px; white-space: nowrap; }
.scope-box { display: flex; flex-direction: column; gap: 6px; min-width: 240px; flex: 1; max-width: 460px; }
.roles-pick, .roles-inline { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.roles-inline { margin-top: 6px; padding: 6px 8px; background: var(--quay); border-radius: var(--r-sm); }
#view-knowledge .panel, #view-users .panel { margin-top: 14px; }
.kb-hit { border-top: 1px solid var(--line); padding: 10px 0; }
.kb-hit .text { color: #36404c; }
.user-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.user-form label { min-width: 0; }
.user-form input, .user-form select { width: 100%; min-width: 0; }
input.num { width: 100px; padding: 5px 8px; }
td select { padding: 5px 8px; }
#view-settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 480px)); gap: 16px; align-content: start; }
#view-settings.hidden { display: none; }
#view-settings h1 { grid-column: 1 / -1; }
#view-settings .panel.narrow { margin: 0; max-width: none; }
#view-settings .panel.narrow label.check { display: flex; margin: 10px 0; }
#ai-panel label { margin-bottom: 10px; }
#ai-panel select { width: 100%; }
#pw-form { display: grid; gap: 14px; }

/* ===== Đăng nhập ===== */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: var(--harbor) linear-gradient(90deg, transparent 0 calc(100% - 10px), var(--signal) calc(100% - 10px)); }
.login-card { background: #fff; padding: 34px 32px; border-radius: var(--r-lg); width: min(400px, 100%); }
.login-card form { display: grid; gap: 14px; }
.login-card button[type=submit] { margin-top: 4px; padding: 12px; }
.brand-lg { padding: 0 0 24px; }
.brand-lg b { color: var(--harbor); font-size: 30px; }
.brand-lg small { color: var(--steel); font-size: 13px; }

/* ===== Điện thoại ===== */
@media (max-width: 820px) {
  body { font-size: 16px; }
  input, select, textarea { font-size: 16px; }
  .only-mobile { display: inline-flex !important; }
  .layout { display: block; height: auto; min-height: 100dvh; padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  .workspace { display: block; }
  .topbar { position: sticky; top: 0; z-index: 30; height: auto; min-height: 56px; padding: env(safe-area-inset-top) 6px 0 4px;
    background: var(--harbor); color: #fff; border: 0; gap: 4px; }
  .topbar .icon-btn { color: #fff; margin-left: 0; }
  .topbar .icon-btn:hover { background: rgba(255,255,255,.08); }
  #topbar-title { flex: 1; font-family: var(--display); font-size: 22px; font-weight: 600; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ask { display: none; }
  .rail { position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 84vw); z-index: 40;
    transform: translateX(-105%); transition: transform .22s ease; padding-top: calc(18px + env(safe-area-inset-top));
    padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  body.drawer-open .rail { transform: translateX(0); }
  .drawer-backdrop:not(.hidden) { display: block; position: fixed; inset: 0; background: rgba(8,20,32,.45); z-index: 35; }
  .rail .nav { padding: 11px 10px; font-size: 16px; }
  .main { padding: 16px 14px 24px; overflow: visible; }
  h1 { font-size: 28px; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: 0; color: var(--steel);
    font-size: 11.5px; padding: 6px 0 4px; border-radius: var(--r-sm); position: relative; }
  .tab .ic { width: 22px; height: 22px; }
  .tab.active { color: var(--harbor); font-weight: 600; }
  .tab.active::before { content: ""; position: absolute; top: -5px; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--signal); }
  .grid2, .today-split { grid-template-columns: 1fr; }
  .panel { padding: 14px; border-radius: var(--r); }
  .cards { grid-template-columns: 1fr 1fr; }
  .card b { font-size: 26px; }
  .board { margin-left: -14px; margin-right: -14px; border-radius: 0; }
  .board .card { flex-basis: 40%; padding: 12px 14px; }
  .board .card b { font-size: 32px; }
  .today-head { margin-bottom: 14px; }
  .report-grid { grid-template-columns: 1fr 1fr; }
  /* Hỏi AI: toàn màn hình, ô nhập luôn ở dưới */
  #view-chat:not(.hidden) { margin: -16px -14px -24px; height: calc(100dvh - 56px - env(safe-area-inset-top) - 62px - env(safe-area-inset-bottom)); }
  .chat-shell { display: block; height: 100%; position: relative; }
  .history { position: absolute; inset: 0; z-index: 5; background: #f6f8fa; display: none; }
  .chat-shell.show-history .history { display: flex; }
  #history-toggle { display: inline-flex; width: 38px; height: 38px; }
  .chat-main { height: 100%; padding: 6px 12px 10px; }
  .chat-top { padding-bottom: 6px; gap: 4px; }
  .chat-top h1 { font-size: 16px; }
  .opts-toggle { display: inline-block; font-size: 14px; }
  .chat-opts { display: none; width: 100%; gap: 10px 16px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--r); }
  .chat-opts.open { display: flex; }
  .mode select { max-width: 60vw; }
  .msg { font-size: 15px; }
  .msg.user { max-width: 92%; }
  .msg.user .pin { visibility: visible; }
  .composer { padding: 6px 6px 6px 12px; align-items: center; }
  .composer textarea { min-height: 40px; max-height: 130px; padding: 8px 0; }
  .composer #send span { display: none; }
  .composer button[type=submit] { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
  .chip { padding: 8px 14px; }
  .mem-form textarea { min-width: 100%; }
  .user-form { grid-template-columns: 1fr; }
  .alert-card { padding: 12px 14px; }
  .md table { font-size: 13px; }
  .chart { padding: 8px 6px 4px; }
  #view-settings { grid-template-columns: 1fr; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .chiho-bar label { min-width: 0; flex: 1 1 140px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Văn phòng (1.8) */
.rail a.nav { text-decoration: none; }
.rail a.nav small { color: #8ea4ba; font-size: 12px; }
#view-today .office { margin-bottom: 16px; }
.office-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.office-head h2 { margin: 0; }
.office-head .btn { margin-left: auto; text-decoration: none; }
.office-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 18px; }
.dept-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; }
.dept { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid var(--line-soft); min-width: 0; }
.dept .dot { width: 10px; height: 10px; border-radius: 50%; background: #c3ccd5; margin-top: 6px; flex: 0 0 auto; }
.dept.st-work .dot { background: var(--ok); }
.dept.st-wait .dot { background: var(--signal); }
.dept.st-err .dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dept div { min-width: 0; }
.dept b { display: block; font-size: 14px; font-weight: 600; }
.dept span { display: block; font-size: 12.5px; color: var(--steel); overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dept.st-idle b { color: var(--steel); font-weight: 500; }
.approvals h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
.appr-list { list-style: none; margin: 0; padding: 0; }
.appr-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.appr-list li:last-child { border-bottom: 0; }
.appr-list b { display: block; font-size: 13.5px; font-weight: 500; }
.appr-list span { display: block; }
.appr-list .amt { font-weight: 600; white-space: nowrap; font-size: 14px; color: var(--ink); }
@media (max-width: 820px) { .office-grid { grid-template-columns: 1fr; } .dept-list { grid-template-columns: 1fr; } .office-head .btn { margin-left: 0; } }
