/* Super Admin console — design tokens and shared components.
   Layout utilities come from Tailwind (see layouts/base.html); everything that repeats
   across pages (cards, tables, badges, fields, skeletons) lives here once. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --ok: #047857;       --ok-bg: #ecfdf5;
  --warn: #b45309;     --warn-bg: #fffbeb;
  --bad: #b91c1c;      --bad-bg: #fef2f2;
  --info: #1d4ed8;     --info-bg: #eff6ff;
  --neutral: #475569;  --neutral-bg: #f1f5f9;
  --side: #0b1020;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
}

html, body { background: var(--bg); color: var(--text); font-family: 'Inter', ui-sans-serif, system-ui, sans-serif; }
body { font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
code, .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* ── Sidebar ───────────────────────────────────────────── */
.side { background: var(--side); color: #cbd5e1; }
.side-link {
  display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; border-radius: 8px;
  font-weight: 500; color: #94a3b8; transition: background .15s, color .15s;
}
.side-link i { font-size: 1.05rem; width: 1.25rem; text-align: center; }
.side-link:hover { background: rgba(255,255,255,.06); color: #f1f5f9; }
.side-link[aria-current="page"] { background: rgba(99,102,241,.18); color: #fff; }
.side-count {
  margin-left: auto; min-width: 1.25rem; padding: 0 .375rem; border-radius: 999px; text-align: center;
  background: #f59e0b; color: #1c1917; font-size: 11px; font-weight: 700; line-height: 1.25rem;
}

/* ── Surfaces ──────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.card-title { font-size: 14px; font-weight: 600; }
.page-title { font-size: 1.25rem; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--text-3); }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }

.stat { padding: 1rem 1.25rem; }
.stat-value { font-size: 1.625rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-3); margin-top: .125rem; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; height: 2.25rem; padding: 0 .85rem;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 13px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: #9ca3af; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: #fff; color: var(--bad); border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: var(--bad-bg); border-color: #fca5a5; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 1.875rem; padding: 0 .6rem; font-size: 12px; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-color: #9ca3af #9ca3af #9ca3af transparent; animation: spin .7s linear infinite;
}
.btn-primary.is-busy::after { border-color: #fff #fff #fff transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Fields ────────────────────────────────────────────── */
.field { display: block; width: 100%; height: 2.25rem; padding: 0 .7rem; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; font-size: 13px; color: var(--text); }
textarea.field { height: auto; padding: .5rem .7rem; }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.field[aria-invalid="true"] { border-color: #f87171; }
.field-error { color: var(--bad); font-size: 12px; margin-top: .25rem; }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: .25rem; }

/* ── Badges ────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .125rem .5rem; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 1.25rem; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-ok { color: var(--ok); background: var(--ok-bg); }
.badge-warn { color: var(--warn); background: var(--warn-bg); }
.badge-bad { color: var(--bad); background: var(--bad-bg); }
.badge-info { color: var(--info); background: var(--info-bg); }
.badge-neutral { color: var(--neutral); background: var(--neutral-bg); }

/* ── Tables (cards on phones) ──────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; padding: .6rem 1rem; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.th-sort { display: inline-flex; align-items: center; gap: .3rem; background: none; border: 0; padding: 0; font: inherit;
  letter-spacing: inherit; text-transform: inherit; color: inherit; cursor: pointer; }
.th-sort i { font-size: .7rem; opacity: .45; }
.th-sort:hover, .th-sort.is-on { color: var(--text); }
.th-sort.is-on i, .th-sort:hover i { opacity: 1; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { text-align: right; min-width: 9rem; max-width: 21rem; }
.tbl .actions .btn { margin: .125rem 0 .125rem .25rem; }
[data-table-body] { overflow-x: auto; }
.cell-main { font-weight: 550; }
.cell-sub { font-size: 12px; color: var(--text-3); }
.truncate-cell { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 767px) {
  .tbl thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
  .tbl tbody tr:last-child { border-bottom: 0; }
  .tbl td { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; border: 0; text-align: right; }
  .tbl td::before { content: attr(data-label); flex: none; color: var(--text-3); font-size: 12px; font-weight: 600; text-align: left; }
  .tbl td.cell-first { display: block; text-align: left; padding-bottom: .4rem; }
  .tbl td.cell-first::before, .tbl td[data-label=""]::before { content: none; }
  .tbl td.actions { justify-content: flex-end; padding-top: .5rem; }
  .truncate-cell { max-width: 60vw; }
}

/* ── Skeleton, empty, error ────────────────────────────── */
.skeleton { position: relative; overflow: hidden; background: #e8ebf0; border-radius: 6px; min-height: 1em; }
.skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.state { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 3rem 1.5rem; text-align: center; color: var(--text-3); }
.state i { font-size: 1.75rem; color: #94a3b8; }
.state-title { color: var(--text); font-weight: 600; }
.state-error i { color: var(--bad); }

/* ── Tabs, drawer, pagination ──────────────────────────── */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { padding: .6rem .9rem; font-weight: 500; color: var(--text-3); border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); z-index: 41; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(15,23,42,.12); animation: slide-in .18s ease-out; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.drawer-body { flex: 1; overflow-y: auto; padding: 1.25rem; }
.kv { display: grid; grid-template-columns: 9rem 1fr; gap: .5rem 1rem; }
.kv dt { color: var(--text-3); font-size: 12.5px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-3); flex-wrap: wrap; }

.switch { position: relative; width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; border: 0; cursor: pointer; transition: background .15s; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.switch:disabled { opacity: .5; cursor: not-allowed; }

.banner { display: flex; gap: .6rem; align-items: center; padding: .6rem 1rem; font-weight: 500; background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #fde68a; }

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

/* SweetAlert2 — match the console */
.swal2-popup { font-family: inherit; border-radius: 14px; }
.swal2-styled.swal2-confirm { background: var(--accent) !important; }
.swal2-styled.swal2-confirm.swal-danger { background: var(--bad) !important; }
