:root {
  --ink: #183134;
  --muted: #617476;
  --primary: #087f78;
  --primary-dark: #05655f;
  --soft: #e9f7f5;
  --page: #f4f8f7;
  --surface: #fff;
  --line: #dce7e6;
  --danger: #a63232;
  --danger-soft: #fff1f1;
  --warning: #996200;
  --warning-soft: #fff9e6;
  --success: #177a42;
  --success-soft: #eefaf2;
  --accent: #205493;
  --accent-soft: #edf4fc;
  --shadow: 0 18px 50px rgba(20, 55, 55, 0.09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.55;
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }
a { color: var(--primary-dark); }

.page-shell {
  width: min(1120px, calc(100% - 32px));
  margin: auto;
  padding: 48px 0 72px;
}

.hero {
  max-width: 850px;
  margin: 0 auto 32px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 3.7rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.subtitle {
  max-width: 760px;
  margin: 16px auto 0;
  color: #40595b;
  font-size: 1.08rem;
}

.hero-note {
  max-width: 720px;
  margin: 12px auto 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.panel, .result-card, .education, .cdi-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calculator-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(350px, 0.92fr);
  align-items: start;
  gap: 20px;
}

.steps-column {
  display: grid;
  gap: 18px;
}

.panel {
  padding: clamp(20px, 3vw, 28px);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.step {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 900;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  min-width: 0;
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: #284346;
  font-size: 0.88rem;
  font-weight: 800;
}

.optional {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.8rem;
}

.field input, .field select {
  width: 100%;
  min-width: 0;
  min-height: 50px;
  padding: 11px 13px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  outline: 0;
}

.field select {
  cursor: pointer;
  appearance: auto;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #bfcfcd;
}

.field select:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 127, 120, 0.14);
}

.input-affix {
  overflow: hidden;
  border: 1px solid #bfcfcd;
  border-radius: 10px;
  display: flex;
  align-items: center;
  background: #fff;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.input-affix:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 127, 120, 0.14);
}

.input-affix:has(input[aria-invalid="true"]) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.input-affix span {
  padding-left: 13px;
  color: #567073;
  font-weight: 800;
}

.input-affix.suffix span {
  padding: 0 13px 0 6px;
}

.input-affix:not(.suffix) input {
  padding-left: 7px;
}

.helper, .error {
  display: block;
  margin-top: 6px;
  font-size: 0.77rem;
  line-height: 1.45;
}

.helper {
  color: var(--muted);
}

.error {
  min-height: 1.1em;
  color: var(--danger);
  font-weight: 750;
}

.running-total {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
}

.running-total span {
  color: #3d585b;
}

.running-total strong {
  color: var(--primary-dark);
  font-size: 1.05rem;
}

.text-button {
  margin-top: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: underline;
  cursor: pointer;
}

.text-button:hover {
  color: var(--primary);
}

.presets-row {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-chip {
  padding: 5px 10px;
  border: 1px solid #c0d8d5;
  border-radius: 999px;
  background: #f7fbfb;
  color: var(--primary-dark);
  font-size: 0.76rem;
  font-weight: 750;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-chip:hover, .preset-chip:focus-visible {
  background: var(--soft);
  border-color: var(--primary);
}

.slider-wrap {
  margin-top: 10px;
}

.slider-wrap input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
}

.calculator-actions {
  padding: 4px 2px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.calculator-actions p {
  flex: 1 0 100%;
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.button {
  min-height: 48px;
  padding: 11px 17px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 850;
  cursor: pointer;
}

.button:focus-visible, summary:focus-visible, .related-grid a:focus-visible {
  outline: 3px solid rgba(8, 127, 120, 0.2);
  outline-offset: 2px;
}

.button.primary {
  background: var(--primary);
  color: #fff;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.secondary {
  border-color: #b9ccca;
  background: #fff;
  color: #365456;
}

.button.secondary:hover {
  background: var(--soft);
}

/* Result Card */
.result-card {
  position: sticky;
  top: 18px;
  padding: clamp(24px, 3vw, 34px);
  overflow: hidden;
}

.result-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--primary);
  content: "";
}

.badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.02em;
}

.status-badge.excellent, .status-badge.healthy {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #c2ebd1;
}

.status-badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid #fce39e;
}

.status-badge.critical, .status-badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fac2c2;
}

.result-card h2 {
  margin: 0;
  font-size: 1.15rem;
  color: #314b4e;
}

