:root {
  /* Brand */
  --blue: #2f6fee;
  --blue-dark: #1d4fb8;
  --blue-soft: #eef3fe;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --green: #16a34a;
  --green-soft: #f0fdf4;
  --amber: #d97706;

  /* Surfaces (light) */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --surface-raised: #ffffff;

  /* Text */
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;

  /* Borders */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-accent: rgba(47, 111, 238, 0.35);
  --border-accent-strong: rgba(47, 111, 238, 0.55);

  /* Input bg */
  --input-bg: #ffffff;
  --input-bg-alt: #f8fafc;

  /* Script block */
  --script-bg: #f1f5f9;
  --script-border: #cbd5e1;
  --script-text: #334155;

  /* Script tag pill */
  --tag-bg: #e2e8f0;
  --tag-text: #64748b;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);

  /* Misc */
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  /* Brand - slightly brighter blue for dark contrast */
  --blue: #60a5fa;
  --blue-dark: #3b82f6;
  --blue-soft: rgba(96, 165, 250, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --green: #4ade80;
  --green-soft: rgba(74, 222, 128, 0.12);

  /* Surfaces (dark) */
  --bg: #0a1120;
  --surface: #111a2e;
  --surface-alt: #1a2540;
  --surface-raised: #152038;

  /* Text */
  --text: #e2e8f0;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  /* Borders */
  --border: #1e2a47;
  --border-strong: #2a3a5e;
  --border-accent: rgba(96, 165, 250, 0.45);
  --border-accent-strong: rgba(96, 165, 250, 0.65);

  /* Input bg */
  --input-bg: #0f1a32;
  --input-bg-alt: #0a1427;

  /* Script block */
  --script-bg: #0f1a32;
  --script-border: #2a3a5e;
  --script-text: #cbd5e1;

  /* Script tag pill */
  --tag-bg: #1e2a47;
  --tag-text: #94a3b8;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  line-height: 1.5;
  /* Safe-area insets for iPhone notch / home indicator */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
input, textarea, select {
  font-family: inherit;
  /* 16px prevents iOS auto-zoom on focus */
  font-size: 16px;
  color: var(--text);
  background: var(--input-bg);
  -webkit-appearance: none;
  appearance: none;
}
@media (min-width: 861px) {
  input, textarea, select { font-size: 14px; }
}
input:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
::placeholder { color: var(--text-muted); opacity: 0.7; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  background: var(--surface);
  color: var(--text);
}
.btn-primary { background: var(--blue); color: white; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
[data-theme="dark"] .btn-primary { color: #0a1120; }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-danger-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--red); }
.btn-danger-ghost:hover { background: var(--red-soft); border-color: var(--red); }

/* Theme toggle button */
.theme-toggle {
  display: grid;
  place-items: center;
  padding: 5px 10px;
  min-width: 34px;
  font-size: 15px;
  line-height: 1;
}
.theme-icon { display: none; }
[data-theme="light"] .theme-icon-light,
:root:not([data-theme="dark"]) .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* ------ Header ------ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: background 0.2s, border-color 0.2s;
}
.header-row {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 24px;
  align-items: center;
  padding: 14px 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--blue);
  color: white;
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  top: 4px; right: 4px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #22d3ee;
}
.brand-title { font-weight: 700; font-size: 16px; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.prospect-fields {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 0.8fr 1fr;
  gap: 10px;
}
.prospect-fields label { display: flex; flex-direction: column; gap: 4px; }
.prospect-fields span {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.prospect-fields input {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}

.timer-block {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  justify-content: end;
}
.timer-display {
  grid-row: 1 / span 2;
  font-variant-numeric: tabular-nums;
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  min-width: 90px;
  text-align: right;
}
.timer-display.running { color: var(--blue); }
.timer-section {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.timer-controls { display: flex; gap: 6px; }
.timer-controls .btn { padding: 5px 12px; font-size: 13px; }

/* ------ Section nav (progress) ------ */
.section-nav {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}
.section-nav button {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  border-right: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: left;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.section-nav button:last-child { border-right: none; }
.section-nav button:hover { background: var(--surface); color: var(--text); }
.section-nav button.active {
  background: var(--surface);
  color: var(--blue);
}
.section-nav button.active::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--blue);
}
.section-nav .nav-time {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.section-nav button.active .nav-time { color: var(--blue); }

/* ------ Layout ------ */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .side-col { order: -1; }
}

/* ------ Main sections ------ */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  scroll-margin-top: 160px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.section-card:hover { border-color: var(--border-accent-strong); }
.section-card.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft), var(--shadow-md);
}
.section-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
.section-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.section-head .time-range {
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.section-body { padding: 16px 20px; }
.section-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 16px;
  font-style: italic;
}
.listening-for {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--blue-soft);
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.listening-for strong { color: var(--blue); }

/* ------ Items (scripts + questions) ------ */
.item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 14px;
  padding: 12px 0;
  border-bottom: 1px dashed var(--border);
}
.item:last-child { border-bottom: none; }
.item-num {
  font-weight: 700;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  padding-top: 2px;
  min-width: 22px;
}
.item-body { min-width: 0; }
.item-text {
  font-size: 14px;
  color: var(--text);
  margin: 0 0 8px;
  line-height: 1.5;
}
.item.script .item-text {
  padding: 10px 14px;
  background: var(--script-bg);
  border-left: 3px solid var(--script-border);
  border-radius: 6px;
  font-style: italic;
  color: var(--script-text);
}
.item textarea {
  width: 100%;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
  background: var(--input-bg-alt);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.item textarea:focus { background: var(--input-bg); border-color: var(--blue); }
.item .script-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tag-text);
  background: var(--tag-bg);
  padding: 2px 6px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 6px;
}
.testimonial-section .section-head { background: linear-gradient(90deg, var(--blue-soft), var(--surface)); }
.testimonial-section .item-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

