/* Treadwell Proposal Generator — minimal styling.
   Single file so the 4 screens share visual language without a build step. */

:root {
  --treadwell-red:       #9e001f;
  --treadwell-red-dark:  #6c0015;
  --treadwell-red-light: #ffdad8;
  --ink:                 #1a1a1a;
  --ink-variant:         #5c403f;
  --surface:             #fbf9f8;
  --surface-low:         #f3eeed;
  --surface-dim:         #dbdad9;
  --surface-lowest:      #ffffff;
  --success:             #16a34a;
  --warning:             #f59e0b;
  --danger:              #ba1a1a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--surface-dim);
  background: var(--surface-lowest);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: inline-flex;
  width: 36px; height: 36px;
  background: var(--treadwell-red);
  color: white;
  font-weight: 800;
  font-size: 18px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.brand-name { font-weight: 800; font-size: 16px; }
.brand-sub  { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-variant); }
.progress   { display: flex; gap: 4px; flex-wrap: wrap; }
.progress .step {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-variant);
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--surface-low);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}
.progress a.step:hover {
  background: var(--treadwell-red-light);
  color: var(--treadwell-red-dark);
}
.progress .step.active {
  background: var(--treadwell-red);
  color: white;
  font-weight: 700;
  cursor: default;
}
.progress .step.active:hover { background: var(--treadwell-red); color: white; }

/* ─── Container ───────────────────────────────────────────────────── */
.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}
.container.wide { max-width: 1200px; }

h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--treadwell-red-dark);
  margin: 0 0 4px;
}
h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin: 24px 0 8px;
}
.lede { color: var(--ink-variant); margin: 0 0 24px; }

/* ─── Forms ───────────────────────────────────────────────────────── */
fieldset {
  border: 1px solid var(--surface-dim);
  border-radius: 8px;
  padding: 16px 20px 20px;
  margin: 0 0 16px;
  background: var(--surface-lowest);
}
legend {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--treadwell-red-dark);
  padding: 0 6px;
}
.hint { font-size: 12px; color: var(--ink-variant); margin: 0 0 12px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin: 12px 0 0;
}
input[type="text"], input[type="email"], input[type="number"],
input[type="date"], textarea, select {
  width: 100%;
  display: block;
  margin-top: 4px;
  padding: 8px 10px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--surface-dim);
  border-radius: 4px;
  min-height: 36px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--treadwell-red-light);
  outline-offset: 1px;
  border-color: var(--treadwell-red);
}
textarea {
  min-height: 100px;
  resize: vertical;
  /* Keep wheel scroll on the textarea from "trapping" the page —
     once the textarea hits top/bottom, the wheel rolls up to the page. */
  overscroll-behavior: contain;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.row.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 600px) {
  .row, .row.three { grid-template-columns: 1fr; }
}

.radio-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }
.radio { display: inline-flex; gap: 6px; align-items: center; font-weight: 500; cursor: pointer; }
.radio input { width: auto; min-height: 0; margin: 0; }

/* ─── Buttons ─────────────────────────────────────────────────────── */
/* Always-visible action bar pinned to the bottom of the viewport.
   Needs body padding-bottom so the last fieldset isn't covered. */
.actions.sticky-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface-lowest);
  padding: 14px 24px;
  margin: 0;
  border-top: 1px solid var(--surface-dim);
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.06);
  z-index: 50;
  justify-content: flex-end;
}
.actions.sticky-bottom button {
  min-width: 280px;
}
/* Give the form room so the floating bar never covers its last input */
body:has(.actions.sticky-bottom) main.container { padding-bottom: 100px; }
@media (max-width: 768px) {
  .actions.sticky-bottom { padding: 10px 14px; }
  .actions.sticky-bottom button { min-width: 0; width: 100%; }
  body:has(.actions.sticky-bottom) main.container { padding-bottom: 90px; }
}
.actions {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 24px;
  flex-wrap: wrap;
}
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 700;
}
.btn-primary {
  background: var(--treadwell-red);
  color: white;
  border-color: var(--treadwell-red-dark);
}
.btn-primary:hover { background: var(--treadwell-red-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }
.btn-secondary {
  background: var(--surface-lowest);
  color: var(--ink);
  border-color: var(--surface-dim);
}
.btn-secondary:hover { background: var(--surface-low); }

/* ─── Two-column layout (estimate review) ────────────────────────── */
.split {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
}
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.totals-card {
  background: var(--surface-lowest);
  border: 1px solid var(--surface-dim);
  border-radius: 8px;
  padding: 20px;
  position: sticky;
  top: 24px;
  align-self: start;
}
.totals-card h2 { margin-top: 0; }
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px dashed var(--surface-dim);
  font-size: 13px;
}
.totals-row:last-child { border-bottom: none; }
.totals-row .label { color: var(--ink-variant); }
.totals-row.total {
  margin-top: 12px;
  padding: 12px 0 0;
  border-top: 2px solid var(--treadwell-red);
  border-bottom: none;
  font-weight: 800;
  font-size: 18px;
  color: var(--treadwell-red-dark);
}

