/**
 * Admin & superadmin theme — shared by /admin, /superadmin and the sign-in pages.
 *
 * Structure (kept framework-neutral so it can move to React/Angular as-is):
 *   1. Design tokens      — every colour, radius, shadow and size lives here.
 *   2. Base               — element defaults, scoped to the admin pages.
 *   3. App shell          — sidebar navigation, top bar, page header.
 *   4. Surfaces           — cards, form cards, callouts, modals.
 *   5. Controls           — buttons, form fields, switches, segmented control.
 *   6. Data display       — tables, badges, stats, pagination, empty states.
 *   7. Feature styles     — reports, router setup, stock banner, auth pages.
 */

/* ---------------------------------------------------------------- 1. Tokens */
:root {
  --font-sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, Menlo, monospace;

  --bg: #f4f6f9;
  --card: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --muted: #64748b; /* alias kept for existing inline styles */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --accent: #1d64d8;
  --accent-hover: #1650b0;
  --accent-soft: #eaf1fd;
  --accent-ring: rgba(29, 100, 216, 0.22);

  --success: #15803d;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --error: #b91c1c;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --warning-border: #fcd34d;
  --info: #0c4a6e;
  --info-bg: #f0f7ff;
  --info-border: #bfdbfe;

  --nav-bg: #0f172a;
  --nav-text: #cbd5e1;
  --nav-text-muted: #64748b;
  --nav-hover: rgba(255, 255, 255, 0.06);
  --nav-active: rgba(255, 255, 255, 0.10);

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.18);

  --sidebar-width: 248px;
  --header-height: 56px;
  --control-height: 40px;
  --container-padding: 28px;
}

@media (max-width: 768px) {
  :root { --container-padding: 16px; }
}

/* ------------------------------------------------------------------ 2. Base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: rgba(15, 23, 42, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mono { font-family: var(--font-mono); font-size: 0.85rem; }
.muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ------------------------------------------------------------- 3. App shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 60;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { display: block; font-weight: 700; font-size: 0.95rem; color: #fff; line-height: 1.2; }
.brand-sub { display: block; font-size: 0.75rem; color: var(--nav-text-muted); }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: 12px 12px 20px; }
.nav-group + .nav-group { margin-top: 18px; }
.nav-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--nav-text-muted);
  padding: 0 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--nav-text);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  min-height: 38px;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: 0.75; }
.nav-item:hover { background: var(--nav-hover); color: #fff; }
.nav-item.active { background: var(--nav-active); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, 0.06); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-footer form { margin: 0; }

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

/* Top bar: only shown on small screens, where the sidebar becomes a drawer. */
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
  padding: 0 var(--container-padding);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-weight: 600; font-size: 1rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-secondary);
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-muted); }
.icon-btn svg { width: 20px; height: 20px; }
.nav-backdrop { display: none; }

@media (max-width: 960px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .app-shell.nav-open .sidebar { transform: none; }
  .app-shell.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 55; }
}

.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px var(--container-padding) 48px;
}

