:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #e6f4f2;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --warn: #a16207;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --ok-border: #bbf7d0;
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #5b6574;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);
  --focus: 0 0 0 3px rgba(15, 118, 110, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 650; }
p { margin: 0; }
a { color: var(--brand); }
a:hover { color: var(--brand-dark); }
.muted { color: var(--muted); }
.small, small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; vertical-align: -0.2em; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.content:focus-visible { outline: none; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: 9px;
  border: 1px solid transparent; background: none; color: inherit;
  font: inherit; font-weight: 600; font-size: 14.5px; text-decoration: none;
  cursor: pointer; transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13.5px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); color: #fff; }
.btn-secondary { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { border-color: #cbd5e1; background: #f8fafc; color: var(--text); }
.btn-ghost { color: var(--brand); padding-inline: 10px; }
.btn-ghost:hover:not(:disabled) { background: var(--brand-soft); }
.btn-light { background: #fff; color: var(--danger); }
.btn-light:hover { background: #fff5f5; color: var(--danger); }
.btn-danger-outline { background: var(--card); border-color: var(--danger-border); color: var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-soft); }
.link { background: none; border: 0; padding: 2px 4px; font: inherit; color: var(--brand); cursor: pointer; text-decoration: underline; border-radius: 4px; }

/* ---------- Ô nhập ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 14px; }
.field small { color: var(--muted); }
input, select {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid #cbd5e1; border-radius: 9px; background: #fff; color: var(--text);
  font: inherit; transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover { border-color: #94a3b8; }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.code-input { font-family: var(--mono); font-size: 24px; letter-spacing: 0.4em; text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); column-gap: 16px; }
.form-actions { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }

/* ---------- Thông báo ---------- */
.live:empty { display: none; }
.live { margin: 4px 0 12px; }
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 9px; border: 1px solid; font-size: 14px; margin: 8px 0;
}
.notice .icon { margin-top: 2px; }
.notice-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.notice-warn { background: var(--warn-soft); border-color: var(--warn-border); color: #854d0e; }
.notice-ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.notice-info { background: var(--brand-soft); border-color: #b7e0db; color: var(--brand-dark); }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 13.5px; font-weight: 600; line-height: 1.4;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: #854d0e; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-idle { background: #f1f5f9; color: var(--muted); }
.tag { font-size: 12.5px; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }

.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #cbd5e1; border-top-color: var(--brand); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } * { transition: none !important; } }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 24px 0; }
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; gap: 10px; }

/* ---------- Đăng nhập / thiết lập ---------- */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), var(--bg) 70%);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08); padding: 32px 28px;
}
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 20px; }
.auth-card form { margin-top: 20px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--brand-dark); margin-bottom: 24px; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: #fff;
}
.who { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 16px;
  padding: 8px 12px; border-radius: 9px; background: var(--bg); font-size: 14px; }
.who > span { display: inline-flex; align-items: center; gap: 6px; }
.hint { display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; font-size: 14px; color: var(--brand-dark);
  background: var(--brand-soft); border-radius: 9px; padding: 10px 12px; }
