@import url("./brand-logo.css");
@import url("./shared/ui/premium-skeleton.css");

/*
 * Braille Link — Design System
 * Canonical design tokens. Loaded by every page.
 * Light theme is the default. Dark override via [data-theme="dark"].
 *
 * Color palette:
 *   Brand:    Deep blue-violet #3B5BDB (Indigo 600)
 *   Neutral:  Slate scale
 *   Success:  Green 600
 *   Warning:  Amber 600
 *   Danger:   Red 600
 *   Info:     Blue 600
 */

@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600&family=Sora:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200");

/* ─── FOUC prevention ───────────────────────────────────────────────────────
   Previously declared as an inline <style> in every HTML file.
   Centralised here to allow a strict style-src CSP with no unsafe-inline.   */
html,
body {
  background: #f8fafc;
}

/* ─── Light (default) ──────────────────────────────────────────────────────── */
:root {
  color-scheme: light;

  /* Fonts */
  --font-body: "Space Grotesk", "Segoe UI", sans-serif;
  --font-ui: "Sora", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", monospace;

  /* Brand */
  --accent: #3b5bdb;
  --accent-dark: #2f4ac7;
  --accent-hover: #3350c4;
  --accent-soft: rgba(59, 91, 219, 0.08);
  --accent-text: #ffffff;
  --accent-2: #2563eb;
  --accent-2-soft: rgba(37, 99, 235, 0.08);

  /* Backgrounds */
  --bg: #f8fafc;
  --bg-2: #f1f5f9;
  --panel: #ffffff;
  --panel-raised: #ffffff;
  --stat-bg: #f8fafc;
  --input-bg: #ffffff;
  --topbar-bg: rgba(255, 255, 255, 0.97);

  /* Borders */
  --panel-border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Text */
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --muted-light: #94a3b8;

  /* Status */
  --ok: #16a34a;
  --ok-bg: rgba(22, 163, 74, 0.08);
  --ok-border: rgba(22, 163, 74, 0.28);
  --ok-text: #15803d;

  --warn: #d97706;
  --warn-bg: rgba(217, 119, 6, 0.08);
  --warn-border: rgba(217, 119, 6, 0.28);
  --warn-text: #b45309;

  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.07);
  --danger-border: rgba(220, 38, 38, 0.25);
  --danger-text: #b91c1c;

  --info: #2563eb;
  --info-bg: rgba(37, 99, 235, 0.07);
  --info-border: rgba(37, 99, 235, 0.25);
  --info-text: #1d4ed8;

  /* Errors (form validation) */
  --error-bg: rgba(220, 38, 38, 0.06);
  --error-border: rgba(220, 38, 38, 0.3);
  --error-text: #b91c1c;
  --error-header: #991b1b;

  /* Buttons */
  --btn-primary-bg: #3b5bdb;
  --btn-primary-bg-hover: #2f4ac7;
  --btn-primary-text: #ffffff;
  --btn-primary-shadow: rgba(59, 91, 219, 0.28);

  --btn-secondary-bg: #f1f5f9;
  --btn-secondary-bg-hover: #e2e8f0;
  --btn-secondary-text: #334155;
  --btn-secondary-border: #e2e8f0;

  --btn-danger-bg: rgba(220, 38, 38, 0.07);
  --btn-danger-bg-hover: rgba(220, 38, 38, 0.12);
  --btn-danger-text: #b91c1c;
  --btn-danger-border: rgba(220, 38, 38, 0.22);

  --btn-ghost-bg: transparent;
  --btn-ghost-bg-hover: #f1f5f9;
  --btn-ghost-text: #64748b;
  --btn-ghost-border: #e2e8f0;

  --control-bg: #f1f5f9;
  --control-bg-soft: rgba(226, 232, 240, 0.7);

  /* Sidebar */
  --sidebar-bg: #ffffff;
  --sidebar-border: #e2e8f0;
  --sidebar-width: 220px;
  --sidebar-link-color: #475569;
  --sidebar-link-hover-bg: #f1f5f9;
  --sidebar-link-active-bg: rgba(59, 91, 219, 0.08);
  --sidebar-link-active-color: #3b5bdb;
  --sidebar-link-active-border: #3b5bdb;

  /* Topbar */
  --topbar-height: 56px;
  --topbar-border: #e2e8f0;
  --topbar-chip-bg: rgba(241, 245, 249, 0.96);
  --topbar-chip-border: #e2e8f0;

  /* Cards */
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --card-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --card-shadow-hover: 0 4px 12px rgba(15, 23, 42, 0.1), 0 8px 24px rgba(15, 23, 42, 0.06);

  /* Shadows */
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);
  --shadow-xl: 0 24px 56px rgba(15, 23, 42, 0.14);
  --elevation-1: 0 2px 8px rgba(15, 23, 42, 0.07);
  --elevation-2: 0 6px 18px rgba(15, 23, 42, 0.1);
  --shell-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);

  /* Overlays / modals */
  --shell-overlay: rgba(15, 23, 42, 0.32);
  --shell-surface: #ffffff;
  --shell-surface-soft: rgba(241, 245, 249, 0.97);
  --splash-overlay: rgba(148, 163, 184, 0.2);
  --splash-card: linear-gradient(180deg, #ffffff, #f8fafc);

  /* Focus */
  --focus-ring: rgba(59, 91, 219, 0.55);

  /* Border radius */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --control-radius: 8px;

  /* Spacing */
  --shell-topbar-height: 56px;
  --shell-section-nav-height: 0px;
  --drawer-width: 360px;
  --topbar-control-height: 40px;
  --control-height: 40px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-9: 36px;
  --space-10: 40px;

  /* Layout — shared page container system */
  --page-max-width: 1200px;
  --layout-max-width: 1400px;
  --layout-content-max-width: 1200px;
  --page-gutter: 20px;
  --page-gutter-sm: 12px;

  /* Help / utility panel */
  --help-overlay: rgba(15, 23, 42, 0.28);
  --help-shell-bg: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  --help-shell-border: #e2e8f0;
  --help-card-bg: linear-gradient(180deg, #ffffff, #f8fafc);
  --help-card-border: #e2e8f0;
  --help-chip-bg: rgba(59, 91, 219, 0.08);
  --help-chip-text: #3b5bdb;
  --help-support-bg: linear-gradient(135deg, rgba(59, 91, 219, 0.06), rgba(22, 163, 74, 0.06));
  --help-phone-bg: rgba(241, 245, 249, 0.9);
  --help-phone-border: #e2e8f0;
  --help-shadow: 0 28px 55px rgba(15, 23, 42, 0.18);

  /* Mobile menu */
  --mobile-menu-surface: linear-gradient(180deg, #ffffff, #f8fafc);
  --mobile-menu-card: rgba(255, 255, 255, 0.98);
  --mobile-menu-card-border: #e2e8f0;

  /* Shell topbar variants */
  --topbar-select-bg: rgba(255, 255, 255, 0.98);
  --topbar-select-border: #e2e8f0;
  --topbar-select-icon: #64748b;
  --topbar-help-bg: linear-gradient(135deg, rgba(59, 91, 219, 0.08), rgba(22, 163, 74, 0.06));
  --topbar-help-border: rgba(59, 91, 219, 0.22);

  /* Misc */
  --bg-gradient: none;
  --bg-texture: none;
  --log-bg: #f8fafc;
  --preview-bg: #f8fafc;
  --panel-strong: rgba(255, 255, 255, 0.97);
  --btn-secondary: #f1f5f9;
}

/* ─── Dark override ────────────────────────────────────────────────────────── */
:root[data-theme="dark"] {
  color-scheme: dark;

  --accent: #ffffff;
  --accent-dark: #e5e5e5;
  --accent-hover: #f5f5f5;
  --accent-soft: rgba(255, 255, 255, 0.12);
  --accent-text: #000000;
  --accent-2: #ffffff;
  --accent-2-soft: rgba(255, 255, 255, 0.1);

  --bg: #000000;
  --bg-2: #0a0a0a;
  --panel: #050505;
  --panel-raised: #0e0e0e;
  --stat-bg: #0a0a0a;
  --input-bg: #000000;
  --topbar-bg: rgba(0, 0, 0, 0.98);

  --panel-border: rgba(255, 255, 255, 0.18);
  --border-strong: rgba(255, 255, 255, 0.34);

  --text: #ffffff;
  --text-2: #e8e8e8;
  --muted: #bdbdbd;
  --muted-light: #8c8c8c;

  --ok: #ffffff;
  --ok-bg: rgba(255, 255, 255, 0.08);
  --ok-border: rgba(255, 255, 255, 0.28);
  --ok-text: #ffffff;

  --warn: #ededed;
  --warn-bg: rgba(255, 255, 255, 0.08);
  --warn-border: rgba(255, 255, 255, 0.26);
  --warn-text: #ffffff;

  --danger: #f5f5f5;
  --danger-bg: rgba(255, 255, 255, 0.08);
  --danger-border: rgba(255, 255, 255, 0.3);
  --danger-text: #ffffff;

  --info: #ffffff;
  --info-bg: rgba(255, 255, 255, 0.08);
  --info-border: rgba(255, 255, 255, 0.26);
  --info-text: #ffffff;

  --error-bg: rgba(255, 255, 255, 0.08);
  --error-border: rgba(255, 255, 255, 0.36);
  --error-text: #ffffff;
  --error-header: #ffffff;

  --btn-primary-bg: #ffffff;
  --btn-primary-bg-hover: #ededed;
  --btn-primary-text: #000000;
  --btn-primary-shadow: none;

  --btn-secondary-bg: #111111;
  --btn-secondary-bg-hover: #1a1a1a;
  --btn-secondary-text: #ffffff;
  --btn-secondary-border: rgba(255, 255, 255, 0.24);

  --btn-danger-bg: #111111;
  --btn-danger-bg-hover: #1a1a1a;
  --btn-danger-text: #ffffff;
  --btn-danger-border: rgba(255, 255, 255, 0.28);

  --btn-ghost-bg: transparent;
  --btn-ghost-bg-hover: rgba(255, 255, 255, 0.1);
  --btn-ghost-text: #dadada;
  --btn-ghost-border: rgba(255, 255, 255, 0.22);

  --control-bg: rgba(255, 255, 255, 0.12);
  --control-bg-soft: rgba(255, 255, 255, 0.08);

  --sidebar-bg: #050505;
  --sidebar-border: rgba(255, 255, 255, 0.16);
  --sidebar-link-color: #d0d0d0;
  --sidebar-link-hover-bg: rgba(255, 255, 255, 0.08);
  --sidebar-link-active-bg: rgba(255, 255, 255, 0.12);
  --sidebar-link-active-color: #ffffff;
  --sidebar-link-active-border: #ffffff;

  --topbar-border: rgba(255, 255, 255, 0.18);
  --topbar-chip-bg: #0a0a0a;
  --topbar-chip-border: rgba(255, 255, 255, 0.28);

  --card-bg: #050505;
  --card-border: rgba(255, 255, 255, 0.18);
  --card-shadow: none;
  --card-shadow-hover: none;

  --shadow: none;
  --shadow-md: none;
  --shadow-lg: none;
  --shadow-xl: none;
  --elevation-1: none;
  --elevation-2: none;
  --shell-shadow: none;

  --shell-overlay: rgba(0, 0, 0, 0.78);
  --shell-surface: #050505;
  --shell-surface-soft: #0e0e0e;
  --splash-overlay: rgba(0, 0, 0, 0.86);
  --splash-card: #050505;

  --focus-ring: rgba(255, 255, 255, 0.76);

  --bg-gradient: #000000;
  --bg-texture: none;
  --log-bg: #0a0a0a;
  --preview-bg: #050505;
  --panel-strong: #0e0e0e;
  --btn-secondary: #111111;

  --help-overlay: rgba(0, 0, 0, 0.72);
  --help-shell-bg: #050505;
  --help-shell-border: rgba(255, 255, 255, 0.2);
  --help-card-bg: #0a0a0a;
  --help-card-border: rgba(255, 255, 255, 0.16);
  --help-chip-bg: rgba(255, 255, 255, 0.12);
  --help-chip-text: #ffffff;
  --help-support-bg: #0a0a0a;
  --help-phone-bg: rgba(255, 255, 255, 0.06);
  --help-phone-border: rgba(255, 255, 255, 0.22);
  --help-shadow: none;

  --mobile-menu-surface: #000000;
  --mobile-menu-card: #0a0a0a;
  --mobile-menu-card-border: rgba(255, 255, 255, 0.28);

  --topbar-select-bg: #000000;
  --topbar-select-border: rgba(255, 255, 255, 0.36);
  --topbar-select-icon: #d0d0d0;
  --topbar-help-bg: #111111;
  --topbar-help-border: rgba(255, 255, 255, 0.32);
}

/* ─── Global reset ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  /* Clip horizontal overflow at the root so no zoom level creates a scrollbar */
  overflow-x: clip;
}

body {
  max-width: 100%;
  overflow-x: clip;
}

img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
}

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

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 320;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  scrollbar-width: none;
  transform: translateX(-100%);
  box-shadow: var(--shadow-xl);
}