/* Page header: title, one-line description, primary actions on the right. */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-header h2 { margin: 0; font-size: 1.4rem; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.page-header p { margin: 4px 0 0; color: var(--text-muted); font-size: 0.92rem; max-width: 68ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Tab panels: one visible section at a time (the nav toggles .active). */
.tab-panel, .panel { display: none; }
.tab-panel.active, .panel.active { display: block; }

/* Legacy horizontal tabs, kept for any page not yet on the shell. */
.tabs { display: flex; gap: 2px; margin-bottom: 20px; border-bottom: 1px solid var(--border-strong); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { padding: 10px 14px; border: none; background: none; cursor: pointer; font: inherit; font-size: 0.92rem; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; min-height: 44px; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }

/* Legacy header, kept for compatibility. */
.app-header { background: var(--card); border-bottom: 1px solid var(--border); padding: 12px var(--container-padding); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.app-header h1 { margin: 0; font-size: 1.25rem; }
.app-header .sub { margin: 2px 0 0; font-size: 0.875rem; color: var(--text-muted); }
.app-header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.panel-header h2 { margin: 0; font-size: 1.1rem; color: var(--text-secondary); }

/* ------------------------------------------------------------- 4. Surfaces */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  min-width: 0;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { margin: 0; font-size: 1rem; font-weight: 600; color: var(--text); }
.card-subtitle { margin: 2px 0 0; font-size: 0.85rem; color: var(--text-muted); }
.card-body { padding: 20px; }
.card-body > :last-child { margin-bottom: 0; }
.card > .table-wrap { margin-bottom: 0; }
.card > .table-wrap table { min-width: 640px; }
.card > .table-wrap th:first-child, .card > .table-wrap td:first-child { padding-left: 20px; }
.card > .table-wrap th:last-child, .card > .table-wrap td:last-child { padding-right: 20px; }
.card > .table-wrap tbody tr:last-child td { border-bottom: none; }
.card > .pagination { padding: 12px 20px; margin: 0; border-top: 1px solid var(--border); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 20px; }
.card-grid > .card { margin-bottom: 0; }
.card-grid + .card, .card-grid + .card-grid { margin-top: 20px; }

/* Form card: the add/edit form that opens above a list. */
.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  scroll-margin-top: 72px;
}
.form-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.form-card-header h3 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.form-card-header p { margin: 2px 0 0; font-size: 0.85rem; color: var(--text-muted); }
.form-card-body { padding: 20px; }
.form-card-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface-muted);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
}
.form-card-footer .btn-primary { order: 2; }
.close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
}
.close-btn:hover { background: var(--surface-muted); color: var(--text); }

/* Numbered steps inside long forms. */
.form-section { margin-bottom: 24px; }
.form-section:last-child { margin-bottom: 0; }
.form-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
}
.form-section-desc { margin: 0 0 14px; font-size: 0.87rem; color: var(--text-muted); }
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  flex: 0 0 auto;
}
.subsection { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 20px; }

/* Callouts: contextual help and warnings. */
.callout {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--info-border);
  background: var(--info-bg);
  color: var(--info);
  font-size: 0.87rem;
  line-height: 1.55;
  margin-bottom: 14px;
}
.callout:last-child { margin-bottom: 0; }
.callout-title { display: block; font-weight: 600; margin-bottom: 4px; }
.callout ol, .callout ul { margin: 6px 0 0 18px; padding: 0; }
.callout li + li { margin-top: 3px; }
.callout code { background: rgba(255, 255, 255, 0.7); }
.callout-warning { border-color: var(--warning-border); background: var(--warning-bg); color: #78350f; }
.callout-neutral { border-color: var(--border); background: var(--surface-muted); color: var(--text-secondary); }
.callout + .callout { margin-top: -4px; }

/* Plain disclosure for optional or advanced settings. */
details.disclosure { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 14px; }
details.disclosure > summary { cursor: pointer; padding: 10px 14px; font-size: 0.88rem; font-weight: 600; color: var(--text-secondary); list-style: none; display: flex; align-items: center; gap: 8px; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 0.15s; }
details.disclosure[open] > summary::before { transform: rotate(45deg); }
details.disclosure > .disclosure-body { padding: 4px 14px 14px; }

/* Modals */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 100; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.show { display: flex; }
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 280px;
  width: 100%;
  max-width: min(440px, 95vw);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin: 0 0 16px; font-size: 1.1rem; font-weight: 600; color: var(--text); }
.modal .form-group + .form-group { margin-top: 12px; }
.modal .actions { margin-top: 20px; justify-content: flex-end; }
.modal .actions .btn-primary, .modal .actions .btn-danger { order: 2; }
.detail-box {
  padding: 10px 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 2.6em;
}
.detail-box.mono { font-family: var(--font-mono); font-size: 0.82rem; }

/* Toast-style page message. */
.msg { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.9rem; border: 1px solid transparent; }
.msg.error { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }
.msg.success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.app-main > .container > .msg#msg {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  max-width: min(420px, calc(100vw - 32px));
  margin: 0;
  box-shadow: var(--shadow-lg);
}

