/* ================================================================
   ebart Perf Tool — Global Styles
   ================================================================ */

/* ── CSS Variables ─────────────────────────────────────────────── */
:root {
  /* Palette */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --accent: #0ea5e9;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;

  /* Neutrals */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-focus: #93c5fd;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #94a3b8;

  /* Typography */
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Spacing & Radius */
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow: 0 1px 3px rgba(0, 0, 0, .1), 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .07), 0 2px 4px rgba(0, 0, 0, .06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, .1), 0 4px 6px rgba(0, 0, 0, .05);
  --transition: 0.2s ease;
}

/* ── Reset & Base ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

h1,
h2,
h3,
h4 {
  line-height: 1.3;
  color: var(--text);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* ── Navigation ────────────────────────────────────────────────── */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

nav .brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

nav .brand span {
  color: var(--primary);
}

nav .nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

nav .nav-links a,
nav .nav-links button,
nav .nav-links form button {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  line-height: 1.6;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

nav .nav-links a:hover,
nav .nav-links button:hover,
nav .nav-links form button:hover {
  background: var(--bg);
  color: var(--primary);
  text-decoration: none;
}

/* ── Page wrapper ──────────────────────────────────────────────── */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

/* ── Form elements ─────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input::placeholder {
  color: var(--muted);
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

/* Password wrapper */
.pw-wrap {
  position: relative;
  display: flex;
}

.pw-wrap input {
  flex: 1;
  padding-right: 3rem;
}

.pw-toggle {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 2.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: color var(--transition), background var(--transition);
}

.pw-toggle:hover {
  color: var(--text-secondary);
  background: var(--bg);
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

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

.btn-login {
  width: 100%;
  padding: 0.7rem;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.btn-run {
  padding: 0.65rem 1.75rem;
  font-size: 0.95rem;
}

/* ── Alerts ────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

.alert-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #86efac;
}

.alert-warning {
  background: var(--warning-bg);
  color: #92400e;
  border: 1px solid #fcd34d;
}

/* ── Login page ────────────────────────────────────────────────── */
body:has(.login-logo) {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
}

body:has(.login-logo) .page {
  width: 100%;
  max-width: 400px;
  padding: 2rem 1.25rem;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
  color: #fff;
}

.login-logo .icon {
  display: inline-block;
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  animation: float 3s ease-in-out infinite;
}

.login-logo h1 {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
}

.login-logo p {
  color: #94a3b8;
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

body:has(.login-logo) .card {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-lg);
}

.footer-note {
  text-align: center;
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 1.75rem;
}

/* ── Phase 2 login — email badge ───────────────────────────────── */
.login-step-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  background: var(--primary-light);
  border: 1px solid var(--border-focus);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}

.step-label {
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.step-email {
  font-weight: 700;
  color: var(--primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Back link row */
.login-back-row {
  text-align: center;
  margin-top: 1rem;
}

.login-back-link {
  font-size: 0.825rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

.login-back-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ── Config strip (dashboard) ──────────────────────────────────── */
.config-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.75rem;
  box-shadow: var(--shadow-sm);
}

.config-strip .row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.config-strip .kv {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
}

.config-strip .kv span {
  font-weight: 700;
  color: var(--text);
}

/* ── Two-column layout (dashboard) ─────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  /* align-items defaults to stretch — both columns match the tallest,
     which is required for position:sticky on #debug-wrap to work. */
}

/* ── Airport search ────────────────────────────────────────────── */
.airport-search {
  width: 100%;
  padding: 0.55rem 0.8rem 0.55rem 2.1rem;
  font-family: var(--font);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 0.65rem center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  margin-bottom: 0.5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.airport-search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.airport-search::placeholder {
  color: var(--muted);
}

/* ── Airport list (checkboxes) ─────────────────────────────────── */
.airport-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.airport-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}

.airport-item:hover {
  border-color: var(--border-focus);
  background: #f8fafc;
}

.airport-item.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.airport-item input[type="checkbox"] {
  margin-top: 0.2rem;
  accent-color: var(--primary);
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  cursor: pointer;
}

.ap-label {
  flex: 1;
  min-width: 0;
}

.ap-icao {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.ap-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
}

.ap-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* Custom scrollbar for airport list */
.airport-list::-webkit-scrollbar {
  width: 6px;
}

.airport-list::-webkit-scrollbar-track {
  background: transparent;
}

.airport-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.airport-list::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ── Run row ───────────────────────────────────────────────────── */
.run-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
}

/* ── Status badge ──────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  white-space: nowrap;
}

.status-badge.running {
  background: var(--primary-light);
  color: var(--primary);
}

.status-badge.done {
  background: var(--success-bg);
  color: var(--success);
}

.status-badge.error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Debug output ──────────────────────────────────────────────── */
#debug-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);

  /* Stick to viewport as the form scrolls */
  position: sticky;
  top: 4rem;
  /* clears the sticky nav bar */
  height: calc(75vh - 4rem);
  /* near-full viewport height, 1rem bottom gap */

  /* Flex column so #debug-box can grow to fill remaining space */
  display: flex;
  flex-direction: column;
}

#debug-wrap h3 {
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* The header row (title + Clear button) must not shrink */
#debug-wrap>div:first-child {
  flex-shrink: 0;
}

#debug-box {
  width: 100%;
  /* Fill the remaining space inside the flex panel */
  flex: 1;
  min-height: 0;
  /* required: allows flex child to shrink below content size */
  max-height: none;
  resize: none;
  /* no manual resize inside a sticky flex panel */
  padding: 0.75rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  color: #e2e8f0;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: var(--radius);
  outline: none;
}

