:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fb;
  --bg-card: #ffffff;
  --text-primary: #0a0f1e;
  --text-secondary: #4a5568;
  --text-muted: #94a3b8;
  --accent: #00dcff;
  --accent-dark: #0099bb;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --font-heading: 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Inter', sans-serif;
  --radius: 8px;
  --max-width: 1200px;
}

html[data-theme='dark'] {
  --bg-primary: #05050a;
  --bg-secondary: #0d0d18;
  --bg-card: #0d0d18;
  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --border: #1e2535;
  --border-light: #1a2030;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
}

a {
  color: var(--accent-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 12px;
  color: var(--text-primary);
  font-family: var(--font-heading);
  letter-spacing: 0.02em;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.25;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.3;
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.35;
}

p {
  margin: 0 0 16px;
  color: var(--text-secondary);
}

small,
.caption,
.footer-small {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.secondary,
.meta {
  font-size: 14px;
  color: var(--text-secondary);
}

.page {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

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

.section {
  padding: 24px 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card + .card {
  margin-top: 16px;
}

/* Grid cells already use gap — cancel the stacked margin so all cards in a row are equal height */
.grid .card + .card {
  margin-top: 0;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn:hover {
  text-decoration: none;
  filter: brightness(0.98);
}

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

.btn-secondary {
  border-color: var(--border);
  background: var(--bg-card);
}

.btn-secondary.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #041019;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

.btn-danger {
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}

.nav-shell {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-card) 95%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.nav-inner {
  width: min(100%, var(--max-width));
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  gap: 1px;
}

.brand-name {
  display: block;
}

.brand-sub {
  display: block;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: #222;
  text-transform: none;
}

.brand .accent {
  color: var(--accent);
}

.nav-links,
.nav-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-api-nudge {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent, #00b5cc);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.nav-links a,
.nav-actions a,
.nav-actions button {
  font-size: 14px;
  font-weight: 500;
}

.hero {
  padding: 48px 0;
}

.hero p {
  max-width: 720px;
}

.ticker-strip {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
}

.ticker-track {
  display: flex;
  gap: 18px;
  padding: 12px 16px;
  min-width: max-content;
  animation: ticker-scroll 26s linear infinite;
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-size: 14px;
}

@keyframes ticker-scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}

.stat {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
}

.kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.kpi {
  flex: 1;
  min-width: 120px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px;
}

.input,
.select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 16px;
  font-family: var(--font-body);
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--border-light);
  padding: 12px 10px;
  text-align: left;
  font-size: 14px;
}

th {
  color: var(--text-secondary);
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.pos {
  color: var(--success);
}

.neg {
  color: var(--danger);
}

.warn {
  color: var(--warning);
}

.asset-card {
  border-left: 4px solid var(--accent);
}

.footer {
  border-top: 1px solid var(--border);
  margin-top: 48px;
  background: var(--bg-card);
}

.footer-inner {
  width: min(100%, var(--max-width));
  margin: 0 auto;
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.footer-badges {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.footer-divider {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: var(--border);
  opacity: 0.5;
  flex-shrink: 0;
}

.footer-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.15s;
}

.footer-badge:hover { color: var(--text); }
.footer-badge svg { flex-shrink: 0; }

.footer-badge-logo {
  display: block;
  flex-shrink: 0;
  object-fit: contain;
}

.footer-badge-logo--stripe {
  opacity: 0.85;
}

.footer-badge-logo--stripe:hover,
.footer-badge:hover .footer-badge-logo--stripe {
  opacity: 1;
}

.footer-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.footer-social-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.15s;
}

.footer-social-link:hover { color: var(--text); }

.hide-mobile {
  display: inline-flex;
}

.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  align-items: start;
  gap: 16px;
}

@media (max-width: 960px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-links {
    display: none;
  }

  .app-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .container {
    padding: 20px;
  }

  .hero {
    padding: 36px 0;
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .form-row {
    grid-template-columns: 1fr;
  }

  .hide-mobile {
    display: none;
  }

  .nav-inner {
    padding: 12px 20px;
  }

  .footer-inner {
    padding: 20px;
  }
}

/* ── Theme toggle icon button ─────────────── */
.btn-icon {
  padding: 8px 10px;
  min-width: 40px;
  font-size: 18px;
  border-color: transparent;
  background: transparent;
  line-height: 1;
}
.btn-icon:hover {
  background: var(--bg-card);
  border-color: var(--border);
  filter: none;
}

/* ── Pricing cards — equal height + hover pop ─── */
.pricing-grid {
  align-items: stretch;
}
.pricing-grid .card {
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: default;
}
.pricing-grid .card .btn {
  margin-top: auto;
}
.pricing-grid .card:hover {
  transform: scale(1.035);
  box-shadow: 0 8px 32px rgba(0, 220, 255, 0.15), 0 2px 8px rgba(0,0,0,0.12);
  z-index: 1;
  position: relative;
}

/* ── Profile Dropdown ─────────────────────────────────── */
.nav-profile-wrap {
  position: relative;
}
.nav-avatar-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px 5px 6px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.2s, background 0.2s;
}
.nav-avatar-btn:hover {
  border-color: #4488ff66;
  background: #4488ff11;
}
.nav-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #4488ff33;
  color: #4488ff;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-chevron {
  width: 14px;
  height: 14px;
  color: var(--secondary);
  flex-shrink: 0;
}
.nav-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
  z-index: 200;
  overflow: hidden;
}
.nav-dropdown[hidden] { display: none; }
.nav-dropdown-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid #e5e7eb;
}
.nav-dropdown-header .nav-dropdown-greeting {
  font-weight: 700;
  font-size: 1rem;
  color: #111827;
  font-family: 'Plus Jakarta Sans', Inter, sans-serif;
}
.nav-dropdown-header .nav-dropdown-plan {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 2px;
}
.nav-dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-size: 0.88rem;
  color: #374151;
  text-decoration: none;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  box-sizing: border-box;
}
.nav-dropdown-item:hover {
  background: #f3f4f6;
  color: #111827;
}
.nav-dropdown-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 4px 0;
}
.nav-dropdown-signout {
  color: var(--danger) !important;
}
.nav-dropdown-signout:hover {
  background: rgba(239,68,68,0.08) !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   MOBILE-FIRST OPTIMIZATIONS  v8
   Design priority: mobile phone is the PRIMARY screen. Desktop is bonus.
   Target: WordPress-quality mobile UX — native-feel nav, touch targets,
           readable typography, zero horizontal overflow.
   Breakpoints: <480px (small phone) · 480–767px (large phone) · 768px+ (desktop)
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Mobile Nav Drawer + Overlay ──────────────────────────── */
.nav-ham-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  flex-shrink: 0;
  padding: 0;
  margin-left: 8px;
}
.nav-ham-btn svg { display: block; }