/* ------------------------------------------------------------- 5. Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  min-height: var(--control-height);
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--card); color: var(--text-secondary); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-muted); border-color: #94a3b8; }
.btn-danger { background: var(--card); color: var(--error); border-color: var(--error-border); }
.btn-danger:hover:not(:disabled) { background: var(--error-bg); border-color: #f87171; }
.modal .btn-danger, .btn-danger.btn-solid { background: #dc2626; color: #fff; border-color: #dc2626; }
.modal .btn-danger:hover:not(:disabled), .btn-danger.btn-solid:hover:not(:disabled) { background: #b91c1c; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; min-height: auto; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }
.btn-ghost { background: none; color: var(--nav-text); border: none; justify-content: flex-start; width: 100%; font-weight: 500; }
.btn-ghost:hover { background: var(--nav-hover); color: #fff; }
.btn-compact, .btn-sm { padding: 0 10px; font-size: 0.82rem; min-height: 32px; }
td .btn { padding: 0 10px; font-size: 0.82rem; min-height: 32px; }
td .btn + .btn { margin-left: 6px; }
td .btn-link { padding: 0; min-height: auto; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; align-items: center; }

/* Fields */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 16px 20px; margin-bottom: 16px; }
.form-grid:last-child { margin-bottom: 0; }
.form-grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.span-all { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-group label, .field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }
.form-group label .optional, .field-label .optional { font-weight: 400; color: var(--text-muted); }
.required-mark { color: var(--error); font-weight: 700; margin-left: 2px; }
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.93rem;
  min-height: var(--control-height);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-group select { cursor: pointer; }
.form-group input:hover:not(:focus):not([readonly]), .form-group select:hover:not(:focus) { border-color: #94a3b8; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.form-group input[readonly], .form-group textarea[readonly] { background: var(--surface-muted); color: var(--text-secondary); }
.form-group input:disabled, .form-group select:disabled { background: var(--surface-muted); color: var(--text-muted); cursor: not-allowed; }
.form-group textarea { min-height: 84px; resize: vertical; }
.form-hint { margin: 0; font-size: 0.8rem; color: var(--text-muted); line-height: 1.45; }
.input-with-action { display: flex; gap: 8px; align-items: stretch; }
.input-with-action input { flex: 1 1 auto; min-width: 0; }
.input-with-action input.mono, .form-group textarea.mono { font-family: var(--font-mono); font-size: 0.82rem; }

/* Checkbox / radio rows: a box with its label and an optional hint. */
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}
.check input { width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent); flex: 0 0 auto; cursor: pointer; }
.check small { display: block; font-size: 0.8rem; font-weight: 400; color: var(--text-muted); margin-top: 1px; }
.check-row { display: flex; gap: 20px; flex-wrap: wrap; }
.form-group .check { font-weight: 500; color: var(--text); }

