/* Earnings calculator — mobile-first, light theme, optional dark mode. */

:root {
  --bg: #F6F7FB;
  --surface: #FFFFFF;
  --surface-2: #F1F3F8;
  --text: #1F2433;
  --muted: #535A6B;          /* 6.9:1 on white */
  --border: #D5DAE5;
  --accent: #3730A3;         /* indigo-800, 10:1 on white */
  --accent-text: #FFFFFF;
  --focus: #2563EB;
  --error: #B42318;          /* 6.1:1 on white */
  --error-bg: #FEF3F2;
  --warn-bg: #FFF7E6;
  --warn-text: #7A4A00;
  --you: #047857;            /* emerald-700, 5.5:1 on white */
  --you-bg: #ECFDF5;
  --clinic: #4338CA;
  --clinic-bg: #EEF2FF;
  --pink-bg: #FDF2F8;
  --pink-border: #F5C2DD;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141B;
    --surface: #1C1F2A;
    --surface-2: #252937;
    --text: #EEF0F6;
    --muted: #B3B9C8;
    --border: #3A4052;
    --accent: #A5B4FC;
    --accent-text: #12141B;
    --focus: #93C5FD;
    --error: #FCA5A5;
    --error-bg: #3B1717;
    --warn-bg: #3A2C10;
    --warn-text: #FCD9A0;
    --you: #6EE7B7;
    --you-bg: #0F2E25;
    --clinic: #C7D2FE;
    --clinic-bg: #22264A;
    --pink-bg: #2E1A26;
    --pink-border: #6B2D50;
    --shadow: none;
  }
}

