/* KBID Proposal Generator — single stylesheet.
   Tokens + visual language ported from the approved Claude Design UI
   (KBID = modern luxury minimalism: warm ivory, camel accent, Fraunces + Inter). */
:root {
  --paper: #F7F5F0;
  --ink: #1A1A1A;
  --greige: #E4DFD6;
  --line: #C9C2B6;
  --accent: #A9855F;
  --accent-dark: #8A6A48;
  --muted: #6F6858;
  --card: #FDFCF9;
  --good: #5E7D5A;
  --warn: #B08A3E;
  --danger: #9E3B2E;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 2px 14px rgba(26, 26, 26, .05);
  --shadow-pop: 0 12px 32px rgba(26, 26, 26, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); overflow-x: hidden; }
input, button, textarea, select { font: inherit; color: inherit; }
textarea { resize: vertical; }
::placeholder { color: #A39B8B; opacity: 1; }
::selection { background: #E6D9C6; }
a { color: var(--accent-dark); text-underline-offset: 2px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; }
@keyframes kbfade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes kbspin { to { transform: rotate(360deg); } }

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

/* ---------- header + stage bar ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: rgba(247,245,240,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--greige); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }
.brand .mark { font-family: var(--serif); font-weight: 600; font-size: 20px; letter-spacing: .18em; }
.brand .sub { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.stages { flex: 1; display: flex; justify-content: center; min-width: 0; }
.stages ol { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.stages li { display: flex; align-items: center; gap: 4px; }
.stage-btn { display: flex; align-items: center; gap: 8px; border: none; background: transparent; padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; color: var(--muted); white-space: nowrap; }
.stage-btn:hover { background: #EFEAE0; }
.stage-btn[aria-current="true"] { color: var(--ink); font-weight: 500; }
.stage-num { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; }
.stage-btn[aria-current="true"] .stage-num { background: var(--accent); color: #fff; border-color: var(--accent); }
.stage-btn.done .stage-num { background: var(--ink); color: #fff; border-color: var(--ink); }
.stage-sep { width: 22px; height: 1px; background: var(--line); }
.stages .mobile-stage { font-size: 12px; color: var(--muted); white-space: nowrap; }
.stages .mobile-stage b { color: var(--ink); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.save-ind { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.save-dot.saving { background: var(--warn); }
.save-dot.saved { background: var(--good); }
.user-chip { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }

/* ---------- main ---------- */
main.content { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 28px 20px 120px; }
main.content.wide { max-width: none; margin: 0; padding: 0 0 70px; display: flex; }
main.content.wide .estimate-workspace { flex: 1 1 auto; height: calc(100vh - 130px); min-height: 480px; border-left: none; border-right: none; }
.card { background: var(--card); border: 1px solid var(--greige); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 32px; animation: kbfade .18s ease; }
.eyebrow { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-dark); font-weight: 600; }
.step-head { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 22px; }
.step-head .right { font-size: 12px; color: var(--muted); }
h1.title { font-size: 27px; margin: 6px 0 4px; }
h2.title { font-size: 20px; }
.lede { color: var(--muted); font-size: 14.5px; line-height: 1.6; margin: 0 0 20px; }
.intake-step-nav { margin: -2px 0 14px; overflow-x: auto; scrollbar-width: thin; }
.intake-step-nav ol { display: flex; gap: 6px; list-style: none; margin: 0; padding: 2px 0 6px; min-width: max-content; }
.intake-step-btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px 6px 6px; background: #fff; color: var(--muted); cursor: pointer; font-size: 12px; white-space: nowrap; }
.intake-step-btn:hover { border-color: var(--accent); background: #FBF6EE; }
.intake-step-btn.current { border-color: var(--accent); background: #FBF6EE; color: var(--ink); font-weight: 600; }
.intake-step-btn.incomplete { border-color: #C99354; color: #7A4B17; }
.intake-step-num { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #EFEAE0; color: var(--muted); font-size: 11px; font-weight: 700; }
.intake-step-btn.current .intake-step-num { background: var(--accent); color: #fff; }
.intake-step-btn.incomplete .intake-step-num { background: #F5E1C2; color: #8A5B1F; }
.intake-step-alert { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: -2px; border-radius: 50%; background: #C99354; color: #fff; font-size: 11px; font-weight: 800; }
.required-mark { color: var(--danger); font-size: 10px; font-weight: 700; letter-spacing: .04em; margin-left: 4px; text-transform: uppercase; }
.required-input, input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: #C99354 !important; background: #FFF9F0 !important; }
.required-choice { border-left: 3px solid #C99354; padding-left: 10px; }

/* ---------- forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; font-size: 14px;
}
textarea { min-height: 120px; line-height: 1.55; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* selectable cards (radio / checkbox) */
.select-grid { display: grid; gap: 10px; }
.select-card { display: flex; align-items: flex-start; gap: 12px; border: 1px solid var(--line); background: #fff; border-radius: var(--radius-sm); padding: 14px 16px; cursor: pointer; text-align: left; transition: border-color .12s, background .12s; }
.select-card:hover { background: #FBF8F2; }
.select-card .tick { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line); flex-shrink: 0; margin-top: 1px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; color: transparent; }
.select-card.checkbox .tick { border-radius: 5px; }
.select-card .t { font-weight: 500; font-size: 14.5px; }
.select-card .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.select-card[aria-pressed="true"] { border-color: var(--accent); background: #FBF6EE; box-shadow: inset 0 0 0 1px var(--accent); }
.select-card[aria-pressed="true"] .tick { background: var(--accent); border-color: var(--accent); color: #fff; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 13px; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: #FBF6EE; color: var(--ink); font-weight: 500; }

/* pills (exclusions) */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 8px 6px 14px; font-size: 13px; }
.pill button { border: none; background: #EFEAE0; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; color: var(--muted); line-height: 1; }
.pill button:hover { background: var(--danger); color: #fff; }

/* ---------- estimate workbook ---------- */
.estimate-workspace { display: flex; flex-direction: column; border: 1px solid #B7B7B7; background: #fff; color: #111; font-family: Calibri, Arial, sans-serif; box-shadow: 0 2px 12px rgba(26, 26, 26, .08); }
.est-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 9px 12px; background: #F3F3F3; border-bottom: 1px solid #C8C8C8; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: none; background: #fff; padding: 7px 11px; cursor: pointer; font-size: 12px; color: #444; }
.seg button.on, .sheet-round.on { background: #545454; border-color: #545454; color: #fff; }
.sheet-round { margin-left: auto; font-size: 12px; padding: 7px 11px; }
.workbook-tabs { display: flex; gap: 2px; overflow-x: auto; padding: 8px 8px 0; background: #E9E9E9; border-bottom: 1px solid #B7B7B7; }
.workbook-tab { border: 1px solid #B7B7B7; border-bottom: none; padding: 7px 14px; background: #D9D9D9; color: #333; font: 600 12px Calibri, Arial, sans-serif; cursor: pointer; white-space: nowrap; }
.workbook-tab.active { background: #fff; position: relative; top: 1px; color: #111; }
.formula-bar { display: grid; grid-template-columns: 76px 28px minmax(180px, 1fr); align-items: center; gap: 7px; padding: 6px 10px; border-bottom: 1px solid #C8C8C8; background: #F7F7F7; font: 12px Calibri, Arial, sans-serif; }
.formula-bar input { width: 100%; min-height: 28px; border: 1px solid #B7B7B7; border-radius: 0; padding: 4px 7px; background: #fff; }
.formula-bar input:disabled { background: #EEE; color: #666; }
.formula-name { text-align: center; }
.sheet-viewport { position: relative; flex: 1 1 auto; overflow: auto; min-height: 0; background: #fff; }
.sheet-empty { display: grid; place-items: center; min-height: 360px; padding: 32px; color: #666; font-size: 14px; }
.sheet-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font: 12px Calibri, Arial, sans-serif; }
.sheet-table th, .sheet-table td { min-width: 90px; height: 28px; border-right: 1px solid #D1D1D1; border-bottom: 1px solid #D1D1D1; padding: 3px 6px; white-space: nowrap; }
.sheet-columns th { position: sticky; top: 0; z-index: 5; min-width: 72px; height: 23px; padding: 2px 6px; background: #F3F3F3; color: #444; text-align: center; font-size: 11px; font-weight: 600; }
.col-resize { position: absolute; z-index: 9; top: 0; right: -4px; bottom: 0; width: 8px; cursor: col-resize; }
.row-resize { position: absolute; z-index: 9; right: 0; bottom: -4px; left: 0; height: 8px; cursor: row-resize; }
.col-resize:hover, .row-resize:hover { background: rgba(175, 126, 79, .45); }
.sheet-resize-ghost { position: absolute; z-index: 40; pointer-events: none; background: #AF7E4F; opacity: .75; }
.sheet-resize-ghost.col { top: 0; bottom: 0; width: 2px; }
.sheet-resize-ghost.row { right: 0; left: 0; height: 2px; }
.resizing-sheet { user-select: none; }
.sheet-corner, .sheet-row { position: sticky; left: 0; z-index: 6; min-width: 42px !important; width: 42px; background: #F3F3F3; color: #555; text-align: center; font-size: 11px; font-weight: 600; }
.sheet-columns .sheet-corner { z-index: 7; }
.sheet-title, .sheet-phase { background: #D9D9D9; color: #111; font-weight: 700; text-align: left; }
.sheet-phase { text-align: center; background: #C4AACE; }
.sheet-label { position: sticky; left: 42px; z-index: 4; min-width: 196px !important; background: #fff; color: #111; font-weight: 600; }
.sheet-label span { color: #666; font-weight: 400; }
.sheet-label.muted { color: #666; }
.sheet-role-edit { position: sticky; left: 42px; z-index: 4; min-width: 196px !important; }
.sheet-role-edit input { text-align: left !important; font-weight: 600; }
.editable-row-head { overflow: visible; }
.editable-row-head > button { width: 100%; height: 100%; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; }
.editable-row-head > button:hover { background: #DDD; }
.row-menu { position: absolute; z-index: 30; top: 25px; left: 34px; width: 160px; padding: 5px; background: #fff; border: 1px solid #AAA; box-shadow: 0 8px 24px rgba(0,0,0,.22); text-align: left; }
.row-menu button { display: block; width: 100%; border: 0; background: transparent; padding: 7px 9px; text-align: left; color: #222; cursor: pointer; font-size: 12px; }
.row-menu button:hover { background: #EFEFEF; }
.row-menu button.danger { color: var(--danger); }
.sheet-cell { text-align: right; font-variant-numeric: tabular-nums; background: #fff; }
.sheet-edit { padding: 0 !important; background: #FFFFCC; }
.sheet-edit input { width: 100%; height: 100%; min-height: 27px; border: 2px solid transparent; border-radius: 0; padding: 3px 6px; background: #FFFFCC; text-align: right; font: inherit; outline: none; }
.sheet-edit input[type=text], .sheet-edit input[type=date] { text-align: left; }
.sheet-edit:focus-within { outline: 2px solid #4285F4; outline-offset: -2px; }
.sheet-edit.formula-cell input { color: #5C403F; font-style: italic; }
.sheet-edit.formula-error input { color: #B42318; }
.sheet-calc { color: #333; background: #F3F3F3; }
.sheet-calc:focus { outline: 2px solid #4285F4; outline-offset: -2px; }
.sheet-total td, .sheet-total .sheet-label { border-top: 2px solid #555; background: #EFEFEF; font-weight: 700; }
.simple-sheet { min-width: 540px; max-width: 760px; }
.simple-sheet .sheet-cell { min-width: 300px; }
.estimate-total-bar { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; padding: 9px 14px; border-top: 1px solid #AFAFAF; background: #F3F3F3; font: 12px Calibri, Arial, sans-serif; }
.estimate-total-bar > div { display: flex; align-items: baseline; gap: 7px; }
.estimate-total-bar strong { font-size: 17px; }
.tb-label { color: #666; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.estimate-total-bar .good { color: #277338; font-weight: 700; }
.estimate-total-bar .warn { color: #9A5D10; font-weight: 700; }
.toggle { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--line); border: none; cursor: pointer; }
.toggle.on { background: var(--accent); }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on::after { left: 20px; }

/* proposal preview */
.doc-preview { background: #fff; border: 1px solid var(--greige); border-radius: var(--radius); padding: 28px; font-size: 13.5px; line-height: 1.6; }
.doc-preview h3 { font-size: 16px; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin: 20px 0 8px; }
.section-block { margin-bottom: 8px; }
.section-block .edit { font-size: 12px; }

/* files */
.files-center { text-align: center; }
.check-circle { width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 24px; color: var(--accent); margin-bottom: 10px; }
.dl-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 18px 0 8px; }
.feedback-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.feedback-grid .fb { border: 1px solid var(--greige); border-radius: var(--radius-sm); padding: 16px; }

/* ---------- buttons + footer ---------- */
.btn { border: 1px solid var(--line); background: #fff; padding: 10px 18px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; }
.btn:hover { background: #EFEAE0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.footer-nav { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(247,245,240,.94); backdrop-filter: blur(8px); border-top: 1px solid var(--greige); }
.footer-inner { max-width: 860px; margin: 0 auto; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; }

/* gate / loading */
.center-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 40px 24px; text-align: center; }
.center-screen .mark { font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: .18em; }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: kbspin .8s linear infinite; }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .est-layout { grid-template-columns: 1fr; }
  .summary { position: static; }
  .two-col, .feedback-grid { grid-template-columns: 1fr; }
  .stages ol { display: none; }
  .topbar-inner { gap: 10px; }
}
@media (min-width: 821px) { .stages .mobile-stage { display: none; } }