#debug-box::placeholder {
  color: #475569;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Stack the two-column dashboard layout */
  .layout {
    grid-template-columns: 1fr;
  }

  /* Nav: brand + links stack vertically */
  nav {
    flex-direction: column;
    gap: 0;
    padding: 0.6rem 1rem;
  }

  nav .brand {
    padding-bottom: 0.5rem;
    width: 100%;
    justify-content: center;
    border-bottom: 1px solid var(--border);
  }

  nav .nav-links {
    width: 100%;
    justify-content: center;
    padding-top: 0.4rem;
  }

  /* Config strip — tighter gaps, smaller pills */
  .config-strip {
    padding: 0.75rem 1rem;
  }

  .config-strip .row {
    gap: 0.35rem 0.5rem;
  }

  .config-strip .kv {
    font-size: 0.76rem;
    padding: 0.25rem 0.55rem;
  }

  /* Airport list — shorter on mobile to avoid excessive scrolling */
  .airport-list {
    max-height: 240px;
  }

  /* Touch-friendly airport items (≥44px tap target) */
  .airport-item {
    min-height: 44px;
    padding: 0.7rem 0.85rem;
    align-items: center;
  }

  /* Touch-friendly form inputs and selects */
  .form-group input[type="text"],
  .form-group input[type="password"],
  .form-group input[type="number"],
  .form-group input[type="email"],
  .form-group select {
    min-height: 44px;
    font-size: 1rem;
    /* prevents iOS auto-zoom on focus */
  }

  .airport-search {
    min-height: 44px;
    font-size: 1rem;
  }

  /* Run row — stack vertically; Run button fills full width */
  .run-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .btn-run {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
    font-size: 1rem;
  }

  #status-badge {
    text-align: center;
  }

  /* Debug panel — revert to normal document flow on mobile */
  #debug-wrap {
    position: static;
    height: auto;
  }

  #debug-box {
    flex: none;
    min-height: 350px;
    max-height: 600px;
    resize: vertical;
  }

  body:has(.login-logo) .page {
    padding: 1.5rem 1rem;
  }
}