.nav-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 98;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.nav-mobile-overlay.open {
  display: block;
  opacity: 1;
}

.nav-mobile-drawer {
  position: fixed;
  top: 0;
  left: -300px;
  width: 280px;
  height: 100dvh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  z-index: 99;
  display: flex;
  flex-direction: column;
  transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 24px);
}
.nav-mobile-drawer.open {
  left: 0;
}

.nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.nav-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text-primary);
  flex-shrink: 0;
}

.nav-drawer-links {
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  flex: 1;
}
.nav-drawer-links a,
.nav-drawer-links button {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  min-height: 52px;
  transition: background 0.15s;
}
.nav-drawer-links a:hover,
.nav-drawer-links button:hover {
  background: var(--bg-secondary);
  text-decoration: none;
}
.nav-drawer-links a[aria-current="page"] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-weight: 600;
}
.nav-drawer-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 20px;
}
.nav-drawer-cta {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border);
}
.nav-drawer-cta .btn {
  width: 100%;
  justify-content: center;
  min-height: 48px;
  font-size: 15px;
}

/* Show hamburger, hide desktop links below 768px */
@media (max-width: 767px) {
  .nav-ham-btn { display: flex; }
  .nav-links { display: none !important; }
  .nav-api-nudge { display: none; }
}

/* Hide hamburger above 768px */
@media (min-width: 768px) {
  .nav-ham-btn { display: none !important; }
  .nav-mobile-drawer,
  .nav-mobile-overlay { display: none !important; }
}