.hint .icon { margin-top: 3px; }
.auth-alt { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 16px;
  padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------- Khung ---------- */
/* Thanh bên sticky chỉ cao 100vh; nền + viền tô cho cả cột lưới để trang dài hơn màn hình vẫn liền mạch. */
.layout {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh;
  background: linear-gradient(90deg, var(--card) 239px, var(--border) 239px 240px, transparent 240px);
}
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; background: var(--card); border-right: 1px solid var(--border); padding: 18px 12px;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 16px; }
.nav { display: flex; flex-direction: column; flex: 1; gap: 14px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: 0 10px 4px; font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #667080; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-size: 14.5px; font-weight: 500; white-space: nowrap;
}
.nav-item:hover { background: #f1f5f9; color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 650; }
.nav-item.active .icon { color: var(--brand); }
.nav-item:focus-visible { outline: none; box-shadow: var(--focus); }
.mnav { display: none; }
.mnav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; padding: 4px 2px;
  border-radius: 9px; color: var(--text); text-decoration: none; font-size: 12.5px; font-weight: 600; line-height: 1.25; cursor: pointer; list-style: none;
}
.mnav-item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mnav-item:hover { background: #f1f5f9; color: var(--text); }
.mnav-item.active { background: var(--brand-soft); color: var(--brand-dark); }
.mnav-item.active .icon { color: var(--brand); }
.mnav-item:focus-visible { outline: none; box-shadow: var(--focus); }
.nav-more { position: relative; }
.nav-more > summary::-webkit-details-marker { display: none; }
.nav-more-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; display: flex; flex-direction: column; gap: 2px;
  min-width: 240px; padding: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.14);
}
.nav-more-menu .nav-item { min-height: 44px; }
.nav-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.me { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.me small { color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.strip {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: 10px 28px; font-size: 14.5px; font-weight: 600; border-bottom: 1px solid transparent;
}
.strip-text { display: inline-flex; align-items: center; gap: 8px; }
.strip-danger { background: var(--danger); color: #fff; }
.strip-warn { background: #fbbf24; color: #422006; }
.strip-ok { background: var(--ok); color: #fff; }
.strip-idle { background: #e2e8f0; color: var(--muted); }
.content { padding: 28px; max-width: 1180px; width: 100%; }
.page-head { margin-bottom: 20px; }
.page-head p { margin-top: 4px; }

/* ---------- Thẻ ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px;
}
.card > h2 { margin-bottom: 14px; }
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid > .card { margin-bottom: 0; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-top { align-items: start; }
.grid-qr { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.stat { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.stat-head { display: flex; align-items: center; gap: 10px; }
.stat-icon { display: inline-flex; padding: 8px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); }
.facts { margin: 0; display: grid; gap: 10px; }
.facts > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.facts dd { margin: 0; font-weight: 600; text-align: right; }
.last-error { margin: 10px 0 6px; font-weight: 600; }
.empty { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 40px 24px; }
.empty .icon { color: var(--muted); }
.empty h1 { font-size: 20px; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); font-weight: 700;
}
.avatar-sm { width: 30px; height: 30px; font-size: 13px; }
.avatar-lg { width: 64px; height: 64px; font-size: 26px; }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 20px; }
.account-info { flex: 1; min-width: 180px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.account > .live { flex-basis: 100%; }
.link-out { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.reset-row td { background: #f8fafc; white-space: normal; }
.reset-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.reset-form .field { margin: 0; min-width: 220px; }
.reset-form .live { flex-basis: 100%; margin: 0; }
.list { list-style: none; margin: 0 0 12px; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }

/* ---------- QR ---------- */
.steps { margin: 0 0 12px; padding-left: 22px; display: grid; gap: 8px; }
.steps + .notice { margin-bottom: 16px; }
.qr-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }
.qr-box {
  width: 296px; height: 296px; max-width: 100%; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 14px; background: #fff; padding: 8px;
}
.qr-img { width: 280px; height: 280px; max-width: 100%; image-rendering: pixelated; }
.qr-placeholder { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); }
.qr-placeholder.ok { color: var(--ok); font-weight: 600; }
.qr-progress { width: 240px; height: 6px; margin-top: 8px; appearance: none; border: 0; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.qr-progress::-webkit-progress-bar { background: #e2e8f0; border-radius: 999px; }
.qr-progress::-webkit-progress-value { background: var(--brand); border-radius: 999px; }
.qr-progress::-moz-progress-bar { background: var(--brand); border-radius: 999px; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th { text-align: left; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.table th.th-wrap { white-space: normal; }

.subhead { font-size: 14px; font-weight: 650; margin: 16px 0 6px; }
.list .push { margin-left: auto; white-space: nowrap; }

/* ---------- Phiên chat ---------- */
textarea {
  width: 100%; min-height: 64px; padding: 9px 12px; resize: vertical;
  border: 1px solid #cbd5e1; border-radius: 9px; background: #fff; color: var(--text); font: inherit;
}
textarea:focus-visible { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.chat { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; height: calc(100vh - 190px); min-height: 480px; }
.chat > .card { margin: 0; display: flex; flex-direction: column; min-height: 0; }
.chat-search { display: flex; gap: 8px; margin-bottom: 8px; }
.conv-list { list-style: none; margin: 0 -8px; padding: 0; overflow-y: auto; flex: 1; }
.conv {
  display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 10px 8px; border: 0; border-radius: 9px;
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.conv:hover { background: #f1f5f9; }
.conv.active { background: var(--brand-soft); }
.conv:focus-visible { outline: none; box-shadow: var(--focus); }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.conv-sub { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-preview { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-wrap { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.conv mark { background: #fde68a; color: var(--text); border-radius: 3px; padding: 0 1px; }
.found-head { justify-content: space-between; margin-bottom: 6px; }
.thread-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
/* Nút "← Danh sách" và nhãn không bị bóp/xuống dòng; tên dài tự xuống dòng trong phần còn lại. */
.thread-head > .btn, .thread-head > .tag { flex: none; white-space: nowrap; }
.thread-head > h2 { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.msgs { list-style: none; margin: 0; padding: 12px 2px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.msgs-top { align-self: center; }
.msg { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; max-width: 78%; }
.msg-self { align-self: flex-end; align-items: flex-end; }
.msg-from { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.msg-bubble { padding: 8px 12px; border-radius: 14px 14px 14px 4px; background: #f1f5f9; overflow-wrap: anywhere; }
.msg-self .msg-bubble { background: var(--brand); color: #fff; border-radius: 14px 14px 4px 14px; }
.msg-self .msg-bubble a { color: #fff; }
.msg-text { white-space: pre-wrap; }
.msg-kind { font-style: italic; opacity: .85; }
.msg-time { font-size: 12.5px; color: var(--muted); }
.compose { border-top: 1px solid var(--border); padding-top: 12px; }
.compose-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; }
.chat-empty { margin: auto; }
.only-mobile { display: none; }

/* ---------- Nhật ký ---------- */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.check input { flex: none; width: 20px; height: 20px; min-height: 0; margin: 0; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.audit-day + .audit-day { margin-top: 18px; }
.audit-day-head { font-size: 14px; font-weight: 700; color: var(--muted); padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.audit-list { list-style: none; margin: 0; padding: 0; }
.audit-item { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.audit-item:last-child { border-bottom: 0; }
.audit-time { flex: none; width: 44px; color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.audit-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.audit-fail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 4px; }
.audit-tech summary { display: inline-flex; align-items: center; min-height: 32px; color: var(--brand); font-size: 13px; font-weight: 600; cursor: pointer; }
.load-more { margin-top: 12px; }

/* ---------- Phân quyền Bot ---------- */
.perm { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }
.perm > .card { margin: 0; display: flex; flex-direction: column; min-height: 0; }
/* Cột trái dính khi cuộn khung sửa dài (dưới dải trạng thái). */
.perm-list { position: sticky; top: 64px; max-height: calc(100vh - 84px); }
.perm-list .conv-name .icon { margin-right: 4px; }
.perm-list .conv-top { align-items: center; }
.perm-list .badge { flex: none; white-space: nowrap; padding: 2px 8px; font-size: 12.5px; }
.perm-note { margin-top: 12px; }
.perm-note-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; }
.perm-note-row .perm-note { flex: 1 1 260px; }
.perm-note-row .btn { margin-top: 8px; flex: none; }
/* Hộp: fieldset có legend, hoặc <details> gập được có summary tóm tắt "a/b đang bật". */
.perm-box { border: 1px solid var(--border); border-radius: 10px; margin: 14px 0; padding: 6px 14px 10px; min-width: 0; background: var(--card); }
.perm-box legend { padding: 0 6px; font-weight: 650; font-size: 14px; }
details.perm-box { padding: 0 14px; }
details.perm-box > summary {
  display: flex; align-items: center; gap: 6px; min-height: 44px; cursor: pointer; list-style: none;
  font-weight: 650; font-size: 14px; border-radius: 8px;
}
details.perm-box > summary::-webkit-details-marker { display: none; }
details.perm-box > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.perm-box[open] > summary::before { transform: rotate(90deg); }
details.perm-box[open] > summary { border-bottom: 1px solid var(--border); }
details.perm-box > summary:focus-visible { outline: none; box-shadow: var(--focus); }
details.perm-box > .perm-grid { padding: 4px 0 10px; }
.perm-box-sum { font-weight: 500; }
.perm-grid { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); column-gap: 24px; }
@media (min-width: 1100px) { .perm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* Ô bị tắt: chỉ làm mờ ô check, chữ giữ đủ tương phản; lý do nằm ở thông báo phía trên hộp. */
fieldset:disabled .check { cursor: not-allowed; }
fieldset:disabled .check input { opacity: .45; }
.perm-row { display: flex; flex-direction: column; gap: 0; padding: 2px 0 6px; border-bottom: 1px solid var(--border); }
.perm-row:last-child, .perm-grid > .perm-row { border-bottom: 0; }
.perm-row .check { min-height: 44px; }
.perm-row small, .perm-row .more-hint { padding-left: 28px; }
.more-hint summary { display: inline-flex; align-items: center; min-height: 32px; padding: 0 4px; color: var(--brand); font-size: 13px; font-weight: 600; cursor: pointer; }
.more-hint p { margin-bottom: 4px; }
.check input[type="radio"] { accent-color: var(--brand); }
/* Ai được nhắn: ba thẻ chọn ngang (máy tính), dọc (điện thoại); chỉ hiện gợi ý của lựa chọn đang chọn. */
.radio-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 8px 0; }
.radio-card {
  display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding: 11px 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; font-weight: 600; font-size: 14.5px; line-height: 1.4;
}
.radio-card:hover { border-color: #94a3b8; }
.radio-card.selected { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.radio-card:has(input:focus-visible) { box-shadow: var(--focus); }
.radio-card input { flex: none; width: 20px; height: 20px; min-height: 0; margin: 0; padding: 0; accent-color: var(--brand); }
fieldset:disabled .radio-card { cursor: not-allowed; }
/* Danh sách người: hàng gập ~56px, mở một người một lúc. */
.dm-add-box > summary {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; cursor: pointer; list-style: none;
  color: var(--brand); font-weight: 650; border-radius: 8px;
}
.dm-add-box > summary::-webkit-details-marker { display: none; }
.dm-add-box > summary:focus-visible { outline: none; box-shadow: var(--focus); }
.dm-add-box[open] { padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.dm-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.dm-add input, .dm-add select { flex: 1 1 180px; min-width: 0; }
.dm-add .btn { flex: none; }
.dm-add-error { color: var(--danger); margin: 6px 0 0; }
.dm-add-error:empty { display: none; }
.dm-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 4px; }
.dm-filter input { flex: 1 1 200px; min-width: 0; }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }
.dm-people { list-style: none; margin: 4px 0 0; padding: 0; }
.dm-person { border-bottom: 1px solid var(--border); }
.dm-person:last-child { border-bottom: 0; }
.dm-row { display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 3px 0; }
.dm-who { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.dm-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-who small { flex: none; }
.dm-row .badge { flex: none; white-space: nowrap; padding: 2px 8px; font-size: 12.5px; }
.dm-row .btn { flex: none; min-width: 72px; }
.dm-person.open .dm-row .btn { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }
.dm-panel { margin: 0 0 12px; padding: 4px 0 4px 14px; border-left: 2px solid var(--brand); }
.dm-panel-actions { margin-top: 6px; }
.dm-more { margin-top: 6px; }
.dm-empty { margin: 8px 0; }
/* Thanh Lưu dính đáy khung sửa: luôn thấy số thay đổi + Hoàn tác + Lưu. */
.perm-form { display: flex; flex-direction: column; }
.save-bar {
  position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  margin: 12px -22px -20px; padding: 12px 22px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 -6px 12px -10px rgba(15, 23, 42, 0.25);
}
.save-bar-text { margin-right: auto; font-weight: 600; font-size: 14px; }
.save-bar .live { flex-basis: 100%; margin: 0; }
.save-bar .notice { margin: 0 0 4px; }

/* ---------- Thương hiệu ---------- */
.logo-img { object-fit: contain; background: transparent; }
.powered { margin-top: 16px; font-size: 12.5px; color: var(--muted); text-align: center; }
.nav-foot .powered { margin-top: 8px; }
.logo-pick { display: flex; gap: 14px; align-items: flex-start; margin: 12px 0 4px; }
.logo-pick .field { margin-bottom: 8px; min-width: 0; }
.file-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.file-btn { position: relative; }
.file-btn:has(input:focus-visible) { box-shadow: var(--focus); }
.file-btn:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.file-name { font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.brand-colors { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.brand-colors legend { padding: 0; margin-bottom: 6px; font-weight: 600; font-size: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.swatch {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--card); color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}
.swatch:hover { background: #f1f5f9; }
.swatch.selected { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); font-weight: 600; }
.swatch-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--swatch); }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type="color"] { width: 48px; height: 40px; padding: 2px; flex: none; cursor: pointer; }
.color-row input:not([type]) { max-width: 140px; }
.contrast { display: flex; gap: 6px; align-items: flex-start; margin-top: 8px; font-size: 14px; }
.contrast .icon { margin-top: 3px; flex: none; }
.contrast-ok { color: var(--ok); }
.contrast-bad { color: var(--danger); }
.form-end { margin-top: 18px; }
.brand-preview {
  display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 14px; margin-top: 14px; padding: 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg); pointer-events: none;
}
.pv-side { display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); }
.pv-side .side-brand { padding: 0 6px 10px; font-size: 14px; }
.pv-side .side-brand > span:last-child { display: inline; overflow-wrap: anywhere; }
.pv-login {
  display: flex; flex-direction: column; gap: 12px; padding: 18px; border: 1px solid var(--border); border-radius: 10px;
  background: radial-gradient(400px 200px at 50% -10%, var(--brand-soft), var(--card) 70%);
}
.pv-login .auth-brand { margin-bottom: 0; overflow-wrap: anywhere; }
.brand-col { min-width: 0; }
@media (max-width: 760px) {
  .brand-preview { grid-template-columns: minmax(0, 1fr); }
  .nav-foot .powered { display: none; }
}

/* ---------- Chủ nhân bot ---------- */
.banner { flex-wrap: wrap; align-items: center; margin: 0 0 16px; }
.banner > div { flex: 1 1 260px; }
.restart-progress { flex-basis: 100%; display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 600; }
.restart-progress .spinner { flex: none; }
.notice p { margin: 0 0 4px; }
.fix-steps { margin: 0; padding-left: 20px; }
.fix-steps code, .notice p code { overflow-wrap: anywhere; }
.owner-list { list-style: none; margin: 8px 0 12px; padding: 0; }
.owner-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.owner-list li:last-child { border-bottom: 0; }
.owner-list .avatar { width: 32px; height: 32px; }
.owner-list .btn { flex: none; }
.owner-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; overflow-wrap: anywhere; }

/* ---------- Sức khoẻ máy chủ ---------- */
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-ok { color: var(--ok); }
.stat-warn { color: var(--warn); }
.stat-danger { color: var(--danger); }
.stat-idle { color: var(--muted); }
.charts { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: 12px; }
.chart-box { margin: 0; min-width: 0; }
.chart-box figcaption { margin-bottom: 6px; }
/* Chiều cao cố định, giãn ngang theo khung (preserveAspectRatio="none"); nét vẽ không co giãn theo. */
.chart { display: block; width: 100%; height: 110px; overflow: visible; }
.chart-bars .chart { height: 140px; }
.chart-grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-limit { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-bar { fill: var(--brand); }
.chart-axis { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.chart-bars { margin-bottom: 12px; }
.chart-plot { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px; }
.chart-main { min-width: 0; }
/* Nhãn trục Y: 100 % ở vạch trên, 50 % giữa, 0 % đáy — cùng chiều cao với .chart. */
.chart-y { display: flex; flex-direction: column; justify-content: space-between; height: 126px; margin-top: -8px;
  font-size: 12.5px; line-height: 16px; color: var(--muted); text-align: right; }
.usage-days { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-top: 12px; }
.usage-day { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.usage-day .stat-value { margin-top: 4px; }
.svc-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.svc-list li:last-child { border-bottom: 0; }
.svc-main { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Điện thoại ---------- */
@media (max-width: 760px) {
  /* Thanh trên cùng chỉ cao đúng nội dung; phần còn lại của màn hình thuộc về nội dung (trang ngắn không bị giãn thanh). */
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; background: none; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center; gap: 8px;
    padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--border); overflow: visible;
  }
  /* Nhường chỗ cho đủ chữ 5 mục điều hướng; tên và logo thương hiệu vẫn ở trang đăng nhập. */
  .side-brand { display: none; }
  /* 4 mục chính + "Thêm ▾" thay cho thanh cuộn ngang 11 mục. */
  .nav { display: none; }
  .mnav { display: flex; flex: 1; min-width: 0; gap: 2px; }
  .mnav > a, .mnav > .nav-more { flex: 1 1 0; min-width: 0; }
  .strip { padding: 10px 16px; }
  .content { padding: 20px 16px; }
  .card { padding: 18px 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  h1 { font-size: 21px; }
  .chat { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .chat.has-thread .chat-list, .chat:not(.has-thread) .chat-thread { display: none; }
  .chat-list { max-height: calc(100vh - 220px); }
  .chat-thread { height: calc(100vh - 240px); height: calc(100dvh - 240px); min-height: 400px; }
  .only-mobile { display: inline-flex; }
  .perm { grid-template-columns: minmax(0, 1fr); }
  .perm.has-sel .perm-list, .perm:not(.has-sel) .perm-edit { display: none; }
  .perm-list { position: static; max-height: none; }
  .save-bar { margin: 12px -16px -18px; padding-inline: 16px; }
  .radio-cards { grid-template-columns: minmax(0, 1fr); }
  .dm-row { flex-wrap: wrap; gap: 4px 10px; }
  .dm-who { flex: 1 1 100%; }
  .dm-row .btn { margin-left: auto; }
  /* Vùng bấm tối thiểu 44px trên màn cảm ứng. */
  .btn, .btn-sm { min-height: 44px; }
  input, select { min-height: 44px; }
  .more-hint summary, .audit-tech summary { min-height: 44px; }
  .msg { max-width: 90%; }

  /* Bảng → thẻ xếp chồng (vẫn là <table> cho trình đọc màn hình) */
  .table-cards { font-size: 15px; }
  .table-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tbody tr { border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; margin-bottom: 12px; background: #fff; }
  .table-cards tbody tr:hover { background: #fff; }
  .table-cards td { white-space: normal; overflow-wrap: anywhere; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .table-cards tbody tr td:last-child, .table-cards tbody tr:last-child td:last-child { border-bottom: 0; }
  .table-cards td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; font-size: 12.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .table-cards .actions { flex-wrap: wrap; justify-content: flex-start; }
  .table-cards .reset-row { background: #f8fafc; }
  .table-cards .reset-row td { padding: 8px 0; border-bottom: 0; }
}