.sidebar.sidebar-open {
  transform: translateX(0);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 310;
  background: var(--shell-overlay);
  backdrop-filter: blur(2px);
}

.sidebar-backdrop.visible {
  display: block;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

/* Brand area */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  order: 0;
  padding: 16px 14px 14px;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}

.sidebar-brand-name {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-brand > div:not(.logo) {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

/* Legacy spinner card is replaced by in-content skeletons */
.startup-splash .startup-loader-card,
.startup-splash .startup-splash-card,
.startup-splash .startup-splash-loader {
  display: none !important;
}

/* While loading, the splash is a transparent layer: the real shell
   (sidebar, topbar, toolbars) stays visible, pointer clicks on
   not-yet-wired controls are held back, and data regions show
   skeletons. The id selector outranks the per-page overlay rules. */
#startupSplash.startup-splash {
  background: transparent !important;
  backdrop-filter: none !important;
  cursor: progress;
}

/* Status text is for assistive technology only; the skeletons are the
   visual loading cue. */
.page-loading-status > p {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sidebar-brand-sub {
  margin: 2px 0 0;
  font-family: var(--font-ui);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* Navigation */
.sidebar-nav {
  order: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 2px;
}

.sidebar-section-label {
  padding: 10px 8px 4px;
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-light);
  user-select: none;
}

.sidebar-section-label:first-child {
  padding-top: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--sidebar-link-color);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link:hover {
  background: var(--sidebar-link-hover-bg);
  color: var(--text);
}

.sidebar-link.active {
  background: var(--sidebar-link-active-bg);
  color: var(--sidebar-link-active-color);
  font-weight: 600;
}

.sidebar-link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.sidebar-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Footer */
.sidebar-foot {
  order: 1;
  flex-shrink: 0;
  padding: 10px 14px 14px;
  border-top: 0;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-foot-info {
  min-width: 0;
  flex: 1;
}

.sidebar-foot-name {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot-role {
  margin: 2px 0 0;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-ui);
}

/* ─── App body (right of sidebar) ──────────────────────────────────────────── */
.app-body {
  flex: 1;
  min-width: 0; /* Critical: allows flex child to shrink below content size */
  margin-left: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden; /* Belt-and-suspenders: nothing inside .app-body spills right */
  width: 100%; /* Fill exactly the space left by the sidebar */
}

/* Admin/sidebar pages: topbar + content share the same full-width column.
   Scoped to pages that use .page-topbar — workspace pages are unaffected. */
.app-body:has(.page-topbar) {
  width: 100%;
}

.app-body:has(.page-topbar) > .page-topbar,
.app-body:has(.page-topbar) > .layout,
.app-body:has(.page-topbar) > main.layout,
.app-body:has(.page-topbar) > main.app,
.app-body:has(.page-topbar) > main.app-shell {
  width: min(100%, var(--layout-max-width));
  margin-inline: auto;
}

.layout-container {
  width: min(100%, var(--layout-max-width));
  margin-inline: auto;
  padding-inline: var(--page-gutter);
}

.layout-content {
  width: min(100%, var(--layout-content-max-width));
  margin-inline: auto;
}

/* ─── Page topbar (thin strip inside app-body) ─────────────────────────────── */
.page-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--page-gutter);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}

.page-topbar-title {
  flex: 1;
  min-width: 0;
}

.page-topbar-title h1 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-topbar-title p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Topbar profile button — hidden on desktop (use sidebar), visible on mobile */
.page-topbar-profile.profile-trigger-btn {
  display: none;
}

@media (max-width: 820px) {
  .page-topbar-profile.profile-trigger-btn {
    display: none;
    align-items: center;
    justify-content: center;
  }
}

/* Sidebar toggle button */
.sidebar-toggle {
  display: inline-flex;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--control-bg);
  color: var(--muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ─── Base body styles ─────────────────────────────────────────────────────── */
body {
  margin: 0;
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="dark"] body {
  background-image: var(--bg-gradient), var(--bg-texture);
}

/* ─── Typography ───────────────────────────────────────────────────────────── */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-ui);
  letter-spacing: -0.01em;
}

