/* =========================================================
   Lisa Aromano — Funnel Dashboard styles
   Light + dark theme via [data-theme] on <html>
   ========================================================= */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --sidebar-w: 250px;
  --grad-violet: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
  --grad-cyan: linear-gradient(135deg, #22d3ee 0%, #3b82f6 100%);
  --grad-pink: linear-gradient(135deg, #f472b6 0%, #a855f7 100%);
  --grad-green: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  --grad-amber: linear-gradient(135deg, #fbbf24 0%, #f97316 100%);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Dark theme (default) ---------- */
html[data-theme="dark"] {
  --bg: #0e0f1f;
  --bg-soft: #12142a;
  --card: #191b34;
  --card-alt: #1e2140;
  --border: #2a2d4d;
  --text: #f1f2fb;
  --text-muted: #9195b8;
  --text-faint: #6b6f92;
  --sidebar-bg: #12142a;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --accent: #a855f7;
  --accent-2: #22d3ee;
  --track: #262a4d;
}

/* ---------- Light theme ---------- */
html[data-theme="light"] {
  --bg: #f5f6fb;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-alt: #f8f7ff;
  --border: #e8e8f2;
  --text: #1c1d2e;
  --text-muted: #6a6d85;
  --text-faint: #9fa2b8;
  --sidebar-bg: #ffffff;
  --shadow: 0 10px 30px rgba(99,102,241,0.08);
  --accent: #7c3aed;
  --accent-2: #0ea5e9;
  --track: #e8e8f2;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  transition: background .25s ease, color .25s ease;
  /* Belt-and-suspenders: nothing should be able to force a horizontal
     page scrollbar even if a future card's content runs wide. */
  overflow-x: hidden;
}

img, svg { display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
ul { list-style: none; }

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

/* ================= Sidebar ================= */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  /* Stick to the viewport instead of the (much taller) page, so the
     export card at the bottom stays visible without scrolling all
     the way down the main content. */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  align-self: flex-start;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--grad-violet);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 15px;
}
.brand-text { line-height: 1.1; }
.brand-text strong { font-size: 14.5px; font-weight: 700; }
.brand-text span { font-size: 11.5px; color: var(--text-muted); }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); padding: 10px 10px 6px;
  font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--card-alt); color: var(--text); }
.nav-item.active {
  background: var(--grad-violet);
  color: #fff;
  box-shadow: 0 6px 16px rgba(124,58,237,0.35);
}

.sidebar-footer { margin-top: auto; }
.export-card {
  background: var(--card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}
.export-card p { font-size: 12.5px; color: var(--text-muted); margin-bottom: 10px; line-height: 1.4; }
.btn-grad {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px 14px; border-radius: 999px;
  background: var(--grad-violet); color: #fff; font-size: 13px; font-weight: 600;
}
.btn-grad svg { width: 15px; height: 15px; }

/* ================= Main ================= */
.main { flex: 1; min-width: 0; padding: 22px 28px 40px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.topbar h1 { font-size: 21px; font-weight: 700; }
.topbar .sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 14px; min-width: 220px;
}
.search-box svg { width: 15px; height: 15px; color: var(--text-faint); }
.search-box input {
  border: none; outline: none; background: transparent; color: var(--text);
  font-size: 13px; width: 100%;
}
.search-box input::placeholder { color: var(--text-faint); }

.range-pill {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; color: var(--text-muted);
}

.date-filter { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.custom-range { display: flex; align-items: center; gap: 8px; }
.custom-range[hidden] { display: none; } /* .custom-range's own display:flex otherwise beats the hidden attribute's UA display:none at equal specificity */
.custom-range .to-sep { font-size: 12.5px; color: var(--text-faint); }
.custom-range input[type="date"] { color-scheme: dark; }
html[data-theme="light"] .custom-range input[type="date"] { color-scheme: light; }
.custom-apply-btn { width: auto; padding: 8px 16px; font-size: 12.5px; }

.theme-toggle {
  display: flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px; position: relative;
}
.theme-toggle button {
  width: 30px; height: 30px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); position: relative; z-index: 1;
  transition: color .2s ease;
}
.theme-toggle button svg { width: 15px; height: 15px; }
.theme-toggle button.on { color: #fff; }
.theme-toggle .knob {
  position: absolute; top: 5px; left: 5px; width: 30px; height: 30px;
  border-radius: 999px; background: var(--grad-violet);
  transition: transform .25s ease; z-index: 0;
}
html[data-theme="light"] .theme-toggle .knob { transform: translateX(30px); }

.avatar {
  width: 38px; height: 38px; border-radius: 999px;
  background: var(--grad-cyan);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
}

.logout-link {
  width: 38px; height: 38px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text-muted);
  transition: color .15s ease, border-color .15s ease;
}
.logout-link:hover { color: #f87171; border-color: rgba(248,113,113,0.4); }
.logout-link svg { width: 16px; height: 16px; }

/* ================= Grid & cards ================= */
.grid { display: grid; gap: 18px; }
.stat-row { grid-template-columns: repeat(5, 1fr); margin-bottom: 18px; }
.mid-row { grid-template-columns: 1.4fr 1fr; margin-bottom: 18px; align-items: stretch; }
.chart-row { grid-template-columns: 1fr 1fr 1fr; margin-bottom: 18px; }
.table-row { grid-template-columns: 1.2fr 1fr; }

@media (max-width: 1180px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr 1fr; }
  .mid-row { grid-template-columns: 1fr; }
  .table-row { grid-template-columns: 1fr; }
}

/* ================= Mobile (≤720px) ================= */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 720px) {
  .chart-row { grid-template-columns: 1fr; }
  /* .stat-row intentionally left alone here — it inherits the
     repeat(2, 1fr) 2-up grid from the 1180px breakpoint above, which
     works fine down to phone width too. */

  /* Mobile top bar with hamburger replaces the always-visible sidebar */
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    background: var(--sidebar-bg); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 60;
  }
  .mobile-topbar strong { font-size: 14.5px; }
  .hamburger {
    width: 36px; height: 36px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); background: var(--card-alt); color: var(--text);
  }
  .hamburger svg { width: 19px; height: 19px; }

  /* Sidebar becomes an off-canvas drawer instead of disappearing */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: min(78vw, 280px);
    z-index: 90; transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.45); }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(4,4,12,0.55);
    z-index: 80; opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

  .main { padding: 16px 14px 32px; }
  .topbar h1 { font-size: 18.5px; }
  .search-box { display: none; } /* not wired to anything yet; just eats space on phones */
  .topbar-actions { gap: 8px; }
}

