/*
 * Trang quản lý SnapAsk — khung ứng dụng sau đăng nhập và các trang tài khoản.
 *
 * Nạp sau tokens.css: dùng lại bảng màu chung (nền đen ngả ấm, một màu nhấn hổ
 * phách duy nhất), chỉ thêm vài sắc độ bề mặt để sidebar, vùng nội dung và lớp
 * nổi tách lớp mà không cần bóng nặng.
 *
 * Xanh lá và đỏ chỉ dùng cho trạng thái (ổn / lỗi), luôn đi kèm chữ hoặc icon —
 * không bao giờ là cách duy nhất để nói điều gì đó.
 */

:root {
  --bg: #121110;
  --bg-side: #171513;
  --surface: #1c1a17;
  --surface-2: #24211d;
  --surface-3: #2c2823;

  /* Sáng hơn --text-faint gốc để chữ phụ vẫn đạt tương phản AA trên nền tối. */
  --text-faint: #8a8276;

  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --ok-soft: color-mix(in srgb, var(--ok) 14%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 13%, transparent);

  --font: 'Be Vietnam Pro', system-ui, sans-serif;
  --r-pill: 999px;
  --side-w: 248px;
  /* Bề ngang thanh bên khi thu về chỉ còn icon, ở dải máy tính bảng. */
  --rail-w: 72px;
  --top-h: 60px;
}

[hidden] { display: none !important; }

body.portal { background: var(--bg); }

img, svg { display: block; }
.icon { flex: none; }

h1, h2, h3 { color: var(--text); letter-spacing: -.018em; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 26px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 620; }
h3 { font-size: 15px; font-weight: 600; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.break { overflow-wrap: anywhere; }

/* ============================================================
 * Khung ứng dụng
 * ============================================================ */

.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 12px 14px;
  background: var(--bg-side); border-right: 1px solid var(--line-soft);
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 4px 10px; margin-bottom: 14px;
  border-radius: var(--r-sm); color: var(--text); text-decoration: none;
}
.brand svg { width: 28px; height: 28px; }
.brand__name { font-size: 15.5px; font-weight: 650; letter-spacing: -.015em; }
.brand:hover .brand__name { color: var(--accent); }

.nav { display: flex; flex-direction: column; gap: 2px; list-style: none; }
.nav__label {
  padding: 14px 12px 6px; font-size: 11.5px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint);
}
.nav__link {
  position: relative; display: flex; align-items: center; gap: 11px;
  min-height: 40px; padding: 8px 12px; border-radius: var(--r-sm);
  color: var(--text-dim); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: color .16s var(--ease), background .16s var(--ease);
}
.nav__link:hover { color: var(--text); background: var(--surface); }
.nav__link[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.nav__link[aria-current="page"]::before {
  content: ''; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav__link[aria-current="page"] .icon { color: var(--accent); }

.sidebar__foot { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }

.get-app {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px;
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
  color: var(--text); text-decoration: none; font-size: 13.5px; font-weight: 550;
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.get-app:hover { border-color: var(--line); background: var(--surface); }
.get-app .icon { color: var(--accent); }
.get-app small { display: block; font-size: 12px; font-weight: 400; color: var(--text-faint); }

.who { display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-width: 0; }
.who__text { min-width: 0; line-height: 1.35; }
.sidebar__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.sidebar__top .brand { margin-bottom: 0; }
.who__name { display: block; font-size: 13.5px; font-weight: 600; }
.who__meta { display: block; font-size: 12px; color: var(--text-faint); }

.avatar {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 12.5px; font-weight: 650; letter-spacing: .02em;
  color: var(--accent-ink); background: var(--accent);
}
.avatar--sm { width: 30px; height: 30px; font-size: 11.5px; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--top-h); padding: 10px 28px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-bottom: 1px solid var(--line-soft);
}
.topbar__title { font-size: 14px; font-weight: 600; color: var(--text-dim); }
.topbar__end { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.quota-chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 34px; padding: 6px 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line-soft); background: var(--surface);
  font-size: 12.5px; color: var(--text-dim); text-decoration: none; white-space: nowrap;
}
.quota-chip:hover { color: var(--text); border-color: var(--line); }
.quota-chip b { color: var(--text); font-weight: 600; }
.quota-chip--low b { color: var(--danger); }

.content { flex: 1; padding: 32px 28px 72px; }
.page { width: 100%; max-width: 1180px; margin-inline: auto; }
.page--narrow { max-width: 820px; }

/* ============================================================
 * Thanh tiêu đề trang
 * ============================================================ */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 28px; }