/* ─── Page content wrapper ─────────────────────────────────────────────────── */
/* max-width is now handled by .app-body:has(.page-topbar) — layout just pads */
.layout {
  padding: var(--page-gutter);
  display: grid;
  gap: 18px;
  /* Never exceed container width; prevents child overflow at high zoom */
  max-width: 100%;
  box-sizing: border-box;
  width: 100%;
  margin-inline: auto;
}

.layout > *,
.card > *,
.row > *,
.action-row > * {
  min-width: 0;
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  padding: 20px;
  box-shadow: var(--card-shadow);
}

.card h2 {
  margin: 0 0 4px;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.card > .muted:first-of-type {
  margin: 0 0 14px;
  font-size: 13px;
}

.card-section-label {
  margin: 0 0 10px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ─── Button system ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 16px;
  border-radius: var(--control-radius);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color 130ms ease,
    border-color 130ms ease,
    box-shadow 130ms ease,
    transform 100ms ease,
    opacity 130ms ease;
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* Primary */
.btn.primary,
.btn[data-variant="primary"] {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.btn.primary:hover,
.btn[data-variant="primary"]:hover {
  background: var(--btn-primary-bg-hover);
  box-shadow: 0 4px 12px var(--btn-primary-shadow);
  transform: translateY(-1px);
}

.btn.primary:active,
.btn[data-variant="primary"]:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Secondary */
.btn.secondary,
.btn[data-variant="secondary"] {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border-color: var(--btn-secondary-border);
}

.btn.secondary:hover,
.btn[data-variant="secondary"]:hover {
  background: var(--btn-secondary-bg-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.btn.secondary:active,
.btn[data-variant="secondary"]:active {
  transform: translateY(0);
}

/* Danger */
.btn.danger,
.btn[data-variant="danger"] {
  background: var(--btn-danger-bg);
  color: var(--btn-danger-text);
  border-color: var(--btn-danger-border);
}

.btn.danger:hover,
.btn[data-variant="danger"]:hover {
  background: var(--btn-danger-bg-hover);
  transform: translateY(-1px);
}

.btn.danger:active,
.btn[data-variant="danger"]:active {
  transform: translateY(0);
}

/* Ghost */
.btn.ghost,
.btn[data-variant="ghost"] {
  background: var(--btn-ghost-bg);
  color: var(--btn-ghost-text);
  border-color: var(--btn-ghost-border);
}

.btn.ghost:hover,
.btn[data-variant="ghost"]:hover {
  background: var(--btn-ghost-bg-hover);
  color: var(--text);
  transform: translateY(-1px);
}

/* Focus */
.btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Disabled */
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

/* Loading */
.btn.loading,
.btn[aria-busy="true"] {
  cursor: wait;
  pointer-events: none;
}

.btn .btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  flex-shrink: 0;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Icon within button */
.btn .icon,
.btn svg.icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Button sizes */
.btn.btn-sm {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 12px;
  border-radius: var(--radius-xs);
}

.btn.btn-lg {
  min-height: 44px;
  padding: 10px 20px;
  font-size: 14px;
}

/* ─── Form elements ────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.field > span,
.field > label {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
}

.field .field-hint {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  margin-top: -2px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--control-height);
  padding: 8px 12px;
  border: 1px solid var(--panel-border);
  border-radius: var(--control-radius);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.4;
  appearance: none;
  -webkit-appearance: none;
  transition:
    border-color 130ms ease,
    box-shadow 130ms ease;
}

.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: var(--border-strong);
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted-light);
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled {
  background: var(--bg-2);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
}

.field.field-error input,
.field.field-error select,
.field.field-error textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px var(--danger-bg);
}

.field-error-msg {
  font-size: 11px;
  color: var(--danger);
  font-weight: 500;
}

.required-mark {
  color: var(--danger);
  margin-left: 2px;
}

/* ─── Status / feedback ────────────────────────────────────────────────────── */
.status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font-ui);
  min-height: 18px;
}

.status.ok,
.status.success {
  color: var(--ok);
}
.status.error {
  color: var(--danger);
}
.status.warn {
  color: var(--warn);
}

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge.badge-active,
.badge.badge-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
  border: 1px solid var(--ok-border);
}
.badge.badge-warn,
.badge.badge-pending {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}
.badge.badge-danger,
.badge.badge-failed,
.badge.badge-suspended {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}
.badge.badge-info,
.badge.badge-invited {
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid var(--info-border);
}
.badge.badge-neutral,
.badge.badge-expired {
  background: var(--bg-2);
  color: var(--muted);
  border: 1px solid var(--panel-border);
}

/* Billing pills (legacy alias) */
.billing-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--stat-bg);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.billing-pill.ok {
  color: var(--ok-text);
  border-color: var(--ok-border);
  background: var(--ok-bg);
}

.billing-pill.warn {
  color: var(--warn-text);
  border-color: var(--warn-border);
  background: var(--warn-bg);
}

.billing-pill.danger {
  color: var(--danger-text);
  border-color: var(--danger-border);
  background: var(--danger-bg);
}

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table-shell {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  width: 100%;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--text);
}

