/* Queen Children — Đồng hành · Parent Console v0.1 (không phụ thuộc ngoài, mobile-first) */
:root {
  --bg: #f5f6fa; --surface: #ffffff; --surface-2: #f0f2f7; --border: #e2e5ee;
  --text: #1b2030; --muted: #667085; --primary: #2f6fed; --primary-fg: #fff; --primary-soft: #e8efff;
  --ok: #16a34a; --ok-soft: #e7f7ed; --warn: #d97706; --warn-soft: #fff4e0; --err: #dc2626; --err-soft: #fdecec;
  --study: #16a34a; --game: #ea580c; --video: #9333ea; --web: #0284c7; --blocked: #dc2626; --uncat: #94a3b8;
  --radius: 14px; --radius-sm: 9px; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b24; --surface-2: #1f2430; --border: #2a3040;
  --text: #e7eaf2; --muted: #98a2b3; --primary: #5b8cff; --primary-fg: #0b1020; --primary-soft: #1c2a4d;
  --ok: #34d17a; --ok-soft: #12301f; --warn: #f5a524; --warn-soft: #362a12; --err: #f87171; --err-soft: #3a1717;
  --study: #34d17a; --game: #fb8c3c; --video: #b57bff; --web: #38bdf8; --blocked: #f87171; --uncat: #7b8798;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
/* Tránh chớp nền sáng trước khi JS đặt data-theme */
@media (prefers-color-scheme: dark) { :root:not([data-theme]) { --bg: #0f1218; --text: #e7eaf2; color-scheme: dark; } }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
h1, h2, h3, p { margin: 0; }
code, .mono { font-family: var(--mono); }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.is-embed body { background: var(--bg); }

/* ---------- Tiện ích ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.min0 { min-width: 0; }
.center, .center-text { text-align: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; max-width: 100%; vertical-align: bottom; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.row-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row2, .row3 { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .row2 { grid-template-columns: 1fr 1fr; } .row3 { grid-template-columns: 2fr 1fr 1fr; } }

/* ---------- Khung ---------- */
.app-root { min-height: 100vh; }
.boot { display: grid; place-items: center; min-height: 60vh; }
.shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; grid-template-areas: "top" "nav" "view"; }
.topbar { grid-area: top; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 52px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; white-space: nowrap; }
.brand-mark { font-size: 34px; text-align: center; }
.brand-mark.sm { font-size: 20px; }
.brand-title { font-size: 19px; text-align: center; }
.fam { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; }
.fam-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fam-select { max-width: 220px; flex: 0 1 auto; }
@media (max-width: 479px) { .brand-name, .fam .chip { display: none; } .topbar { gap: 8px; padding: 8px 10px; } }
.top-right { display: flex; align-items: center; gap: 8px; }
.who { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: none; }
@media (min-width: 700px) { .who { display: inline; } }
.conn-wrap { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--uncat); }
.conn.open { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.conn.connecting { background: var(--warn); }
.conn-text { display: none; }
@media (min-width: 480px) { .conn-text { display: inline; } }

.tabs { grid-area: nav; position: sticky; top: 52px; z-index: 15; display: flex; gap: 4px; overflow-x: auto; padding: 6px 8px; background: var(--surface); border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tab.disabled { opacity: .45; pointer-events: none; }
.view { grid-area: view; min-width: 0; padding: 14px 12px 40px; width: 100%; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; outline: none; }
@media (min-width: 900px) {
  .shell { grid-template-columns: 224px minmax(0, 1fr); grid-template-rows: auto 1fr; grid-template-areas: "top top" "nav view"; }
  .tabs { flex-direction: column; top: 52px; align-self: start; height: calc(100vh - 52px); padding: 14px 10px; border-bottom: 0; border-right: 1px solid var(--border); overflow: auto; }
  .tab { border-radius: var(--radius-sm); padding: 9px 12px; }
  .view { padding: 22px 26px 48px; }
}

.view-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.view-head.wrap { justify-content: space-between; }
.view-title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.section-title { display: flex; align-items: center; gap: 8px; font-size: 16px; margin: 4px 0 8px; }
.sub-title { font-size: 14px; font-weight: 600; margin: 14px 0 8px; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 2px; }
.intro { margin-top: -6px; }

/* ---------- Thẻ ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; font-weight: 650; }
.login-card { max-width: 440px; margin: 8vh auto; display: flex; flex-direction: column; gap: 12px; }
.error-card { border-color: var(--err); color: var(--err); }
.hint-box { margin-top: 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.dev-box { padding: 12px; border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
details > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
.fold[open] > summary { margin-bottom: 10px; }
.fold-inline { margin-top: 12px; }
.fold-inline > summary { font-size: 13px; color: var(--primary); }
.fold-inline[open] > summary { margin-bottom: 10px; }
.danger-zone > summary { color: var(--err); font-size: 13px; }
.danger-zone[open] { display: flex; flex-direction: column; gap: 10px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.kv.compact { font-size: 13px; gap: 3px 12px; }
.mono-big { font-size: 15px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); overflow-wrap: anywhere; user-select: all; }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; min-height: 38px; width: 100%; min-width: 0;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.filters select, .filters input[type="date"] { width: auto; }

/* ---------- Nút ---------- */
.btn { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 8px 14px; min-height: 38px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, opacity .12s; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.busy { cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger-ghost { color: var(--err); border-color: var(--err-soft); background: transparent; }
.btn.danger-ghost:hover { background: var(--err-soft); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--err-soft); color: var(--err); }
.link { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ---------- Chip / badge ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.big { font-size: 13px; padding: 6px 12px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.role-owner { background: var(--primary-soft); color: var(--primary); }
.chip.role-parent { background: var(--ok-soft); color: var(--ok); }
.chip.cat-study { background: color-mix(in srgb, var(--study) 15%, transparent); color: var(--study); }
.chip.cat-game { background: color-mix(in srgb, var(--game) 15%, transparent); color: var(--game); }
.chip.cat-video { background: color-mix(in srgb, var(--video) 15%, transparent); color: var(--video); }
.chip.cat-web { background: color-mix(in srgb, var(--web) 15%, transparent); color: var(--web); }
.chip.cat-blocked { background: var(--err-soft); color: var(--blocked); }
.chip.sev-err { background: var(--err-soft); color: var(--err); }
.chip.sev-warn { background: var(--warn-soft); color: var(--warn); }
.pill { margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 700; background: var(--warn-soft); color: var(--warn); vertical-align: 1px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.online { background: var(--ok-soft); color: var(--ok); }
.badge.offline { background: var(--surface-2); color: var(--muted); }
.banner { padding: 8px 12px; border-radius: var(--radius-sm); font-weight: 600; margin-top: 10px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.err { background: var(--err-soft); color: var(--err); margin-top: 0; }
.avatar { flex: none; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.avatar.soft { background: var(--surface-2); color: var(--muted); }
.avatar.sm { width: 26px; height: 26px; font-size: 13px; }

/* ---------- Danh sách / Khởi tạo ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list > li { padding: 10px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; padding-top: 0; }
.child-row { display: flex; flex-direction: column; gap: 10px; }
.pair-btn { align-self: stretch; min-height: 46px; font-size: 15px; }
@media (min-width: 640px) { .pair-btn { align-self: flex-start; } }
.pair-panel { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border); text-align: center; }
.pair-panel.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.pair-code { font-family: var(--mono); font-size: 56px; font-weight: 700; letter-spacing: .18em; line-height: 1.05; padding-left: .18em; color: var(--text); user-select: all; }
.pair-code.otp { font-size: 40px; letter-spacing: .12em; }
.pair-code.expired { opacity: .35; text-decoration: line-through; }
@media (max-width: 380px) { .pair-code { font-size: 44px; } .pair-code.otp { font-size: 32px; } }
.pair-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; }
.countdown { font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--ok); }
.countdown.urgent { color: var(--err); animation: blink 1s steps(2) infinite; }
.countdown.expired { color: var(--err); font-family: var(--font); }
@keyframes blink { 50% { opacity: .55; } }
.steps { margin: 0; padding-left: 20px; text-align: left; display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
.cmd { display: flex; align-items: center; gap: 6px; width: 100%; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); text-align: left; }
.cmd code { flex: 1; overflow-wrap: anywhere; font-size: 13px; }

/* ---------- Thiết bị ---------- */
.child-section { display: flex; flex-direction: column; gap: 10px; }
.device-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .device-grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); } }
.device-card { display: flex; flex-direction: column; gap: 10px; border-left: 4px solid var(--border); }
.device-card.is-online { border-left-color: var(--ok); }
.dev-head { display: flex; align-items: center; gap: 10px; }
.update-box { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: var(--radius-sm); background: var(--primary-soft); }
.notes { white-space: pre-line; }
.update-state { display: flex; flex-direction: column; gap: 5px; }
.update-state.tone-ok { color: var(--ok); }
.update-state.tone-warn { color: var(--warn); }
.update-state.tone-err { color: var(--err); }
.update-state.tone-progress { color: var(--primary); }
.progress { height: 6px; border-radius: 99px; background: var(--surface); overflow: hidden; }
.progress > span { display: block; height: 100%; background: currentColor; border-radius: inherit; transition: width .4s; }
.settings-group { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; border-top: 1px solid var(--border); }
.settings-group:first-of-type { border-top: 0; }
.switch-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; position: relative; }
.switch-row.is-disabled { cursor: not-allowed; opacity: .7; }
.switch-row select { width: auto; }
.switch-label { font-weight: 500; }
.switch-row input[type="checkbox"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { flex: none; position: relative; width: 40px; height: 23px; border-radius: 99px; background: var(--border); transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch-row input:checked + .switch { background: var(--ok); }
.switch-row input:checked + .switch::after { transform: translateX(17px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--primary); outline-offset: 2px; }
.sys-list, .tl-list { list-style: none; margin: 0; padding: 0; }
.sys-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); }
.sys-row:first-child { border-top: 0; }
.sys-icon { flex: none; width: 22px; text-align: center; }
.sys-row time { flex: none; white-space: nowrap; }
.tone-warn { color: var(--warn); }
.tone-err { color: var(--err); }

/* ---------- Dòng thời gian ---------- */
.date-nav { display: inline-flex; align-items: center; gap: 2px; }
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 24px; font-weight: 750; letter-spacing: -.02em; }
.top-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.timeline { padding-top: 6px; }
.hour-head { position: sticky; top: 100px; z-index: 2; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface); padding: 8px 0 4px; border-bottom: 1px solid var(--border); }
@media (min-width: 900px) { .hour-head { top: 52px; } }
.tl-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.tl-row:last-child { border-bottom: 0; }
.tl-row.sys { align-items: center; padding: 5px 0; color: var(--muted); }
.tl-row.sys.tone-warn { color: var(--warn); }
.tl-row.sys.tone-err { color: var(--err); }
.tl-time { flex: none; width: 42px; font-family: var(--mono); font-size: 12.5px; color: var(--muted); padding-top: 1px; }
.tl-main { display: flex; gap: 6px; min-width: 0; }
.tl-tags { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

/* ---------- Thống kê ---------- */
.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-2); }
.segmented button { font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 5px 14px; border-radius: 999px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat-text-study .stat-value { color: var(--study); }
.cat-text-game .stat-value { color: var(--game); }
@media (max-width: 420px) { .stat-value { font-size: 19px; } }
.ratio-bar { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.ratio-seg { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.swatch { flex: none; width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.bg-study { background: var(--study); } .bg-game { background: var(--game); } .bg-video { background: var(--video); }
.bg-web { background: var(--web); } .bg-blocked { background: var(--blocked); } .bg-uncat { background: var(--uncat); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; margin-top: 14px; }
.cat-cell { display: flex; align-items: center; gap: 6px; }
.two-col { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .two-col { grid-template-columns: 1fr 1fr; } }
.two-col .sub-title { margin-top: 0; }
.bar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.bar-label { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 3px; min-width: 0; }
.bar-track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: inherit; }

/* ---------- Bảo mật ---------- */
.tamper-list { list-style: none; margin: 0; padding: 4px 14px; }
.tamper-row { display: flex; flex-direction: column; gap: 3px; padding: 10px 0 10px 10px; border-left: 3px solid var(--uncat); border-bottom: 1px solid var(--border); margin-left: -6px; }
.tamper-row:last-child { border-bottom: 0; }
.tamper-row.tone-warn { border-left-color: var(--warn); }
.tamper-row.tone-err { border-left-color: var(--err); }
.tamper-extra { color: var(--muted); }

/* ---------- Trạng thái trống / tải ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 8px; text-align: center; }
.empty-icon { font-size: 30px; }
.empty-title { font-weight: 600; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 22px; color: var(--muted); }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.wide { width: min(860px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(10, 14, 22, .5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 0; }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 12px 14px; overflow: auto; max-height: calc(100vh - 150px); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 14px 14px; }
.diag { margin: 0; max-height: 55vh; overflow: auto; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; }

/* ---------- Toast ---------- */
.toasts { position: fixed; z-index: 100; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-weight: 500; animation: toast-in .2s ease-out; transition: opacity .3s, transform .3s; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.err { background: var(--err); color: #fff; }
.toast.warn { background: var(--warn); color: #1b1300; }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

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

/* Chia sẻ máy (device_grants) */
[hidden] { display: none !important; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.soft { background: var(--primary-soft); color: var(--primary); }
.chip.muted { opacity: .75; }
.chip input[type="checkbox"] { margin: 0; }

/* Thống kê: donut, cột xếp chồng, mẫu tin Queen Chat */
.donut-wrap { display: grid; grid-template-columns: minmax(150px, 210px) 1fr; gap: 16px; align-items: center; }
@media (max-width: 520px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } .donut-legend { width: 100%; } }
.donut { width: 100%; max-width: 210px; height: auto; display: block; }
.donut-track { fill: none; stroke: var(--surface-2); stroke-width: 17; }
.donut-seg { cursor: pointer; transition: opacity .15s, transform .15s; transform-origin: 60px 60px; }
.donut-seg:hover { transform: scale(1.03); }
.donut-seg.dim, .bar-group.dim { opacity: .3; }
.donut-big { font-size: 15px; font-weight: 750; fill: var(--text); }
.donut-small { font-size: 8.5px; fill: var(--muted); }
.donut-legend { display: grid; gap: 6px; }
.legend-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.legend-btn:hover, .legend-btn.active { background: var(--surface-2); border-color: var(--primary); }
.legend-btn:disabled { opacity: .5; cursor: default; }
.seg-study { fill: var(--study); } .seg-game { fill: var(--game); } .seg-uncat { fill: var(--uncat); }
.chart-box { margin-top: 6px; }
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.bar-chart { display: block; width: 100%; min-width: 560px; max-height: 300px; height: auto; }
.chart-grid line { stroke: var(--border); stroke-dasharray: 3 3; }
.chart-grid text, .chart-x { font-size: 12px; fill: var(--muted); }
.bar-seg { transition: opacity .15s; }
.bar-hit { fill: transparent; cursor: pointer; outline: none; }
.bar-hit:focus-visible { stroke: var(--primary); stroke-width: 1.5; }
.late-band { fill: color-mix(in srgb, var(--video) 10%, transparent); }
.late-label { font-size: 10px; fill: var(--video); font-weight: 600; }
.chart-detail { min-height: 1.4em; margin: 6px 0 0; }
.chat-preview { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: var(--radius); background: var(--surface-2); }
.chat-avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); font-size: 18px; }
.chat-bubble { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.chat-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.chat-line { margin: 4px 0 0; }
.view, .usage-body, .usage-body > *, .chart-box, .chart-scroll { min-width: 0; max-width: 100%; }
