/* ============================================================
   AXA BG Driving Tuition — Calculator UI styles
   Single CSS file, no framework. Light theme, indigo accent.
   ============================================================ */

:root {
  --bg:       #f5f7fb;
  --card:    #ffffff;
  --border:  #e5e7eb;
  --text:    #111827;
  --muted:   #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --shadow:  0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  /* Hard guard against horizontal scroll caused by a single
     stray wide element (long select option text, an image, etc). */
  overflow-x: hidden;
}

a { color: var(--primary); }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 3px; font-size: 0.9em; }

/* ─── Top bar / footer ─────────────────────────────────────── */

.topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  background: #00008f; color: white;
  font-weight: 800; padding: 6px 10px; letter-spacing: 0.05em;
  border-radius: 4px;
}
.brand h1 { font-size: 18px; margin: 0; font-weight: 700; }
.brand p  { font-size: 12px; margin: 0; color: var(--muted); }

footer {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 24px;
}

/* ─── Layout ───────────────────────────────────────────────── */

main {
  max-width: 1180px;
  margin: 32px auto;
  padding: 0 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  /* Nothing inside a card should escape it horizontally. */
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}
/* Bullets in callouts / banners — long reasons must wrap, not
   overflow. */
.card ul,
.card ol,
.status-banner ul,
.status-banner ol {
  word-break: break-word;
  overflow-wrap: anywhere;
}
.card h2 { margin-top: 0; font-size: 20px; }
.card .muted { color: var(--muted); }
.center { text-align: center; }

/* ─── Buttons ──────────────────────────────────────────────── */

.primary-btn, .ghost-btn {
  font: inherit;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  font-weight: 600;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:hover { background: var(--primary-dark); }
.primary-btn:disabled { background: #c7d2fe; cursor: not-allowed; }
.ghost-btn  { background: white; border-color: var(--border); color: var(--text); }
.ghost-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ─── Forms ────────────────────────────────────────────────── */

.field-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  margin-top: 16px;
  /* The grid itself never expands beyond its parent — without
     this, a very wide cell can stretch the whole grid wider than
     the card. */
  max-width: 100%;
  min-width: 0;
}
.field-group h3 {
  grid-column: 1 / -1;
  font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted);
  margin: 24px 0 4px; font-weight: 700;
}
/* Same min-width fix for the grid cells themselves so they can
   shrink. minmax(0, 1fr) is the canonical way to do this. */