thead {
  background: var(--bg-2);
  border-bottom: 1px solid var(--panel-border);
}

th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--panel-border);
  line-height: 1.45;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--accent-soft) 60%, transparent);
}

.table-empty-cell {
  text-align: center;
  padding: 32px 14px;
  color: var(--muted);
  font-size: 13px;
}

/* ─── Stats grid ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 12px;
  min-width: 0;
}

.stat {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--stat-bg);
  min-width: 0;
}

.stat-label {
  margin: 0 0 4px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-sub {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* ─── Topbar / shell actions ───────────────────────────────────────────────── */
.topbar-action-cluster {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--topbar-chip-border);
  background: var(--topbar-chip-bg);
}

.topbar-quick-btn {
  min-height: 32px;
  padding: 5px 12px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition:
    background 130ms,
    color 130ms;
  white-space: nowrap;
}

.topbar-quick-btn:hover {
  background: var(--btn-ghost-bg-hover);
  color: var(--text);
}

.topbar-quick-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.topbar-quick-btn .icon {
  width: 14px;
  height: 14px;
}

#helpOpen.topbar-quick-btn {
  background: var(--topbar-help-bg);
  border: 1px solid var(--topbar-help-border);
  color: var(--accent);
}

/* ─── Loading / splash ─────────────────────────────────────────────────────── */
.startup-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: var(--splash-overlay);
}

