/* =========================================================================
   Design Tokens (foundation for upcoming redesign — see brief/gpt.md
   sections 4 "Color System" and 6 "Global UI Rules").

   NOTE: The current app is dark-only (see <html class="dark"> in
   index.html and tailwind.config darkMode: 'class'). These tokens are
   defined here for later redesign agents to consume, but nothing in the
   existing UI has been switched to use them yet, and no light/dark
   toggle has been wired up. The dark-mode block below simply mirrors the
   app's current always-dark look using the brief's dark-mode values.
   ========================================================================= */
:root {
  /* Primary */
  --color-primary: #6366F1;
  --color-primary-dark: #4F46E5;
  --color-primary-light: #818CF8;

  /* Background (light mode default) */
  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-surface-secondary: #F1F5F9;

  /* Text (light mode default) */
  --color-text-primary: #0F172A;
  --color-text-secondary: #64748B;
  --color-text-muted: #94A3B8;

  /* Status */
  --color-success: #10B981;
  --color-warning: #F59E0B;
  --color-error: #EF4444;
  --color-info: #3B82F6;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadow */
  --shadow-subtle: 0 4px 20px rgba(15, 23, 42, 0.06);
}

/* Dark mode via prefers-color-scheme, unless an explicit light choice
   is set via data-theme="light" (guard kept per the brief's own pattern
   for future use — not wired to any toggle today). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #020617;
    --color-surface: #0F172A;
    --color-surface-secondary: #1E293B;

    --color-text-primary: #F8FAFC;
    --color-text-secondary: #CBD5E1;
    --color-text-muted: #94A3B8;
  }
}

/* Dark mode via explicit opt-in (data-theme="dark"), so a future toggle
   can win in both directions regardless of system preference. */
:root[data-theme="dark"] {
  --color-bg: #020617;
  --color-surface: #0F172A;
  --color-surface-secondary: #1E293B;

  --color-text-primary: #F8FAFC;
  --color-text-secondary: #CBD5E1;
  --color-text-muted: #94A3B8;
}

/* =========================================================================
   Existing app styles (moved verbatim from the inline <style> block that
   used to live in index.html <head>). Not modified for this refactor.
   ========================================================================= */
body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background-color: #030712;
}
.glass {
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.glass-card {
  background: rgba(30, 41, 59, 0.5);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.glow-brand {
  box-shadow: 0 0 50px -10px rgba(99, 102, 241, 0.35);
}
/* =========================================================================
   Landing page redesign additions (see brief/gpt.md sections 7-12, 28, 31).
   Scoped to landing-specific classes; reuses the :root tokens above for
   colors/radius rather than introducing a parallel palette.
   ========================================================================= */

/* How-it-works 4-step stepper: connector arrow between cards on desktop. */
.landing-stepper-item {
  position: relative;
}
.landing-stepper-arrow {
  position: absolute;
  top: 50%;
  right: -1.85rem;
  transform: translateY(-50%);
  z-index: 1;
}

/* FAQ accordion: smooth expand/collapse within the brief's 150-300ms range. */
.faq-answer {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 250ms ease, opacity 200ms ease;
}
.faq-item.faq-open .faq-answer {
  opacity: 1;
}
.faq-icon {
  transition: transform 200ms ease;
  flex-shrink: 0;
}
.faq-item.faq-open .faq-icon {
  transform: rotate(45deg);
  color: var(--color-primary-light);
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #090d16; }
::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: #334155; }

/* =========================================================================
   Inbox / Email Viewer components (brief/gpt.md sections 19-22, 32, 43).
   Scoped with an "ibx-" prefix and built on the design tokens above so
   they stay isolated from the rest of the (still-legacy) styling.
   ========================================================================= */

/* Realtime status pill + dot — 4 distinct states, pulse only on "live". */
.ibx-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.ibx-status-dot { width: 7px; height: 7px; border-radius: 9999px; flex-shrink: 0; }

.ibx-pill--live { background: rgba(16, 185, 129, .12); color: var(--color-success); border: 1px solid rgba(16, 185, 129, .3); }
.ibx-status-dot--live { background: var(--color-success); animation: ibx-pulse 1.8s ease-in-out infinite; }

.ibx-pill--syncing { background: rgba(59, 130, 246, .12); color: var(--color-info); border: 1px solid rgba(59, 130, 246, .3); }
.ibx-status-dot--syncing { background: var(--color-info); }

.ibx-pill--offline { background: rgba(148, 163, 184, .12); color: var(--color-text-muted); border: 1px solid rgba(148, 163, 184, .28); }
.ibx-status-dot--offline { background: var(--color-text-muted); }

.ibx-pill--error { background: rgba(239, 68, 68, .12); color: var(--color-error); border: 1px solid rgba(239, 68, 68, .3); }
.ibx-status-dot--error { background: var(--color-error); }

@keyframes ibx-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .45; transform: scale(.82); }
}

/* Segmented control (HTML / Text / Raw) */
.ibx-segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: rgba(15, 23, 42, .6);
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: var(--radius-md);
}
.ibx-segment-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--color-text-muted);
  border-radius: calc(var(--radius-md) - 4px);
  transition: background-color .18s ease, color .18s ease, box-shadow .18s ease;
}
.ibx-segment-btn:hover { color: #e2e8f0; }
.ibx-segment-btn.is-active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-subtle);
}
.ibx-segment-btn:focus-visible,
.ibx-pill:focus-visible {
  outline: 2px solid var(--color-primary-light);
  outline-offset: 2px;
}