/* Switch: a styled checkbox for on/off settings. Keeps the native input for JS. */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch input {
  appearance: none;
  -webkit-appearance: none;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  flex: 0 0 auto;
  margin: 1px 0 0;
  cursor: pointer;
  transition: background-color 0.15s;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-text { font-size: 0.9rem; font-weight: 600; color: var(--text); line-height: 1.35; }
.switch-text small { display: block; font-weight: 400; font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* Filter bar above lists. */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters .form-group { min-width: 160px; flex: 1 1 160px; }
.filter-bar { padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface-muted); border-radius: var(--radius) var(--radius) 0 0; }
.filter-summary { padding: 10px 20px; font-size: 0.82rem; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.report-filters { margin-bottom: 0; }
.report-filters .form-group { flex: 1 1 180px; min-width: 170px; }
.filter-actions { display: flex; flex-direction: row; gap: 8px; align-items: flex-end; justify-content: flex-end; flex: 0 0 auto !important; min-width: fit-content !important; }
.filter-actions .btn { min-width: 88px; }

/* Segmented control */
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; max-width: 100%; background: var(--card); }
.segmented button { border: none; background: none; color: var(--text-secondary); padding: 0 14px; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; min-height: 34px; }
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button:hover { background: var(--surface-muted); }
.segmented button.active { background: var(--accent); color: #fff; }

/* Legacy toggle buttons (superadmin enable/disable). */
.toggle { cursor: pointer; padding: 0 12px; border-radius: 999px; font: inherit; font-size: 0.8rem; font-weight: 600; border: 1px solid transparent; min-height: 28px; }
.toggle.on { background: #dcfce7; color: #166534; border-color: var(--success-border); }
.toggle.off { background: #f1f5f9; color: var(--text-muted); border-color: var(--border-strong); }

/* --------------------------------------------------------- 6. Data display */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 500px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  background: var(--surface-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}
tbody tr:hover { background: #fafbfd; }
td:last-child:not(.num) { white-space: nowrap; }
th.num, td.num { text-align: right; white-space: nowrap; }
.compact-table { font-size: 0.82rem; }
.compact-table th, .compact-table td { padding: 8px 10px; }
.cell-title { display: block; font-weight: 600; }
.cell-sub { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
tr.row-warn { background: #fffbeb; }
tr.row-warn:hover { background: #fef3c7; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  background: #f1f5f9;
  color: var(--text-secondary);
}
.badge-available, .badge-success { background: #dcfce7; color: #166534; }
.badge-allocated { background: #dbeafe; color: #1d4ed8; }
.badge-inactive, .badge-created { background: #f1f5f9; color: var(--text-muted); }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-failed { background: #fee2e2; color: var(--error); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 16px 18px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.stat-card .label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1.2; letter-spacing: -0.01em; }
.stat-card .value.accent { color: var(--accent); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }
.stat-card .sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.pagination:empty { display: none; }
.pagination button { padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--card); color: var(--text-secondary); cursor: pointer; font: inherit; font-size: 0.85rem; min-height: 34px; }
.pagination button:hover:not(:disabled) { background: var(--surface-muted); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination span { color: var(--text-muted); font-size: 0.85rem; }

.empty { color: var(--text-muted); text-align: center; padding: 40px 24px; font-size: 0.9rem; }
td.empty { background: var(--card); }
.test-connection-result { margin-top: 10px; font-size: 0.86rem; padding: 10px 12px; border-radius: var(--radius-sm); display: none; }
.test-connection-result.success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); display: block; }
.test-connection-result.error { background: var(--error-bg); color: var(--error); border: 1px solid var(--error-border); display: block; }

/* ------------------------------------------------------- 7. Feature styles */

/* Router brand picker */
.brand-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.brand-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s, box-shadow 0.12s;
}
.brand-option:hover { border-color: #94a3b8; }
.brand-option.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.brand-option input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.brand-option strong { display: block; color: var(--text); font-size: 0.93rem; }
.brand-option span { display: block; font-size: 0.8rem; color: var(--text-muted); line-height: 1.45; margin-top: 2px; }
.brand-option:focus-within { outline: 2px solid var(--accent-ring); outline-offset: 1px; }

.router-setup-section { border-top: 1px solid var(--border); margin-top: 24px; padding-top: 24px; }
.router-wizard-panel > :first-child { margin-top: 0; }
.connection-check { margin-top: 20px; padding: 16px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius); }

/* Reports */
.report-hint { margin: 0 0 12px; font-size: 0.85rem; color: var(--text-muted); }
.report-section-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 4px 0 12px; font-weight: 600; }
.report-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; min-width: 0; box-shadow: var(--shadow); }
.report-card h3 { margin: 0 0 4px; font-size: 1rem; font-weight: 600; color: var(--text); }
.report-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.report-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); column-gap: 20px; }
.report-range { margin-bottom: 12px; }
.report-summary-line { font-size: 0.9rem; margin: 4px 0 12px; }
.report-ok { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); font-size: 0.9rem; }
.report-empty-note { font-size: 0.85rem; color: var(--text-muted); text-align: center; padding: 24px 0; margin: 0; }
.chart-box { position: relative; height: 240px; }
.chart-box-lg { height: 300px; }
.chart-label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.trend { font-weight: 600; }
.trend.up { color: var(--success); }
.trend.down { color: var(--error); }
.trend.flat { color: var(--text-muted); }
.share-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; min-width: 64px; }
.share-bar span { display: block; height: 100%; background: var(--accent); }

/* Banners at the top of the page */
.stock-banner, .impersonation-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 20px;
  padding: 12px 16px;
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  background: var(--warning-bg);
  color: #78350f;
}
.stock-banner-icon { width: 28px; height: 28px; border-radius: 50%; background: #f59e0b; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.stock-banner-text { flex: 1 1 240px; font-size: 0.9rem; }
.stock-banner-text strong { display: block; }
.stock-banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tenant 360 (superadmin) */
.entity-header { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
.entity-header h3 { margin: 0; font-size: 1.2rem; }
.status-chips { display: flex; flex-wrap: wrap; gap: 10px; }

@media (max-width: 768px) {
  .report-filters .form-group { flex-basis: 100%; min-width: 0; }
  .report-filters .filter-actions { width: 100%; justify-content: stretch; }
  .report-filters .filter-actions .btn { flex: 1 1 auto; }
  .page-header h2 { font-size: 1.2rem; }
  .card-header, .card-body, .form-card-header, .form-card-body, .form-card-footer, .filter-bar { padding-left: 16px; padding-right: 16px; }
  .app-main > .container > .msg#msg { left: 16px; right: 16px; bottom: 16px; }
}

/* Auth pages: sign in, sign up, password reset */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, #e3ecfb 0%, var(--bg) 60%);
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 20px; }
.auth-brand .brand-name { color: var(--text); font-size: 1.05rem; }
.auth-brand .brand-sub { color: var(--text-muted); }
.auth-box { background: var(--card); padding: 28px; border-radius: var(--radius-lg); box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 10px 30px rgba(15, 23, 42, 0.06); border: 1px solid var(--border); }
.auth-box h1 { margin: 0 0 6px; font-size: 1.35rem; font-weight: 700; color: var(--text); }
.auth-box .lead { margin: 0 0 20px; font-size: 0.9rem; color: var(--text-muted); }
.auth-box .form-group { margin-bottom: 16px; }
.auth-box .form-group input:not([type="checkbox"]) { min-height: 44px; }
.auth-box .label-row { display: flex; justify-content: space-between; align-items: baseline; }
.auth-box .label-row a { font-size: 0.82rem; font-weight: 600; color: var(--accent); text-decoration: none; }
.auth-box .label-row a:hover { text-decoration: underline; }
.auth-box .btn { width: 100%; min-height: 44px; font-size: 0.95rem; margin-top: 4px; }
.auth-box .msg { margin-bottom: 16px; line-height: 1.5; }
.auth-link { margin: 18px 0 0; text-align: center; font-size: 0.88rem; color: var(--text-muted); }
.auth-link a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-link a:hover { text-decoration: underline; }

/* Hidden-by-default token codes */
.secret { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.secret-value { letter-spacing: 0.06em; color: var(--text-secondary); }
.secret.revealed .secret-value { color: var(--text); letter-spacing: 0.02em; font-weight: 600; }
.secret-toggle { border: none; background: none; padding: 0; font: inherit; font-size: 0.78rem; font-weight: 600; color: var(--accent); cursor: pointer; }
.secret-toggle:hover { text-decoration: underline; }

/* Key insights: plain-language findings with a next step */
.insight-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 12px; }
.insight { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.insight-icon { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; font-size: 0.85rem; font-weight: 700; }
.insight-body { flex: 1 1 auto; min-width: 0; }
.insight-title { display: block; font-weight: 600; font-size: 0.9rem; color: var(--text); }
.insight-text { margin: 2px 0 0; font-size: 0.84rem; color: var(--text-muted); line-height: 1.45; }
.insight-action { margin-top: 8px; }
.insight-good .insight-icon { background: #dcfce7; color: #166534; }
.insight-bad .insight-icon { background: #fee2e2; color: var(--error); }
.insight-bad { border-color: var(--error-border); }
.insight-warn .insight-icon { background: #fef3c7; color: #92400e; }
.insight-info .insight-icon { background: var(--accent-soft); color: var(--accent); }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--border-strong); background: var(--card); color: var(--text-secondary); border-radius: 999px; padding: 0 12px; min-height: 30px; font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.chip:hover { background: var(--surface-muted); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Ranked list (earnings by access point) */
.rank-table td, .rank-table th { padding: 8px 10px; }
.rank-table { min-width: 0; margin-top: 12px; }

/* Step funnel (capture insights) */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-step-head { display: flex; justify-content: space-between; gap: 8px; font-size: 0.86rem; margin-bottom: 4px; }
.funnel-step-head strong { color: var(--text); }
.funnel-bar { height: 26px; background: var(--surface-muted); border-radius: 6px; overflow: hidden; }
.funnel-bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; min-width: 2px; }
.funnel-step:nth-child(2) .funnel-bar span { background: #6366f1; }
.funnel-step:nth-child(3) .funnel-bar span { background: #16a34a; }
.funnel-drop { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }
.funnel-drop.bad { color: var(--error); }

/* Keep filter fields a readable width on wide screens. */
@media (min-width: 769px) {
  .report-filters .form-group:not(.filter-actions) { max-width: 320px; }
}

/* ------------------------------------------------- 8. Shared list components
 * Used through AdminShell (admin-shell.js): status badges, details dialogs,
 * pagination, clickable rows, the setup checklist and status breakdowns.
 */

/* Badge tones (AdminShell.statusBadge / AdminShell.badge) */
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: var(--error); }
.badge-neutral { background: #f1f5f9; color: var(--text-muted); }

/* Key / value rows in details dialogs (AdminShell.detailList) */
.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: 0.88rem; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.modal-section-title { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 20px 0 10px; }
.modal-section-title:first-of-type { margin-top: 4px; }
.modal-text { margin: -6px 0 4px; color: var(--text-secondary); font-size: 0.9rem; }
.modal-wide { max-width: min(560px, 95vw); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal-head h3 { margin: 0; }
pre.code-block {
  margin: 0;
  max-height: 55vh;
  overflow: auto;
  padding: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Rows that open a details dialog */
tr.row-link { cursor: pointer; }
tr.row-link:hover { background: #f5f8fe; }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
td .row-actions .btn + .btn { margin-left: 0; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Result count and "Clear filters" under a filter bar */
.filter-summary { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.filter-summary .btn-link { font-size: 0.82rem; }

.pagination .pager-info { margin-right: auto; }

/* Setup checklist on the dashboard */
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; min-width: 120px; }
.progress span { display: block; height: 100%; background: var(--success); transition: width 0.3s; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.checklist li:first-child { border-top: none; padding-top: 0; }
.checklist li:last-child { padding-bottom: 0; }
.check-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.checklist li.done .check-icon { background: var(--success); border-color: var(--success); color: #fff; }
.checklist li.next .check-icon { border-color: var(--accent); color: var(--accent); }
.checklist-body { flex: 1 1 auto; min-width: 0; }
.checklist-title { display: block; font-weight: 600; font-size: 0.9rem; color: var(--text); }
.checklist li.done .checklist-title { color: var(--text-muted); font-weight: 500; }
.checklist-text { display: block; font-size: 0.82rem; color: var(--text-muted); margin-top: 1px; }

/* Status breakdown: one stacked bar and a legend */
.stack-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--border); }
.stack-bar span { display: block; height: 100%; }
.legend { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 0.86rem; color: var(--text-secondary); }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend strong { color: var(--text); }
.tone-success { background: #16a34a; }
.tone-info { background: #3b82f6; }
.tone-warning { background: #f59e0b; }
.tone-danger { background: #dc2626; }
.tone-neutral { background: #94a3b8; }

/* Search box in a card header */
.card-search { min-height: 34px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: inherit; font-size: 0.86rem; width: min(240px, 100%); }
.card-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
