/* ---------- Design tokens ---------- */
:root {
  --brand: #0e9384;
  --brand-strong: #0b7d70;
  --brand-soft: #e6f4f2;
  --chart: #0e9384; /* màu cột biểu đồ — đã kiểm tra độ sáng & tương phản trên nền sáng */
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --danger-solid: #dc2626; /* nền nút đỏ, luôn đi với chữ trắng */
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --ok: #047857;
  --ok-soft: #e6f5ef;

  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #fbfcfc;
  --text: #16202a;
  --muted: #64748b;
  --line: #e4e9ec;
  --shadow: 0 1px 2px rgba(16, 32, 42, .04), 0 8px 24px rgba(16, 32, 42, .06);

  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 232px;
  --topbar-h: 62px;
  --max-w: 1080px;
}

:root[data-theme="dark"] {
  --brand: #2dd4bf;
  --brand-strong: #5eead4;
  --brand-soft: #10302e;
  --chart: #10a393; /* bậc riêng cho nền tối — #2dd4bf quá sáng cho mảng màu lớn */
  --danger: #f87171;
  --danger-soft: #341d1d;
  --danger-solid: #d13636;
  --warn: #fbbf24;
  --warn-soft: #33270f;
  --ok: #34d399;
  --ok-soft: #10281f;

  --bg: #0e1317;
  --surface: #161d23;
  --surface-2: #1b232a;
  --text: #e8edf1;
  --muted: #93a3b2;
  --line: #26313a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.app { min-height: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; margin-right: auto; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 11px;
  background: var(--brand); color: #fff;
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: 11.5px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.family-picker { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.family-picker select {
  appearance: none;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 15px;
  border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 28px 7px 11px;
  font: inherit; font-size: 13.5px; max-width: 190px;
}

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 3px;
  border-right: 1px solid var(--line); background: var(--surface);
}
.sidebar a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.sidebar a:hover { background: var(--surface-2); color: var(--text); }
.sidebar a.active { background: var(--brand-soft); color: var(--brand-strong); }
.sidebar a.nav-sos.active { background: var(--danger-soft); color: var(--danger); }
.sidebar a[hidden] { display: none !important; }

.content {
  padding: 26px 22px 64px;
  margin-left: var(--sidebar-w);
  max-width: calc(var(--max-w) + var(--sidebar-w));
  outline: none;
}

@media (max-width: 860px) {
  .sidebar {
    top: auto; bottom: 0; width: 100%; flex-direction: row; justify-content: space-around;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); z-index: 30;
  }
  .sidebar a { flex-direction: column; gap: 3px; font-size: 11px; padding: 7px 4px; flex: 1; min-width: 0; justify-content: center; text-align: center; }
  .sidebar a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .content { margin-left: 0; padding: 18px 14px 92px; }
  .brand-text small { display: none; }
}

.only-mobile { display: none; }
@media (max-width: 860px) { .only-desktop { display: none; } }

/* ---------- Trạng thái chưa đăng nhập ---------- */
.app[data-auth="guest"] .sidebar,
.app[data-auth="loading"] .sidebar { display: none; }
.app[data-auth="guest"] .content,
.app[data-auth="loading"] .content { margin-left: 0; max-width: none; padding: 0; }

.auth-wrap {
  min-height: calc(100vh - var(--topbar-h));
  display: grid; place-items: center; padding: 26px 16px 60px;
}
.auth-card {
  width: min(520px, 100%);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px;
}
.auth-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; }
.auth-brand h1 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.auth-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.auth-brand .brand-mark { width: 44px; height: 44px; border-radius: 13px; }
.auth-brand .brand-mark svg { width: 25px; height: 25px; }

.auth-tabs {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 20px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.auth-tab {
  flex: 1; padding: 9px 12px; border: 0; border-radius: 7px; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; font-size: 14px; font-weight: 500;
}
.auth-tab.active { background: var(--surface); color: var(--brand-strong); box-shadow: var(--shadow); }

/* Mã khôi phục khoá mã hoá (màn hình khởi tạo) */
.recovery-code {
  padding: 14px; border-radius: var(--radius-sm); text-align: center;
  background: var(--surface-2); border: 1px dashed var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px; letter-spacing: .04em; word-break: break-all; user-select: all;
}

.auth-sep {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0 16px; color: var(--muted); font-size: 12.5px;
}
.auth-sep::before, .auth-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.auth-foot { margin: 16px 0 0; text-align: center; font-size: 13.5px; color: var(--muted); }
.auth-foot a { color: var(--brand-strong); font-weight: 500; }

/* ---------- Thanh tài khoản ---------- */
.account-box { display: flex; align-items: center; gap: 8px; }
.account-chip {
  display: flex; flex-direction: column; line-height: 1.25; cursor: pointer;
  padding: 5px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); max-width: 230px;
}
.account-chip:hover { border-color: var(--brand); }
.account-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .account-sub { display: none; } .account-chip { max-width: 130px; } }