@media (max-width: 480px) {
  .funnel-step { grid-template-columns: 84px 1fr 54px; gap: 8px; }
  .funnel-step .fname { font-size: 11px; }
  .funnel-step .fmeta { font-size: 10px; }
  .funnel-step .fmeta strong { font-size: 12px; }

  .ring-item svg { width: 68px; height: 68px; }
  .ring-item .ring-label { font-size: 11px; }

  .stat-card .value { font-size: 22px; }

  .modal { padding: 18px; }
  .cust-head { gap: 10px; }
  .cust-ltv strong { font-size: 17px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  /* Grid items default to min-width:auto, which lets a wide canvas or
     table force the whole column (and the page) wider than the
     viewport. This lets cards shrink properly instead. */
  min-width: 0;
}
canvas { max-width: 100%; }
/* Line chart: Chart.js's default aspect ratio makes a full-width card
   absurdly tall. Fixing the wrapper's height + maintainAspectRatio:false
   (set in app.js) keeps it a sane, constant height regardless of width. */
.chart-box { position: relative; height: 220px; }
@media (max-width: 720px) {
  .chart-box { height: 170px; }
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 10px;
}
.card-head h3 { font-size: 14.5px; font-weight: 700; }
.card-head p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-head .legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }

/* stat cards (gradient) */
.stat-card {
  border-radius: var(--radius-lg);
  padding: 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
  min-height: 128px;
  min-width: 0;
  display: flex; flex-direction: column; justify-content: space-between;
}
.stat-card.grad-1 { background: var(--grad-pink); }
.stat-card.grad-2 { background: var(--grad-cyan); }
.stat-card.grad-3 { background: var(--grad-violet); }
.stat-card.grad-4 { background: var(--grad-green); }
.stat-card.grad-5 { background: var(--grad-amber); }
.stat-card .label { font-size: 13px; opacity: .92; font-weight: 500; }
.stat-card .value { font-size: 30px; font-weight: 700; margin-top: 10px; }
.stat-card .value small { font-size: 15px; font-weight: 600; opacity: .85; }
.stat-card .badge {
  align-self: flex-start;
  background: rgba(255,255,255,0.22);
  border-radius: 999px; padding: 4px 10px; font-size: 11.5px; font-weight: 600;
  margin-top: 12px;
}

/* neutral stat card (used in table row summary) */
.stat-plain .value { color: var(--text); }
.stat-plain .label { color: var(--text-muted); }