.startup-loader-card,
.startup-splash-card {
  width: min(260px, calc(100vw - 30px));
  padding: 24px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  display: grid;
  justify-items: center;
  gap: 12px;
}

.startup-loader-card p,
.startup-splash-card p {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  text-align: center;
}

.startup-splash-loader {
  width: 32px;
  height: 32px;
  border: 3px solid var(--panel-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: splash-spin 0.8s linear infinite;
}

@keyframes splash-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Logo (braille dots) ──────────────────────────────────────────────────── */
.logo {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  padding: 6px;
  background: var(--accent);
  flex-shrink: 0;
}

.logo .dot {
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}

.logo .dot.on {
  background: rgba(255, 255, 255, 0.92);
}

:root[data-theme="dark"] .logo {
  background: #000000 !important;
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: none;
}

:root[data-theme="dark"] .logo .dot {
  background: rgba(255, 255, 255, 0.28);
}

:root[data-theme="dark"] .logo .dot.on {
  background: #ffffff;
}

/* ─── Row utility ──────────────────────────────────────────────────────────── */
.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ─── Muted / helper text ──────────────────────────────────────────────────── */
.muted {
  color: var(--muted);
  font-size: 13px;
}

/* ─── Section header ───────────────────────────────────────────────────────── */
.page-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.page-section-header-text h2 {
  margin: 0 0 2px;
  font-size: 18px;
}

.page-section-header-text p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ─── Empty states ─────────────────────────────────────────────────────────── */
.empty-state {
  display: grid;
  place-items: center;
  padding: 48px 24px;
  text-align: center;
  gap: 8px;
}

.empty-state-icon {
  width: 40px;
  height: 40px;
  color: var(--muted-light);
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
}

.empty-state-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
}