.page-head__text { min-width: 0; max-width: 68ch; }
.eyebrow { margin-bottom: 6px; font-size: 12.5px; font-weight: 600; letter-spacing: .04em; color: var(--accent); }
.page-head p.lead { margin-top: 8px; color: var(--text-dim); text-wrap: pretty; }
.page-head__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.back {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; margin-bottom: 10px;
  font-size: 13.5px; color: var(--text-dim); text-decoration: none;
}
.back:hover { color: var(--text); }

/* ============================================================
 * Nút và control
 * ============================================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border: 1px solid transparent; border-radius: var(--r-sm);
  font: 600 14px/1.3 var(--font); text-decoration: none; white-space: nowrap;
  color: var(--accent-ink); background: var(--accent); cursor: pointer;
  transition: background .16s var(--ease), border-color .16s var(--ease), color .16s var(--ease), transform .1s var(--ease);
}
.btn:hover { color: var(--accent-ink); background: var(--accent-press); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }

.btn--secondary { color: var(--text); background: var(--surface); border-color: var(--line); }
.btn--secondary:hover { color: var(--text); background: var(--surface-2); border-color: #4a4239; }

.btn--ghost { color: var(--text-dim); background: transparent; }
.btn--ghost:hover { color: var(--text); background: var(--surface-2); }

.btn--danger { color: var(--danger); background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn--danger:hover { color: var(--text); background: color-mix(in srgb, var(--danger) 22%, transparent); border-color: var(--danger); }
.btn--danger-solid { color: #1d0b07; background: var(--danger); }
.btn--danger-solid:hover { color: #1d0b07; background: #cf5f4b; }

.btn--sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn--icon { width: 40px; padding: 0; }
.btn--icon.btn--sm { width: 34px; }

/* Nút đang chờ máy chủ: giữ nguyên kích thước, thay nội dung bằng vòng quay. */
.btn[aria-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--text-dim); border-right-color: transparent;
  animation: spin .7s linear infinite;
}
.btn:not(.btn--secondary):not(.btn--ghost):not(.btn--danger)[aria-busy="true"]::after { border-color: var(--accent-ink); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.inline-form { display: inline; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ============================================================
 * Biểu mẫu
 * ============================================================ */

.form { display: flex; flex-direction: column; gap: 18px; }
.form__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form__grid > .field--full { grid-column: 1 / -1; }
.form__actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field__label { font-size: 13.5px; font-weight: 550; color: var(--text); }
.field__label .faint { font-weight: 400; }
.field__hint { font-size: 12.5px; line-height: 1.55; color: var(--text-faint); }
.field__error { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--danger); }

.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 10px 12px;
  font: 400 14.5px/1.4 var(--font); color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.textarea { min-height: 96px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: #463f37; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 0; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a49c90' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; }

.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; color: var(--text); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }

/* Ô mật khẩu kèm nút Hiện/Ẩn nằm gọn trong mép phải. */
.pw { position: relative; display: flex; flex-direction: column; }
.pw input { padding-right: 70px; }
.pw__toggle {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  min-height: 32px; padding: 4px 10px; border: 0; border-radius: 6px;
  font: 500 12.5px/1.2 var(--font); color: var(--text-dim); background: transparent; cursor: pointer;
}
.pw__toggle:hover { color: var(--text); background: var(--surface-2); }

/* Tóm tắt lỗi: đầu biểu mẫu, mỗi dòng dẫn thẳng tới ô sai. */
.error-summary {
  padding: 14px 16px; border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft);
}
.error-summary h3 { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--danger); }
.error-summary ul { margin: 8px 0 0 26px; font-size: 13.5px; }
.error-summary a { color: var(--text); }

/* ============================================================
 * Thông báo
 * ============================================================ */

