/* Moc Lan's Life — hệ thống giao diện dùng chung (mockup + app).
   Nguyên tắc: bố cục chặt, không bao giờ tràn ngang, PWA không zoom / không vuốt ngang.
   Font: Be Vietnam Pro (nội dung), Lora (tiêu đề). Màu lấy từ icon mộc lan hồng. */

:root {
  --r-sm: 8px; --r-md: 10px; --r-lg: 12px; --r-pill: 999px;
  --gap: 12px; --pad: 14px;
  --side-w: 224px; --top-h: 52px; --tab-h: 58px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: Lora, Georgia, serif;
}

/* ---------- bộ màu (color profile). Đặt trên <html data-theme> hoặc trên một phần tử con
   (ô xem trước) — mọi thành phần chỉ dùng biến bên dưới. ---------- */
:root, [data-theme="moclan"], [data-theme="auto"] {
  --ground: #FBF6F3; --surface: #FFFFFF; --surface-2: #F6EFEC;
  --line: #EADDD8; --line-strong: #E2CFD6;
  --ink: #2B1B22; --ink-2: #5E4C53; --muted: #6E5A62;
  --accent: #A8336A; --accent-hover: #93295B; --accent-ink: #7E2450; --accent-soft: #F6DCE6; --on-accent: #FFFFFF;
  --ok: #3F5A2E;   --ok-soft: #E4EEDC;
  --warn: #8A4B10; --warn-soft: #FBEBD6;
  --bad: #A1261C;  --bad-soft: #FBE1DE;
  --info: #2F4E73; --info-soft: #E3EAF3;
  --on-ink: #FFFFFF; --scrim: rgba(43,27,34,.35); --glow: rgba(168,51,106,.22);
  --shadow: 0 1px 2px rgba(43,27,34,.05), 0 4px 12px rgba(43,27,34,.05); --shadow-lg: 0 10px 30px rgba(43,27,34,.15);
  color-scheme: light;
}
[data-theme="cham"] {
  --ground: #F5F6FA; --surface: #FFFFFF; --surface-2: #EDF0F6;
  --line: #DEE2EC; --line-strong: #CBD2E2;
  --ink: #1B2133; --ink-2: #474F6C; --muted: #5A627E;
  --accent: #34488F; --accent-hover: #293A77; --accent-ink: #253568; --accent-soft: #E0E6F6; --on-accent: #FFFFFF;
  --scrim: rgba(27,33,51,.35); --glow: rgba(52,72,143,.22);
  --shadow: 0 1px 2px rgba(27,33,51,.05), 0 4px 12px rgba(27,33,51,.05); --shadow-lg: 0 10px 30px rgba(27,33,51,.15);
}
[data-theme="reu"] {
  --ground: #F6F7F1; --surface: #FFFFFF; --surface-2: #EEF0E6;
  --line: #DEE2D2; --line-strong: #CDD4BC;
  --ink: #1F2619; --ink-2: #4A5340; --muted: #5B654F;
  --accent: #4D6A2E; --accent-hover: #3F5824; --accent-ink: #34491D; --accent-soft: #E2EBD4; --on-accent: #FFFFFF;
  --ok: #2F6A4A; --ok-soft: #DCEFE4;
  --scrim: rgba(31,38,25,.35); --glow: rgba(77,106,46,.22);
  --shadow: 0 1px 2px rgba(31,38,25,.05), 0 4px 12px rgba(31,38,25,.05); --shadow-lg: 0 10px 30px rgba(31,38,25,.15);
}
[data-theme="bien"] {
  --ground: #F3F7FB; --surface: #FFFFFF; --surface-2: #E9F0F7;
  --line: #D9E3EE; --line-strong: #C4D3E4;
  --ink: #14212F; --ink-2: #3F5268; --muted: #526479;
  --accent: #1F5F99; --accent-hover: #194F80; --accent-ink: #184C7B; --accent-soft: #DCE9F6; --on-accent: #FFFFFF;
  --scrim: rgba(20,33,47,.35); --glow: rgba(31,95,153,.22);
  --shadow: 0 1px 2px rgba(20,33,47,.05), 0 4px 12px rgba(20,33,47,.05); --shadow-lg: 0 10px 30px rgba(20,33,47,.15);
}
[data-theme="troi"] {
  --ground: #F2F8FC; --surface: #FFFFFF; --surface-2: #E6F2FA;
  --line: #D4E6F2; --line-strong: #BCD8EA;
  --ink: #10242F; --ink-2: #3A5563; --muted: #4D6775;
  --accent: #1A6E9E; --accent-hover: #155C85; --accent-ink: #145A82; --accent-soft: #D8EDF8; --on-accent: #FFFFFF;
  --scrim: rgba(16,36,47,.35); --glow: rgba(26,110,158,.22);
  --shadow: 0 1px 2px rgba(16,36,47,.05), 0 4px 12px rgba(16,36,47,.05); --shadow-lg: 0 10px 30px rgba(16,36,47,.15);
}
[data-theme="ngoc"] {
  --ground: #F1F8F7; --surface: #FFFFFF; --surface-2: #E5F1EF;
  --line: #D2E5E2; --line-strong: #B9D8D3;
  --ink: #122624; --ink-2: #3B5552; --muted: #4D6764;
  --accent: #0E6B68; --accent-hover: #0B5856; --accent-ink: #0B5654; --accent-soft: #D5ECE9; --on-accent: #FFFFFF;
  --ok: #2F6A4A; --ok-soft: #DCEFE4;
  --scrim: rgba(18,38,36,.35); --glow: rgba(14,107,104,.22);
  --shadow: 0 1px 2px rgba(18,38,36,.05), 0 4px 12px rgba(18,38,36,.05); --shadow-lg: 0 10px 30px rgba(18,38,36,.15);
}
[data-theme="tra"] {
  --ground: #F3F8F2; --surface: #FFFFFF; --surface-2: #E8F1E6;
  --line: #D6E5D3; --line-strong: #BFD7BB;
  --ink: #15251A; --ink-2: #3F5545; --muted: #516756;
  --accent: #2B7044; --accent-hover: #235C38; --accent-ink: #225A36; --accent-soft: #DAEDDD; --on-accent: #FFFFFF;
  --ok: #2F6A4A; --ok-soft: #DCEFE4;
  --scrim: rgba(21,37,26,.35); --glow: rgba(43,112,68,.22);
  --shadow: 0 1px 2px rgba(21,37,26,.05), 0 4px 12px rgba(21,37,26,.05); --shadow-lg: 0 10px 30px rgba(21,37,26,.15);
}
[data-theme="demxanh"] {
  --ground: #0E1520; --surface: #162130; --surface-2: #1E2B3D;
  --line: #29384D; --line-strong: #364A63;
  --ink: #E6EEF7; --ink-2: #C0CDDC; --muted: #93A4B8;
  --accent: #7DB4EC; --accent-hover: #98C5F1; --accent-ink: #A9CDF3; --accent-soft: #1F3A5A; --on-accent: #0C1824;
  --ok: #9FD3A8;   --ok-soft: #1C3326;
  --warn: #E8B276; --warn-soft: #3B2A17;
  --bad: #F29A90;  --bad-soft: #45211C;
  --info: #A0BBE0; --info-soft: #1F2C3E;
  --on-ink: #0E1520; --scrim: rgba(0,0,0,.55); --glow: rgba(0,0,0,.4);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25); --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}
[data-theme="dat"] {
  --ground: #FBF5EF; --surface: #FFFFFF; --surface-2: #F5ECE3;
  --line: #EADBCD; --line-strong: #DFCAB6;
  --ink: #2D1E15; --ink-2: #5D4A3C; --muted: #6D5748;
  --accent: #A3462A; --accent-hover: #8B3B22; --accent-ink: #78331D; --accent-soft: #F6DFD3; --on-accent: #FFFFFF;
  --warn: #7A5A0C; --warn-soft: #F7EDCF;
  --scrim: rgba(45,30,21,.35); --glow: rgba(163,70,42,.22);
  --shadow: 0 1px 2px rgba(45,30,21,.05), 0 4px 12px rgba(45,30,21,.05); --shadow-lg: 0 10px 30px rgba(45,30,21,.15);
}
[data-theme="dem"] {
  --ground: #17121A; --surface: #211A24; --surface-2: #2B222E;
  --line: #392E3C; --line-strong: #4B3D4F;
  --ink: #F3E9EE; --ink-2: #D2C2CA; --muted: #AC9AA4;
  --accent: #E58AB3; --accent-hover: #EFA3C5; --accent-ink: #F5BCD5; --accent-soft: #4A2639; --on-accent: #26121C;
  --ok: #A9CB8E;   --ok-soft: #26331D;
  --warn: #E8B276; --warn-soft: #3B2A17;
  --bad: #F29A90;  --bad-soft: #45211C;
  --info: #A0BBE0; --info-soft: #1F2C3E;
  --on-ink: #17121A; --scrim: rgba(0,0,0,.55); --glow: rgba(0,0,0,.4);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25); --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --ground: #17121A; --surface: #211A24; --surface-2: #2B222E;
    --line: #392E3C; --line-strong: #4B3D4F;
    --ink: #F3E9EE; --ink-2: #D2C2CA; --muted: #AC9AA4;
    --accent: #E58AB3; --accent-hover: #EFA3C5; --accent-ink: #F5BCD5; --accent-soft: #4A2639; --on-accent: #26121C;
    --ok: #A9CB8E;   --ok-soft: #26331D;
    --warn: #E8B276; --warn-soft: #3B2A17;
    --bad: #F29A90;  --bad-soft: #45211C;
    --info: #A0BBE0; --info-soft: #1F2C3E;
    --on-ink: #17121A; --scrim: rgba(0,0,0,.55); --glow: rgba(0,0,0,.4);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25); --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

/* ---------- nền tảng: chống tràn ngang, chống zoom ---------- */
*, *::before, *::after { box-sizing: border-box; min-width: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: hidden; overflow-x: clip; overscroll-behavior: none; }
body { margin: 0; width: 100%; max-width: 100vw; overflow-x: hidden; overflow-x: clip; overscroll-behavior-x: none; touch-action: pan-y;
  font: 14px/1.5 var(--font); background: var(--ground); color: var(--ink); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, a, input, select, textarea, label { touch-action: manipulation; }
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
p, h1, h2, h3, b, span, a, td, li { overflow-wrap: anywhere; }
a { color: var(--accent); text-decoration: none; } a:hover { color: var(--accent-hover); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; letter-spacing: -.2px; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ellipsis { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- khung ứng dụng ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; width: 100%; }
.side { position: sticky; top: 0; height: 100vh; height: 100dvh; background: var(--surface); border-right: 1px solid var(--line); padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; padding: 2px 6px 10px; font-family: var(--display); font-weight: 600; font-size: 16px; color: var(--ink); }
.brand img { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.switch { position: relative; margin-bottom: 6px; }
.page-switch { width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 8px; min-height: 40px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--ground);
  font: inherit; font-weight: 600; font-size: 13px; color: var(--ink); cursor: pointer; text-align: left; }
.page-switch .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-switch .av { width: 24px; height: 24px; font-size: 10px; }
.menu { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-lg); padding: 4px; display: flex; flex-direction: column; min-width: 220px; }
.menu button, .menu a { font: inherit; font-size: 13px; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 8px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink); cursor: pointer; text-align: left; }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu.menu-up { top: auto; bottom: calc(100% + 4px); }
.menu .av { width: 24px; height: 24px; font-size: 10px; }
.menu .badge { margin-left: auto; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; border-radius: var(--r-sm); color: var(--ink); font-size: 13px; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.count, .badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill); background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.nav .count { margin-left: auto; }
.side .foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 8px 4px 0; border-top: 1px solid var(--line); font-size: 13px; }
.side .foot .av { width: 28px; height: 28px; font-size: 11px; }

.main { width: 100%; max-width: 1180px; padding: 16px 20px 32px; display: flex; flex-direction: column; gap: var(--gap); }
.head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.head .sub { color: var(--muted); font-size: 12px; }
.head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* thanh dưới cho điện thoại (ẩn trên desktop) */
.tabbar { display: none; }

/* ---------- thành phần ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: var(--pad); }
.card.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: var(--gap); }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 auto; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.btn { font: inherit; font-size: 13px; font-weight: 600; min-height: 36px; padding: 0 14px; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; text-decoration: none; white-space: nowrap; flex: none; }
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--on-accent); } .btn.pri:hover { background: var(--accent-hover); }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.bad { background: transparent; border-color: transparent; color: var(--bad); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 12px; border-radius: var(--r-sm); }
.btn.icon { width: 36px; padding: 0; } .btn.sm.icon { width: 30px; }
.btn.block { width: 100%; min-height: 44px; font-size: 14px; }
.btn.armed { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn.liked { color: var(--accent); background: var(--accent-soft); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
input, textarea, select { font: inherit; font-size: 14px; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm); min-height: 36px; padding: 0 10px; width: 100%; max-width: 100%; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { padding: 8px 10px; min-height: 96px; resize: vertical; line-height: 1.5; }
input[type=checkbox], input[type=radio] { min-height: 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-pill); font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tag.new { background: var(--accent-soft); color: var(--accent-ink); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--info-soft); color: var(--info); }

.av { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex: none; overflow: hidden; }
.av.sm { width: 24px; height: 24px; font-size: 10px; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.prov { width: 28px; height: 28px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; flex: none; background: var(--accent-soft); color: var(--accent-ink); }
.prov svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.btn .prov { background: transparent; color: currentColor; width: 22px; height: 22px; } .btn .prov svg { width: 20px; height: 20px; }

/* tab: xuống dòng, không cuộn ngang */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tabs a { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: var(--r-pill); color: var(--ink-2); font-weight: 600; font-size: 13px; background: var(--surface); border: 1px solid var(--line); }
.tabs a.on { color: var(--on-ink); background: var(--ink); border-color: var(--ink); }
.fchips button { font: inherit; display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 10px; border-radius: var(--r-pill); color: var(--ink-2); font-weight: 600; font-size: 12px; background: var(--surface); border: 1px dashed var(--line-strong); cursor: pointer; }
.fchips button.on { color: var(--accent-ink); background: var(--accent-soft); border: 1px solid var(--accent-soft); }
.tabs .n:empty { display: none; }
.tabs .n { font-size: 11px; opacity: .85; }

.flash { padding: 10px 12px; border-radius: var(--r-md); background: var(--ok-soft); color: var(--ok); font-size: 13px; font-weight: 500; }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

.stat { display: flex; flex-direction: column; gap: 2px; color: var(--ink); padding: 12px; }
.stat .v { font-family: var(--display); font-size: 22px; font-weight: 600; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat .d { font-size: 11px; font-weight: 600; color: var(--ok); }

/* danh sách dạng hàng — thay cho bảng, không bao giờ tràn ngang */
.list { display: flex; flex-direction: column; }
.list > .item { display: flex; align-items: center; gap: 10px; padding: 10px var(--pad); border-top: 1px solid var(--line); flex-wrap: wrap; }
.list > .item:first-child { border-top: 0; }
.item .main-col { flex: 1 1 200px; display: flex; flex-direction: column; gap: 2px; }
.item .side-col { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 10px var(--pad); border-bottom: 1px solid var(--line); }

/* phân quyền: mỗi dòng = (trang hoặc người) + vai trò + các quyền dạng chip */
.pr { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.pr:first-child { border-top: 0; padding-top: 0; }
.pr-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pr-head .grow { min-width: 0; }
.pr-head select { width: auto; max-width: 46%; flex: none; margin-left: auto; }
.pr.off .pr-head .grow { opacity: .6; }
.pr-perms { display: flex; flex-wrap: wrap; gap: 6px; }
.pchip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r-pill); font-size: 12px; background: var(--ground); color: var(--ink-2); cursor: pointer; max-width: 100%; }
.pchip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.link-item { color: inherit; text-decoration: none; }
.link-item:hover { background: var(--surface-2); }
.danger-zone { border-color: var(--bad-soft); }
.perm-sum { display: flex; flex-wrap: wrap; gap: 4px; }
.log-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.log-filter .field { flex: 1 1 150px; }

/* bài viết */
.post { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 12px; align-items: start; }
.thumb { width: 72px; height: 72px; border-radius: var(--r-md); background: var(--surface-2); border: 1px dashed var(--line-strong); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 10px; text-align: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.metrics { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 12px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* bình luận */
.cmt { display: flex; flex-direction: column; gap: 8px; }
.cmt .who { display: flex; align-items: center; gap: 8px; }
.cmt .who .meta { flex: 1; display: flex; flex-direction: column; }
.on-post { font-size: 12px; color: var(--muted); padding: 4px 8px; background: var(--surface-2); border-radius: var(--r-sm); }
.reply { display: flex; gap: 6px; flex-wrap: wrap; }
.reply input { flex: 1 1 200px; width: auto; }
.mine { display: flex; gap: 6px; align-items: flex-start; margin-left: 20px; padding: 6px 10px; background: var(--accent-soft); border-radius: var(--r-md); font-size: 13px; }
.leaving { opacity: 0; transform: scale(.98); transition: opacity .3s, transform .3s; }

/* hộp thư: 2 cột desktop, 1 màn mỗi lúc trên điện thoại */
.chat { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: var(--gap); height: calc(100dvh - 120px); min-height: 420px; }
.threads { display: flex; flex-direction: column; overflow-y: auto; padding: 4px; }
.thread { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: var(--r-md); color: var(--ink); }
.thread:hover { background: var(--surface-2); color: var(--ink); }
.thread.on { background: var(--accent-soft); }
.thread .t { flex: 1; display: flex; flex-direction: column; }
.thread .s { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread.unread b::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }
.conv { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.conv-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.conv-head .back { display: none; }
.msgs { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--ground); overflow-y: auto; overflow-x: hidden; }
.bubble { align-self: flex-start; max-width: 78%; padding: 7px 11px; border-radius: 16px 16px 16px 4px; background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.bubble.me { align-self: flex-end; background: var(--accent); border-color: var(--accent); color: var(--on-accent); border-radius: 16px 16px 4px 16px; }
.bubble .tm { display: block; font-size: 10px; opacity: .75; margin-top: 2px; }
.day { align-self: center; font-size: 11px; color: var(--muted); padding: 2px 8px; background: var(--surface-2); border-radius: var(--r-pill); }
.composer { border-top: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; max-height: 64px; overflow: hidden; }
.chips button { font: inherit; font-size: 12px; min-height: 28px; padding: 0 10px; border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--ground); color: var(--ink-2); cursor: pointer; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.window { font-size: 11px; font-weight: 600; }

/* tạo bài */
.kinds { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.kinds label { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border: 1px solid var(--line-strong); border-radius: var(--r-md); font-size: 12px; font-weight: 600; cursor: pointer; background: var(--surface); text-align: center; }
.kinds input { position: absolute; opacity: 0; pointer-events: none; }
.kinds label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.drop { display: block; border: 2px dashed var(--line-strong); border-radius: var(--r-lg); padding: 16px; text-align: center; color: var(--muted); background: var(--ground); }
.preview-fb { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.preview-fb .ph { aspect-ratio: 4 / 3; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }

/* đăng nhập */
.auth-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.auth .logo { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.auth .logo img { width: 76px; height: 76px; border-radius: 20px; box-shadow: 0 8px 24px var(--glow); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* toast, hộp thoại, trạng thái trống, biểu đồ */
#toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 100; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: var(--on-ink); padding: 8px 14px; border-radius: var(--r-pill); font-size: 13px; box-shadow: var(--shadow); transition: opacity .3s, transform .3s; text-align: center; }
.toast.bad { background: var(--bad); color: var(--surface); }
.toast.out { opacity: 0; transform: translateY(8px); }
dialog { border: 0; border-radius: var(--r-lg); padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 48px); box-shadow: 0 24px 60px var(--scrim); color: var(--ink); background: var(--surface); }
dialog::backdrop { background: var(--scrim); }
dialog:has(.ai-menu:not([hidden])) { overflow: visible; } /* menu AI trong hộp thoại không bị cắt */
dialog .dlg { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.empty { text-align: center; padding: 24px 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; }
.empty img { width: 48px; height: 48px; border-radius: 12px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 110px; }
.bars span { flex: 1; background: var(--accent-soft); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars span:hover { background: var(--accent); }
.legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.copy { display: flex; gap: 6px; } .copy input { flex: 1; font-size: 12px; width: auto; }

/* ================= điện thoại ================= */
@media (max-width: 760px) {
  :root { --pad: 12px; --gap: 10px; }
  .app { grid-template-columns: minmax(0, 1fr); padding-top: var(--top-h); padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
  /* menu trái -> thanh trên cố định: logo + chọn trang + tài khoản */
  .side { position: fixed; z-index: 30; top: 0; left: 0; right: 0; height: var(--top-h); padding: 0 8px; padding-top: env(safe-area-inset-top);
    flex-direction: row; align-items: center; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .side .brand { padding: 0; font-size: 0; gap: 0; } .side .brand img { width: 28px; height: 28px; }
  .side .switch { flex: 1; margin: 0; } .side .page-switch { min-height: 36px; }
  .side .nav { display: none; }
  .side .bell { position: relative; top: auto; right: auto; width: 36px; height: 36px; }
  .themes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side .foot { margin: 0; padding: 0; border: 0; } .side .foot > div, .side .foot .btn { display: none; }
  /* thanh tab dưới */
  .tabbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
    height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
  .tabbar a, .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font: inherit; font-size: 10px; font-weight: 600; color: var(--muted); background: none; border: 0; cursor: pointer; }
  .tabbar .on { color: var(--accent); }
  .tabbar svg.i { width: 22px; height: 22px; }
  .tabbar .count { position: absolute; top: 6px; left: calc(50% + 6px); }
  .tabbar .menu { top: auto; bottom: calc(100% + 6px); left: auto; right: 6px; min-width: 200px; }
  .main { padding: 12px 12px 20px; }
  h1 { font-size: 19px; }
  .head .actions .btn { min-height: 36px; }
  /* chống iPhone tự zoom khi gõ: chữ ô nhập ≥ 16px */
  input, textarea, select { font-size: 16px; min-height: 40px; }
  .btn { min-height: 40px; } .btn.sm { min-height: 34px; } .btn.icon { width: 40px; } .btn.sm.icon { width: 34px; }
  .post { grid-template-columns: 56px minmax(0, 1fr); } .thumb { width: 56px; height: 56px; }
  .kinds { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  /* hộp thư: 1 màn mỗi lúc */
  .chat { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - var(--top-h) - var(--tab-h) - env(safe-area-inset-bottom) - 64px); }
  .chat .conv { display: none; } .chat.open .conv { display: flex; } .chat.open .threads { display: none; }
  .conv-head .back { display: inline-flex; }
  .bubble { max-width: 86%; }
}

/* ================= tiện ích (thay cho style viết tay trong HTML) ================= */
.ml-auto { margin-left: auto; } .center { text-align: center; } .right { justify-content: flex-end; }
.between { justify-content: space-between; } .top { align-items: flex-start; } .end { align-items: flex-end; }
.pre { white-space: pre-wrap; } .nowrap-text { white-space: nowrap; }
.ink { color: var(--ink); } .warn-text { color: var(--warn); } .bad-text { color: var(--bad); } .ok-text { color: var(--ok); }
.stat .d.warn { color: var(--warn); } .stat .d.muted { color: var(--muted); }
.fs-13 { font-size: 13px; } .fw-6 { font-weight: 600; }
.mt-auto { margin-top: auto; } .p-0 { padding: 0; } .w-full { width: 100%; }
.dim { opacity: .7; }
.time-col { flex: 0 0 72px; color: var(--muted); font-size: 12px; }
.av.lg { width: 48px; height: 48px; font-size: 16px; }
.logo-md { width: 48px; height: 48px; border-radius: 12px; flex: none; }
.sec-title { display: flex; align-items: center; gap: 8px; }
.sec-title a { margin-left: auto; font-size: 13px; }
.linkrow { display: flex; align-items: flex-start; gap: 8px; color: var(--ink); padding: 6px 0; }
.linkrow:hover { color: var(--ink); }
.linkrow .txt { flex: 1; }
.bars span { height: var(--h, 2px); }
.pill-input { border-radius: var(--r-pill); }
.chat-send { border-radius: 50%; }
.icon-xl { width: 36px; height: 36px; color: var(--muted); }
.icon-xl.warn { color: var(--warn); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.inline { display: inline; }
form.inline-flex { display: inline-flex; }
.check { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; font-size: 13px; }
.kv { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card.link { color: var(--ink); } .card.link:hover { border-color: var(--line-strong); color: var(--ink); }
.hint { font-size: 12px; color: var(--muted); }
.code-box { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-2); padding: 8px; border-radius: var(--r-sm); overflow-wrap: anywhere; }
.card-pad { padding: 10px 14px; }
.tabbar .switch { position: relative; display: flex; margin: 0; }
.tabbar .switch > button { width: 100%; }
.tabbar > span { display: block; }
.side .foot a.av { color: var(--accent-ink); }
details > summary { cursor: pointer; list-style: none; padding: 4px 0; }
details > summary::-webkit-details-marker { display: none; }
fieldset { border: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; }
.thread .nowrap-text { font-size: 11px; }
.row.nowrap > .tag, .row.nowrap > .badge, .linkrow > .tag, .linkrow > .badge { flex: none; }

/* ---------- thông báo ---------- */
@media (min-width: 761px) { .side > .brand { padding-right: 40px; } }
.bell { position: absolute; top: 14px; right: 10px; width: 32px; height: 32px; border-radius: var(--r-md); display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); flex: none; }
.bell:hover, .bell.on { background: var(--surface-2); color: var(--accent); }
.bell .count { position: absolute; top: -2px; right: -4px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; box-shadow: 0 0 0 2px var(--surface); }
.bell.ring svg { animation: ring .8s ease-in-out 2; transform-origin: 50% 10%; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(14deg); } 75% { transform: rotate(-14deg); } }
@media (prefers-reduced-motion: reduce) { .bell.ring svg { animation: none; } }
.day { font-family: var(--font); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.list > .notif { color: var(--ink); align-items: flex-start; flex-wrap: nowrap; }
.notif:hover { background: var(--surface-2); color: var(--ink); }
.list > .notif .main-col { flex: 1 1 auto; }
.notif .body { font-size: 13px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif:not(.unread) b { font-weight: 500; }
.notif:not(.unread) .ni { opacity: .6; }
.notif .side-col { flex: none; flex-wrap: nowrap; }
.ni { width: 32px; height: 32px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-ink); }
.ni svg.i { width: 16px; height: 16px; }
.ni.warn { background: var(--warn-soft); color: var(--warn); } .ni.info { background: var(--info-soft); color: var(--info); } .ni.ok { background: var(--ok-soft); color: var(--ok); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.check-row { cursor: pointer; flex-wrap: nowrap; }

/* công tắc bật/tắt */
input.switch-input { appearance: none; -webkit-appearance: none; width: 40px; height: 24px; border-radius: var(--r-pill); background: var(--line-strong); position: relative; cursor: pointer; transition: background .2s; flex: none; border: 0; margin-left: auto; }
input.switch-input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
input.switch-input:checked { background: var(--accent); }
input.switch-input:checked::after { transform: translateX(16px); }

/* chọn bộ màu: mỗi ô xem trước mang data-theme riêng nên tự lấy đúng màu */
.themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.theme-opt { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r-md); cursor: pointer; background: var(--surface); }
.theme-opt:hover { border-color: var(--line-strong); }
.theme-opt input { position: absolute; opacity: 0; pointer-events: none; }
.theme-opt:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.theme-opt:has(input:focus-visible) { outline: 3px solid var(--accent-soft); }
.swatch { display: flex; height: 34px; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); background: var(--ground); padding: 5px; gap: 4px; margin-bottom: 4px; }
.swatch i { flex: 1; border-radius: 4px; background: var(--surface); }
.swatch i:nth-child(2) { flex: .6; background: var(--accent); }
.swatch i:nth-child(3) { flex: .6; background: var(--ink); }
.swatch[data-theme="auto"] { background: linear-gradient(135deg, #FBF6F3 50%, #17121A 50%); }
.t-name { font-weight: 600; font-size: 13px; color: var(--ink); }
.t-sub { font-size: 11px; color: var(--muted); line-height: 1.35; }

/* ---------- môi trường mockup ---------- */
.mock-index { margin: 0 auto; }
.mock-ribbon { position: fixed; z-index: 90; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--warn-soft); color: var(--warn); font-size: 11px; font-weight: 700; letter-spacing: .3px; box-shadow: var(--shadow); opacity: .9; }
@media (max-width: 760px) { .mock-ribbon { right: 50%; transform: translateX(50%); bottom: calc(var(--tab-h) + 4px + env(safe-area-inset-bottom)); font-size: 10px; padding: 1px 8px; } }

/* ---------- Kho media ---------- */
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.uploads { display: flex; flex-direction: column; gap: 6px; }
.uploads:empty { display: none; }
.up { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.up .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up .pct { color: var(--muted); font-weight: 600; text-align: right; max-width: 60vw; overflow-wrap: anywhere; }
.up .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.up .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up.ok .pct { color: var(--ok); } .up.bad .pct { color: var(--bad); } .up.bad .bar i { background: var(--bad); }
.search { display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); color: var(--muted); min-width: 0; flex: 0 1 260px; }
.search input { border: 0; background: transparent; min-height: 34px; padding: 0; width: 100%; min-width: 0; font: inherit; color: var(--ink); outline: none; box-shadow: none; }
.media-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); }
.mcard { padding: 0; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.mthumb { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1; background: var(--surface-2); overflow: hidden; }
.mthumb img, .mthumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mbadge { position: absolute; left: 8px; bottom: 8px; display: inline-flex; padding: 4px; border-radius: var(--r-sm); background: var(--scrim); color: var(--on-ink); }
.mmeta { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 0; min-width: 0; font-size: 13px; }
.mact { padding: 6px 6px 8px; gap: 2px; }
.mcard { position: relative; }
.msel { position: absolute; top: 8px; left: 8px; z-index: 2; width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.28); box-shadow: 0 1px 4px rgba(0,0,0,.35); cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; color: var(--on-accent); font: 700 13px var(--font); }
.msel[aria-pressed="true"] { background: var(--accent); border-color: #fff; }
.mcard.on { outline: 3px solid var(--accent); outline-offset: -3px; }
.mbar { position: sticky; bottom: 12px; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-top: var(--gap); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); flex-wrap: wrap; }
.mbar[hidden] { display: none; }
@media (max-width: 760px) { .mbar { bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px); } }
.preview-fb .ph:has(.pv-grid) { aspect-ratio: auto; }
.pv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; width: 100%; }
.pv-grid img, .pv-more { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.pv-grid > :only-child { grid-column: 1 / -1; aspect-ratio: auto; }
.pv-more { position: relative; } .pv-more img { width: 100%; height: 100%; }
.pv-more b { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); color: #fff; font-size: 24px; }
.mact form { margin-left: auto; }
.pick-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); max-height: 60dvh; overflow-y: auto; }
.pick { display: flex; flex-direction: column; gap: 4px; padding: 0; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; overflow: hidden; font: inherit; font-size: 11px; color: var(--ink-2); text-align: left; }
.pick img, .pick video { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--surface-2); }
.pick span { padding: 0 6px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick:hover, .pick:focus-visible { border-color: var(--accent); }
@media (max-width: 760px) { .search { flex: 1 1 100%; } .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mact .lb { display: none; } .mact .btn.sm { width: 34px; padding: 0; } }

/* ---------- ảnh đại diện ---------- */
.av.xl { width: 64px; height: 64px; font-size: 20px; }
.av.add { background: var(--surface-2); color: var(--muted); }
.avatar-opts { display: flex; flex-wrap: wrap; gap: 10px; }
.avatar-opts form { display: contents; }
.avatar-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 104px; padding: 10px 6px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12px; font-weight: 600; text-align: center; cursor: pointer; }
.avatar-opt:hover { border-color: var(--line-strong); }
.avatar-opt.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); color: var(--accent-ink); cursor: default; }
@media (max-width: 760px) { .avatar-opt { width: calc(33.333% - 7px); min-width: 0; } }

/* ---------- loading ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.spin { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; vertical-align: -2px; flex: none; }
#nav-loader { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: rgba(127, 127, 127, .12); background: color-mix(in srgb, var(--ground) 55%, transparent);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); opacity: 0; visibility: hidden; transition: opacity .15s, visibility .15s; }
#nav-loader.on { opacity: 1; visibility: visible; }
#nav-loader .box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 24px; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-lg); color: var(--ink-2); font-size: 13px; font-weight: 600; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink-2); border-right-color: transparent; animation: spin .7s linear infinite; }
.btn.pri.loading::after { border-color: var(--on-accent); border-right-color: transparent; }
.btn.soft.loading::after { border-color: var(--accent-ink); border-right-color: transparent; }
.btn.bad.loading::after { border-color: var(--bad); border-right-color: transparent; }
.btn.sm.loading::after { width: 13px; height: 13px; }
[aria-busy=true]:not(.btn):not(button) { position: relative; opacity: .6; pointer-events: none; transition: opacity .15s; }
.theme-opt[aria-busy=true]::after { content: ""; position: absolute; top: 8px; right: 8px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin .7s linear infinite; }
.loading-note { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; grid-column: 1 / -1; }
@media (prefers-reduced-motion: reduce) { .spinner, .spin, .btn.loading::after, .theme-opt[aria-busy=true]::after { animation-duration: 1.6s; } #nav-loader { transition: none; } }

/* ---------- nút + hộp thoại Giao diện ---------- */
.theme-btn { gap: 8px; }
.swatch.mini { width: 34px; height: 20px; padding: 3px; gap: 2px; margin: 0; border-radius: 5px; flex: none; }
.swatch.mini i { border-radius: 2px; }
#dlg-theme { width: min(600px, calc(100vw - 24px)); }
#dlg-theme .dlg { overflow-y: auto; max-height: calc(100dvh - 48px); }

/* ---------- icon theo bộ màu trong picker ---------- */
.t-top { display: flex; gap: 6px; align-items: stretch; margin-bottom: 4px; }
.t-top .swatch { flex: 1; margin: 0; height: auto; }
.t-icon { width: 40px; height: 40px; border-radius: 10px; flex: none; object-fit: cover; box-shadow: 0 1px 3px var(--scrim); }
.t-icon.mini { width: 22px; height: 22px; border-radius: 6px; box-shadow: none; }

/* ---------- picker bộ màu: icon chủ đạo bên trái, tên + 3 chấm màu bên phải ---------- */
.theme-opt { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; padding: 6px; }
.theme-opt .t-icon { width: 56px; height: 56px; border-radius: 13px; }
.t-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.t-info .t-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dots { display: flex; gap: 4px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--ground); }
.dots i:nth-child(2) { background: var(--accent); border-color: var(--accent); }
.dots i:nth-child(3) { background: var(--ink); border-color: var(--ink); }
.dots[data-theme="auto"] i:first-child { background: linear-gradient(135deg, #FBF6F3 50%, #17121A 50%); }
@media (max-width: 760px) { .theme-opt .t-icon { width: 48px; height: 48px; border-radius: 11px; } }
.dots i { flex: none; }
@media (max-width: 760px) { .themes { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Tổng quan: thưa, dễ theo dõi ---------- */
.all-av { background: var(--surface-2); color: var(--ink-2); }
.all-av .i { width: 16px; height: 16px; }
.av.md { width: 36px; height: 36px; font-size: 13px; }
.av.xxl { width: 88px; height: 88px; font-size: 28px; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.kpi { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "i v" "i l" "i s"; column-gap: 14px; row-gap: 2px; align-items: center; padding: 18px; color: var(--ink); }
a.kpi:hover { border-color: var(--line-strong); color: var(--ink); }
.kpi .ki { grid-area: i; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-ink); align-self: start; }
.kpi .kv { grid-area: v; font-family: var(--display); font-size: 30px; font-weight: 600; line-height: 1.1; }
.kpi .kl { grid-area: l; font-weight: 600; font-size: 14px; }
.kpi .ks { grid-area: s; font-size: 12px; color: var(--muted); }
.kpi.warn .ki { background: var(--warn-soft); color: var(--warn); } .kpi.warn .ks { color: var(--warn); font-weight: 600; }
.kpi.ok .ki { background: var(--ok-soft); color: var(--ok); }
.pgrid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.pcard { position: relative; display: flex; flex-direction: column; gap: 16px; padding: 18px; }
.pc-head { display: flex; align-items: center; gap: 14px; color: var(--ink); min-width: 0; }
.pc-head:hover { color: var(--ink); } .pc-head:hover b { color: var(--accent-ink); }
.pc-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pc-name b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-name .muted { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-name .tag { align-self: flex-start; margin-top: 2px; }
.pc-nums { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 10px; }
.pc-nums a { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); color: var(--muted); }
.pc-nums a:hover { color: var(--ink); }
.pc-nums .n { font-family: var(--display); font-size: 24px; font-weight: 600; line-height: 1.1; color: var(--ink-2); }
.pc-nums .l { font-size: 12px; }
.pc-nums a.on { background: var(--accent-soft); } .pc-nums a.on .n { color: var(--accent-ink); }
.pc-nums a.warn { background: var(--warn-soft); } .pc-nums a.warn .n { color: var(--warn); }
.phero { display: flex; align-items: center; gap: 20px; padding: 20px; position: relative; flex-wrap: wrap; }
.ph-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.ph-main h2 { font-size: 22px; margin: 0; }
.ph-main p { margin: 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ph-all { position: absolute; top: 14px; right: 14px; }
.dash-lists > .card { padding: 18px; gap: 6px; }
.qlist { display: flex; flex-direction: column; }
.qrow { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); color: var(--ink); }
.qrow:first-child { border-top: 0; padding-top: 4px; }
.qrow:hover { color: var(--ink); } .qrow:hover b { color: var(--accent-ink); }
.qt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.qh { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; } .qh .muted { font-size: 12px; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 13px; color: var(--ink-2); }
.qempty { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
@media (max-width: 760px) {
  .kpis { gap: 8px; }
  .kpi { grid-template-columns: 1fr; grid-template-areas: "v" "l" "s"; padding: 12px; }
  .kpi .ki { display: none; } .kpi .kv { font-size: 24px; } .kpi .kl { font-size: 12px; } .kpi .ks { display: none; }
  .phero { flex-direction: column; align-items: flex-start; } .av.xxl { width: 72px; height: 72px; }
  .ph-all { position: static; }
}

/* ---------- Bài viết: lưới thẻ ảnh trái, bấm thẻ để mở danh sách thao tác ---------- */
.post-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); align-items: start; }
.post-grid[hidden] { display: none; }
.post-grid > .empty { grid-column: 1 / -1; }
.post-wrap { position: relative; min-width: 0; }
.post { display: grid; grid-template-columns: 40% minmax(0, 1fr); gap: 0; padding: 0; height: 200px; overflow: hidden; cursor: pointer; text-align: left; }
.post:hover { border-color: var(--line-strong); }
.post[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.pthumb { height: 100%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* nạp dần: hoa mộc lan giữ chỗ → ảnh thật tải xong mờ dần lên trên; thẻ bài lần lượt hiện lên mềm mại */
.pthumb { position: relative; }
.pthumb .pth-ph { width: 40%; max-width: 76px; height: auto; object-fit: contain; opacity: .5; }
.pthumb .pth-img { position: absolute; inset: 0; opacity: 0; transition: opacity .8s cubic-bezier(.4, 0, .2, 1); }
.pthumb .pth-img.in { opacity: 1; }
@keyframes mll-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes mll-breathe { 0%, 100% { opacity: .32; } 50% { opacity: .6; } }
@keyframes mll-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
/* backwards (không phải both): chạy xong thì bỏ hẳn animation, thẻ không giữ lớp xếp chồng riêng — nếu giữ,
   thẻ sau sẽ đè lên menu ••• của thẻ trước */
.post-grid > .post-wrap { animation: mll-rise .6s cubic-bezier(.22, .8, .3, 1) backwards; animation-delay: calc(min(var(--i, 0), 10) * 55ms); }
.post-wrap:has(> .menu:not([hidden])) { z-index: 30; }   /* thẻ đang mở menu luôn nằm trên các thẻ khác */
.post-wrap.sk .post { cursor: default; }
.post-wrap.sk .pth-ph { animation: mll-breathe 2.2s ease-in-out infinite; }
.sk-line { display: block; height: 10px; width: 100%; border-radius: 6px; margin-top: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%); background-size: 200% 100%;
  animation: mll-shimmer 1.6s ease-in-out infinite; }
.sk-line.w30 { width: 30%; margin: 0 0 6px; } .sk-line.w60 { width: 60%; }
.part-err { gap: 10px; }
@media (prefers-reduced-motion: reduce) {
  .post-grid > .post-wrap, .post-wrap.sk .pth-ph, .sk-line { animation: none; }
  .pthumb .pth-img { transition: none; }
}
.pbody { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; min-width: 0; }
.pmeta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.ptext { margin: 0; flex: 1; min-height: 0; font-size: 13px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.pbody .metrics { align-items: center; }
.metrics span { display: inline-flex; align-items: center; gap: 4px; }
.pmore { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; justify-content: center; color: var(--ink-2); background: var(--surface-2); }
.post[aria-expanded="true"] .pmore { background: var(--accent-soft); color: var(--accent-ink); }
.pmenu { left: auto; right: 10px; top: calc(100% - 14px); width: 230px; min-width: 0; }
.pmenu.menu-up { top: auto; bottom: 48px; } /* mở lên: đáy menu nằm ngay trên nút ••• */
.pmenu form { display: flex; flex-direction: column; }
.pmenu button { width: 100%; }
.pmenu .bad { color: var(--bad); }
@media (max-width: 760px) {
  .post { height: 150px; grid-template-columns: 38% minmax(0, 1fr); }
  .ptext { -webkit-line-clamp: 3; }
  .pmenu { right: 6px; width: min(240px, calc(100% - 12px)); }
}
.pbody .metrics { margin-top: auto; } .ptext { flex: 0 1 auto; }
.post { align-items: stretch; grid-template-rows: 100%; }

/* ---------- bảng chọn trang: lưới thẻ vuông, ảnh 16:9 trên + tên dưới ---------- */
.menu.pgpick { position: fixed; z-index: 60; top: 12px; left: calc(var(--side-w) + 8px); right: auto;
  width: min(560px, calc(100vw - var(--side-w) - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 12px; gap: 10px; }
.pg-head { display: flex; align-items: baseline; gap: 8px; padding: 0 2px; }
.pg-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.menu .pg-card { display: flex; flex-direction: column; align-items: stretch; gap: 0; padding: 0; min-height: 0; aspect-ratio: 1; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); color: var(--ink); }
.menu .pg-card:hover { background: var(--surface); border-color: var(--line-strong); }
.menu .pg-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.pg-img { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 16 / 9; width: 100%; background: var(--surface-2); overflow: hidden; flex: none; }
.pg-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pg-img.all { background: var(--accent-soft); color: var(--accent-ink); flex-direction: column; gap: 4px; }
.pg-img.all .i { width: 28px; height: 28px; }
.pg-n { font-size: 11px; font-weight: 600; }
.pg-ini { font-family: var(--display); font-size: 28px; font-weight: 600; color: var(--accent-ink); }
.pg-name { flex: 1; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; padding: 8px 10px; font-size: 13px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.pg-card.on .pg-name { color: var(--accent-ink); }
@media (max-width: 760px) {
  .menu.pgpick { top: calc(var(--top-h) + env(safe-area-inset-top) + 4px); left: 8px; right: 8px; width: auto;
    max-height: calc(100dvh - var(--top-h) - var(--tab-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px); }
  .pg-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
  .pg-name { font-size: 12px; padding: 6px 8px; }
}
@media (min-width: 761px) { .side { z-index: 50; } }   /* sticky tạo lớp xếp chồng riêng: nâng cả sidebar (kèm bảng chọn trang) lên trên nội dung */
/* bảng chọn trang: thẻ đứng 9:16 — logo vuông (không bị cắt) ở trên, tên trang ở dưới */
.menu .pg-card { aspect-ratio: 9 / 16; }
.pg-img { aspect-ratio: 1; }
.pg-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.pg-name { -webkit-line-clamp: 4; text-align: center; }
@media (max-width: 760px) { .pg-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); } }
/* thẻ 3:4 — logo vuông + chân vừa đủ 2 dòng tên */
.menu .pg-card { aspect-ratio: 3 / 4; }
.pg-name { -webkit-line-clamp: 2; padding: 6px 8px; font-size: 12px; line-height: 1.3; display: -webkit-box; align-content: center; }
@media (max-width: 760px) { .pg-name { font-size: 11px; line-height: 1.2; padding: 3px 6px; } }

/* ---------- bảng chọn trang: tên luôn ở chính giữa chân thẻ; ảnh cắt bỏ 5% viền ---------- */
.menu .pg-card .pg-name { display: flex; align-items: center; justify-content: center; text-align: center; -webkit-line-clamp: unset; }
.pg-name > span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pg-img img { transform: scale(1.1112); }              /* 1 / 0.9: bỏ 5% mỗi cạnh */

/* ---------- ảnh bìa trang: header các màn thao tác với trang ---------- */
.page-cover { position: relative; height: 140px; border-radius: var(--r-lg); overflow: hidden; background: linear-gradient(135deg, var(--accent-soft), var(--surface-2)); flex: none; }
.page-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0) 60%); }
.page-cover.no-img::after { background: none; }
.pc-id { position: absolute; z-index: 1; left: 14px; bottom: 12px; right: 14px; display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.pc-id b { font-family: var(--display); font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 3px rgba(0,0,0,.4); }
.pc-id .av { border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.page-cover.no-img .pc-id { color: var(--ink); } .page-cover.no-img .pc-id b { text-shadow: none; }

/* ---------- mobile: bảng chọn trang như tiêu đề, ảnh trang thay logo app ---------- */
@media (max-width: 760px) {
  .side .brand { display: none; }
  .side .page-switch { border: 0; background: transparent; padding: 0 4px; gap: 10px; min-height: 40px; }
  .side .page-switch .av { width: 32px; height: 32px; font-size: 12px; }
  .side .page-switch .nm { font-family: var(--display); font-size: 17px; font-weight: 600; color: var(--ink); }
  .page-cover { height: 96px; border-radius: var(--r-md); }
  .page-cover .pc-id { display: none; }                 /* trên mobile tên trang đã ở thanh trên cùng */
}

/* ---------- trợ lý viết AI: nút ✨ AI + danh sách sổ xuống; khung kết quả riêng ---------- */
.aiwrap { position: relative; flex: none; display: flex; }
.ai-btn { gap: 4px; padding: 0 12px; color: var(--accent-ink); border-color: var(--accent-soft); background: var(--surface); }
.ai-btn:hover, .ai-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.menu.ai-menu { left: 0; right: auto; top: calc(100% + 6px); width: 260px; min-width: 0; z-index: 45; }
.menu.ai-menu.align-right { left: auto; right: 0; }
.menu.ai-menu.open-up { top: auto; bottom: calc(100% + 6px); }
.menu.ai-menu button { flex-direction: column; align-items: flex-start; gap: 1px; min-height: 0; padding: 8px 10px; }
.menu.ai-menu button b { font-size: 13px; }
.menu.ai-menu button span { font-size: 11px; color: var(--muted); }
.ai-out { flex-basis: 100%; min-width: 0; border: 1px solid var(--accent-soft); background: var(--surface); border-radius: var(--r-md); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-out[hidden] { display: none; }
.ai-head { display: flex; align-items: center; gap: 8px; font-size: 13px; } .ai-head .ai-x { margin-left: auto; width: 28px; min-height: 28px; font-size: 18px; }
.ai-kb { margin: 0; }
.ai-opt { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.ai-head + .ai-opt, .ai-kb + .ai-opt { border-top: 0; padding-top: 0; }
.ai-text { margin: 0; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-text mark { background: var(--ok-soft); color: var(--ok); border-radius: 3px; padding: 0 2px; }
.ai-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.learn-opt { gap: 6px; cursor: pointer; } .learn-opt input { accent-color: var(--accent); }
.composer .ai-out { max-height: 40dvh; overflow-y: auto; }
.reply > input[name="message"] { flex: 1 1 220px; min-width: 0; }
@media (max-width: 760px) { .ai-btn .lb { display: none; } .ai-btn { width: 40px; padding: 0; justify-content: center; } }

/* ---------- Kho kiến thức ---------- */
.kn-meta { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.kn-tools .tabs { flex: 1 1 auto; min-width: 0; }
.kn-list { display: flex; flex-direction: column; gap: 10px; }
.kn { padding: 0; }
.kn > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; flex-wrap: wrap; }
.kn > summary::-webkit-details-marker { display: none; }
.kn > summary::after { content: "›"; margin-left: auto; color: var(--muted); font-size: 18px; transition: transform .15s; }
.kn[open] > summary::after { transform: rotate(90deg); }
.kn[open] > summary { border-bottom: 1px solid var(--line); }
.kn > form { padding: 14px 16px 16px; }
.kn-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 260px; }
.kn-title b { overflow-wrap: anywhere; } .kn-title .muted { font-size: 12px; }
.kn-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.kn-raw p { max-height: 240px; overflow-y: auto; font-size: 13px; background: var(--surface-2); padding: 10px; border-radius: var(--r-md); margin: 6px 0 0; }
@media (max-width: 760px) { .kn-meta { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Tin nhắn: không header thứ hai; khung chat lấp đầy phần còn lại ---------- */
.chat { height: calc(100dvh - 48px); }                 /* 48 = lề trên/dưới của .main trên máy tính */
.threads { padding-top: 0; }
.threads-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 10px; background: var(--surface); border-bottom: 1px solid var(--line); margin: 0 -4px 4px; }
.threads-head .muted { font-size: 12px; }
.chat-sync { margin-left: auto; display: flex; }
.conv-head .chat-sync { flex: none; }
@media (max-width: 760px) {
  .chat { height: calc(100dvh - var(--top-h) - var(--tab-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 32px); }
  .chat .threads-head { margin-top: 0; }
}
/* header các màn của một trang: tên trang đã có ở sidebar/topbar + ảnh bìa; mobile gọn 1 hàng */
@media (max-width: 760px) {
  .head.compact { flex-wrap: nowrap; gap: 8px; }
  .head.compact > div:first-child { min-width: 0; }
  .head.compact h1 { font-size: 20px; }
  .head.compact .sub { display: none; }
  .head.compact .actions { flex-wrap: nowrap; }
}
@media (max-width: 760px) {   /* câu trả lời nhanh: 1 hàng, vuốt ngang (không làm tràn trang) */
  .composer .chips { flex-wrap: nowrap; overflow-x: auto; max-height: none; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .composer .chips::-webkit-scrollbar { display: none; }
  .composer .chips button { flex: none; }
}
.qr-btn .i { width: 16px; height: 16px; }
.menu.ai-menu button[data-fill] b { font-weight: 500; }

/* ---------- hộp thư: media trong tin, đính kèm, tự cập nhật ---------- */
.bubble { display: flex; flex-direction: column; gap: 6px; }
.bubble .m-text { white-space: pre-wrap; }
.bubble.has-media { padding: 4px; }
.bubble.has-media .m-text, .bubble.has-media .tm { padding: 0 7px; }
.bubble.has-media .tm { padding-bottom: 3px; }
.m-img { display: block; border-radius: 12px; overflow: hidden; max-width: 260px; background: var(--surface-2); }
.m-img img { display: block; width: 100%; height: auto; max-height: 320px; object-fit: cover; }
.m-sticker { width: 96px; height: 96px; object-fit: contain; }
.bubble:has(> .m-sticker:only-of-type) { background: transparent; border-color: transparent; }
.m-video { display: block; width: 260px; max-width: 100%; max-height: 360px; border-radius: 12px; background: #000; }
.m-audio { width: 240px; max-width: 100%; }
.m-file { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); color: var(--ink); max-width: 260px; font-size: 13px; }
.bubble.me .m-file { background: rgba(255,255,255,.18); color: var(--on-accent); }
.m-receipt, .m-card { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); color: var(--ink); font-size: 13px; max-width: 280px; }
.bubble.me .m-receipt, .bubble.me .m-card { background: rgba(255,255,255,.18); color: var(--on-accent); }
.bubble.me .m-card a { color: inherit; text-decoration: underline; }
.m-total { font-weight: 700; }
.m-gone { font-size: 12px; font-style: italic; opacity: .75; padding: 4px 7px; }
.att-list { display: flex; gap: 6px; flex-wrap: wrap; }
.att-list[hidden] { display: none; }
.att { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; padding: 3px 4px 3px 3px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); font-size: 12px; }
.att img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.att > b { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 6px; }
.att .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.att .x { border: 0; background: none; font-size: 18px; line-height: 1; padding: 0 4px; color: var(--muted); cursor: pointer; }
.att-link { display: flex; gap: 6px; align-items: center; }
.att-link[hidden] { display: none; }
.att-link input { flex: 1; min-width: 0; }
.menu.ai-menu label.mi-file { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.menu.ai-menu label.mi-file:hover { background: var(--surface-2); }
.menu.ai-menu label.mi-file b { font-size: 13px; } .menu.ai-menu label.mi-file span { font-size: 11px; color: var(--muted); }
.menu.ai-menu .qr-manage { font-size: 12px; color: var(--accent-ink); border-top: 1px solid var(--line); border-radius: 0; margin-top: 2px; }
.att-btn .i { width: 16px; height: 16px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); animation: live 2s ease-in-out infinite; }
@keyframes live { 50% { opacity: .35; } }
.pick-file { display: flex; align-items: center; justify-content: center; aspect-ratio: 1; font-size: 32px; background: var(--surface-2); }
.composer .uploads:empty { display: none; }
@media (max-width: 760px) { .m-img, .m-video { max-width: 220px; } }
@media (prefers-reduced-motion: reduce) { .live { animation: none; } }

/* ---------- câu trả lời mẫu ---------- */
.qr-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.qr-item textarea { min-height: 52px; resize: vertical; }
.qr-side { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.qr-side select { max-width: 200px; }
@media (max-width: 760px) { .qr-item { grid-template-columns: minmax(0, 1fr); } .qr-side { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; } }

/* ---------- Bình luận: thẻ gọn (nội dung nổi bật), 2 cột trên màn rộng; thao tác khác trong popup ---------- */
.cmt-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); align-items: start; }
.cmt-grid > .empty { grid-column: 1 / -1; }
.cmt { gap: 8px; padding: 12px 14px; }
.cmt-text { margin: 0; font-size: 15.5px; line-height: 1.45; color: var(--ink); font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.cmt-text[data-open-cmt] { cursor: pointer; border-radius: 6px; }
.cmt-text[data-open-cmt]:hover { color: var(--accent-ink); }
.cmt-foot { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cmt-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.cmt-meta b { font-size: 13px; } .cmt-meta .muted { font-size: 11.5px; }
.cmt-foot .tag { flex: none; }
.cmt-acts { display: flex; align-items: center; gap: 2px; flex: none; }
.cmt-acts form { display: flex; }
.cmt.dim .cmt-text { color: var(--ink-2); font-weight: 400; }
dialog.dlg-wide { width: min(600px, calc(100vw - 24px)); }
dialog.dlg-scroll .dlg { overflow-y: auto; max-height: calc(100dvh - 48px); }
.grp-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 0 0; }
.list > .sub-item { padding-left: 34px; }
.list > .item.nowrap { flex-wrap: nowrap; }
.btn > .n { font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; }
.list > .pw-item { display: block; }
.pw-item > summary { gap: 10px; align-items: center; }
.pw-item > form { padding: 10px 0 4px 34px; }
.cmt-dlg-head { display: flex; align-items: center; gap: 10px; }
.cmt-dlg-head .btn { font-size: 20px; }
.cmt-dlg-text { margin: 0; font-size: 16px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 30dvh; overflow-y: auto;
  padding: 10px 12px; background: var(--surface-2); border-radius: var(--r-md); }
#dlg-cmt .row.nowrap > input { flex: 1; min-width: 0; }
.cmt-dlg-acts { display: flex; flex-wrap: wrap; gap: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.cmt-dlg-acts .bad { margin-left: auto; }
@media (max-width: 760px) {
  .cmt-foot { flex-wrap: wrap; } .cmt-acts { margin-left: auto; }
  .cmt-foot .tag { order: 3; }
}
dialog .ai-menu { max-height: min(320px, 60dvh); overflow-y: auto; }
dialog.dlg-wide { overflow: visible; } dialog .ai-menu { max-height: none; overflow: visible; }

/* ---------- ô soạn tin: máy tính 1 hàng; mobile 2 hàng (nút | ô nhập + Gửi); ô nhập tự giãn tới 4 dòng ---------- */
.cmp-row { display: flex; gap: 6px; align-items: flex-end; min-width: 0; }
.cmp-tools { display: flex; gap: 6px; flex: none; }
.cmp-input { display: flex; gap: 6px; align-items: flex-end; flex: 1; min-width: 0; }
.msg-box { flex: 1; min-width: 0; resize: none; overflow-y: hidden; min-height: 40px; padding: 9px 14px; line-height: 20px;
  border-radius: 20px; font: inherit; font-size: 15px; }
.cmp-input .chat-send { flex: none; width: 40px; height: 40px; min-height: 40px; }
.cmp-tools .ai-btn { min-height: 36px; }
@media (max-width: 760px) {
  .cmp-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .cmp-tools .ai-btn .lb { display: inline; }
  .cmp-tools .ai-btn { width: auto; padding: 0 12px; }
  .msg-box { font-size: 16px; }              /* 16px: iOS không tự phóng to khi chạm vào ô */
}
/* popup bình luận: câu nhắc khách xem tin nhắn khi nhắn riêng */
.nudge { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); }
.nudge-on { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.nudge-on input { accent-color: var(--accent); }
.nudge .row.nowrap > input { flex: 1; min-width: 0; font-size: 14px; }
.nudge:has(.nudge-on input:not(:checked)) .row { opacity: .45; }
#dlg-cmt .row.nowrap > .msg-box { flex: 1; }
.nudge-box { font-size: 14px; min-height: 36px; padding: 7px 12px; border-radius: 12px; background: var(--surface); }
/* popup bình luận: nhóm thao tác ngay dưới nội dung; icon, bấm 2 lần mới thực hiện */
.cmt-dlg-acts { border-top: 0; padding-top: 0; margin-top: -4px; align-items: center; gap: 4px; }
.cmt-dlg-acts .bad { margin-left: 0; }
.two-step { gap: 6px; transition: background .15s, color .15s; }
.two-step .lb { display: none; white-space: nowrap; }
.two-step.armed { width: auto; padding: 0 10px; background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.two-step.armed .lb { display: inline; }
.two-step.danger { color: var(--bad); }
.two-step.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
.cmt-dlg-acts > a.btn { margin-left: auto; }
.acts-hint { flex-basis: 100%; font-size: 11.5px; min-height: 0; }
.acts-hint:empty { display: none; }
.btn.sm.icon.two-step.armed { width: auto; padding: 0 10px; }

/* ---------- trang chính sách công khai ---------- */
.auth:has(.legal) { max-width: 820px; width: 100%; }
.legal { display: flex; flex-direction: column; gap: 10px; padding: 18px 20px; line-height: 1.6; font-size: 14.5px; }
.legal h2 { font-size: 17px; margin: 10px 0 0; }
.legal ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.legal p { margin: 0; }
.legal hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; width: 100%; }
.legal-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.legal-nav a { padding: 4px 12px; border-radius: var(--r-pill); border: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }
.legal-nav a.on { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.legal-status { padding: 12px; background: var(--ok-soft); color: var(--ok); }
.legal-links { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.legal-links a { color: var(--muted); }