.main-result {
  display: block;
  margin: 10px 0 4px;
  color: var(--primary-dark);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.result-status {
  min-height: 1.45em;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.result-status.error-state {
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 750;
}

.result-section-title {
  margin: 18px 0 8px;
  color: #284346;
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-list {
  margin: 0;
  border-top: 1px solid var(--line);
}

.result-list div {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  font-size: 0.88rem;
}

.result-list dt {
  color: var(--muted);
}

.result-list dd {
  margin: 0;
  color: var(--ink);
  font-weight: 850;
  text-align: right;
}

.result-list .highlight-row {
  background: #f7fcfb;
  margin: 0 -8px;
  padding: 9px 8px;
  border-radius: 6px;
}

.result-list .highlight-row dd {
  color: var(--primary-dark);
}

.composition {
  margin-top: 20px;
}

.composition h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.composition-bar {
  width: 100%;
  height: 24px;
  overflow: hidden;
  border-radius: 8px;
  display: flex;
  background: #edf2f1;
}

.composition-bar span {
  width: 0;
  min-width: 0;
  transition: width 0.25s ease;
}

.bar-costs { background: #d97706; }
.bar-franchise { background: #9333ea; }
.bar-profit { background: #087f78; }

.composition-legend {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.composition-legend p {
  margin: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
}

.legend-marker {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border-radius: 4px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 900;
}

.marker-costs { background: #d97706; }
.marker-franchise { background: #9333ea; }
.marker-profit { background: #087f78; }

/* CDI Box */
.cdi-box {
  margin-top: 24px;
  padding: 20px;
  background: linear-gradient(135deg, #f0fdf9 0%, #edf4fc 100%);
  border: 1px solid #bfd8f5;
}

.cdi-box h3 {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 1.1rem;
}

.cdi-box p {
  margin: 0 0 10px;
  color: #38595b;
  font-size: 0.86rem;
}

.cdi-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.cdi-card {
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #d4e3f5;
}

.cdi-card span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
}

.cdi-card strong {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 1rem;
}

/* Quick guide and Education */
.quick-guide {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.quick-guide article {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}

.quick-guide h2 {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.3;
}

.quick-guide p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.77rem;
}

.ad-space {
  min-height: 120px;
  margin: 35px 0;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.education {
  padding: clamp(24px, 5vw, 46px);
}

.education > h2 {
  margin: 30px 0 7px;
  font-size: 1.45rem;
}

.education > .eyebrow + h2 {
  margin-top: 0;
}

.education > p:not(.eyebrow) {
  max-width: 850px;
  color: #496366;
}

.education ul {
  max-width: 850px;
  color: #496366;
  padding-left: 20px;
}

.education li {
  margin-bottom: 8px;
}

.faq {
  margin-top: 34px;
}

.faq h2 {
  margin-bottom: 12px;
}

.faq details {
  border-top: 1px solid var(--line);
}

.faq details:last-child {
  border-bottom: 1px solid var(--line);
}

.faq summary {
  padding: 14px 2px;
  font-weight: 800;
  cursor: pointer;
}

.faq details p {
  margin: -2px 2px 15px;
  color: #496366;
}

.related {
  margin-top: 35px;
  padding-top: 25px;
  border-top: 1px solid var(--line);
}

.related h2 {
  margin: 0 0 14px;
  font-size: 1.25rem;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.related-grid a {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
}

.related-grid a:hover {
  border-color: #9ccdc8;
  background: var(--soft);
}

.related-grid span {
  color: var(--muted);
  font-size: 0.8rem;
}

.related-grid strong {
  color: var(--primary-dark);
  font-size: 0.82rem;
}

.disclaimer {
  margin-top: 28px;
  padding: 16px;
  border-left: 4px solid var(--primary);
  border-radius: 0 10px 10px 0;
  background: var(--soft);
  color: #405d60;
  font-size: 0.8rem;
}

.notice {
  padding: 13px;
  border-radius: 10px;
}

.notice.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

@media (max-width: 950px) {
  .calculator-layout { grid-template-columns: 1fr; }
  .result-card { position: static; }
}

@media (max-width: 680px) {
  .page-shell { width: min(100% - 20px, 1120px); padding-top: 34px; }
  .hero { margin-bottom: 25px; }
  .field-grid, .cdi-stats { grid-template-columns: 1fr; }
  .calculator-actions .button { width: 100%; }
  .quick-guide, .related-grid { grid-template-columns: 1fr; }
  .result-list div { font-size: 0.86rem; }
}

@media (max-width: 420px) {
  .page-shell { width: min(100% - 16px, 1120px); }
  .panel, .result-card { border-radius: 14px; }
  .composition-legend { grid-template-columns: 1fr; }
  .main-result { font-size: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .composition-bar span { transition: none; }
}