/* Loading skeleton for the email list (replaces bare "Loading..." text) */
.ibx-skeleton {
  background: linear-gradient(90deg, rgba(148, 163, 184, .08) 25%, rgba(148, 163, 184, .18) 37%, rgba(148, 163, 184, .08) 63%);
  background-size: 400% 100%;
  animation: ibx-shimmer 1.4s ease infinite;
}
@keyframes ibx-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .ibx-status-dot--live,
  .ibx-skeleton {
    animation: none;
  }
}

/* =========================================================================
   Cloudflare setup wizard step indicator (brief/gpt.md §24 "Cloudflare
   Setup"). Numbered circles connected by lines, with per-step status
   (completed / current / pending / error). Presentation only — driven by
   public/js/views/domain.js, which maps the *existing* connect-domain
   steps onto these 5 visual nodes.
   ========================================================================= */
.wizard-steps {
  display: flex;
  align-items: flex-start;
}
.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  width: 64px;
}
.wizard-step-circle {
  width: 28px;
  height: 28px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border: 2px solid var(--color-text-muted);
  color: var(--color-text-muted);
  background: transparent;
  transition: all 200ms ease;
}
.wizard-step-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.25;
}
.wizard-connector {
  flex: 1 1 auto;
  height: 2px;
  min-width: 8px;
  background: rgba(148, 163, 184, 0.25);
  margin-top: 13px;
  transition: background 200ms ease;
}
.wizard-connector-completed {
  background: var(--color-success);
}
.wizard-step[data-status="completed"] .wizard-step-circle {
  border-color: var(--color-success);
  background: var(--color-success);
  color: #fff;
}
.wizard-step[data-status="completed"] .wizard-step-label {
  color: var(--color-success);
}
.wizard-step[data-status="current"] .wizard-step-circle {
  border-color: var(--color-primary);
  color: var(--color-primary-light);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18);
}
.wizard-step[data-status="current"] .wizard-step-label {
  color: var(--color-primary-light);
}
.wizard-step[data-status="error"] .wizard-step-circle {
  border-color: var(--color-error);
  background: var(--color-error);
  color: #fff;
}
.wizard-step[data-status="error"] .wizard-step-label {
  color: var(--color-error);
}

/* =========================================================================
   Auth page components (login/register — brief/gpt.md section 13 & 34).
   Additive only, built from the :root design tokens above.
   ========================================================================= */
.auth-card {
  max-width: 420px;
}
.auth-tabs {
  background: var(--color-surface-secondary, #1e293b);
}
.auth-alert-error {
  background: color-mix(in srgb, var(--color-error) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-error) 28%, transparent);
}
.auth-alert-error .auth-alert-icon {
  color: var(--color-error);
}
.auth-alert-error .auth-alert-text {
  color: var(--color-error);
}

/* =========================================================================
   Dashboard shell components (brief/gpt.md §14-18: Sidebar, Statistic
   Cards, Mailbox Management, Create Mailbox). Built from the :root tokens
   above; reused verbatim by inbox/admin/domain views for visual
   consistency, so avoid introducing parallel one-off styles for the same
   patterns (buttons, inputs, badges, empty states) elsewhere.
   ========================================================================= */