.flash {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; margin-bottom: 24px; border-radius: var(--r-md);
  font-size: 14px; color: var(--text);
  border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-soft);
  animation: rise .28s var(--ease) both;
}
.flash .icon { color: var(--ok); margin-top: 2px; }
.flash--danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft); }
.flash--danger .icon { color: var(--danger); }
.flash--accent { border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); }
.flash--accent .icon { color: var(--accent); }
.flash__body { min-width: 0; flex: 1; }
.flash__body p + p { margin-top: 4px; color: var(--text-dim); font-size: 13.5px; }

@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

/* ============================================================
 * Khối nội dung
 * ============================================================ */

.section { margin-top: 40px; }
.section:first-child { margin-top: 0; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section__head p { font-size: 13.5px; color: var(--text-dim); }
.link { display: inline-flex; align-items: center; gap: 4px; font-size: 13.5px; font-weight: 550; color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

.panel { border: 1px solid var(--line-soft); border-radius: var(--r-md); background: var(--surface); }
.panel--pad { padding: 20px 22px; }
.panel--accent { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

/* Dải số liệu: các ô ngăn bằng đường kẻ, không phải từng thẻ riêng. */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 10px; padding: 20px 22px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line-soft); }
.stat__label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 550; color: var(--text-dim); }
.stat__label .icon { color: var(--text-faint); }
.stat__value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
.stat__value small { font-size: 14px; font-weight: 500; color: var(--text-dim); letter-spacing: 0; }
.stat__meta { font-size: 13px; color: var(--text-dim); }
.stat__foot { margin-top: auto; padding-top: 4px; }

.meter { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.meter__bar { height: 100%; border-radius: inherit; background: var(--accent); }
.meter--low .meter__bar { background: var(--danger); }

.kv { display: grid; grid-template-columns: minmax(120px, 34%) minmax(0, 1fr); }
.kv > dt, .kv > dd { padding: 13px 0; border-top: 1px solid var(--line-soft); font-size: 14px; }
.kv > dt { color: var(--text-dim); padding-right: 16px; }
.kv > dd { min-width: 0; overflow-wrap: anywhere; }
.kv > dt:first-of-type, .kv > dt:first-of-type + dd { border-top: 0; }

/* ============================================================
 * Danh sách
 * ============================================================ */

.list { list-style: none; border: 1px solid var(--line-soft); border-radius: var(--r-md); background: var(--surface); }
.list > li + li { border-top: 1px solid var(--line-soft); }

.row { display: flex; align-items: flex-start; gap: 16px; padding: 16px 18px; min-width: 0; }
.row__main { flex: 1; min-width: 0; }
.row__title { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 15px; font-weight: 600; }
.row__title a { color: var(--text); text-decoration: none; }
.row__title a:hover { color: var(--accent); }
.row__title a::after { content: ''; position: absolute; inset: 0; }
.row--link { position: relative; }
.row--link:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.row--link:focus-within { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.row--link .row__side { position: relative; z-index: 1; }
.row__preview { margin-top: 4px; font-size: 13.5px; color: var(--text-dim); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.row__meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12.5px; color: var(--text-faint); }
.row__meta > span { display: inline-flex; align-items: center; gap: 5px; }
.row__side { display: flex; align-items: center; gap: 6px; flex: none; }

/* ============================================================
 * Nhãn trạng thái, chip
 * ============================================================ */

.badge {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 24px; padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; line-height: 1.4; white-space: nowrap;
  color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--line-soft);
}
.badge .icon { width: 13px; height: 13px; }
.badge--ok { color: var(--ok); background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.badge--danger { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 32%, transparent); }
.badge--accent { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 32%, transparent); }