.empty-state-body {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  max-width: 340px;
}

/* ─── Toast / alert notifications ─────────────────────────────────────────── */
.toast-zone {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: grid;
  gap: 8px;
  min-width: min(280px, calc(100vw - 40px));
  max-width: 380px;
}

.toast {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  animation: toast-in 200ms ease forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.action-notification-zone {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}

.action-notification-zone::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(1px);
  opacity: 0;
  transition: opacity 180ms ease;
}

.action-notification-zone.is-active::before {
  opacity: 1;
}

.action-notification {
  pointer-events: auto;
  position: relative;
  width: min(430px, calc(100vw - 32px));
  display: grid;
  justify-items: center;
  gap: 13px;
  padding: 28px 24px 22px;
  text-align: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  box-shadow:
    var(--shadow-lg),
    0 18px 55px rgba(15, 23, 42, 0.18);
  animation: action-notification-pop-in 240ms ease-out both;
}

.action-notification-error {
  animation-name: action-notification-error-in;
}

.action-notification-visual {
  width: 90px;
  height: 90px;
  display: grid;
  place-items: center;
}

.action-notification-success .action-notification-visual {
  color: var(--ok);
}

.action-notification-error .action-notification-visual {
  color: var(--danger);
}

.action-notification-pending .action-notification-visual {
  color: var(--warn);
  animation: action-notification-soft-pulse 1.5s ease-in-out infinite;
}

.action-notification-processing .action-notification-visual,
.action-notification-info .action-notification-visual {
  color: var(--info);
}

.action-notification-icon {
  width: 90px;
  height: 90px;
  overflow: visible;
}

.action-notification-ring-track,
.action-notification-ring,
.action-notification-check,
.action-notification-x-line,
.action-notification-info-line {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action-notification-ring-track {
  stroke-width: 5;
  opacity: 0.18;
}

.action-notification-ring {
  stroke-width: 5;
  transform: rotate(-90deg);
  transform-origin: center;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: action-notification-ring-draw 520ms ease-out forwards;
}

.action-notification-check {
  stroke-width: 6;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: action-notification-mark-draw 320ms ease-out 340ms forwards;
}

.action-notification-x-line {
  stroke-width: 6;
  stroke-dasharray: 32;
  stroke-dashoffset: 32;
  animation: action-notification-mark-draw 240ms ease-out 320ms forwards;
}

.action-notification-x-line-b {
  animation-delay: 420ms;
}

.action-notification-pending .action-notification-ring,
.action-notification-processing .action-notification-ring {
  stroke-dasharray: 72 28;
  stroke-dashoffset: 0;
  animation: action-notification-spinner 1.25s linear infinite;
}

.action-notification-dots circle {
  fill: currentColor;
  opacity: 0.35;
  animation: action-notification-dot 1.15s ease-in-out infinite;
}

.action-notification-dots circle:nth-child(2) {
  animation-delay: 130ms;
}

.action-notification-dots circle:nth-child(3) {
  animation-delay: 260ms;
}

.action-notification-info-dot {
  fill: currentColor;
  opacity: 0;
  animation: action-notification-info-in 220ms ease-out 360ms forwards;
}

.action-notification-info-line {
  stroke-width: 6;
  stroke-dasharray: 18;
  stroke-dashoffset: 18;
  animation: action-notification-mark-draw 260ms ease-out 300ms forwards;
}

.action-notification-copy {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.action-notification-title {
  font-size: 18px;
  line-height: 1.25;
}

.action-notification-message {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.action-notification-actions {
  margin-top: 3px;
  display: flex;
  justify-content: center;
}

.action-notification-action,
.action-notification-close {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--shell-surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.action-notification-action {
  padding: 9px 12px;
  font-weight: 700;
}

.action-notification-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--muted);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.action-notification-action:hover,
.action-notification-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.action-notification.is-dismissing {
  animation: action-notification-out 150ms ease-in both;
}

.action-notification.reduce-motion,
.action-notification.reduce-motion .action-notification-visual,
.action-notification.reduce-motion .action-notification-ring,
.action-notification.reduce-motion .action-notification-check,
.action-notification.reduce-motion .action-notification-x-line,
.action-notification.reduce-motion .action-notification-dots circle,
.action-notification.reduce-motion .action-notification-info-dot,
.action-notification.reduce-motion .action-notification-info-line,
body.reduce-motion .action-notification,
body.reduce-motion .action-notification-visual,
body.reduce-motion .action-notification-ring,
body.reduce-motion .action-notification-check,
body.reduce-motion .action-notification-x-line,
body.reduce-motion .action-notification-dots circle,
body.reduce-motion .action-notification-info-dot,
body.reduce-motion .action-notification-info-line {
  animation: none !important;
}

body.reduce-motion .action-notification-ring,
.action-notification.reduce-motion .action-notification-ring,
body.reduce-motion .action-notification-check,
.action-notification.reduce-motion .action-notification-check,
body.reduce-motion .action-notification-x-line,
.action-notification.reduce-motion .action-notification-x-line,
body.reduce-motion .action-notification-info-line,
.action-notification.reduce-motion .action-notification-info-line {
  stroke-dashoffset: 0;
}

body.reduce-motion .action-notification-info-dot,
.action-notification.reduce-motion .action-notification-info-dot,
body.reduce-motion .action-notification-dots circle,
.action-notification.reduce-motion .action-notification-dots circle {
  opacity: 1;
}

@keyframes action-notification-pop-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes action-notification-error-in {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.94);
  }
  45% {
    opacity: 1;
    transform: translateX(-5px) scale(1);
  }
  70% {
    transform: translateX(4px);
  }
  100% {
    transform: translateX(0) scale(1);
  }
}

@keyframes action-notification-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}