/* ---------- Page header ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 14px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 3px; font-size: 22px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ---------- Cards & grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card { margin-top: 16px; }
/* Thẻ nằm cạnh nhau trong lưới đã có `gap` — không đẩy thẻ sau xuống. */
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 15.5px; letter-spacing: -.01em; }
.card-head .sub { color: var(--muted); font-size: 13px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }

/* ---------- Stat tiles ---------- */
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 27px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.stat .value.ok { color: var(--ok); }
.stat .value.warn { color: var(--warn); }
.stat .value.danger { color: var(--danger); }

/* ---------- Person ---------- */
.person { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 15px;
  background: var(--brand-soft); color: var(--brand-strong);
}
.avatar.child { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.person .name { font-weight: 600; }
.person .meta { color: var(--muted); font-size: 13px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand-strong); border-color: transparent; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }

.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* Hiện biểu tượng của chế độ sẽ chuyển sang, không phải chế độ hiện tại. */
:root[data-theme="light"] .icon-sun,
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px; border-top: 1px solid var(--line);
}
.list .row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; }
.row .sub { color: var(--muted); font-size: 13px; }
.row .actions { display: flex; gap: 6px; flex: none; }
.row.clickable { cursor: pointer; border-radius: var(--radius-sm); }
.row.clickable:hover { background: var(--surface-2); }

.time-chip {
  flex: none; width: 58px; text-align: center;
  font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px;
  padding: 7px 0; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line);
}

.banner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
  background: linear-gradient(180deg, var(--brand-soft), var(--surface));
  margin-bottom: 16px;
}

.alert {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px; margin-bottom: 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-size: 13.5px; line-height: 1.5;
}
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert.danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert span { color: var(--text); }
.alert a { color: inherit; font-weight: 600; }
.alert code { font-size: 12.5px; }

/* ---------- Tabs (trang Quản trị) ---------- */
.tabs {
  display: flex; gap: 4px; margin-bottom: 16px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  overflow-x: auto;
}
.tab {
  flex: 1; min-width: max-content; padding: 8px 14px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--brand-strong); box-shadow: var(--shadow); }
.section-title { margin: 20px 0 10px; font-size: 15px; letter-spacing: -.01em; }

/* Cặp nhãn – giá trị */
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13.5px; }
.kv > span { color: var(--muted); }

/* Bảng dữ liệu — cuộn ngang trên màn hình hẹp */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px;
  padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Khu quản trị ---------- */
/* Sidebar đổi menu theo khu: gia đình / quản trị */
.sidebar .nav-group { display: contents; }
.sidebar .nav-group.nav-admin { display: none; }
.app[data-area="admin"] .sidebar .nav-group.nav-family { display: none; }
.app[data-area="admin"] .sidebar .nav-group.nav-admin { display: contents; }
.app[data-area="admin"] .content { max-width: none; }
.sidebar .nav-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 12px 12px 4px;
}
@media (max-width: 860px) { .sidebar .nav-label, .sidebar .nav-back span { display: none; } }

/* Thanh công cụ lọc — một hàng phía trên bảng */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; padding: 8px 10px; font-size: 13.5px; }
.toolbar .search { flex: 1 1 240px; }
.toolbar .spacer { flex: 1; }

/* Bảng dữ liệu phân trang */
.dt { position: relative; }
.dt .table th.sortable { cursor: pointer; user-select: none; }
.dt .table th.sortable:hover { color: var(--text); }
.dt .table th .arrow { opacity: .35; margin-left: 3px; }
.dt .table th.sorted .arrow { opacity: 1; color: var(--brand-strong); }
.dt .table tbody tr.clickable { cursor: pointer; }
.dt .table tbody tr.clickable:hover td { background: var(--surface-2); }
.dt.loading tbody { opacity: .45; transition: opacity .15s; }
.dt .cell-main { font-weight: 500; }
.dt .cell-sub { color: var(--muted); font-size: 12.5px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 10px; font-size: 13px; color: var(--muted); }
.pager .inline { gap: 6px; }
.pager select { width: auto; padding: 5px 8px; font-size: 13px; }