/* ================= Funnel ================= */
.funnel-card .funnel { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.funnel-step { display: grid; grid-template-columns: 160px 1fr 90px; align-items: center; gap: 14px; }
.funnel-step .fname { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.funnel-step .fbar-track { background: var(--track); border-radius: 999px; height: 28px; overflow: hidden; }
.funnel-step .fbar {
  height: 100%; border-radius: 999px;
  display: flex; align-items: center; justify-content: flex-end; padding-right: 12px;
  color: #fff; font-size: 12.5px; font-weight: 700;
  transition: width .6s ease;
}
.funnel-step .fmeta { font-size: 12px; color: var(--text-faint); text-align: right; }
.funnel-step .fmeta strong { color: var(--text); font-size: 13px; }

/* ================= Rings ================= */
.ring-row { display: flex; gap: 20px; margin-top: 6px; }
.ring-item { flex: 1; text-align: center; }
.ring-item svg { width: 92px; height: 92px; margin: 0 auto; }
.ring-item .ring-value { font-size: 18px; font-weight: 700; }
.ring-item .ring-label { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ================= Tables ================= */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 600; padding: 0 10px 10px; border-bottom: 1px solid var(--border);
}
tbody td { padding: 11px 10px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--card-alt); }
.cell-muted { color: var(--text-muted); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
}
.pill.completed { background: rgba(52,211,153,0.16); color: #10b981; }
.pill.pending { background: rgba(251,191,36,0.18); color: #d97706; }
.pill.abandoned { background: rgba(248,113,113,0.16); color: #f87171; }
.pill.renewal { background: rgba(168,85,247,0.16); color: #a855f7; }
.pill.new { background: rgba(34,211,238,0.16); color: #0891b2; }
.pill.visitor-only { background: rgba(148,163,184,0.16); color: #94a3b8; }
.pill.purchased { background: rgba(168,85,247,0.18); color: #a855f7; }
.pill.subscription { background: rgba(59,130,246,0.16); color: #3b82f6; }
.pill.payment-plan { background: rgba(249,115,22,0.16); color: #f97316; }
.pill.free { background: rgba(148,163,184,0.16); color: #94a3b8; }
.plan-tag { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 7px; }
.plan-weekly { background: rgba(56,189,248,0.15); color: #0284c7; }
.plan-monthly { background: rgba(168,85,247,0.15); color: #9333ea; }
.plan-quarterly { background: rgba(244,114,182,0.15); color: #db2777; }
.plan-yearly { background: rgba(52,211,153,0.15); color: #059669; }

footer.foot {
  margin-top: 24px; text-align: center; font-size: 12px; color: var(--text-faint);
}

/* ================= Views / nav ================= */
.nav-item { width: 100%; text-align: left; }
.view[hidden] { display: none; }

.select-pill {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.select-pill:focus { outline: none; border-color: var(--accent); }

.table-wrap.scroll { max-height: 480px; overflow-y: auto; }
tbody tr[data-lead-id] { cursor: pointer; }

/* ================= Modal ================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 10, 22, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 85vh; overflow-y: auto;
  padding: 26px; position: relative;
}
.modal-close {
  position: absolute; top: 16px; right: 16px;
  width: 30px; height: 30px; border-radius: 999px;
  background: var(--card-alt); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.modal-close:hover { color: var(--text); }

.cust-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding-right: 30px; }
.cust-avatar {
  width: 50px; height: 50px; border-radius: 999px; background: var(--grad-violet);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.cust-head h2 { font-size: 17px; font-weight: 700; }
.cust-head p { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.cust-meta-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  background: var(--card-alt); border-radius: var(--radius-md); padding: 14px; margin-bottom: 20px;
}
.cust-meta-grid div span {
  display: block; font-size: 10.5px; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px;
}
.cust-meta-grid div strong { font-size: 13.5px; }

.cust-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); margin-bottom: 12px;
}

.timeline { margin-bottom: 22px; }
.timeline-item { display: grid; grid-template-columns: 14px 1fr; gap: 12px; position: relative; padding-bottom: 18px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot { width: 12px; height: 12px; border-radius: 999px; background: var(--accent); margin-top: 3px; position: relative; z-index: 1; }
.timeline-dot.abandoned { background: #f87171; }
.timeline-item:not(:last-child)::before {
  content: ""; position: absolute; left: 5px; top: 16px; bottom: -4px; width: 2px; background: var(--border);
}
.timeline-item .t-label { font-size: 13px; font-weight: 600; }
.timeline-item .t-date { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

.cust-ltv {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--grad-violet); color: #fff; border-radius: var(--radius-md);
  padding: 14px 16px; margin-top: 2px;
}
.cust-ltv span { font-size: 12.5px; opacity: .9; }
.cust-ltv strong { font-size: 20px; }

/* ================= Login page ================= */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  text-align: center;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.login-brand .brand-mark { width: 46px; height: 46px; border-radius: 13px; font-size: 19px; }
.login-brand h1 { font-size: 18px; font-weight: 700; }
.login-brand p { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.login-field { text-align: left; margin-bottom: 16px; }
.login-field label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em;
}
.login-field input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color .15s ease;
}
.login-field input:focus { border-color: var(--accent); }
.login-error {
  background: rgba(248,113,113,0.12);
  color: #f87171;
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 18px;
  text-align: left;
}
.login-submit {
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 14px;
}
.login-foot {
  margin-top: 22px;
  font-size: 11.5px;
  color: var(--text-faint);
}