/* ------ Side column ------ */
.side-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 160px;
  align-self: start;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}
.side-card {
  background: var(--surface);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: background 0.2s, border-color 0.2s;
}
.side-card:hover { border-color: var(--border-accent-strong); }
.side-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}
.side-card .muted { font-size: 12px; color: var(--text-muted); margin: 0 0 10px; }

.reminders {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.reminders li {
  padding-left: 14px;
  position: relative;
}
.reminders li::before {
  content: "";
  position: absolute;
  left: 0; top: 8px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--blue);
}

.flag-group { margin-bottom: 12px; }
.flag-group:last-child { margin-bottom: 0; }
.flag-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  display: inline-block;
  border-radius: 4px;
  margin-bottom: 6px;
}
.flag-red { background: var(--red-soft); color: var(--red); }
.flag-green { background: var(--green-soft); color: var(--green); }
.flag-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 3px 0;
  cursor: pointer;
}
.flag-row input { accent-color: var(--blue); }

.roi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.roi-grid > div {
  background: var(--input-bg-alt);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.roi-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.roi-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.roi-total { color: var(--blue); font-size: 16px; }
.roi-note { margin-top: 8px !important; font-size: 11px !important; }

.action-stack { display: flex; flex-direction: column; gap: 8px; }
.action-stack .btn { width: 100%; }

/* ------ Recap ------ */
.recap-section {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 32px 24px 64px;
  transition: background 0.2s, border-color 0.2s;
}
.recap-wrapper { max-width: 1060px; margin: 0 auto; }
.recap-wrapper h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.recap-wrapper .muted {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-muted);
}
.recap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin-bottom: 24px;
}
.recap-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.recap-grid label.full { grid-column: 1 / -1; }
.recap-grid span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.recap-grid input, .recap-grid textarea {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}
.granola-heading { margin: 20px 0 4px; font-size: 15px; font-weight: 700; color: var(--text); }
.recap-wrapper textarea[data-recap="granola"] {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  resize: vertical;
  background: var(--input-bg);
  color: var(--text);
}