/* ---- Button system (brief §36: primary / ghost / danger + loading state) ---- */
.btn-primary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  transition: all 180ms ease;
  white-space: nowrap;
}
.btn-primary {
  color: #fff;
  background: linear-gradient(90deg, var(--color-primary-dark), var(--color-primary));
  box-shadow: 0 10px 25px -8px rgba(99, 102, 241, 0.45);
}
.btn-primary:hover {
  filter: brightness(1.08);
}
.btn-primary:active {
  transform: translateY(1px);
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: none;
  transform: none;
}
.btn-ghost {
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(51, 65, 85, 0.8);
}
.btn-ghost:hover {
  background: #1e293b;
  color: #fff;
}
.btn-danger {
  color: var(--color-error);
  background: color-mix(in srgb, var(--color-error) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-error) 30%, transparent);
}
.btn-danger:hover {
  background: color-mix(in srgb, var(--color-error) 20%, transparent);
}
/* Small square icon-only action button — always pair with title+aria-label (brief §38). */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(51, 65, 85, 0.8);
  color: #94a3b8;
  transition: all 180ms ease;
}
.btn-icon:hover {
  color: #fff;
  background: #1e293b;
}
.btn-icon-danger:hover {
  color: var(--color-error);
  background: color-mix(in srgb, var(--color-error) 15%, transparent);
  border-color: color-mix(in srgb, var(--color-error) 35%, transparent);
}

/* ---- Input system (brief §37) ---- */
.input-field {
  width: 100%;
  padding: 0.625rem 1rem;
  border-radius: var(--radius-md);
  background: #020617;
  border: 1px solid #334155;
  color: #fff;
  font-size: 0.75rem;
  transition: border-color 150ms ease;
}
.input-field:focus {
  outline: none;
  border-color: var(--color-primary);
}
.input-field::placeholder {
  color: var(--color-text-muted);
}

/* ---- Badge system ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success {
  color: var(--color-success);
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-success) 25%, transparent);
}
.badge-warning {
  color: var(--color-warning);
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-warning) 25%, transparent);
}
.badge-neutral {
  color: #cbd5e1;
  background: #1e293b;
  border: 1px solid #334155;
}

/* ---- StatCard (brief §16): number is the largest element, status/delta line beneath ---- */
.stat-card {
  background: rgba(30, 41, 59, 0.5);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(30, 41, 59, 0.8);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  transition: border-color 180ms ease;
}
.stat-card-icon {
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 1px solid;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-card-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.2;
}
.stat-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ---- Sidebar nav item (brief §15): active item = subtle bg + primary text/icon ---- */
.dash-nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
  transition: all 180ms ease;
  width: 100%;
  text-align: left;
}
.dash-nav-item:hover {
  color: #fff;
  background: rgba(15, 23, 42, 0.7);
}
.dash-nav-item-active {
  color: #fff;
  background: var(--color-primary);
  box-shadow: 0 8px 20px -6px rgba(99, 102, 241, 0.5);
}
.dash-nav-item-admin {
  color: var(--color-warning);
  background: color-mix(in srgb, var(--color-warning) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-warning) 30%, transparent);
}
.dash-nav-item-admin-active,
.dash-nav-item-admin.dash-nav-item-active {
  color: #020617;
  background: var(--color-warning);
  border-color: var(--color-warning);
  font-weight: 800;
}

/* ---- Mailbox management: data-table/card hybrid (brief §17) ----
   Column widths mirror the desktop header row markup in index.html
   (#dash-view-manager column-header div) so cells line up. */
.mailbox-row-card {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  background: rgba(30, 41, 59, 0.5);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(30, 41, 59, 0.9);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color 180ms ease;
}
.mailbox-row-card:hover {
  border-color: #334155;
}
@media (min-width: 768px) {
  .mailbox-row-card {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
  }
}

/* ---- Skeleton loading card for the mailbox list (brief §32) — reuses the
   shimmer keyframes already defined for the inbox list (.ibx-skeleton). ---- */
.skeleton-card {
  height: 76px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, rgba(148, 163, 184, .08) 25%, rgba(148, 163, 184, .18) 37%, rgba(148, 163, 184, .08) 63%);
  background-size: 400% 100%;
  animation: ibx-shimmer 1.4s ease infinite;
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-card {
    animation: none;
  }
}

/* ---- EmptyState (brief §33): icon + title + description + primary action ---- */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(30, 41, 59, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}
.empty-state-icon {
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-lg);
  background: #0f172a;
  border: 1px solid #1e293b;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #e2e8f0;
}
.empty-state-desc {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  max-width: 26rem;
}