@media (max-width: 480px) {
  .page {
    padding: 1.25rem 0.75rem 2rem;
  }

  .card {
    padding: 1rem;
  }

  /* Config strip pills wrap gracefully on very narrow screens */
  .config-strip {
    padding: 0.65rem 0.75rem;
  }

  .config-strip .kv {
    font-size: 0.72rem;
    padding: 0.2rem 0.45rem;
  }

  .login-logo h1 {
    font-size: 1.35rem;
  }

  /* Slightly smaller debug box on very small phones */
  #debug-box {
    min-height: 260px;
  }
}

/* ================================================================
   Dark theme — applied when <body class="dark-theme"> (dashboard)
   Matches the deep navy gradient used on the login page.
   ================================================================ */

body.dark-theme {
  /* Re-map all design tokens to dark values */
  --bg: #0b1221;
  --surface: #1e293b;
  --border: #334155;
  --border-focus: #3b82f6;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --muted: #64748b;
  --primary-light: rgba(37, 99, 235, 0.22);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .5), 0 2px 4px rgba(0, 0, 0, .4);
  --success-bg: rgba(22, 163, 74, 0.15);
  --danger-bg: rgba(220, 38, 38, 0.15);
  --warning-bg: rgba(245, 158, 11, 0.15);

  /* Full-page gradient — same as login, fixed so it doesn't scroll */
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

/* Nav */
body.dark-theme nav {
  background: rgba(15, 23, 42, 0.85);
  border-bottom-color: var(--border);
  backdrop-filter: blur(8px);
}

body.dark-theme nav .brand {
  color: var(--text);
}

body.dark-theme nav .nav-links a,
body.dark-theme nav .nav-links button,
body.dark-theme nav .nav-links form button {
  color: var(--text-secondary);
}

body.dark-theme nav .nav-links a:hover,
body.dark-theme nav .nav-links button:hover,
body.dark-theme nav .nav-links form button:hover {
  background: rgba(255, 255, 255, .07);
  color: #fff;
}

/* Cards */
body.dark-theme .card {
  background: var(--surface);
  border-color: var(--border);
}

body.dark-theme .card-title {
  border-bottom-color: var(--border);
}

/* Config strip */
body.dark-theme .config-strip {
  background: var(--surface);
  border-color: var(--border);
}

body.dark-theme .config-strip .kv {
  background: rgba(255, 255, 255, .05);
  color: var(--text-secondary);
}

body.dark-theme .config-strip .kv span {
  color: var(--text);
}

/* Form inputs & selects */
body.dark-theme .form-group input[type="text"],
body.dark-theme .form-group input[type="password"],
body.dark-theme .form-group input[type="number"],
body.dark-theme .form-group textarea {
  background: rgba(255, 255, 255, .05);
  border-color: var(--border);
  color: var(--text);
  color-scheme: dark;
}

/* Select needs a solid background so the native dropdown popup is readable.
   rgba() backgrounds render as white in the OS-native option list on most
   platforms, giving white-on-white text. */
body.dark-theme .form-group select {
  background: #1e293b;
  border-color: var(--border);
  color: var(--text);
  color-scheme: dark;
}

body.dark-theme .form-group select option {
  background: #1e293b;
  color: #f1f5f9;
}

body.dark-theme .form-group input::placeholder {
  color: var(--muted);
}

body.dark-theme .form-group input:focus,
body.dark-theme .form-group select:focus,
body.dark-theme .form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .3);
}

/* Airport search */
body.dark-theme .airport-search {
  background-color: rgba(255, 255, 255, .05);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  border-color: var(--border);
  color: var(--text);
}

body.dark-theme .airport-search::placeholder {
  color: var(--muted);
}

/* Airport list items */
body.dark-theme .airport-item {
  background: rgba(255, 255, 255, .04);
  border-color: var(--border);
}

body.dark-theme .airport-item:hover {
  background: rgba(255, 255, 255, .08);
  border-color: var(--border-focus);
}

body.dark-theme .airport-item.selected {
  background: rgba(37, 99, 235, .18);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .25);
}

body.dark-theme .ap-icao {
  color: var(--text);
}

body.dark-theme .ap-name {
  color: var(--text-secondary);
}

body.dark-theme .ap-meta {
  color: var(--muted);
}