.tag {
  display: inline-block; max-width: 100%; padding: 2px 8px; border-radius: 6px;
  font: 500 12px/1.5 ui-monospace, Consolas, monospace; color: var(--text-dim); background: var(--surface-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 6px 13px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  font: 500 12.5px/1.3 ui-monospace, Consolas, monospace; color: var(--text-dim);
  transition: color .16s var(--ease), background .16s var(--ease), border-color .16s var(--ease);
}
.chip:hover { color: var(--text); background: var(--surface-2); border-color: #4a4239; }
.chip[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.chip[aria-pressed="true"]:hover { background: var(--accent-press); }

kbd {
  padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line);
  font: 600 12px/1.4 ui-monospace, Consolas, monospace; color: var(--text); background: var(--surface-2);
}

/* ============================================================
 * Trạng thái rỗng
 * ============================================================ */

.empty {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 32px 28px; border: 1px dashed var(--line); border-radius: var(--r-md);
}
.empty__icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; color: var(--accent); background: var(--accent-soft); }
.empty h2, .empty h3 { font-size: 16px; }
.empty p { max-width: 60ch; font-size: 14px; color: var(--text-dim); text-wrap: pretty; }
.empty .actions { margin-top: 6px; }

/* ============================================================
 * Mở rộng / thu gọn (details)
 * ============================================================ */

.disclosure > summary {
  display: flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; list-style: none;
  font-size: 14px; font-weight: 600; color: var(--text);
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary .icon--chevron { color: var(--text-faint); transition: transform .18s var(--ease); }
.disclosure--panel > summary .icon--chevron { margin-left: auto; }
.disclosure[open] > summary .icon--chevron { transform: rotate(180deg); }
.disclosure__body { padding-top: 14px; }

.disclosure--panel { border: 1px solid var(--line-soft); border-radius: var(--r-md); background: var(--surface); }
.disclosure--panel > summary { padding: 12px 18px; min-height: 52px; }
.disclosure--panel > .disclosure__body { padding: 4px 18px 20px; border-top: 1px solid var(--line-soft); padding-top: 18px; }

.disclosure--quiet > summary { min-height: 32px; font-size: 13px; font-weight: 550; color: var(--text-dim); }
.disclosure--quiet > summary:hover { color: var(--text); }

/* ============================================================
 * Menu tài khoản
 * ============================================================ */

.menu { position: relative; }
.menu__trigger {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 8px 4px 4px;
  border: 1px solid transparent; border-radius: var(--r-pill); background: transparent; cursor: pointer; color: var(--text-dim);
  font-family: inherit;
}
.menu__trigger:hover, .menu__trigger[aria-expanded="true"] { background: var(--surface); border-color: var(--line-soft); color: var(--text); }
.menu__panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40;
  width: 264px; padding: 6px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: 0 18px 48px rgba(8, 6, 4, .55);
  transform-origin: top right; animation: pop .16s var(--ease) both;
}
.menu__head { padding: 10px 12px 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 6px; }
.menu__head strong { display: block; font-size: 14px; }
.menu__head span { display: block; font-size: 12.5px; color: var(--text-faint); }
.menu__item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer;
  font: 500 14px/1.3 var(--font); color: var(--text-dim); text-decoration: none; text-align: left;
}
.menu__item:hover, .menu__item:focus-visible { color: var(--text); background: var(--surface-2); }
.menu__sep { height: 1px; margin: 6px 4px; background: var(--line-soft); }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }

.lang-switch {
  display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 36px; padding: 6px 10px;
  border: 1px solid var(--line-soft); border-radius: var(--r-sm); background: transparent; cursor: pointer;
  font: 600 12.5px/1 var(--font); color: var(--text-dim);
}
.lang-switch:hover { color: var(--text); border-color: var(--line); background: var(--surface); }

/* ============================================================
 * Hộp thoại xác nhận
 * ============================================================ */

.dialog {
  width: min(440px, calc(100vw - 32px)); margin: auto; padding: 0;
  border: 1px solid var(--line); border-radius: var(--r-md);
  color: var(--text); background: var(--surface);
  box-shadow: 0 30px 80px rgba(6, 5, 3, .6);
}
.dialog[open] { animation: pop .18s var(--ease) both; }
.dialog::backdrop { background: rgba(10, 9, 8, .72); }
.dialog__body { display: flex; gap: 14px; padding: 22px 22px 8px; }
.dialog__icon { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 10px; color: var(--danger); background: var(--danger-soft); }
.dialog h2 { font-size: 16.5px; }
.dialog p { margin-top: 6px; font-size: 14px; color: var(--text-dim); overflow-wrap: anywhere; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 22px 20px; }

