/* Tuan Inbox · giao diện nội bộ. Màu đặt bằng token trên :root; không dùng style attribute trong HTML (CSP). */

@font-face { font-family: 'Inter'; src: local('Inter'), local('Inter Regular'), local('Inter-Regular'); font-weight: 100 900; font-style: normal; font-display: swap; }

:root {
  color-scheme: light;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --bg: #f6f6fa;
  --surface: #ffffff;
  --surface-2: #fafafd;
  --surface-3: #f1f1f7;
  --border: #e5e5ee;
  --border-strong: #d6d6e3;
  --text: #1f2132;
  --text-2: #4a4d63;
  --muted: #5f6479;
  --muted-2: #a3a7bb;
  --accent: #5d4fd1;
  --accent-hover: #4d40bd;
  --accent-soft: #ece9fc;
  --rail: #1d2038;
  --rail-text: #9da2c2;
  --nav-bg: #5d4fd1;
  --nav-text: #ffffff;
  --nav-hover: rgb(255 255 255 / 0.14);
  --nav-active: rgb(255 255 255 / 0.24);
  --nav-avatar: rgb(255 255 255 / 0.28);
  --ok: #17704f;
  --ok-soft: #e4f5ec;
  --warn: #8a5a12;
  --warn-soft: #fbf1de;
  --danger: #b02c4c;
  --danger-soft: #fbe8ed;
  --focus: #7f72e6;
  --shadow: 0 10px 30px rgb(29 32 56 / 0.12);
  --radius: 10px;
  --radius-sm: 7px;
  --row-h: 84px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #15161f;
    --surface: #1c1e2b;
    --surface-2: #191b27;
    --surface-3: #252838;
    --border: #2c2f42;
    --border-strong: #3a3e55;
    --text: #eceef8;
    --text-2: #c3c7dc;
    --muted: #9196ae;
    --muted-2: #6f7490;
    --accent: #9d93f5;
    --accent-hover: #b1a9ff;
    --accent-soft: #2d2a4d;
    --rail: #101119;
    --rail-text: #8a90b3;
    --nav-bg: #2b2d6e;
    --nav-text: #f2f3fb;
    --nav-hover: rgb(255 255 255 / 0.10);
    --nav-active: rgb(255 255 255 / 0.18);
    --nav-avatar: rgb(255 255 255 / 0.20);
    --ok: #5dcca1;
    --ok-soft: #1c3a2e;
    --warn: #e9b862;
    --warn-soft: #3a2f18;
    --danger: #ff8aa5;
    --danger-soft: #3d1d28;
    --focus: #b5adff;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #15161f;
  --surface: #1c1e2b;
  --surface-2: #191b27;
  --surface-3: #252838;
  --border: #2c2f42;
  --border-strong: #3a3e55;
  --text: #eceef8;
  --text-2: #c3c7dc;
  --muted: #9196ae;
  --muted-2: #6f7490;
  --accent: #9d93f5;
  --accent-hover: #b1a9ff;
  --accent-soft: #2d2a4d;
  --rail: #101119;
  --rail-text: #8a90b3;
  --nav-bg: #2b2d6e;
  --nav-text: #f2f3fb;
  --nav-hover: rgb(255 255 255 / 0.10);
  --nav-active: rgb(255 255 255 / 0.18);
  --nav-avatar: rgb(255 255 255 / 0.20);
  --ok: #5dcca1;
  --ok-soft: #1c3a2e;
  --warn: #e9b862;
  --warn-soft: #3a2f18;
  --danger: #ff8aa5;
  --danger-soft: #3d1d28;
  --focus: #b5adff;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.5);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 18px; font-weight: 650; }
h2 { font-size: 20px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
h4 { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
p { margin: 0 0 10px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
code { background: var(--surface-3); border-radius: 4px; padding: 1px 5px; color: var(--text-2); word-break: break-all; }
pre.secret { background: var(--surface-3); border: 1px dashed var(--border-strong); padding: 14px; border-radius: var(--radius-sm); font-size: 15px; user-select: all; overflow-wrap: anywhere; white-space: pre-wrap; }
kbd { font: 11px var(--font); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); background: var(--surface); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.noscript { padding: 24px; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.narrow { max-width: 420px; }
.hide-sm { }
.mobile-only { display: none; }
.boot { height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); }
.boot-mark { font-size: 40px; font-weight: 750; color: var(--accent); }

/* ---------- Form ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-2); font-weight: 550; }
input, select, textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 8px 10px;
  font-weight: 400;
  min-height: 34px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
input[type='search'] { padding-left: 30px; }
input[type='checkbox'], input[type='radio'] { width: auto; min-height: 0; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; color: var(--text); }
.form-error { color: var(--danger); font-size: 12px; min-height: 0; margin: 0; }
.form-error:empty { display: none; }
.inline-error { color: var(--danger); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin: 0; display: grid; gap: 10px; }
legend { padding: 0 6px; color: var(--muted); font-size: 12px; }
.grant-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; }
.small-check { font-size: 12px; }

/* ---------- Buttons & chips ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 6px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; white-space: nowrap; transition: background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-danger-ghost { border-color: transparent; background: transparent; color: var(--danger); }
.btn-small { min-height: 26px; padding: 3px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn .ico { width: 15px; height: 15px; }
.icon-btn { width: 30px; height: 30px; display: inline-grid; place-items: center; border-radius: var(--radius-sm); color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn .ico { width: 16px; height: 16px; }
.link-btn { color: var(--accent); font-size: 12px; font-weight: 550; padding: 2px 4px; border-radius: 4px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.chip-toggle { border: 1px solid var(--border-strong); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--text-2); background: var(--surface); }
.chip-toggle.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.segmented { display: inline-flex; background: var(--surface-3); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.segmented button { padding: 4px 10px; border-radius: 5px; font-size: 12px; color: var(--muted); font-weight: 550; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.ico { width: 16px; height: 16px; flex: none; }
.badge { display: inline-block; font-size: 11px; background: var(--accent-soft); color: var(--accent); padding: 3px 9px; border-radius: 999px; margin-bottom: 18px; font-weight: 600; }
.pill { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pill.tone-ok { background: var(--ok-soft); color: var(--ok); }
.pill.tone-warn { background: var(--warn-soft); color: var(--warn); }
.pill.tone-danger { background: var(--danger-soft); color: var(--danger); }
.pill.tone-admin { background: var(--accent-soft); color: var(--accent); }
.pill.tone-open { background: var(--accent-soft); color: var(--accent); }
.status-pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.status-pill.ok { background: var(--ok-soft); color: var(--ok); }
.status-pill.warn { background: var(--warn-soft); color: var(--warn); }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 14px; font-size: 12px; }
.notice code { background: transparent; color: inherit; }
.label-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: var(--tone, var(--accent)); background: color-mix(in srgb, var(--tone, var(--accent)) 14%, transparent); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.label-chip.removable button { color: inherit; font-size: 14px; line-height: 1; padding: 0 2px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--muted-2)); flex: none; }

/* ---------- Avatar ---------- */
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; background: var(--tone-bg, var(--accent-soft)); color: var(--tone-fg, var(--accent)); }
.avatar.xs { width: 24px; height: 24px; font-size: 9px; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.tone-violet { --tone-bg: #ece9fc; --tone-fg: #5d4fd1; }
.tone-rose { --tone-bg: #fbe7ee; --tone-fg: #bf4d70; }
.tone-mint { --tone-bg: #e2f4ec; --tone-fg: #23875f; }
.tone-amber { --tone-bg: #fbf0dc; --tone-fg: #a8701b; }
.tone-blue { --tone-bg: #e4ecfb; --tone-fg: #3568b8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .tone-violet { --tone-bg: #2d2a4d; --tone-fg: #b5adff; }
  :root:not([data-theme='light']) .tone-rose { --tone-bg: #3d1d28; --tone-fg: #ff9ab4; }
  :root:not([data-theme='light']) .tone-mint { --tone-bg: #1c3a2e; --tone-fg: #7fe0b6; }
  :root:not([data-theme='light']) .tone-amber { --tone-bg: #3a2f18; --tone-fg: #f0c57a; }
  :root:not([data-theme='light']) .tone-blue { --tone-bg: #1f2b45; --tone-fg: #9bbcf0; }
}
:root[data-theme='dark'] .tone-violet { --tone-bg: #2d2a4d; --tone-fg: #b5adff; }
:root[data-theme='dark'] .tone-rose { --tone-bg: #3d1d28; --tone-fg: #ff9ab4; }
:root[data-theme='dark'] .tone-mint { --tone-bg: #1c3a2e; --tone-fg: #7fe0b6; }
:root[data-theme='dark'] .tone-amber { --tone-bg: #3a2f18; --tone-fg: #f0c57a; }
:root[data-theme='dark'] .tone-blue { --tone-bg: #1f2b45; --tone-fg: #9bbcf0; }

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); overflow: auto; }
.auth-logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 24px; font-weight: 750; letter-spacing: -2px; }
.auth-card h1 { font-size: 18px; font-weight: 650; }
.auth-brand { background: linear-gradient(150deg, #2a2a52 0%, #1d2038 70%); color: #e8e9f7; padding: 56px 9%; display: flex; flex-direction: column; justify-content: center; }
.auth-brand h1 { color: #fff; font-size: 40px; font-weight: 600; margin: 14px 0 12px; }
.auth-brand p { color: #b6b9d6; font-size: 15px; max-width: 420px; }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 30px; font-weight: 750; letter-spacing: -3px; }
.auth-points { margin: 26px 0 0; padding: 0; list-style: none; display: grid; gap: 10px; color: #cfd2ea; font-size: 13px; }
.auth-points li::before { content: '✓ '; color: #9b93f5; }
.auth-form { display: grid; place-items: center; padding: 40px 20px; background: var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 34px 32px; box-shadow: var(--shadow); }
.auth-card h2 { margin-bottom: 6px; }
.auth-card > p { margin-bottom: 22px; }

/* ---------- Shell: bố cục theo Pancake (thanh chức năng trên cùng, cột icon bên trái, vùng làm việc) ---------- */
.app-shell { height: 100dvh; display: grid; grid-template-columns: 56px minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); min-width: 0; }
.top-nav { grid-column: 1 / -1; grid-row: 1; display: flex; align-items: stretch; gap: 0; background: var(--nav-bg); color: var(--nav-text); min-width: 0; }
.top-brand { width: 56px; display: grid; place-items: center; font-size: 22px; font-weight: 750; letter-spacing: -1px; color: var(--nav-text); flex: none; }
.top-brand:hover { color: var(--nav-text); }
.top-tabs { display: flex; align-items: stretch; min-width: 0; overflow-x: auto; }
.top-tab { display: inline-flex; align-items: center; padding: 0 16px; color: var(--nav-text); font-weight: 600; font-size: 14px; white-space: nowrap; opacity: 0.86; }
.top-tab:hover { opacity: 1; background: var(--nav-hover); }
.top-tab.active { opacity: 1; background: var(--nav-active); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; padding: 0 12px; min-width: 0; }
.top-me { display: inline-flex; align-items: center; gap: 8px; color: var(--nav-text); font-weight: 600; font-size: 13px; min-width: 0; }
.top-me-avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--nav-avatar); color: var(--nav-text); flex: none; }
.top-me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.conn { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--nav-hover); color: var(--nav-text); white-space: nowrap; }
.conn::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: middle; }
.conn[data-state='online'] { background: var(--ok); color: #fff; }
.conn[data-state='reconnecting'], .conn[data-state='connecting'] { background: var(--warn); color: #fff; }
.conn[data-state='offline'] { background: var(--danger); color: #fff; }
.mode-badge { font-size: 11px; font-weight: 600; color: var(--nav-text); background: var(--nav-hover); padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.rail { grid-column: 1; grid-row: 2; background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 4px; min-height: 0; border-right: 1px solid var(--border); }
.rail-link { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; color: var(--rail-text); }
.rail-link:hover { background: var(--surface-3); color: var(--text); }
.rail-link.active { background: var(--accent-soft); color: var(--accent); }
.rail-link .ico { width: 19px; height: 19px; }
.rail-bottom { margin-top: auto; }
.main { grid-column: 2; grid-row: 2; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- Inbox ---------- */
.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: 330px minmax(0, 1fr) 280px; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.list-pane { border-right: 1px solid var(--border); }
.pane-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.pane-head strong { font-size: 14px; }
.count { margin-left: 6px; font-size: 11px; color: var(--muted); font-weight: 500; }
.search-row { position: relative; margin: 2px 12px 8px; }
.search-row input { padding-right: 44px; background: var(--surface-2); }
.search-row .search-ico { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--muted); pointer-events: none; }
.search-row kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 10px; }
.filters { padding: 0 12px 6px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.filter-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.filter-selects { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filter-selects select { font-size: 12px; min-height: 30px; padding: 4px 6px; }
.filter-selects select:last-child { grid-column: span 2; }
.conv-list { flex: 1; overflow-y: auto; min-height: 0; }
.conv { position: relative; display: flex; gap: 10px; width: 100%; text-align: left; padding: 11px 12px 11px 14px; border-bottom: 1px solid var(--border); min-width: 0; }
.conv:hover { background: var(--surface-2); }
.conv.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.conv-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv.is-unread .conv-name { font-weight: 750; }
.conv-time { font-size: 11px; color: var(--muted); flex: none; }
.conv-preview { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.is-unread .conv-preview { color: var(--text-2); font-weight: 550; }
.conv-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); min-width: 0; overflow: hidden; }
.conv-meta > span { white-space: nowrap; }
.kind-tag { background: var(--surface-3); padding: 0 6px; border-radius: 4px; color: var(--text-2); }
.page-tag { display: inline-flex; align-items: center; gap: 4px; overflow: hidden; text-overflow: ellipsis; }
.assignee-tag { color: var(--text-2); }
.assignee-tag.muted { color: var(--muted); }
.lock-tag { color: var(--warn); }
.conv-labels { display: flex; gap: 4px; flex-wrap: wrap; }
.unread-dot { position: absolute; left: 4px; top: 50%; transform: translateY(-50%); width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.list-footer { padding: 10px 12px; text-align: center; border-top: 1px solid var(--border); }
.btn-block.btn-ghost { width: 100%; }

.chat-pane { background: var(--surface); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); min-width: 0; }
.chat-head .avatar { width: 36px; height: 36px; }
.chat-title { min-width: 0; flex: 1; }
.chat-title h2 { font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.window { font-size: 11px; padding: 1px 7px; border-radius: 4px; }
.window.ok { color: var(--ok); background: var(--ok-soft); }
.window.expired { color: var(--danger); background: var(--danger-soft); }
.chat-actions { display: flex; gap: 6px; flex: none; }
.assign-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); flex-wrap: wrap; min-width: 0; }
.assign-bar select { width: auto; min-width: 150px; min-height: 28px; padding: 3px 8px; font-size: 12px; }
.assign-bar strong { color: var(--text); font-weight: 600; }
.muted-ico { width: 14px; height: 14px; }
.assign-spacer { flex: 1; }
.lock-banner { background: var(--warn-soft); color: var(--warn); padding: 8px 16px; font-size: 12px; }
.post-card { margin: 12px 16px 0; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.post-card p { margin: 4px 0 0; color: var(--text-2); }
.post-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.thread { flex: 1; overflow-y: auto; padding: 14px 16px 18px; min-height: 0; background: var(--surface-2); }
.load-older { display: block; margin: 0 auto 12px; font-size: 12px; color: var(--accent); padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.day-divider { text-align: center; font-size: 11px; color: var(--muted); margin: 14px 0; position: relative; }
.day-divider span { background: var(--surface-2); padding: 0 10px; position: relative; }
.day-divider::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--border); }
.msg { display: flex; gap: 8px; margin: 8px 0; max-width: 78%; min-width: 0; }
.msg.out { margin-left: auto; flex-direction: row-reverse; }
.msg.note { max-width: 88%; margin: 10px auto; }
.msg.nested { margin-left: 34px; max-width: 80%; }
.msg.out.nested { margin-left: auto; margin-right: 34px; }
.msg-main { min-width: 0; display: grid; gap: 3px; }
.msg.out .msg-main { justify-items: end; }
.msg-author { font-size: 11px; color: var(--muted); padding: 0 4px; }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 12px 12px 12px 3px; padding: 8px 11px; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
.msg.out .bubble { background: var(--accent-soft); border-color: transparent; border-radius: 12px 12px 3px 12px; }
.msg.note .bubble { background: var(--warn-soft); border-color: transparent; color: var(--warn); border-radius: 10px; }
.msg-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 11px; color: var(--muted); padding: 0 4px; }
.msg.out .msg-foot { justify-content: flex-end; }
.delivery { font-size: 10px; font-weight: 650; padding: 1px 6px; border-radius: 4px; }
.delivery.demo { background: var(--warn-soft); color: var(--warn); }
.delivery.pending { background: var(--surface-3); color: var(--muted); }
.delivery.sent { background: var(--ok-soft); color: var(--ok); }
.delivery.failed { background: var(--danger-soft); color: var(--danger); }
.delivery-error { color: var(--danger); }
.thread-root { margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
.thread-root:last-child { border-bottom: 0; }
.composer { margin: 0; border-top: 1px solid var(--border); padding: 0 16px 12px; background: var(--surface); display: grid; gap: 6px; }
.composer.note-mode textarea { background: var(--warn-soft); }
.composer-tabs { display: flex; gap: 4px; margin-top: 8px; }
.composer-tabs button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: var(--radius-sm); font-size: 12px; color: var(--muted); font-weight: 550; }
.composer-tabs button .ico { width: 14px; height: 14px; }
.composer-tabs button.active { background: var(--surface-3); color: var(--text); }
.reply-target { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 5px 10px; border-radius: var(--radius-sm); display: flex; justify-content: space-between; gap: 8px; }
.composer-note { font-size: 12px; color: var(--warn); margin: 0; }
.composer textarea { min-height: 72px; max-height: 220px; border: 1px solid var(--border-strong); }
.composer-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.count-hint { font-size: 11px; color: var(--muted); }
.composer .btn-primary { min-width: 104px; }

.customer-pane { border-left: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
.customer-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; }
.customer-head h3 { flex: 1; }
.customer-head .icon-btn { display: none; }
.customer-card { display: grid; justify-items: center; text-align: center; gap: 4px; padding: 16px; border-bottom: 1px solid var(--border); }
.customer-card strong { font-size: 15px; margin-top: 8px; }
.section { padding: 14px 16px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.section h4 { margin-bottom: 0; }
.section .btn { justify-self: start; }
.label-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.label-list.spacious { gap: 10px; }
.label-row { display: inline-flex; align-items: center; gap: 10px; }
.row-actions { display: inline-flex; gap: 6px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; margin: 0; font-size: 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.facts.wide { grid-template-columns: 180px 1fr; }
.shortcut-hint { padding: 12px 16px; font-size: 11px; color: var(--muted); }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; align-items: center; }
.shortcuts dt { margin: 0; }
.shortcuts dd { margin: 0; }

/* ---------- Trạng thái ---------- */
.empty-state { margin: auto; text-align: center; padding: 36px 22px; display: grid; justify-items: center; gap: 8px; max-width: 380px; }
.empty-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 6px; }
.empty-icon .ico { width: 22px; height: 22px; }
.empty-state p { color: var(--muted); margin: 0; }
.skeleton { padding: 14px; display: grid; gap: 12px; }
.skeleton span { display: block; height: 52px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Tổng quan, nhân viên, cài đặt ---------- */
.page-section { padding: 22px 24px 40px; overflow-y: auto; height: 100%; display: grid; gap: 18px; align-content: start; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head p { margin: 4px 0 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 4px; }
.stat-card span { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-card strong { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; }
.stat-card small { color: var(--muted); font-size: 11px; }
.stat-card.warn strong { color: var(--danger); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; align-content: start; min-width: 0; }
.card > h3 { margin: 0; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table td.num, .table th.num { text-align: right; }
.table td.actions-col, .table th.actions-col { width: auto; }
.team td.actions-col { white-space: normal; min-width: 280px; }
.team td.actions-col .btn { margin: 2px 4px 2px 0; }
.person { display: flex; gap: 10px; align-items: center; }
.person > span:last-child { display: grid; min-width: 0; }
.person small { color: var(--muted); }
.grant { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 4px; margin: 0 4px 4px 0; background: var(--ok-soft); color: var(--ok); }
.grant.view { background: var(--surface-3); color: var(--text-2); }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.plain-list li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.settings { display: grid; grid-template-columns: 200px minmax(0, 1fr); height: 100%; overflow: hidden; }
.settings-nav { border-right: 1px solid var(--border); padding: 18px 12px; display: grid; align-content: start; gap: 2px; background: var(--surface-2); }
.settings-nav a { text-decoration: none; color: var(--text-2); padding: 7px 10px; border-radius: 7px; font-weight: 550; }
.settings-nav a:hover { background: var(--surface-3); }
.settings-nav a.active { background: var(--accent-soft); color: var(--accent); }
.settings-body { padding: 22px 24px; overflow-y: auto; display: grid; gap: 16px; align-content: start; min-width: 0; }
.reply-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.reply-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; display: grid; gap: 6px; background: var(--surface-2); min-width: 0; }
.reply-card h4 { text-transform: none; color: var(--text); font-size: 13px; letter-spacing: 0; margin: 0; }
.reply-card p { color: var(--text-2); font-size: 12px; margin: 0; overflow-wrap: anywhere; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; border: 0; padding: 0; }
.swatch input { position: absolute; opacity: 0; }
.swatch i { display: block; width: 26px; height: 26px; border-radius: 50%; background: var(--tone); border: 2px solid transparent; cursor: pointer; }
.swatch input:checked + i { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }
.swatch i[data-color] { background: var(--tone); }
.swatch { position: relative; flex-direction: row; }
.reply-list { display: grid; gap: 8px; max-height: 50dvh; overflow-y: auto; }
.reply-option { text-align: left; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; display: grid; gap: 4px; }
.reply-option:hover { border-color: var(--accent); background: var(--accent-soft); }
.reply-option span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* ---------- Modal & toast ---------- */
.modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: 88dvh; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.modal.wide { width: min(720px, calc(100vw - 24px)); }
.modal.narrow { width: min(420px, calc(100vw - 24px)); }
.modal::backdrop { background: rgb(15 16 28 / 0.5); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-content { padding: 16px 18px 18px; overflow-y: auto; max-height: calc(88dvh - 60px); display: grid; gap: 12px; }
#modal-body { display: contents; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 16px); background: #252838; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s; z-index: 50; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast[data-tone='error'] { background: #7d1f35; }

/* ---------- Responsive ---------- */
@media (max-width: 1279px) {
  .inbox { grid-template-columns: 300px minmax(0, 1fr); }
  .customer-pane { position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 90vw); z-index: 20; transform: translateX(100%); transition: transform 0.2s; box-shadow: var(--shadow); }
  .customer-pane.open { transform: translateX(0); }
  .customer-head .icon-btn { display: inline-grid; }
  .mobile-only { display: inline-grid; }
  .hide-sm { display: inline; }
}
@media (max-width: 1023px) {
  .app-shell { grid-template-columns: 56px minmax(0, 1fr); }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .chat-pane { display: none; }
  .inbox.has-selection .chat-pane { display: flex; position: absolute; inset: 0; z-index: 5; }
  .inbox.has-selection .list-pane { display: none; }
  .inbox { position: relative; }
  .list-pane { border-right: 0; }
  .settings { grid-template-columns: 1fr; }
  .settings-nav { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px; }
  .settings-nav a { white-space: nowrap; }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
}
@media (max-width: 640px) {
  :root { --row-h: 76px; }
  .app-shell { grid-template-columns: 52px minmax(0, 1fr); }
  .rail { padding: 10px 0; }
  .rail-link { width: 36px; height: 36px; }
  .conn { font-size: 10px; padding: 2px 6px; }
  .conn::before { display: none; }
  .mode-badge { font-size: 10px; }
  .page-section { padding: 16px 14px 32px; }
  .stat-card strong { font-size: 22px; }
  .table { font-size: 12px; }
  .msg { max-width: 92%; }
  .msg.nested { margin-left: 18px; }
  .chat-head { padding: 10px 10px; gap: 8px; }
  .chat-head .avatar { width: 30px; height: 30px; }
  .chat-title h2 { font-size: 14px; }
  .chat-actions .btn span { display: none; }
  .chat-actions .btn { padding: 6px; min-width: 32px; }
  .assign-bar { padding: 8px 10px; }
  .thread { padding: 12px 10px; }
  .composer { padding: 0 10px 10px; }
  .composer-foot .count-hint { display: none; }
  .composer .btn-primary { min-width: 0; margin-left: auto; }
  .customer-pane { width: 100vw; max-width: 100vw; }
  .facts.wide { grid-template-columns: 1fr; }
  .modal { width: calc(100vw - 16px); }
  .filter-selects { grid-template-columns: 1fr 1fr; }
  .filter-selects select:last-child { grid-column: auto; }
  .filter-selects select { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

/* ---------- Lọc theo (bố cục Pancake: nút mở bảng bộ lọc dưới ô tìm kiếm) ---------- */
.list-tools { padding: 0 12px 6px; }
.filter-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 5px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.filter-toggle:hover { background: var(--surface-3); }
.filter-toggle .ico { width: 14px; height: 14px; }
.filter-toggle[aria-expanded='true'] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.filters[hidden] { display: none; }
@media (max-width: 640px) {
  .top-me-name { display: none; }
  .top-tab { padding: 0 10px; font-size: 13px; }
  .top-actions { padding: 0 8px; }
}

/* Liên kết trong thanh chức năng và cột icon không gạch chân (giống bố cục Pancake). */
.top-brand, .top-tab, .rail-link { text-decoration: none; }
.top-tab:focus-visible, .rail-link:focus-visible, .top-brand:focus-visible { outline-color: #fff; }

/* Số liệu căn đều cột (thời gian, số đếm, bảng thống kê). */
.conv-time, .count, .stat-card strong, .num, .side-link b, .unread-badge { font-variant-numeric: tabular-nums; }