@keyframes action-notification-ring-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes action-notification-mark-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes action-notification-spinner {
  to {
    transform: rotate(270deg);
  }
}

@keyframes action-notification-dot {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@keyframes action-notification-info-in {
  to {
    opacity: 1;
  }
}

@keyframes action-notification-soft-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.04);
    opacity: 0.78;
  }
}

@media (max-width: 700px) {
  .action-notification-zone {
    padding: 16px;
  }

  .action-notification {
    width: min(100%, 390px);
    padding: 26px 20px 20px;
  }

  .action-notification-visual,
  .action-notification-icon {
    width: 82px;
    height: 82px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .action-notification,
  .action-notification-visual,
  .action-notification-ring,
  .action-notification-check,
  .action-notification-x-line,
  .action-notification-dots circle,
  .action-notification-info-dot,
  .action-notification-info-line {
    animation: none !important;
  }

  .action-notification-ring,
  .action-notification-check,
  .action-notification-x-line,
  .action-notification-info-line {
    stroke-dashoffset: 0;
  }

  .action-notification-info-dot,
  .action-notification-dots circle {
    opacity: 1;
  }
}

/* ─── Confirmation dialog ──────────────────────────────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: var(--shell-overlay);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
}

.confirm-dialog {
  width: min(420px, calc(100vw - 24px));
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: var(--shell-surface);
  box-shadow: var(--shell-shadow);
  padding: 24px;
  display: grid;
  gap: 14px;
}

.confirm-dialog h2 {
  margin: 0;
  font-size: 16px;
}

.confirm-dialog p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ─── Error panel ──────────────────────────────────────────────────────────── */
.error-panel {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 13px;
}

.error-panel strong {
  color: var(--error-header);
  font-size: 13px;
}

/* ─── Admin toolbar ────────────────────────────────────────────────────────── */
.admin-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-toolbar-search input {
  min-width: min(100%, 220px);
  max-width: 320px;
}

/* ─── Pagination ───────────────────────────────────────────────────────────── */
.paging-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 10px;
}

/* ─── Bulk action row ──────────────────────────────────────────────────────── */
.bulk-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--panel-border);
  background: var(--bg-2);
  font-size: 12px;
  color: var(--muted);
}

/* ─── Responsive sidebar ───────────────────────────────────────────────────── */
/* (Responsive sidebar rules now handled globally above) */

@media (max-width: 640px) {
  .layout {
    padding: 16px 12px;
    gap: 14px;
  }

  .layout-container {
    padding-inline: 12px;
  }

  .card {
    padding: 14px;
  }

  .stats-grid {
    gap: 10px;
  }

  /* Tighter topbar side gutters on large phones / small tablets */
  .page-topbar {
    padding: 0 12px;
  }
}