/* Type colours (used only for stripes/chips; text always uses --text). */
.t-ind50_off { --type: #3B82F6; }
.t-ind50_on { --type: #6366F1; }
.t-ind75_off { --type: #10B981; }
.t-ind75_on { --type: #0D9488; }
.t-cpl75_off { --type: #F59E0B; }
.t-cpl75_on { --type: #EA580C; }
.t-sliding50 { --type: #DB2777; }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  overflow-x: hidden;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button, input { font: inherit; color: inherit; }

/* ---- Layout ---- */

.site-header, main {
  max-width: 960px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.site-header { padding-top: 20px; padding-bottom: 8px; }
.site-header h1 { margin: 0; font-size: 1.6rem; line-height: 1.2; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }

main { padding-bottom: 32px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 14px 0;
  min-width: 0;
}

.section-title { margin: 0 0 10px; font-size: 1.2rem; display: flex; align-items: center; gap: 8px; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 10px; }

.app-error, .form-error {
  background: var(--error-bg);
  color: var(--error);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  margin: 8px 0;
}

/* ---- Period ---- */

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--surface-2);
  padding: 6px;
  border-radius: 12px;
}

.seg-btn {
  min-height: 48px;
  border: 2px solid transparent;
  border-radius: 9px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
}

.seg-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  text-decoration: underline;          /* shape cue, not colour alone */
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
}

.period-label { margin: 10px 0 0; font-weight: 600; overflow-wrap: anywhere; }

/* Anything that can echo user text must wrap instead of widening the page. */
main, .card, .results-card, #results-body, .export, .tile, .breakdown td, .svc, .math {
  min-width: 0;
  overflow-wrap: anywhere;
}

.custom-period { margin-top: 12px; display: grid; gap: 4px; }
.custom-period label { font-weight: 600; }

input[type="text"], input[type="number"] {
  min-height: 44px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 6px 10px;
  width: 100%;
  min-width: 0;
}

input[aria-invalid="true"] { border-color: var(--error); }

.field-error {
  color: var(--error);
  font-size: 0.9rem;
  font-weight: 600;
  margin: 4px 0 0;
}
.field-error::before { content: "\26A0\00a0"; }

/* ---- Session cards ---- */

.session-group { margin-top: 14px; }
.group-title { margin: 0 0 8px; font-size: 1rem; color: var(--muted); }
.group-cards { display: grid; gap: 10px; }

.session-card {
  border: 1px solid var(--border);
  border-left: 8px solid var(--type);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
}

.card-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 10px;
}

.card-label { font-weight: 700; font-size: 1.05rem; }
.card-rate { margin-left: auto; color: var(--muted); font-size: 0.95rem; }

.chip {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--type);
  flex: none;
  vertical-align: middle;
}

.stepper {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  gap: 8px;
  align-items: stretch;
  max-width: 280px;
}

.step-btn {
  min-height: 52px;
  min-width: 52px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.step-btn:active { background: var(--border); }

.count-input {
  text-align: center;
  font-size: 1.5rem !important;
  font-weight: 700;
  min-height: 52px !important;
  -moz-appearance: textfield;
  appearance: textfield;
}
.count-input::-webkit-outer-spin-button,
.count-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- Sliding scale ---- */

.sliding-card {
  background: var(--pink-bg);
  border-color: var(--pink-border);
  border-left: 8px solid var(--type);
}

.sliding-entry {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--pink-border);
  margin-bottom: 10px;
}

.price-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-right: 44px; }
.price-label { font-weight: 700; }
.big-price { font-size: 2rem; font-weight: 800; line-height: 1.1; }

.price-range {
  width: 100%;
  min-height: 44px;
  accent-color: #DB2777;
  margin: 4px 0;
}

.exact-price {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  font-size: 0.95rem;
}
.exact-price label { color: var(--muted); }
.exact-price input { width: 7.5em; flex: none; }
.exact-price .hint { margin: 0; }

.sliding-count { display: grid; gap: 6px; }
.sliding-count .stepper { max-width: 280px; }

.remove-entry {
  position: absolute;
  top: 6px; right: 6px;
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.remove-entry:hover { background: var(--surface-2); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  font-weight: 600;
  padding: 10px 4px;
  min-height: 44px;
  cursor: pointer;
}

/* ---- Voice entry (optional) ---- */

.voice { margin: 4px 0 6px; }

.v-icon { width: 1.35em; height: 1.35em; flex: none; }

.voice-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
  border-radius: 14px;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}
.voice-btn:active { transform: translateY(1px); }
.voice-btn.is-active { background: var(--accent); color: var(--accent-text); }
.voice-btn[aria-disabled="true"] { cursor: progress; opacity: 0.75; }

.voice-privacy, .voice-unsupported {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.voice-status { margin: 8px 0 0; font-weight: 700; }
.voice-status:empty { display: none; }
.voice-status-line { display: flex; align-items: flex-start; gap: 8px; }
.voice-status-line .v-icon { margin-top: 1px; }
.voice-status-line.is-error { color: var(--error); }
.voice-status-line.is-done, .voice-status-line.is-filled { color: var(--you); }

.voice-transcript {
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-style: italic;
  overflow-wrap: anywhere;
}

.voice-review {
  margin-top: 12px;
  padding: 14px;
  border: 2px solid var(--accent);
  border-radius: 12px;
  background: var(--surface);
  min-width: 0;
  overflow-wrap: anywhere;
}
.voice-review-title { margin: 0 0 6px; font-size: 1.1rem; }
.voice-review-title:focus { outline: none; }
.voice-review-title:focus-visible { outline: 3px solid var(--focus); }
.voice-heard { margin: 0 0 10px; color: var(--muted); font-style: italic; }
.voice-empty { margin: 0 0 10px; }

.voice-lines, .voice-issues, .voice-notes { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.voice-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-left: 6px solid var(--type, var(--border));
  border-radius: 10px;
}
.vl-label { font-weight: 700; }
.vl-detail { color: var(--muted); }

.voice-issue {
  padding: 10px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-text);
}
.vi-q { margin: 0; display: flex; gap: 8px; align-items: flex-start; font-weight: 700; }
.vi-src { font-weight: 400; }
.vi-choices { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.choice-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 14px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
.vi-tag { margin: 6px 0 0; font-size: 0.85rem; }

.voice-notes li { display: flex; gap: 8px; align-items: flex-start; font-size: 0.9rem; color: var(--muted); }

.voice-conflict { margin: 0 0 10px; font-weight: 700; }
.voice-blocked {
  display: flex; gap: 8px; align-items: flex-start;
  margin: 0 0 10px; padding: 10px 12px; border-radius: 10px;
  background: var(--error-bg); color: var(--error); font-weight: 700;
}

.voice-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.voice-actions .voice-fill { grid-column: 1 / -1; }
.voice-primary {
  min-height: 52px;
  border: 2px solid var(--accent);
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
}
.voice-secondary {
  min-height: 48px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}

/* Fields just filled by voice: a brief outline, not colour alone (it fades). */
.voice-filled {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  transition: outline-color 0.6s ease;
}

/* ---- Rates ---- */

.rates-summary {
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  list-style: none;
  gap: 10px;
}
.rates-summary::-webkit-details-marker { display: none; }
.rates-summary::before { content: "\25B8"; font-size: 1rem; width: 1em; }
details[open] > .rates-summary::before { content: "\25BE"; }
.rates-summary .hint { margin: 0; font-weight: 400; font-size: 0.9rem; }
details[open] .rates-summary { margin-bottom: 8px; }

/* The whole row is the click/touch target (>= 48px high); the track stays centred. */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 4px 8px 4px 0;
  cursor: pointer;
  width: fit-content;
  max-width: 100%;
  font-weight: 600;
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 56px; height: 32px;
  flex: none;
  border-radius: 999px;
  background: #8A91A3;
  border: 2px solid #6B7285;
  cursor: pointer;
  margin: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  transition: transform 0.15s ease;
}
.switch:checked { background: var(--you); border-color: var(--you); }
.switch:checked::after { transform: translateX(24px); }
.switch:checked::before {
  content: "\2713";
  position: absolute;
  left: 8px; top: 2px;
  color: #FFFFFF;
  font-size: 0.9rem;
  font-weight: 700;
}

.note {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.rates-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.rates-table th, .rates-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.rates-table thead th { font-size: 0.85rem; color: var(--muted); }
.rates-table tbody th { font-weight: 500; }
.rates-table td { width: 9.5em; }
.money-wrap { display: flex; align-items: center; gap: 4px; }
.rate-value { font-weight: 700; }

.small-btn {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}

/* ---- Calculate ---- */

.calc-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.calc-btn {
  width: 100%;
  min-height: 58px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(55, 48, 163, 0.3);
}
.calc-btn:active { transform: translateY(1px); }

/* ---- Results ---- */

.results-card { scroll-margin-top: 12px; }
.results-title { margin: 0 0 12px; font-size: 1.3rem; overflow-wrap: anywhere; min-width: 0; }
.results-title:focus { outline: none; }
.results-title:focus-visible { outline: 3px solid var(--focus); }
.results-period { color: var(--muted); font-weight: 600; font-size: 1rem; }

.stale-note {
  background: var(--warn-bg);
  color: var(--warn-text);
  font-weight: 700;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
}
.stale-note::before { content: "\21BB\00a0"; }
.results-card.is-stale #results-body,
.results-card.is-stale .export { opacity: 0.6; }

.tiles-main, .tiles-small { display: grid; gap: 10px; margin-bottom: 10px; }
.tiles-main { grid-template-columns: 1fr; }
/* Small tiles wrap to a second row on phones so each amount has room. */
.tiles-small { grid-template-columns: repeat(auto-fit, minmax(min(100%, 8.5rem), 1fr)); }

.tile {
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.tile-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
/* Money never splits mid-number: no wrapping inside a value, and the font
   scales with the tile's own width so $99,999.99 fits a 360px phone. */
.tile { container-type: inline-size; }
.tile-value {
  font-size: 1.1rem; /* fallback: no container query units */
  font-size: clamp(0.8rem, 15cqi, 1.25rem);
  font-weight: 800;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  font-variant-numeric: tabular-nums;
}
.tile-extra { font-size: 0.85rem; color: var(--muted); }

.tile-you { background: var(--you-bg); border: 2px solid var(--you); }
.tile-clinic { background: var(--clinic-bg); border: 2px solid var(--clinic); }
.tile-you .tile-value, .tile-clinic .tile-value {
  font-size: 1.9rem; /* fallback: no container query units */
  font-size: clamp(1.5rem, 13cqi, 2.4rem);
  line-height: 1.1;
}
.tile-you .tile-label, .tile-clinic .tile-label { color: var(--text); font-size: 1rem; }

.breakdown-title { margin: 18px 0 8px; font-size: 1.1rem; }

/* Breakdown: stacked cards on phones, table on wider screens. */
.breakdown { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.breakdown thead { display: none; }
.breakdown, .breakdown tbody, .breakdown tfoot, .breakdown tr, .breakdown td { display: block; }

.breakdown .row-group {
  border: 1px solid var(--border);
  border-left: 8px solid var(--type);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
}
.breakdown .data-row td {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
}
.breakdown .data-row td::before {
  content: attr(data-label);
  color: var(--muted);
  font-weight: 600;
}
.breakdown .data-row td.col-service { font-weight: 700; font-size: 1.02rem; justify-content: flex-start; align-items: center; gap: 8px; }
.breakdown .data-row td.col-service::before { display: none; }
.breakdown td.you { font-weight: 700; color: var(--you); }
.breakdown .math-row td { padding: 4px 0 0; }
.math {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  color: var(--muted);
}
.empty-note { font-size: 0.85rem; color: var(--muted); }
.breakdown .is-empty td { color: var(--muted); font-weight: 400; }
.breakdown .is-empty td.you { color: var(--muted); }
.breakdown .is-empty .chip { opacity: 0.45; }

.breakdown tfoot tr {
  border: 2px solid var(--text);
  border-radius: 12px;
  padding: 8px 12px;
}
.breakdown tfoot td {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-weight: 700;
}
.breakdown tfoot td::before { content: attr(data-label); color: var(--muted); }
.breakdown tfoot td.col-service::before { display: none; }
.breakdown tfoot td:empty { display: none; }

/* ---- Export ---- */

.export { margin-top: 18px; }
.export-title { margin: 0 0 8px; font-size: 1.1rem; }

.summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin: 0 0 10px;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 22rem;
  overflow: auto;            /* scrolls inside itself, never widens the page */
  max-width: 100%;
  word-break: break-word;
}

.export-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-btn {
  min-height: 52px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}
.export-status { min-height: 1.5em; font-weight: 600; color: var(--you); margin: 8px 0 0; }
.export-status.is-error { color: var(--error); }

/* ---- Wider screens ---- */

@media (min-width: 560px) {
  .group-cards { grid-template-columns: 1fr 1fr; }
  .voice-btn { width: auto; min-width: 320px; }
  .tiles-main { grid-template-columns: 1fr 1fr; }
  .stepper { max-width: none; }
  .sliding-entry { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
  .sliding-entry .sliding-count { padding-right: 40px; }
}

@media (min-width: 800px) {
  body { font-size: 17px; }
  .calc-bar { position: static; background: none; }
  .calc-btn { max-width: 360px; display: block; margin: 0 auto; }

  .breakdown { display: table; }
  .breakdown thead { display: table-header-group; }
  .breakdown tbody { display: table-row-group; }
  .breakdown tfoot { display: table-footer-group; }
  .breakdown tr { display: table-row; }
  .breakdown td, .breakdown th { display: table-cell; }
  .breakdown th { text-align: left; font-size: 0.85rem; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--border); }
  .breakdown .row-group { border: none; }
  .breakdown .data-row td,
  .breakdown tfoot td { display: table-cell; padding: 8px 8px 0; }
  .breakdown .data-row td::before,
  .breakdown tfoot td::before { display: none; }
  .breakdown tfoot td:empty { display: table-cell; }
  .breakdown td.num, .breakdown th:nth-child(n+4) { text-align: right; white-space: nowrap; }
  .breakdown .math-row td { padding: 2px 8px 8px 30px; border-bottom: 1px solid var(--border); }
  .breakdown .data-row td.col-service { display: table-cell; }
  .breakdown .data-row td.col-service .chip { margin-right: 8px; }
  .breakdown tfoot tr { border: none; }
  .breakdown tfoot td { border-top: 2px solid var(--text); padding: 10px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