/* ─── Canonical (locked) block on proposal review ─────────────────── */
.canonical-block {
  background: var(--surface-low);
  border-left: 4px solid var(--treadwell-red);
  padding: 12px 16px;
  margin: 0 0 24px;
  border-radius: 0 6px 6px 0;
}
.canonical-block dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-variant);
  font-weight: 700;
  margin-top: 8px;
}
.canonical-block dt:first-child { margin-top: 0; }
.canonical-block dd { margin: 2px 0 0; font-weight: 600; }

/* ─── Done screen ─────────────────────────────────────────────────── */
.success-card {
  background: var(--surface-lowest);
  border: 1px solid var(--surface-dim);
  border-radius: 10px;
  padding: 32px;
  text-align: center;
}
.success-mark {
  display: inline-flex;
  width: 64px; height: 64px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 16px;
}
.download-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.download-link {
  display: inline-block;
  padding: 12px 20px;
  background: var(--treadwell-red);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 700;
  font: inherit;
  font-weight: 700;
  border: none;
  cursor: pointer;
}
.download-link:hover { background: var(--treadwell-red-dark); }
.download-link:disabled { opacity: 0.6; cursor: wait; }
.download-link.secondary {
  background: var(--surface-lowest);
  color: var(--treadwell-red-dark);
  border: 1px solid var(--treadwell-red);
}

/* ═══ Mobile responsive ═══════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Topbar collapses into a stack */
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px 14px; }
  .progress { flex-wrap: wrap; justify-content: flex-start; }
  .progress .step { font-size: 10px; padding: 3px 8px; }

  /* Container loses its desktop padding */
  .container { padding: 16px 12px 48px; }
  .container.wide { padding: 12px; }

  /* Headlines smaller */
  h1 { font-size: 22px; }
  h2 { font-size: 16px; }

  /* Form rows stack vertically */
  .row, .row.three { grid-template-columns: 1fr; gap: 8px; }

  /* Fieldsets get tighter padding */
  fieldset { padding: 12px 14px; margin-bottom: 12px; }

  /* Buttons take full width on phones */
  .actions { flex-direction: column-reverse; gap: 8px; }
  .actions button { width: 100%; }

  /* Topbar progress should wrap nicely */
  .progress { gap: 4px; }
}