/* ============================================================
 * Tổng quan
 * ============================================================ */

.welcome { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 28px; }
.welcome__meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; font-size: 14px; color: var(--text-dim); }

.checklist { list-style: none; counter-reset: step; }
.checklist li { display: flex; align-items: flex-start; gap: 14px; padding: 14px 20px; }
.checklist li + li { border-top: 1px solid var(--line-soft); }
.checklist__mark {
  display: grid; place-items: center; flex: none; width: 26px; height: 26px; margin-top: 1px;
  border-radius: 50%; border: 1.5px solid var(--line); color: var(--text-faint); font-size: 12px; font-weight: 650;
}
.checklist li.is-done .checklist__mark { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.checklist li.is-done .checklist__title { color: var(--text-dim); text-decoration: line-through; text-decoration-color: var(--text-faint); }
.checklist__title { font-size: 14.5px; font-weight: 600; }
.checklist__text { margin-top: 2px; font-size: 13.5px; color: var(--text-dim); }
.checklist__body { flex: 1; min-width: 0; }
.checklist .btn { flex: none; }

.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; margin-top: 36px; }

/* ============================================================
 * Bộ lọc lịch sử
 * ============================================================ */

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(130px, 170px)) auto; gap: 10px; align-items: end; margin-bottom: 18px; }
.search { position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.search .input { padding-left: 38px; }
.toolbar .field__label { font-size: 12.5px; color: var(--text-dim); font-weight: 500; }
.toolbar__actions { display: flex; gap: 6px; }
.results { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; font-size: 13.5px; color: var(--text-dim); }

/* ============================================================
 * Chi tiết hội thoại
 * ============================================================ */

.detail { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 36px; align-items: start; }
.detail__rail { position: sticky; top: calc(var(--top-h) + 24px); display: flex; flex-direction: column; gap: 20px; }

.thread { display: flex; flex-direction: column; gap: 26px; max-width: 760px; }
.msg { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.msg__head { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-faint); }
.msg__who { font-weight: 650; color: var(--text); }
.msg--user .msg__body {
  padding: 12px 16px; border-radius: var(--r-md); background: var(--surface-2);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg--assistant .msg__who { color: var(--accent); }

.prose { font-size: 15px; line-height: 1.72; overflow-wrap: anywhere; }
.prose > * + * { margin-top: .8em; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-size: 16px; margin-top: 1.3em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: .3em; }
.prose a { color: var(--accent); }
.prose blockquote { padding-left: 14px; border-left: 3px solid var(--line); color: var(--text-dim); }
.prose table { width: 100%; border-collapse: collapse; font-size: 14px; display: block; overflow-x: auto; }
.prose th, .prose td { padding: 7px 10px; border: 1px solid var(--line-soft); text-align: left; }
.prose thead th { background: var(--surface-2); font-weight: 650; white-space: nowrap; }
/* CommonMark ghi căn lề bằng thuộc tính align, không phải class như bản desktop. */
.prose th[align="right"], .prose td[align="right"] { text-align: right; font-variant-numeric: tabular-nums; }
.prose th[align="center"], .prose td[align="center"] { text-align: center; }
.prose code { padding: 1px 6px; border-radius: 5px; font: 13px/1.5 ui-monospace, Consolas, monospace; background: var(--surface-2); }
.prose hr { border: 0; border-top: 1px solid var(--line-soft); }

.code { position: relative; }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; border-radius: var(--r-sm); border: 1px solid var(--line-soft); background: #0c0b0a; }
.code pre code { padding: 0; background: none; font-size: 13px; line-height: 1.6; }
.code__copy { position: absolute; top: 6px; right: 6px; opacity: .85; }
.code__copy:hover, .code__copy:focus-visible { opacity: 1; }

.tools { margin-top: 4px; font-size: 13.5px; }
.tools ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.tools li { padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line-soft); }
.tools pre { margin-top: 6px; font: 12px/1.5 ui-monospace, Consolas, monospace; color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; }

.attachment { overflow: hidden; border: 1px solid var(--line-soft); border-radius: var(--r-md); background: var(--surface); }
.attachment__image { display: block; background: #0c0b0a; }
.attachment__image img { width: 100%; height: auto; max-height: 420px; object-fit: contain; }
.attachment__meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 11px 14px; font-size: 12.5px; color: var(--text-dim); border-top: 1px solid var(--line-soft); }
.attachment__gone { display: flex; align-items: flex-start; gap: 10px; padding: 16px; font-size: 13.5px; color: var(--text-dim); }

/* ============================================================
 * Phân trang
 * ============================================================ */

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.pagination__pages { display: flex; gap: 4px; list-style: none; flex-wrap: wrap; }
.pagination__link {
  display: inline-grid; place-items: center; min-width: 40px; min-height: 40px; padding: 0 10px;
  border-radius: var(--r-sm); border: 1px solid var(--line-soft);
  font-size: 13.5px; font-weight: 550; color: var(--text-dim); text-decoration: none;
}
.pagination__link:hover { color: var(--text); border-color: var(--line); background: var(--surface); }
.pagination__link[aria-current="page"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.pagination__link[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.pagination__summary { font-size: 13px; color: var(--text-faint); }

/* ============================================================
 * Nhà cung cấp, dịch vụ
 * ============================================================ */

.option { display: flex; align-items: flex-start; gap: 14px; padding: 18px 20px; }
.option__radio {
  display: grid; place-items: center; flex: none; width: 20px; height: 20px; margin-top: 2px;
  border-radius: 50%; border: 2px solid var(--line);
}
.option.is-active .option__radio { border-color: var(--accent); }
.option.is-active .option__radio::after { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.option__body { flex: 1; min-width: 0; }
.option__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.option__meta { margin-top: 4px; font-size: 13px; color: var(--text-dim); }
.option__models { margin-top: 12px; }
.option__edit { margin-top: 14px; }
.option__side { display: flex; align-items: center; gap: 6px; flex: none; }

.summary-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 28px; }
.summary-strip .stat__value { font-size: 22px; }

.status-note { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; padding: 10px 12px; border-radius: var(--r-sm); font-size: 13.5px; background: var(--danger-soft); color: var(--text); }
.status-note .icon { color: var(--danger); margin-top: 2px; }
.status-note p + p { margin-top: 2px; color: var(--text-dim); }

/* ============================================================
 * Trang tài khoản (khách chưa đăng nhập): đăng nhập, đăng ký, xác thực
 * ============================================================ */

body.guest { display: grid; place-items: start center; padding: 56px 20px 80px; background: var(--bg); }
.guest__wrap { width: 100%; max-width: 420px; }
.guest__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 36px; }
.guest__top .brand { margin: 0; padding: 0; }
.guest h1 { font-size: 26px; }
.guest .lead { margin: 8px 0 26px; color: var(--text-dim); text-wrap: pretty; }
.guest .panel { padding: 24px; }
.guest .form .btn { width: 100%; min-height: 44px; }
.guest__foot { margin-top: 20px; text-align: center; font-size: 14px; color: var(--text-dim); }
.guest__foot a { font-weight: 600; }

/* Link phụ nằm trong biểu mẫu, ngay dưới nút chính. */
.form__foot { margin: -4px 0 0; text-align: center; font-size: 14px; }

/* ============================================================
 * Ngăn kéo điều hướng (màn hình hẹp)
 * ============================================================ */

.nav-toggle { display: none; }
.scrim { display: none; }

@media (max-width: 1279px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .detail { grid-template-columns: minmax(0, 1fr) 260px; gap: 28px; }
  .toolbar { grid-template-columns: minmax(200px, 1fr) repeat(3, minmax(120px, 150px)); }
  .toolbar__actions { grid-column: 1 / -1; }
}

@media (max-width: 1023px) {
  .topbar { padding-inline: 20px; }
  .content { padding: 26px 20px 64px; }

  .detail { grid-template-columns: minmax(0, 1fr); }
  .detail__rail { position: static; order: 2; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-strip .stat:nth-child(3) { border-left: 0; }
  .summary-strip .stat:nth-child(n+3) { border-top: 1px solid var(--line-soft); }
}

/*
 * Máy tính bảng: thanh bên thu về dải icon thay vì thành ngăn kéo.
 *
 * Màn hình cỡ này còn đủ chỗ cho một dải 72px, nên giữ điều hướng luôn hiện
 * còn hơn giấu sau một nút bấm. Nhãn chữ chỉ bị ẩn khỏi mắt bằng `.sr-only`
 * chứ không bị `display: none` — trình đọc màn hình vẫn đọc được tên mục, và
 * `title` lo phần chú thích khi rê chuột.
 */
@media (min-width: 768px) and (max-width: 1023px) {
  .shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }

  .sidebar { padding: 16px 10px 14px; align-items: center; }
  .sidebar__top { justify-content: center; margin-bottom: 16px; }
  .brand { justify-content: center; }
  .brand__name { display: none; }

  .sidebar nav { width: 100%; }
  .nav__link { justify-content: center; gap: 0; padding: 8px; }
  .nav__link > span { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .nav__link[aria-current="page"]::before { left: -10px; }
  .nav__label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

  /* Hai nhóm mục dính liền nhau khi mất tiêu đề nhóm; kẻ một vạch thay chữ. */
  .nav + .nav { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-soft); }

  .sidebar__foot { width: 100%; align-items: center; }
  .get-app { justify-content: center; padding: 11px 8px; }
  .get-app > span { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .who { justify-content: center; padding: 8px 0; }
  .who__text { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@media (max-width: 767px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60; width: min(300px, 86vw);
    transform: translateX(-100%); visibility: hidden;
    transition: transform .2s var(--ease), visibility 0s linear .2s;
    box-shadow: 24px 0 60px rgba(6, 5, 3, .5);
  }
  .shell.is-nav-open .sidebar { transform: none; visibility: visible; transition: transform .2s var(--ease); }
  .scrim { position: fixed; inset: 0; z-index: 55; background: rgba(10, 9, 8, .6); }
  .shell.is-nav-open .scrim { display: block; }

  .nav-toggle { display: inline-flex; }

  h1 { font-size: 22px; }
  .topbar { gap: 8px; padding-inline: 14px; }
  .topbar__title { display: none; }
  .quota-chip span { display: none; }
  .content { padding: 22px 16px 56px; }

  .stats { grid-template-columns: minmax(0, 1fr); }
  .stat + .stat { border-left: 0; border-top: 1px solid var(--line-soft); }
  .summary-strip .stat:nth-child(odd) { border-left: 0; }
  .summary-strip .stat:nth-child(even) { border-left: 1px solid var(--line-soft); border-top: 0; }
  .summary-strip .stat:nth-child(n+3) { border-top: 1px solid var(--line-soft); }

  .toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar > .search-field { grid-column: 1 / -1; }
  .toolbar__actions .btn { flex: 1; }

  .form__grid { grid-template-columns: minmax(0, 1fr); }
  .row { flex-wrap: wrap; padding: 14px; }
  .row__side { width: 100%; justify-content: flex-end; }
  .row--link .row__side { width: auto; }
  .option { flex-wrap: wrap; padding: 16px; }
  .option__side { width: 100%; justify-content: flex-end; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv > dt { padding-bottom: 0; }
  .kv > dd { border-top: 0; padding-top: 4px; }
  .checklist li { flex-wrap: wrap; }
  .checklist .btn { margin-left: 40px; }
  .page-head__actions { width: 100%; }
  .menu__panel { position: fixed; top: calc(var(--top-h) + 6px); left: 12px; right: 12px; width: auto; }

  /*
   * Ngón tay cần chỗ rộng hơn con trỏ chuột. `.btn--icon.btn--sm` và
   * `.lang-switch` phải gọi đích danh: chúng khai width/min-height bằng
   * selector mạnh hơn `.btn` nên quy tắc chung bên dưới không với tới.
   */
  .btn, .chip, .pagination__link, .lang-switch { min-height: 44px; }
  .btn--icon, .btn--icon.btn--sm { width: 44px; }
}

/* Trang tài khoản và cài đặt */
.settings__choices { margin-top: 14px; }
.panel > .field__hint { margin-top: 14px; }
.panel.actions { justify-content: space-between; gap: 14px; }