/* ------ Toast ------ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--surface);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: var(--shadow-md);
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 860px) {
  .header-row { grid-template-columns: 1fr; }
  .prospect-fields { grid-template-columns: 1fr 1fr; }
  .timer-block { justify-content: start; }
  .recap-grid { grid-template-columns: 1fr; }
}

/* ------ iPhone / narrow mobile ------ */
@media (max-width: 600px) {
  /* Header: tighter padding, reorganize */
  .header-row {
    padding: 10px 14px;
    gap: 12px;
  }
  .brand { gap: 10px; }
  .brand-mark { width: 34px; height: 34px; font-size: 17px; border-radius: 8px; }
  .brand-title { font-size: 15px; }
  .brand-sub { display: none; }

  /* Put timer in-line with brand so it's always visible while scrolling */
  .header-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand timer"
      "fields fields";
  }
  .brand { grid-area: brand; min-width: 0; }
  .timer-block {
    grid-area: timer;
    grid-template-columns: auto;
    grid-template-rows: auto auto auto;
    row-gap: 2px;
    justify-items: end;
  }
  .timer-display {
    grid-row: auto;
    font-size: 22px;
    min-width: 0;
    text-align: right;
  }
  .timer-section { font-size: 11px; }
  .timer-controls { gap: 4px; }
  .timer-controls .btn {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 32px;
  }
  .prospect-fields {
    grid-area: fields;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .prospect-fields span { font-size: 9px; }
  .prospect-fields input { padding: 8px 10px; font-size: 16px; }

  /* Section nav: horizontal scroll with snap (8 sections won't fit) */
  .section-nav {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  .section-nav::-webkit-scrollbar { display: none; }
  .section-nav button {
    flex: 0 0 auto;
    min-width: 110px;
    scroll-snap-align: start;
    padding: 8px 12px;
    font-size: 11px;
  }
  .section-nav .nav-time { font-size: 9px; }

  /* Layout: main first, side after (undo order:-1 from 1100px breakpoint) */
  .layout {
    padding: 14px;
    gap: 14px;
  }
  .side-col {
    order: 0;
    position: static;
    max-height: none;
    overflow: visible;
    gap: 12px;
  }

  /* Cards: tighter spacing */
  .section-card { margin-bottom: 14px; scroll-margin-top: 180px; }
  .section-head { padding: 12px 14px; gap: 8px; flex-wrap: wrap; }
  .section-head h2 { font-size: 16px; }
  .section-head .time-range { font-size: 11px; }
  .section-body { padding: 12px 14px; }
  .section-desc { font-size: 12px; }

  /* Items */
  .item {
    grid-template-columns: auto 1fr;
    gap: 6px 10px;
    padding: 10px 0;
  }
  .item-num { font-size: 13px; min-width: 18px; }
  .item-text { font-size: 14px; }
  .item.script .item-text { padding: 9px 11px; font-size: 13px; }
  .item textarea { min-height: 60px; padding: 10px; }

  /* Side cards */
  .side-card { padding: 14px; }
  .side-card h3 { font-size: 12px; }
  .roi-grid { grid-template-columns: 1fr 1fr; }

  /* Flag rows: bigger touch targets */
  .flag-row {
    padding: 8px 0;
    font-size: 14px;
    min-height: 36px;
  }
  .flag-row input {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }

  /* Buttons: meet 44px touch target */
  .btn {
    padding: 10px 14px;
    min-height: 40px;
  }
  .action-stack .btn { min-height: 44px; }

  /* Recap */
  .recap-section {
    padding: 20px 14px calc(48px + env(safe-area-inset-bottom));
  }
  .recap-wrapper h2 { font-size: 18px; }
  .recap-grid { gap: 10px; margin-bottom: 16px; }
  .recap-grid input, .recap-grid textarea { padding: 10px; font-size: 16px; }
  .recap-wrapper textarea[data-recap="granola"] { font-size: 13px; padding: 10px; }

  /* Toast above home-indicator */
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* Short landscape (iPhone landscape): keep header small */
@media (max-width: 900px) and (max-height: 500px) {
  .app-header { position: relative; }
  .section-card { scroll-margin-top: 20px; }
}
