:root {
  --ink: #0b1f3a;
  --muted: #5c6f88;
  --line: #d9e2ec;
  --paper: #ffffff;
  --wash: #f4f7fb;
  --blue: #0d5cab;
  --blue-dark: #072d59;
  --blue-soft: #e7f2ff;
  --orange: #f59e0b;
  --green: #0f766e;
  --red: #b42318;
  --shadow: 0 18px 50px rgba(11, 31, 58, 0.11);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(13, 92, 171, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(13, 92, 171, 0.035) 1px, transparent 1px),
    var(--wash);
  background-size: 32px 32px;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.foundation-shell { max-width: 1240px; margin: 0 auto; padding: 20px; }
.foundation-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 16px; border: 1px solid var(--line); border-radius: 18px;
  background: rgba(255,255,255,.94); position: sticky; top: 10px; z-index: 20;
  box-shadow: 0 8px 30px rgba(11,31,58,.08);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; }
.brand img { width: 38px; height: 38px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.text-button, .primary-button, .secondary-button {
  border: 0; border-radius: 999px; padding: 11px 17px; font-weight: 800;
}
.text-button, .secondary-button { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.primary-button { color: #fff; background: var(--blue-dark); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; }

.foundation-hero {
  margin-top: 18px; border-radius: 28px; padding: 48px;
  color: #fff; background:
    radial-gradient(circle at 88% 20%, rgba(245,158,11,.36), transparent 22%),
    linear-gradient(135deg, #0e67bd, #072d59 72%);
  box-shadow: var(--shadow); overflow: hidden; position: relative;
}
.foundation-hero::after {
  content: ""; position: absolute; right: -80px; bottom: -105px; width: 360px; height: 210px;
  border: 22px solid rgba(255,255,255,.09); transform: rotate(-8deg);
}
.eyebrow { margin: 0 0 10px; letter-spacing: .14em; text-transform: uppercase; font-size: 12px; font-weight: 900; }
.foundation-hero h1 { max-width: 780px; margin: 0; font-size: clamp(38px, 6vw, 72px); line-height: .96; letter-spacing: -.045em; }
.foundation-hero .lead { max-width: 760px; font-size: 18px; line-height: 1.6; color: #dbeafe; }
.hero-pills { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.hero-pills span { border: 1px solid rgba(255,255,255,.28); background: rgba(255,255,255,.1); padding: 9px 13px; border-radius: 999px; font-size: 13px; font-weight: 800; }

.safety-note {
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start;
  margin: 18px 0; padding: 18px; background: #fff7e6; border: 1px solid #f3cd7a; border-radius: 18px;
}
.safety-note strong { display: block; margin-bottom: 4px; }
.safety-icon { font-size: 24px; }

.progress-wrap { margin: 22px 0; }
.progress-meta { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 13px; font-weight: 800; }
.progress-track { height: 8px; background: #dce6f0; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 12.5%; background: linear-gradient(90deg, var(--orange), var(--blue)); transition: width .25s ease; }

.calculator-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; align-items: start; }
.stage {
  display: none; background: var(--paper); border: 1px solid var(--line); border-radius: 24px;
  padding: clamp(22px, 4vw, 38px); box-shadow: var(--shadow); scroll-margin-top: 96px;
}
.stage.is-active { display: block; animation: reveal .28s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
.stage-kicker { color: var(--blue); text-transform: uppercase; letter-spacing: .12em; font-weight: 900; font-size: 12px; }
.stage h2 { font-size: clamp(27px, 4vw, 42px); line-height: 1.05; margin: 8px 0 10px; letter-spacing: -.03em; }
.stage-intro { color: var(--muted); line-height: 1.6; margin: 0 0 25px; max-width: 760px; }
.section-title { margin: 28px 0 12px; font-size: 18px; }

.unit-picker {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 16px; margin: 0 0 22px; border: 1px solid var(--line);
  border-radius: 16px; background: var(--wash);
}
.unit-picker strong, .unit-picker span { display: block; }
.unit-picker span { margin-top: 4px; color: var(--muted); font-size: 13px; }
.unit-toggle { display: inline-flex; padding: 4px; background: #dfe8f2; border-radius: 999px; flex: 0 0 auto; }
.unit-toggle button {
  border: 0; border-radius: 999px; padding: 9px 15px; color: var(--muted);
  background: transparent; font-weight: 900;
}
.unit-toggle button.is-active { color: #fff; background: var(--blue-dark); }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 800; font-size: 14px; }
.field small { color: var(--muted); line-height: 1.4; }
input, select, textarea {
  width: 100%; min-height: 48px; border: 1px solid #c7d3e0; border-radius: 12px;
  padding: 11px 13px; color: var(--ink); background: #fff; outline: none;
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(13,92,171,.12); }
.choice-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.choice-card { position: relative; }
.choice-card input { position: absolute; opacity: 0; pointer-events: none; }
.choice-card label {
  display: block; height: 100%; padding: 18px; border: 1px solid var(--line); border-radius: 16px;
  background: #fff; cursor: pointer; transition: .18s ease;
}
.choice-card label strong { display: block; font-size: 17px; margin-bottom: 5px; }
.choice-card label span { color: var(--muted); font-size: 13px; line-height: 1.45; }
.choice-card input:checked + label { border-color: var(--blue); background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue); }
.toggle-line { display: flex; gap: 10px; align-items: flex-start; padding: 13px; border: 1px solid var(--line); border-radius: 13px; }
.toggle-line input { width: 20px; min-height: 20px; margin-top: 1px; }
.toggle-line label { line-height: 1.45; }
.info-box, .warning-box, .danger-box {
  padding: 16px; border-radius: 14px; margin: 16px 0; line-height: 1.55;
}
.info-box { background: var(--blue-soft); border-left: 4px solid var(--blue); }
.warning-box { background: #fff7e6; border-left: 4px solid var(--orange); }
.danger-box { background: #fff0ee; border-left: 4px solid var(--red); color: #6b1812; }
.conditional[hidden] { display: none !important; }

.stage-nav { display: none; }
.calculator-footer-nav {
  position: sticky; bottom: 12px; z-index: 18; display: grid;
  grid-template-columns: minmax(110px, auto) 1fr minmax(160px, auto);
  gap: 12px; align-items: center; margin-top: 16px; padding: 12px;
  border: 1px solid #cbd8e5; border-radius: 18px;
  background: rgba(255,255,255,.96); box-shadow: 0 14px 40px rgba(11,31,58,.18);
  backdrop-filter: blur(12px);
}
.footer-stage-copy { min-width: 0; text-align: center; }
.footer-stage-copy span, .footer-stage-copy strong { display: block; }
.footer-stage-copy span { color: var(--muted); font-size: 12px; font-weight: 800; }
.footer-stage-copy strong { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar { position: sticky; top: 92px; display: grid; gap: 14px; }
.side-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: 0 9px 28px rgba(11,31,58,.07); }
.side-card h3 { margin: 0 0 8px; font-size: 17px; }
.side-card p { margin: 0; color: var(--muted); line-height: 1.55; font-size: 14px; }
.stage-list { display: grid; gap: 5px; margin-top: 12px; }
.stage-link { display: flex; gap: 10px; align-items: center; border: 0; background: transparent; padding: 8px; text-align: left; color: var(--muted); border-radius: 10px; }
.stage-link span { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; background: #edf2f7; font-size: 12px; font-weight: 900; }
.stage-link.is-active { color: var(--blue-dark); background: var(--blue-soft); font-weight: 800; }
.autosave-status { color: var(--green) !important; font-weight: 800; }

.steel-table, .boq-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.steel-table th, .steel-table td, .boq-table th, .boq-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; }
.steel-table th, .boq-table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.steel-table input, .steel-table select { min-height: 42px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
.remove-row { border: 0; background: #fff0ee; color: var(--red); border-radius: 9px; padding: 9px; font-weight: 900; }

.review-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.review-item { padding: 16px; border-radius: 14px; background: var(--wash); border: 1px solid var(--line); }
.review-item span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 900; }
.review-item strong { display: block; margin-top: 5px; }
#paywallHost { margin-top: 20px; }

.results-wrap { display: grid; gap: 18px; }
.estimate-identity {
  display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px;
  color: #fff; background: var(--blue-dark); border-color: var(--blue-dark);
}
.estimate-identity span, .estimate-identity strong { display: block; }
.estimate-identity span { color: #bfdbfe; font-size: 11px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.estimate-identity strong { margin-top: 5px; overflow-wrap: anywhere; }
.result-stats { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.result-stat { padding: 18px; border-radius: 15px; color: #fff; background: linear-gradient(145deg, var(--blue), var(--blue-dark)); }
.result-stat span { display: block; color: #dbeafe; font-size: 12px; }
.result-stat strong { display: block; font-size: 23px; margin-top: 5px; }
.result-section { border: 1px solid var(--line); border-radius: 17px; padding: 20px; }
.result-section h3 { margin: 0 0 14px; }
.grand-total { font-size: 24px; font-weight: 900; color: var(--blue-dark); }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.empty-results { padding: 28px; text-align: center; color: var(--muted); background: var(--wash); border-radius: 16px; }

@media (max-width: 900px) {
  .calculator-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; order: -1; }
  .stage-list { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .stage-link { justify-content: center; }
  .stage-link b { display: none; }
  .field-grid.three { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .result-stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 620px) {
  .foundation-shell { padding: 10px; }
  .foundation-topbar { top: 4px; }
  .brand span { display: none; }
  .foundation-hero { padding: 32px 22px; border-radius: 22px; }
  .field-grid, .field-grid.three, .choice-grid, .review-grid { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: 1fr 1fr; }
  .estimate-identity { grid-template-columns: 1fr; }
  .stage { padding: 22px 16px; border-radius: 18px; }
  .unit-picker { align-items: stretch; flex-direction: column; }
  .unit-toggle { align-self: flex-start; }
  .calculator-footer-nav {
    bottom: 6px; grid-template-columns: auto 1fr auto; gap: 7px;
    padding: 9px; border-radius: 15px;
  }
  .calculator-footer-nav .primary-button,
  .calculator-footer-nav .secondary-button { padding: 10px 12px; }
  .footer-stage-copy strong { font-size: 13px; }
  .footer-stage-copy span { font-size: 10px; }
}

@media print {
  body { background: #fff; }
  .foundation-topbar, .foundation-hero, .safety-note, .progress-wrap, .sidebar,
  .stage:not([data-stage="8"]), .stage-nav, .calculator-footer-nav, #paywallHost, .result-actions { display: none !important; }
  .foundation-shell { max-width: none; padding: 0; }
  .calculator-layout { display: block; }
  .stage[data-stage="8"] { display: block !important; box-shadow: none; border: 0; padding: 0; }
  .result-stat { color: #000; background: #fff; border: 1px solid #bbb; }
  .result-stat span { color: #555; }
  .estimate-identity { color: #000; background: #fff; border-color: #bbb; }
  .estimate-identity span { color: #555; }
  .result-section, .warning-box, .danger-box { break-inside: avoid; }
}