/* Scrollbar for airport list */
body.dark-theme .airport-list::-webkit-scrollbar-thumb {
  background: var(--border);
}

/* Ghost button */
body.dark-theme .btn-ghost {
  color: var(--text-secondary);
  border-color: var(--border);
}

body.dark-theme .btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, .07);
  color: var(--text);
}

/* Debug output wrapper — enhanced shadow + blue border glow */
body.dark-theme #debug-wrap {
  background: var(--surface);
  border-color: rgba(59, 130, 246, 0.28);
  box-shadow:
    0 0 0 1px rgba(59, 130, 246, 0.10),
    0 8px 32px rgba(0, 0, 0, 0.60),
    0 2px 8px rgba(0, 0, 0, 0.40);
}

body.dark-theme #debug-wrap h3 {
  color: var(--text);
}

/* Status badge variants */
body.dark-theme .status-badge.running {
  background: rgba(37, 99, 235, .2);
  color: #93c5fd;
}

body.dark-theme .status-badge.done {
  background: rgba(22, 163, 74, .2);
  color: #86efac;
}

body.dark-theme .status-badge.error {
  background: rgba(220, 38, 38, .2);
  color: #fca5a5;
}

body.dark-theme .spinner {
  border-color: rgba(37, 99, 235, .3);
  border-top-color: #93c5fd;
}

/* Page headings */
body.dark-theme h1,
body.dark-theme h2,
body.dark-theme h3,
body.dark-theme h4 {
  color: var(--text);
}

body.dark-theme a {
  color: #93c5fd;
}

body.dark-theme a:hover {
  color: #bfdbfe;
}

/* ================================================================
   Admin page
   ================================================================ */

/* Page header */
.admin-header {
  margin-bottom: 1.75rem;
}

.admin-header h2 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.admin-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* Two-column layout — Add User (narrow) | Authorized Users (wide) */
.admin-layout {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
  align-items: start;
}

/* ── User count badge ───────────────────────────────────────────── */
.user-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.45rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  margin-left: 0.5rem;
  vertical-align: middle;
}

/* ── Users table ────────────────────────────────────────────────── */
.user-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  table-layout: fixed;
}

/* Column widths */
.user-table colgroup col:nth-child(1) {
  width: 3rem;
}

/* # */
.user-table colgroup col:nth-child(2) {
  width: 40%;
}

/* Email */
.user-table colgroup col:nth-child(3) {
  width: auto;
}

/* Password */
.user-table colgroup col:nth-child(4) {
  width: 7.5rem;
}

/* Actions */

/* Header */
.user-table thead tr {
  border-left: 3px solid var(--primary);
}