@media (max-width: 480px) {
  /* On very narrow phones, drop the brand subtitle to save vertical space */
  .brand-sub { display: none; }
  .progress .step { font-size: 9px; letter-spacing: 0.03em; }
}

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin: 16px 0;
  font-size: 13px;
}
.alert-info { background: #e0f2fe; color: #075985; border-left: 4px solid #0284c7; }
.alert-warn { background: #fef3c7; color: #92400e; border-left: 4px solid #f59e0b; }
.alert-error { background: #fee2e2; color: #991b1b; border-left: 4px solid #dc2626; }

/* ─── Detected-type badge ─────────────────────────────────────────── */
.type-badge {
  display: inline-block;
  background: var(--treadwell-red);
  color: white;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 99px;
  margin-left: 8px;
}

/* ─── Spreadsheet-style grid (estimate review) ────────────────────── */
/* Colors lifted from Kyle's actual estimate sheet 5.7.xlsx */
:root {
  --xl-input:        #fff4a3;  /* light yellow — editable cells (most inputs) */
  --xl-toggle:       #ffff00;  /* bright yellow — Yes/No toggles in rows 4-6 */
  --xl-calc:         #c6efce;  /* light green — material computed cells */
  --xl-total:        #41ecff;  /* cyan — section subtotals + grand totals */
  --xl-polish-labor: #92d050;  /* dark green — polish-specific labor */
  --xl-note:         #d4beff;  /* light purple — help-text cells */
  --xl-border:       #b1b1b1;  /* Excel cell gridline */
  --xl-header-bg:    #f3f3f3;  /* column/row headers */
}

.xl-tab-bar {
  display: flex;
  gap: 2px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--xl-border);
}
.xl-tab-bar button {
  background: var(--xl-header-bg);
  border: 1px solid var(--xl-border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  padding: 6px 18px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-variant);
  cursor: pointer;
}
.xl-tab-bar button.active {
  background: white;
  color: var(--treadwell-red-dark);
  border-bottom: 1px solid white;
  margin-bottom: -1px;
  position: relative;
  z-index: 1;
}

.xl-sheet {
  background: white;
  border: 1px solid var(--xl-border);
  border-top: none;
  font-family: "Calibri", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  color: var(--ink);
  overflow-x: auto;
}

/* Column letter header row */
.xl-col-headers {
  display: grid;
  background: var(--xl-header-bg);
  border-bottom: 1px solid var(--xl-border);
  font-weight: 600;
  font-size: 10px;
  color: var(--ink-variant);
  text-align: center;
}
.xl-col-headers > div {
  padding: 3px 0;
  border-right: 1px solid var(--xl-border);
}
.xl-col-headers > div:first-child {
  background: var(--xl-header-bg);
}

/* Each cell row */
.xl-row {
  display: grid;
  border-bottom: 1px solid var(--xl-border);
  min-height: 22px;
}
.xl-row > div {
  border-right: 1px solid var(--xl-border);
  padding: 2px 6px;
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.xl-row-num {
  background: var(--xl-header-bg);
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-variant);
  justify-content: center !important;
  text-align: center;
}

/* Cell type variants */
.xl-cell-input    { background: var(--xl-input);  }
.xl-cell-toggle   { background: var(--xl-toggle); font-weight: 700; }
.xl-cell-calc     { background: var(--xl-calc);   font-variant-numeric: tabular-nums; justify-content: flex-end; }
.xl-cell-total    { background: var(--xl-total);  font-variant-numeric: tabular-nums; font-weight: 800; justify-content: flex-end; }
.xl-cell-polish   { background: var(--xl-polish-labor); }
.xl-cell-note     { background: var(--xl-note);  font-style: italic; font-size: 10px; color: var(--ink-variant); }
.xl-cell-label    { font-weight: 600; }
.xl-cell-section-header {
  background: var(--treadwell-red);
  color: white;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  justify-content: flex-start !important;
}
.xl-cell-section-header.span-all {
  grid-column: 2 / -1;
}
.xl-cell-numeric { font-variant-numeric: tabular-nums; justify-content: flex-end; }
.xl-cell-bold    { font-weight: 700; }
.xl-cell-blank   { background: white; }

/* Inputs inside cells */
.xl-row input[type="text"],
.xl-row input[type="number"],
.xl-row input[type="date"],
.xl-row select {
  width: 100%;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 0;
  margin: 0;
  min-height: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
  border-radius: 0;
}
.xl-row input[type="text"],
.xl-row input[type="date"],
.xl-row select {
  text-align: left;
}
.xl-row input:focus,
.xl-row select:focus {
  outline: 2px solid var(--treadwell-red);
  outline-offset: -2px;
  background: white;
}

/* Grid templates — A=2.5fr | B=1.5fr | C=1.5fr | D=1.7fr | E=2fr | F=1.2fr | G=1.2fr | H=1.5fr  */
/* Row-number column = 30px */
.xl-col-headers,
.xl-row {
  grid-template-columns:
    30px           /* row # */
    minmax(200px, 2.5fr)  /* A */
    minmax(110px, 1.5fr)  /* B */
    minmax(110px, 1.5fr)  /* C */
    minmax(130px, 1.7fr)  /* D */
    minmax(120px, 2fr)    /* E */
    minmax(100px, 1.2fr)  /* F */
    minmax(100px, 1.2fr)  /* G */
    minmax(110px, 1.5fr); /* H */
}

/* Polish has a slightly different layout but reuses same grid */
