/*
  Outlet Pulse V2 - Design System
  Fluent-primary: subtle layered surfaces, restrained depth, no glass/blur.
  Notion-influence: calm typography, generous but not wasteful whitespace.
  Apple-influence: considered motion, nothing decorative or gratuitous.

  Everything downstream (every template) reads only the custom properties
  and component classes defined here - never raw hex values - so the
  whole app re-themes from one file, and dark mode is a data-theme
  attribute swap, not a per-page reimplementation.
*/

:root {
  /* ---- Type ---- */
  --font-sans: 'Segoe UI Variable', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;

  --fs-xs: 11.5px;
  --fs-sm: 12.5px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 24px;

  --lh-tight: 1.25;
  --lh-base: 1.5;

  /* ---- Spacing scale (4px base grid) ---- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* ---- Radius (deliberately moderate - Fluent, not pill-shaped) ---- */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;

  /* ---- Motion ---- */
  --ease-fluent: cubic-bezier(0.1, 0.9, 0.2, 1);
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;

  /* ---- Brand ---- */
  --accent-h: 221;
  --accent: hsl(var(--accent-h), 83%, 53%);
  --accent-hover: hsl(var(--accent-h), 83%, 47%);
  --accent-active: hsl(var(--accent-h), 83%, 41%);
  --accent-tint: hsl(var(--accent-h), 90%, 96%);
  --accent-tint-strong: hsl(var(--accent-h), 88%, 91%);
  --on-accent: #ffffff;

  /* ---- Semantic roles ---- */
  --success: #0f7b3f;
  --success-tint: #e5f5ec;
  --warning: #9a5b00;
  --warning-tint: #fdf1de;
  --danger: #c22a2a;
  --danger-tint: #fbe9e9;
}

[data-theme="light"] {
  --surface-0: #f5f5f6;   /* app canvas */
  --surface-1: #ffffff;   /* cards, sidebar */
  --surface-2: #fafafb;   /* nested panels */
  --surface-raised: #ffffff;

  --surface-hover: rgba(0, 0, 0, 0.035);
  --surface-active: rgba(0, 0, 0, 0.06);
  --surface-selected: var(--accent-tint);

  --border: rgba(0, 0, 0, 0.09);
  --border-strong: rgba(0, 0, 0, 0.16);

  --text-primary: #1b1b1e;
  --text-secondary: #5c5c63;
  --text-tertiary: #8b8b93;
  --text-on-accent: #ffffff;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 1px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.06);

  --scrim: rgba(20, 20, 22, 0.42);
}

[data-theme="dark"] {
  --surface-0: #1c1c1e;
  --surface-1: #27272a;
  --surface-2: #232326;
  --surface-raised: #2c2c30;

  --surface-hover: rgba(255, 255, 255, 0.045);
  --surface-active: rgba(255, 255, 255, 0.07);
  --surface-selected: hsl(var(--accent-h), 55%, 22%);

  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text-primary: #f2f2f3;
  --text-secondary: #b6b6bc;
  --text-tertiary: #85858c;
  --text-on-accent: #ffffff;

  --accent: hsl(var(--accent-h), 83%, 63%);
  --accent-hover: hsl(var(--accent-h), 83%, 68%);
  --accent-active: hsl(var(--accent-h), 83%, 72%);
  --accent-tint: hsl(var(--accent-h), 45%, 18%);
  --accent-tint-strong: hsl(var(--accent-h), 45%, 24%);

  --success: #3fd077;
  --success-tint: #123420;
  --warning: #e0a53f;
  --warning-tint: #3a2c0f;
  --danger: #ea6767;
  --danger-tint: #3a1717;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.40);

  --scrim: rgba(0, 0, 0, 0.55);
}

/* ==================== RESET / BASE ==================== */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { color-scheme: light dark; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text-primary);
  background: var(--surface-0);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur-base) var(--ease-standard);
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 { font-weight: 600; line-height: var(--lh-tight); letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }

::selection { background: var(--accent-tint-strong); }

/* Focus rings: visible, on-brand, keyboard-only (Fluent reveal focus) */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

/* ==================== LAYOUT SHELL ==================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--sp-4) var(--sp-3);
  position: sticky;
  top: 0;
  height: 100vh;
  transition: transform var(--dur-base) var(--ease-fluent);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-2) var(--sp-5);
  font-weight: 600;
  font-size: var(--fs-md);
  color: var(--text-primary);
}
.sidebar-brand-mark {
  width: 24px; height: 24px;
  object-fit: contain;
  flex-shrink: 0;
}

.nav-section-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--sp-4) var(--sp-2) var(--sp-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px var(--sp-2);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--fs-base);
  font-weight: 500;
  position: relative;
  transition: background-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--surface-selected);
  color: var(--accent);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 16px;
  background: var(--accent);
  border-radius: var(--radius-full);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; stroke-width: 1.75; }

.sidebar-footer { margin-top: auto; padding-top: var(--sp-4); }

/* ---- Main column ---- */

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