/* ── Very small phones (≤ 430 px) ─────────────────────────────────────────── */
@media (max-width: 430px) {
  /* Tight gutters on tiny screens */
  .page-topbar {
    padding: 0 8px;
  }

  /* Keep title readable without overflow */
  .page-topbar-title h1 {
    font-size: 14px;
  }

  /* Promote sidebar toggle to a full 44 px tap target */
  .sidebar-toggle {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  /* Toasts should span the phone width, not overflow it */
  .toast-zone {
    left: 8px;
    right: 8px;
    min-width: 0;
    width: auto;
  }
}

/* ─── Zoom resilience ──────────────────────────────────────────────────────
   Browser zoom shrinks the effective viewport (125 % zoom on a 1400 px screen
   == ~1120 px effective width). These rules ensure the shell never produces
   horizontal scrollbars and critical containers reflow cleanly.            */

/* Ensure the app shell never exceeds actual viewport width at any zoom */
.app-shell {
  max-width: 100%;
  overflow-x: hidden;
}

/* Fixed-position panels use 100vw which includes scrollbar width.
   Capping at 100% of a positioned ancestor avoids 1–2 px overflow. */
.profile-menu,
.utility-panel,
.sidebar {
  max-width: min(100vw, 100%);
}

/* Page topbar: allow actions to wrap on narrow/zoomed viewports instead of
   overflowing. The sidebar toggle + title + actions row wraps gracefully. */
@media (max-width: 680px) {
  .page-topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--topbar-height);
    padding: 8px var(--page-gutter-sm);
    gap: 6px;
  }

  .page-topbar-title h1 {
    font-size: 14px;
  }

  .page-topbar-actions {
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* ─── Utility classes (replaces one-off inline styles) ────────────────────── */
.field-flex {
  flex: 1 1 220px;
}
.section-divider {
  margin: 1rem 0;
  border: none;
  border-top: 1px solid var(--border-color, #e2e8f0);
}
.mt-sm {
  margin-top: 0.5rem;
}

/* ─── Monochrome dark-mode guardrails ────────────────────────────────────── */
:root[data-theme="dark"] html,
:root[data-theme="dark"] body {
  background: #000000 !important;
  color: #ffffff !important;
}

:root[data-theme="dark"] body,
:root[data-theme="dark"] .app-shell,
:root[data-theme="dark"] .layout,
:root[data-theme="dark"] .layout-container,
:root[data-theme="dark"] .main,
:root[data-theme="dark"] main,
:root[data-theme="dark"] .chat,
:root[data-theme="dark"] .page-shell {
  background-color: #000000 !important;
  background-image: none !important;
  color: #ffffff !important;
}

:root[data-theme="dark"] .card,
:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .section,
:root[data-theme="dark"] .modal,
:root[data-theme="dark"] .dialog,
:root[data-theme="dark"] .settings-shell,
:root[data-theme="dark"] .settings-group,
:root[data-theme="dark"] .utility-panel,
:root[data-theme="dark"] .profile-menu,
:root[data-theme="dark"] .assignment-shell,
:root[data-theme="dark"] .assignment-list-panel,
:root[data-theme="dark"] .assignment-detail-panel,
:root[data-theme="dark"] .assignment-card,
:root[data-theme="dark"] .attempt-card,
:root[data-theme="dark"] .reader-panel,
:root[data-theme="dark"] .reader-card {
  background: #050505 !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.18) !important;
  box-shadow: none !important;
}

:root[data-theme="dark"] .page-topbar,
:root[data-theme="dark"] .topbar,
:root[data-theme="dark"] .sidebar {
  background: #000000 !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
  box-shadow: none !important;
}

:root[data-theme="dark"] .sidebar-toggle {
  background: #111111 !important;
  border-color: rgba(255, 255, 255, 0.42) !important;
  color: #ffffff !important;
  box-shadow: none !important;
}

:root[data-theme="dark"] .sidebar-toggle:hover,
:root[data-theme="dark"] .sidebar-toggle:focus-visible {
  background: #1a1a1a !important;
  border-color: #ffffff !important;
  color: #ffffff !important;
}

:root[data-theme="dark"] .sidebar-backdrop {
  background: rgba(0, 0, 0, 0.24) !important;
  backdrop-filter: none !important;
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] [contenteditable="true"] {
  background: #000000 !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.32) !important;
  box-shadow: none !important;
}

:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
  color: #9d9d9d !important;
}

:root[data-theme="dark"] button,
:root[data-theme="dark"] .btn,
:root[data-theme="dark"] .button {
  box-shadow: none !important;
}

:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .primary,
:root[data-theme="dark"] button.primary {
  background: #ffffff !important;
  color: #000000 !important;
  border-color: #ffffff !important;
}

:root[data-theme="dark"] .btn-secondary,
:root[data-theme="dark"] .secondary,
:root[data-theme="dark"] button.secondary,
:root[data-theme="dark"] .status-pill,
:root[data-theme="dark"] .badge,
:root[data-theme="dark"] .chip {
  background: #111111 !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.24) !important;
}

:root[data-theme="dark"] a,
:root[data-theme="dark"] .link,
:root[data-theme="dark"] .muted,
:root[data-theme="dark"] .subtle,
:root[data-theme="dark"] .hint {
  color: #dadada !important;
}

:root[data-theme="dark"] :focus-visible {
  outline-color: #ffffff !important;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.28) !important;
}