.user-table th {
  padding: 0.7rem 1rem;
  text-align: left;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  background: var(--primary-light);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.user-table th:first-child {
  text-align: center;
  border-radius: var(--radius-lg) 0 0 0;
}

.user-table th:last-child {
  border-radius: 0 var(--radius-lg) 0 0;
}

/* Body rows */
.user-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Zebra striping */
.user-table tbody tr:nth-child(even) td {
  background: rgba(37, 99, 235, 0.03);
}

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

.user-table tbody tr:last-child td:first-child {
  border-radius: 0 0 0 var(--radius-lg);
}

.user-table tbody tr:last-child td:last-child {
  border-radius: 0 0 var(--radius-lg) 0;
}

/* Row hover */
.user-table tbody tr {
  transition: background var(--transition);
}

.user-table tbody tr:hover td {
  background: rgba(37, 99, 235, 0.08) !important;
  cursor: default;
}

/* ── Cell types ──────────────────────────────────────────────────── */
.user-num {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  text-align: center;
  width: 3rem;
}

.user-email {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0;
  /* forces text-overflow on fixed table */
}

.user-date {
  color: var(--text-secondary);
  font-size: 0.82rem;
  white-space: nowrap;
}

/* Empty state */
.user-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.user-empty span {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

.user-empty p {
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ── Nav admin link ─────────────────────────────────────────────── */
.nav-admin-link {
  font-weight: 600 !important;
  color: var(--primary) !important;
}

body.dark-theme .nav-admin-link {
  color: #93c5fd !important;
}

/* ── Dark-theme overrides for admin page ────────────────────────── */
body.dark-theme .user-table th {
  background: rgba(37, 99, 235, 0.18);
  color: #93c5fd;
  border-bottom-color: rgba(37, 99, 235, 0.4);
}

body.dark-theme .user-table thead tr {
  border-left-color: #3b82f6;
}

body.dark-theme .user-table tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}

body.dark-theme .user-table td {
  border-bottom-color: var(--border);
}

body.dark-theme .user-table tbody tr:hover td {
  background: rgba(37, 99, 235, 0.1);
}

body.dark-theme .user-table-wrap {
  border-color: var(--border);
}

body.dark-theme .user-email {
  color: var(--text);
}

body.dark-theme .user-date {
  color: var(--text-secondary);
}

/* ── Generated-password banner ──────────────────────────────────── */
.generated-pw-banner {
  align-items: flex-start;
  flex-direction: column;
  gap: 0;
  padding: 1rem 1.1rem;
  margin-bottom: 1.5rem;
}

.generated-pw-inner {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
}

.generated-pw-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.generated-pw-label {
  font-weight: 600;
  font-size: 0.875rem;
}

.generated-pw-value {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.08);
  color: inherit;
  user-select: all;
}

.generated-pw-note {
  font-size: 0.8rem;
  opacity: 0.8;
  margin-top: 0.1rem;
}

.btn-pw-reveal,
.btn-pw-copy {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
  font-family: var(--font);
  font-weight: 600;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.07);
  cursor: pointer;
  transition: background var(--transition);
  color: inherit;
  line-height: 1.4;
}

.btn-pw-reveal:hover,
.btn-pw-copy:hover {
  background: rgba(0, 0, 0, 0.14);
}

.btn-pw-reveal:disabled,
.btn-pw-copy:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Inline password-reveal button (table) ──────────────────────── */
.user-pw-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.user-pw-mask {
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.btn-inline-reveal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  transition: color var(--transition), background var(--transition),
    border-color var(--transition);
  flex-shrink: 0;
}

.btn-inline-reveal:hover {
  color: var(--text);
  background: var(--bg);
  border-color: var(--border-focus);
}

/* Dark-theme variants */
body.dark-theme .generated-pw-value {
  background: rgba(255, 255, 255, 0.1);
}

body.dark-theme .btn-pw-reveal,
body.dark-theme .btn-pw-copy {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

body.dark-theme .btn-pw-reveal:hover,
body.dark-theme .btn-pw-copy:hover {
  background: rgba(255, 255, 255, 0.15);
}

body.dark-theme .user-pw-mask {
  color: var(--text-secondary);
}

body.dark-theme .btn-inline-reveal {
  border-color: var(--border);
  color: var(--muted);
}

body.dark-theme .btn-inline-reveal:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border-focus);
}

/* ── Actions cell ───────────────────────────────────────────────── */
.user-actions {
  white-space: nowrap;
  text-align: center;
  width: 7rem;
}

.user-actions form {
  display: inline;
}

/* ── Small danger button (Remove) ───────────────────────────────── */
.btn-danger-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  font-family: var(--font);
  font-size: 0.775rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
    box-shadow var(--transition);
  white-space: nowrap;
}

.btn-danger-sm:hover {
  background: #fecaca;
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

.btn-danger-sm:active {
  background: #fca5a5;
}

/* Dark-theme variant */
body.dark-theme .btn-danger-sm {
  color: #fca5a5;
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.35);
}

body.dark-theme .btn-danger-sm:hover {
  background: rgba(220, 38, 38, 0.22);
  border-color: rgba(220, 38, 38, 0.6);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

body.dark-theme .btn-danger-sm:active {
  background: rgba(220, 38, 38, 0.32);
}

/* Responsive */
@media (max-width: 768px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }
}