.field-group > .field { min-width: 0; }
/* min-width: 0 lets the field shrink inside its grid cell so a
   wide <select> or long label can't push the whole layout
   sideways on small screens. */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.field label {
  font-weight: 600; font-size: 13px;
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
  overflow-wrap: anywhere;
}
.field .qcode {
  background: #eef2ff; color: var(--primary);
  font-size: 11px; padding: 1px 6px; border-radius: 3px;
  font-weight: 700;
  flex-shrink: 0;
}
.field .reason {
  font-size: 12px; color: var(--warning);
  font-style: italic;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.field .from-db {
  font-size: 11px; color: var(--success); font-weight: 600;
  flex-shrink: 0;
}
/* All form controls fill their cell. max-width pins them at the
   parent boundary even when the <option> text is much wider than
   the cell. text-overflow keeps the selected option clipped with
   an ellipsis instead of expanding the select. */
.field input[type=text],
.field input[type=number],
.field input[type=date],
.field select {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.field select {
  text-overflow: ellipsis;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0px;
  border-color: var(--primary);
}
.field.missing input,
.field.missing select {
  border-color: var(--warning);
  background: #fffaf0;
}

.toggle {
  display: flex; gap: 8px; align-items: center;
}
.toggle input { width: 18px; height: 18px; accent-color: var(--primary); }

.actions {
  margin-top: 24px;
  display: flex; gap: 12px; justify-content: flex-end;
}

/* ─── Status banners ───────────────────────────────────────── */

.status-banner {
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 24px;
  font-size: 16px;
  font-weight: 600;
  display: flex; align-items: center; gap: 14px;
  border: 1px solid transparent;
}
.status-banner .pill {
  font-size: 13px; padding: 4px 10px; border-radius: 100px;
  background: rgba(255,255,255,0.55); font-weight: 800;
  letter-spacing: 0.04em;
}
.status-banner small {
  font-weight: 400; opacity: 0.9; display: block;
}
.status-acceptable { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.status-declined   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.status-refer      { background: #fffbeb; color: #92400e; border-color: #fde68a; }

/* ─── Premium summary ──────────────────────────────────────── */

.premium-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  margin-bottom: 24px;
}
.premium-grid .pcard {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
}
.premium-grid .pcard .label { color: var(--muted); font-size: 13px; }
.premium-grid .pcard .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.premium-grid .pcard.total { background: #4f46e5; color: white; }
.premium-grid .pcard.total .label { color: rgba(255,255,255,0.85); }

/* ─── Pipeline (13 steps as a collapsible table) ─────────── */

.pipeline-controls {
  display: flex;
  gap: 8px;
  margin: 12px 0 10px;
}
.pt-bulk {
  font: inherit;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.pt-bulk:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Wrapper allows horizontal scroll on tiny phones rather than
   overflowing the card. */
.pipeline-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
}

.pipeline-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.pipeline-table th,
.pipeline-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.pipeline-table tbody tr.pt-row:last-of-type > td { border-bottom: none; }

.pipeline-table thead th {
  background: #f9fafb;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}
.pipeline-table .pt-step {
  width: 56px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.pipeline-table .pt-label {
  font-weight: 600;
}
.pipeline-table .pt-loading {
  width: 90px;
  font-variant-numeric: tabular-nums;
}
.pipeline-table .pt-running {
  width: 130px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pipeline-table .pt-toggle {
  width: 60px;
  text-align: center;
}

/* Loading delta colour (separate from row decoration). */
.pt-positive { color: var(--warning); font-weight: 700; }
.pt-negative { color: var(--success); font-weight: 700; }

/* Per-row tinting matches the old card stripes. */
.pt-row.pt-up      { box-shadow: inset 3px 0 0 var(--warning); }
.pt-row.pt-down    { box-shadow: inset 3px 0 0 var(--success); }
.pt-row.pt-decline { box-shadow: inset 3px 0 0 var(--danger); background: #fef2f2; }
.pt-row.pt-decline .pt-running { color: var(--danger); }

/* Toggle button — small, neutral, becomes primary on hover. */
.pt-toggle-btn {
  font: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--muted);
  min-width: 36px;
  line-height: 1;
}
.pt-toggle-btn:hover {
  background: #eef2ff;
  border-color: var(--primary);
  color: var(--primary);
}

/* Detail row — hidden until the user expands. */
.pt-detail[hidden] { display: none; }
.pt-detail > td {
  background: #f9fafb;
  padding: 12px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.pt-detail-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pt-detail-note {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
  line-height: 1.45;
}
.pt-detail-decline {
  color: var(--danger);
  font-weight: 600;
  font-size: 13px;
}

/* ─── Misc ─────────────────────────────────────────────────── */

.callout {
  background: #eef2ff; color: #3730a3;
  padding: 12px 14px; border-radius: 8px;
  font-size: 13px; margin-bottom: 16px;
}
.error-box {
  background: #fef2f2; color: #991b1b;
  border: 1px solid #fecaca;
  padding: 14px; border-radius: 8px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 16px auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive breakpoints ────────────────────────────────
   Three tiers:
     - Desktop  (>  900px) → unchanged grid layouts
     - Tablet   (≤ 900px)  → single-column forms + tighter padding
     - Mobile   (≤ 560px)  → stacked topbar, full-width buttons,
                              smaller type, reduced gutters
   ──────────────────────────────────────────────────────────── */

/* Tablet */
@media (max-width: 900px) {
  main {
    margin: 20px auto;
    padding: 0 16px;
  }
  .topbar {
    padding: 14px 18px;
  }
  .brand h1 { font-size: 16px; }
  .brand p  { font-size: 11px; }

  .card { padding: 22px 18px; border-radius: 10px; }
  .card h2 { font-size: 18px; }

  .field-group {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .premium-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .premium-grid .pcard .value { font-size: 22px; }

  .pipeline-table { font-size: 13px; }
  .pipeline-table th,
  .pipeline-table td { padding: 8px 10px; }
  .pipeline-table .pt-running { width: 110px; }

  .actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
  }
}

/* Mobile */
@media (max-width: 560px) {
  html, body { font-size: 14px; }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
  }
  .brand { gap: 10px; }
  .brand-mark { padding: 4px 8px; font-size: 13px; }
  .brand h1 { font-size: 15px; }

  #reset-btn { align-self: stretch; }

  main {
    margin: 14px auto;
    padding: 0 12px;
  }

  .card {
    padding: 18px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
  }
  .card h2 { font-size: 16px; margin-bottom: 6px; }

  /* Stack form action buttons full-width and reverse the order
     so the primary CTA sits at the bottom (closest to the thumb). */
  .actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
    margin-top: 18px;
  }
  .actions .primary-btn,
  .actions .ghost-btn {
    width: 100%;
    padding: 12px 16px;
  }

  /* Status banner: stack the pill above the message so long
     decline reasons don't squeeze the banner sideways. */
  .status-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 14px 16px;
    font-size: 14px;
  }
  .status-banner .pill { font-size: 11px; padding: 3px 9px; }

  /* Premium summary: stack cards but keep the headline value bold. */
  .premium-grid { grid-template-columns: 1fr; }
  .premium-grid .pcard { padding: 14px; }
  .premium-grid .pcard .value { font-size: 20px; }

  /* Pipeline table: tighter padding and let the wrapper scroll
     horizontally if step text wraps awkwardly. */
  .pipeline-table { font-size: 12.5px; }
  .pipeline-table th,
  .pipeline-table td { padding: 7px 8px; }
  .pipeline-table .pt-step    { width: 44px; }
  .pipeline-table .pt-loading { width: 70px; }
  .pipeline-table .pt-running { width: 92px; }
  .pipeline-table .pt-toggle  { width: 48px; }
  .pt-toggle-btn { padding: 3px 7px; min-width: 32px; }

  .pipeline-controls { flex-wrap: wrap; }
  .pt-bulk { padding: 5px 10px; font-size: 12px; }

  /* Field-group section headings tighter on small screens. */
  .field-group h3 { font-size: 12px; margin: 16px 0 2px; }

  /* Inputs: keep at least 44px tap target height (Apple guideline)
     and 16px font so iOS Safari doesn't zoom in on focus. */
  .field input[type=text],
  .field input[type=number],
  .field input[type=date],
  .field select {
    min-height: 44px;
    font-size: 16px;
  }
  .toggle input { width: 22px; height: 22px; }

  footer { padding: 18px 12px; }
}

/* Tiny phones (< 360px) — extra-tight gutters so the OGI
   reference input doesn't overflow the viewport. */
@media (max-width: 360px) {
  main { padding: 0 8px; }
  .card { padding: 14px 10px; }
  .topbar { padding: 10px 12px; }
  .brand h1 { font-size: 14px; line-height: 1.25; }
}