/* ── Responsive Typography ─────────────────────────────────── */
@media (max-width: 479px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.05rem; }
  .stat { font-size: 22px; }
  .hero h1 { font-size: 1.65rem; }
}

@media (max-width: 767px) and (min-width: 480px) {
  h1 { font-size: 1.75rem; }
  .hero h1 { font-size: 1.9rem; }
}

/* ── Small phone (<480px) ──────────────────────────────────── */
@media (max-width: 479px) {
  .container { padding: 12px 16px; }
  .card { padding: 16px; }
  .hero { padding: 28px 0; }
  .nav-inner { padding: 10px 16px; }
  .footer-inner { padding: 16px; gap: 16px; flex-direction: column; align-items: flex-start; }
  .footer-right { align-items: flex-start; }
  .section { padding: 16px 0; }

  /* Buttons: always full touch target */
  .btn { min-height: 44px; padding: 10px 14px; }
  .btn-primary, .btn-secondary { font-size: 15px; }
}

/* ── Large phone (480–767px) ───────────────────────────────── */
@media (max-width: 767px) {
  .container { padding: 16px 20px; }
  .card { padding: 18px; }
  .hero { padding: 32px 0; }
  .section { padding: 20px 0; }
  .nav-inner { padding: 12px 20px; }

  /* Grids collapse to 1 col on phone */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }

  /* KPI cards: 2 across on phone */
  .kpis { gap: 10px; }
  .kpi { min-width: 0; flex: 1 1 calc(50% - 5px); padding: 10px 12px; }

  /* App sidebar collapses early */
  .app-layout { grid-template-columns: 1fr !important; }

  /* No hover pop on pricing cards (no hover on touch) */
  .pricing-grid .card:hover { transform: none; box-shadow: var(--shadow); }

  /* Footer */
  .footer-inner { flex-direction: column; align-items: flex-start; gap: 12px; }
  .footer-links { flex-wrap: wrap; gap: 10px; }
  .footer-right { align-items: flex-start; }

  /* Buttons — touch-friendly */
  .btn { min-height: 44px; }
  .nav-actions .btn { padding: 8px 12px; font-size: 13px; }

  /* Stat cards */
  .stat { font-size: 24px; }

  /* Hide brand-sub on very small nav */
  .brand-sub { font-size: 9px; letter-spacing: 0.05em; }

  /* Ticker: touch scroll */
  .ticker-strip { cursor: grab; }
  .ticker-track { animation-duration: 32s; }
}

/* ── Tables — horizontal scroll on mobile ──────────────────── */
@media (max-width: 767px) {
  /* Any table inside a card gets scroll container */
  .card table,
  .table-scroll table {
    min-width: 480px;
    font-size: 13px;
  }
  .card,
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  th, td {
    padding: 10px 8px;
    white-space: nowrap;
  }
  /* Scroll hint gradient on right edge */
  .table-scroll::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 32px;
    pointer-events: none;
    background: linear-gradient(to right, transparent, var(--bg-card));
  }
  .table-scroll { position: relative; }
}

/* ── Forms — prevent iOS zoom (font-size ≥16px on inputs) ─── */
.input, .select, textarea {
  font-size: max(16px, 1rem);
  -webkit-appearance: none;
  appearance: none;
}

/* ── Safe area insets (iPhone notch / home bar) ────────────── */
.nav-shell {
  padding-top: env(safe-area-inset-top, 0px);
}
.footer {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Overflow guard — no horizontal scroll on page ─────────── */
body { overflow-x: hidden; }

/* ── Larger tap targets for inline links in app ────────────── */
@media (max-width: 767px) {
  .nav-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* ── Profile page mobile tweaks ────────────────────────────── */
@media (max-width: 479px) {
  .api-key-row {
    flex-direction: column;
    gap: 8px;
  }
  .api-key-row input { width: 100%; }
}

/* ── Manage-subscription: plan cards ──────────────────────── */
@media (max-width: 767px) {
  .plan-radio-card { padding: 14px 16px; }
  .plan-radio-card:hover { transform: none; }
}

/* ── Confirmation / centered pages ────────────────────────── */
@media (max-width: 479px) {
  .container[style*="max-width:520px"],
  .container[style*="max-width: 520px"] {
    padding: 16px;
  }
}