/* Ngăn chi tiết trượt từ phải */
.drawer-root[hidden] { display: none; }
.drawer-root { position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, .35); }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(640px, 100%);
  background: var(--bg, var(--surface-2)); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0, 0, 0, .12);
  animation: drawer-in .18s ease-out;
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
.drawer > header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.drawer > header h2 { margin: 0; font-size: 17px; }
.drawer > .drawer-body { padding: 16px 18px 32px; overflow-y: auto; }

/* KPI — lưới cố định 4 cột để các hàng thẳng nhau */
.grid.kpi-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.kpi-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .grid.kpi-4 { grid-template-columns: 1fr; } }
/* KPI */
.kpi .value { font-size: 26px; }
.kpi .delta { font-size: 12.5px; font-weight: 500; }
.kpi .delta.up { color: var(--ok); }
.kpi .delta.down { color: var(--danger); }
a.kpi, .kpi.link { text-decoration: none; color: inherit; cursor: pointer; }
a.kpi:hover { border-color: var(--brand); }

/* Biểu đồ cột (SVG) */
.chart { position: relative; }
/* Bỏ kiểu nét của icon (svg { stroke: currentColor }) — biểu đồ tự đặt màu từng phần. */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; fill: none; stroke: none; }
.chart-empty { margin: 0; padding: 36px 0; text-align: center; color: var(--muted); font-size: 13.5px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--chart); }
.chart .bar-hit { fill: transparent; cursor: default; }
.chart .bar-hit:hover + .bar, .chart .bar.hover { filter: brightness(1.12); }
.chart .value-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; transform: translate(-50%, -100%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 6px 10px; font-size: 12.5px; white-space: nowrap;
}
.chart-tip strong { display: block; font-size: 13.5px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 34px 18px; color: var(--muted); }
.empty svg { width: 34px; height: 34px; margin-bottom: 10px; opacity: .5; }
.empty h3 { margin: 0 0 5px; color: var(--text); font-size: 16px; }
.empty p { margin: 0 auto 16px; max-width: 380px; font-size: 13.5px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 13px; font-weight: 500; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
/* Liệt kê theo input[type="..."] sẽ bỏ sót ô không ghi type (mặc định là text)
   và ô type="email" → chúng rơi về giao diện mặc định của trình duyệt, nhìn lệch
   hẳn so với ô số điện thoại/mật khẩu. Loại trừ checkbox/radio thay vì liệt kê. */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 14.5px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input:disabled, select:disabled, textarea:disabled {
  color: var(--muted); background: var(--surface); cursor: not-allowed;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 7px 12px; border-radius: 999px; cursor: pointer; user-select: none;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 13px; color: var(--muted);
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-strong); font-weight: 500; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track {
  width: 40px; height: 23px; border-radius: 999px; background: var(--line);
  position: relative; transition: background .18s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2.5px; left: 2.5px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(17px); }

/* ---------- SOS panel ---------- */
.sos-panel {
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  background: linear-gradient(180deg, var(--danger-soft), var(--surface));
}
.sos-btn {
  width: 100%; padding: 16px; font-size: 16px; font-weight: 600;
  border-radius: var(--radius); border: 0; cursor: pointer;
  background: var(--danger-solid); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
}
.sos-btn:hover { filter: brightness(.95); }
.pulse { animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); } 70% { box-shadow: 0 0 0 14px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 60; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px));
}
@media (max-width: 860px) { .toasts { bottom: 78px; } }
.toast {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px;
  animation: slide-in .2s ease-out;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warn { border-left: 3px solid var(--warn); }
@keyframes slide-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Modal ---------- */
.modal-root[hidden] { display: none; }
.modal-root {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 18px;
  background: rgba(12, 20, 26, .45); backdrop-filter: blur(2px);
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(520px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 4px; }
.modal header h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.modal .body { padding: 14px 20px 4px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }

/* ---------- Utils ---------- */
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skeleton { border-radius: var(--radius-sm); background: var(--surface-2); height: 62px; animation: sk 1.2s ease-in-out infinite; }
@keyframes sk { 50% { opacity: .55; } }

/* Mã QR PayOS — nền trắng cố định để app ngân hàng quét được cả ở chế độ tối */
.qr-pay { display: grid; gap: 14px; justify-items: center; text-align: center; }
.qr-pay img { width: 232px; height: 232px; max-width: 100%; background: #fff; border-radius: 12px; border: 1px solid var(--line, #e5e7eb); }
.qr-pay .kv { width: 100%; text-align: left; }
.qr-pay .waiting { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; }
.qr-pay .waiting::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: qr-pulse 1.2s ease-in-out infinite; }
@keyframes qr-pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .qr-pay .waiting::before { animation: none; } }