.topbar {
  min-height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-6);
  padding-top: max(var(--sp-2), env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--surface-0);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-titles { min-width: 0; }
.topbar-title { font-size: var(--fs-lg); font-weight: 600; color: var(--text-primary); }
.topbar-subtitle { font-size: var(--fs-sm); color: var(--text-tertiary); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }

.user-menu-trigger {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-full);
  transition: background-color var(--dur-fast) var(--ease-standard);
  cursor: pointer;
}
.user-menu-trigger:hover { background: var(--surface-hover); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-tint-strong); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}

.icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
  cursor: pointer;
  border: none; background: transparent;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.icon-btn svg { width: 18px; height: 18px; stroke-width: 1.75; }

.content { padding: var(--sp-6); max-width: 1100px; }

/* ---- Forms ---- */
.field-label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); margin: 0 0 var(--sp-1); }
.field-input, .field-select, textarea.field-input {
  width: 100%; height: 38px; padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-1); color: var(--text-primary);
  font-size: var(--fs-md); font-family: var(--font-sans);
  transition: border-color var(--dur-fast) var(--ease-standard), box-shadow var(--dur-fast) var(--ease-standard);
}
textarea.field-input { height: auto; padding: var(--sp-2) var(--sp-3); resize: vertical; }
.field-input:focus, .field-select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint);
}
.field-input::placeholder { color: var(--text-tertiary); }
.field-group { margin-bottom: var(--sp-3); }
.field-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: flex-end; }

/* ---- Notice / inline banner ---- */
.notice { padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); font-size: var(--fs-sm); margin-bottom: var(--sp-3); }
.notice-success { background: var(--success-tint); color: var(--success); }
.notice-danger { background: var(--danger-tint); color: var(--danger); }

/* ---- List row (record with title/subtitle + trailing content) ---- */
.list-row { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row-title { font-weight: 600; color: var(--text-primary); font-size: var(--fs-base); display: flex; align-items: center; gap: var(--sp-2); }
.list-row-subtitle { font-size: var(--fs-sm); color: var(--text-tertiary); margin-top: 2px; }
.list-row-side { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* ==================== COMPONENTS ==================== */

/* ---- Card ---- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--sp-5); }
.card-title { font-size: var(--fs-base); font-weight: 600; color: var(--text-primary); margin-bottom: var(--sp-3); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 34px; padding: 0 var(--sp-4);
  font-size: var(--fs-base); font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }
.btn-secondary { background: var(--surface-1); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text-primary); }
.btn-sm { height: 28px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }

/* ---- Badge / status pill ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 var(--sp-2);
  border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: 600;
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-success { background: var(--success-tint); color: var(--success); }
.badge-success .badge-dot { background: var(--success); }
.badge-warning { background: var(--warning-tint); color: var(--warning); }
.badge-warning .badge-dot { background: var(--warning); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-danger .badge-dot { background: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); }

/* Color-name aliases for JS-generated markup (e.g. admin_diagnostics.js)
   that predates the semantic badge-{success,warning,danger,neutral} names.
   Keeping these here means that JS never needs to change. */
.badge-green { background: var(--success-tint); color: var(--success); }
.badge-amber { background: var(--warning-tint); color: var(--warning); }
.badge-red { background: var(--danger-tint); color: var(--danger); }
.badge-gray { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.data-table thead th {
  text-align: left;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.03em;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface-1);
}
.data-table tbody td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.data-table tbody tr { transition: background-color var(--dur-fast) var(--ease-standard); }
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ---- List / row card (mobile-friendly alternative to table) ---- */
.row-card {
  display: block;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-2);
  transition: border-color var(--dur-fast) var(--ease-standard), box-shadow var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
}
a.row-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }

/* ---- Tabs / filters ---- */
.tab-group {
  display: inline-flex; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: var(--radius-md);
}
.tab {
  padding: 6px var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--text-secondary);
  transition: background-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.tab:hover { color: var(--text-primary); }
.tab.active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ---- Stat / metric box ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); }
.stat-box { background: var(--surface-2); border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4); }
.stat-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: var(--fs-xl); font-weight: 600; color: var(--text-primary); margin-top: 2px; }

/* ---- Photo grid ---- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--sp-2); }
.photo-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: transform var(--dur-fast) var(--ease-standard);
}
.photo-grid img:hover { transform: scale(1.03); }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: var(--sp-8) var(--sp-4); color: var(--text-tertiary); font-size: var(--fs-base); }

/* ---- Dialog (native <dialog>-friendly) ---- */
dialog.sheet {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface-1);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
}
dialog.sheet::backdrop { background: var(--scrim); }

/* ---- Utility ---- */
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.mono { font-family: var(--font-mono); }
.flex-between { display: flex; align-items: center; justify-content: space-between; }

/* ---- Mobile ---- */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 20; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .content { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
  .sidebar-scrim {
    display: none;
    position: fixed; inset: 0; background: var(--scrim); z-index: 19;
  }
  .sidebar-scrim.open { display: block; }
}
@media (min-width: 861px) {
  .menu-btn { display: none; }
}
