:root {
  color-scheme: light;
  --ink: #172420;
  --muted: #63706b;
  --line: #dce3df;
  --surface: #ffffff;
  --canvas: #f2f5f2;
  --forest: #173f35;
  --forest-2: #255e4f;
  --mint: #dcece5;
  --lime: #d9ee82;
  --amber: #e7a735;
  --red: #c94d45;
  --shadow: 0 18px 45px rgba(22, 45, 37, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 66px;
  padding: 0 max(24px, calc((100vw - 1260px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(242, 245, 242, 0.92);
  border-bottom: 1px solid rgba(220, 227, 223, 0.9);
  backdrop-filter: blur(16px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: white; background: var(--forest); font-size: 18px; }
.privacy-pill { padding: 7px 11px; color: var(--forest-2); background: var(--mint); border-radius: 999px; font-size: 12px; font-weight: 700; }

.page-shell { width: min(1260px, calc(100% - 40px)); margin: 0 auto; padding: 52px 0 80px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; margin-bottom: 34px; }
.intro > div:first-child { max-width: 740px; }
.eyebrow { margin: 0 0 9px; color: var(--forest-2); font-size: 12px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
h1 { margin: 0; max-width: 720px; font-size: clamp(34px, 4.8vw, 64px); line-height: 1.06; letter-spacing: -0.045em; }
.intro p:not(.eyebrow) { max-width: 700px; margin: 18px 0 0; color: var(--muted); font-size: 16px; line-height: 1.75; }
.intro-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.button { min-height: 44px; padding: 0 17px; border: 1px solid transparent; border-radius: 12px; font-weight: 750; transition: transform 150ms ease, border-color 150ms ease, background 150ms ease; }
.button:active { transform: translateY(1px); }
.button.secondary { color: var(--forest); background: var(--mint); }
.button.secondary:hover { background: #d0e6dc; }
.button.ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.button.ghost:hover { color: var(--ink); background: white; }
.button.small { min-height: 44px; padding-inline: 13px; font-size: 13px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.18fr) minmax(360px, 0.82fr); gap: 24px; align-items: start; }
.form-column, .result-column { min-width: 0; }
.form-column { display: grid; gap: 18px; }
.result-column { position: sticky; top: 88px; display: grid; gap: 16px; }
.panel, .result-card { background: var(--surface); border: 1px solid rgba(211, 221, 216, 0.92); border-radius: 20px; box-shadow: var(--shadow); }
.panel { padding: 26px; }
.panel-heading { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 22px; }
.panel-heading h2, .result-card-heading h2 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.panel-heading p, .result-card-heading p:not(.eyebrow) { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.step { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; color: var(--forest); background: var(--lime); border-radius: 11px; font-size: 12px; font-weight: 900; }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.field-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field.wide { grid-column: 1 / -1; }
.field { display: grid; gap: 8px; min-width: 0; }
.field > span:first-child { color: #40504a; font-size: 13px; font-weight: 700; }
.field small { color: #94a09b; font-weight: 500; }
.field input[type="text"], .input-affix { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfb; transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease; }
.field input[type="text"] { padding: 0 14px; color: var(--ink); outline: none; }
.input-affix { display: flex; align-items: center; overflow: hidden; }
.input-affix b { padding: 0 12px; color: #82908a; font-size: 13px; font-weight: 750; }
.input-affix input { min-width: 0; width: 100%; height: 44px; padding: 0 4px; color: var(--ink); border: 0; outline: 0; background: transparent; font-weight: 750; }
.field input[type="text"]:focus, .input-affix:focus-within { border-color: var(--forest-2); background: white; box-shadow: 0 0 0 3px rgba(37, 94, 79, 0.12); }
.input-affix:has(input:disabled) { opacity: 0.48; background: #f1f3f2; }
.quote-field .input-affix { min-height: 58px; border-color: #b8cbc3; background: #f4faf7; }
.quote-field .input-affix input { height: 56px; font-size: 24px; }
.quote-field .input-affix b { color: var(--forest-2); font-size: 18px; }

.toggle-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(140px, 0.7fr); gap: 12px; align-items: stretch; }
.toggle-card { position: relative; min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfb; }
.toggle-card[data-enabled="true"] { border-color: #a8c8ba; background: #f0f8f4; }
.toggle-card input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle-copy { display: grid; gap: 3px; }
.toggle-copy strong { font-size: 13px; }
.toggle-copy small { color: var(--muted); font-size: 12px; }
.switch { position: relative; flex: 0 0 auto; width: 42px; height: 24px; border-radius: 999px; background: #cfd6d3; transition: background 150ms ease; }
.switch::after { content: ''; position: absolute; width: 18px; height: 18px; top: 3px; left: 3px; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: transform 150ms ease; }
.toggle-card input:checked + .switch { background: var(--forest-2); }
.toggle-card input:checked + .switch::after { transform: translateX(18px); }
.inline-field { margin-bottom: 12px; }
.advanced { margin-top: 8px; border-top: 1px solid var(--line); }
.advanced summary { padding: 18px 2px 4px; color: var(--forest-2); font-size: 13px; font-weight: 750; cursor: pointer; }
.advanced-grid { padding-top: 16px; }

.saved-panel { margin-bottom: 24px; border-color: #b8d6c8; background: linear-gradient(135deg, #ffffff 0%, #f0f8f4 100%); box-shadow: 0 20px 50px rgba(23, 63, 53, 0.11); }
.saved-heading { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 18px; }
.saved-heading-copy { min-width: 0; display: flex; align-items: center; gap: 15px; }
.saved-heading-copy h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.saved-heading-copy p:not(.eyebrow) { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.saved-heading-copy .eyebrow { margin-bottom: 5px; }
.recent-mark { flex: 0 0 auto; width: 46px; height: 46px; display: grid; place-items: center; color: var(--forest); background: var(--lime); border-radius: 14px; font-size: 24px; font-weight: 900; }
.autosave-status { min-height: 27px; margin-top: 10px; padding: 0 10px; display: inline-flex; align-items: center; gap: 7px; color: var(--forest-2); background: #e0f0e8; border-radius: 999px; font-size: 11px; font-weight: 800; }
.autosave-status i { width: 7px; height: 7px; border-radius: 50%; background: #4f8d76; }
.autosave-status[data-status="working"] i { background: var(--amber); }
.autosave-status[data-status="error"] { color: var(--red); background: #fff0ef; }
.autosave-status[data-status="error"] i { background: var(--red); }
.empty-state { margin: 0; padding: 17px; color: var(--muted); background: rgba(255,255,255,.72); border: 1px dashed #cbdad3; border-radius: 13px; font-size: 13px; line-height: 1.6; }
.saved-list { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 31.5%); gap: 10px; overflow-x: auto; overscroll-behavior-inline: contain; padding: 2px 2px 8px; scroll-snap-type: inline proximity; scrollbar-width: thin; }
.saved-item { min-width: 0; display: flex; align-items: stretch; gap: 3px; border: 1px solid #d4e1db; border-radius: 14px; overflow: hidden; background: white; scroll-snap-align: start; }
.saved-item[data-active="true"] { border-color: #78a893; box-shadow: inset 0 0 0 1px #78a893; }
.saved-main { flex: 1; min-width: 0; padding: 13px 8px 13px 14px; display: grid; gap: 5px; text-align: left; color: var(--ink); border: 0; background: white; }
.saved-main:hover { background: #f6faf7; }
.saved-title-row { min-width: 0; display: flex; align-items: center; gap: 8px; }
.saved-title-row span { min-width: 0; overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.saved-kind { flex: 0 0 auto; padding: 3px 6px; color: var(--forest-2); background: var(--mint); border-radius: 999px; font-size: 10px; font-style: normal; font-weight: 850; }
.saved-kind[data-kind="snapshot"] { color: #805a18; background: #faedcf; }
.saved-main small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.saved-main time { color: #87958f; font-size: 10px; }
.icon-button { flex: 0 0 auto; width: 42px; min-height: 48px; margin: 5px 4px 5px 0; color: #7b8984; border: 0; border-radius: 10px; background: transparent; font-size: 20px; }
.icon-button:hover { color: var(--red); background: #fff0ef; }

.result-card { padding: 24px; }
.main-result { color: white; background: var(--forest); border-color: var(--forest); box-shadow: 0 22px 50px rgba(23, 63, 53, 0.2); }
.status-row, .result-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.status-badge { display: inline-flex; min-height: 27px; align-items: center; padding: 0 10px; border-radius: 999px; color: #e8f4ef; background: rgba(255,255,255,.12); font-size: 12px; font-weight: 850; }
.status-badge[data-status="loss"], .status-badge[data-status="risk"] { color: #ffe4df; background: rgba(239, 115, 100, .2); }
.status-badge[data-status="watch"] { color: #ffe7b9; background: rgba(231, 167, 53, .2); }
.status-badge[data-status="good"], .status-badge[data-status="great"] { color: #edf8be; background: rgba(217, 238, 130, .16); }
.live-dot { display: inline-flex; align-items: center; gap: 7px; color: #b8cdc5; font-size: 11px; }
.live-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 4px rgba(217, 238, 130, .12); }
.result-label { margin: 24px 0 5px; color: #b8cdc5; font-size: 13px; }
.profit-value { margin: 0; font-size: clamp(42px, 5vw, 60px); font-weight: 850; letter-spacing: -0.045em; }
.profit-value[data-negative="true"] { color: #ffb3aa; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 23px; overflow: hidden; border-radius: 13px; background: rgba(255,255,255,.1); }
.metric-grid > div { padding: 13px 11px; display: grid; gap: 6px; background: rgba(255,255,255,.045); }
.metric-grid span { color: #adc4bb; font-size: 11px; }
.metric-grid strong { font-size: 15px; }
.status-copy { margin-top: 17px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.1); }
.status-copy strong { font-size: 14px; }
.status-copy p { margin: 5px 0 0; color: #b8cdc5; font-size: 12px; line-height: 1.55; }

.result-card-heading { align-items: center; }
.result-card-heading .eyebrow { margin-bottom: 5px; }
.text-button { padding: 7px 0; color: var(--forest-2); border: 0; background: transparent; font-size: 12px; font-weight: 800; }
.price-ladder { display: grid; gap: 7px; margin-top: 20px; }
.price-row { min-height: 45px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 12px; border-radius: 11px; background: #f7f9f7; }
.price-row span { display: inline-flex; align-items: center; gap: 9px; color: #51615b; font-size: 13px; }
.price-row span b { font-weight: 500; }
.price-row strong { font-size: 16px; }
.price-row.featured { background: var(--mint); outline: 1px solid #c0ddd0; }
.price-row.featured strong { color: var(--forest-2); font-size: 18px; }
.price-dot { width: 8px; height: 8px; border-radius: 50%; background: #a7b0ac; }
.price-dot.minimum { background: var(--amber); }
.price-dot.target { background: var(--forest-2); }
.price-dot.safety { background: #77a02a; }
.cost-ceiling { margin: 15px 0 0; padding: 13px 14px; color: var(--muted); background: #fbf7eb; border: 1px solid #eadfbf; border-radius: 11px; font-size: 12px; line-height: 1.55; }
.cost-ceiling strong { color: #8a611a; }
.rounding-note { margin: 9px 2px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.warning { margin: 10px 0 0; color: var(--red); font-size: 12px; }

.distribution-bar { height: 10px; display: flex; margin: 20px 0 18px; overflow: hidden; border-radius: 999px; background: #edf0ee; }
.bar { display: block; height: 100%; transition: width 220ms ease; }
.bar.operating { background: var(--forest); }
.bar.variable { background: var(--amber); }
.bar.profit { background: var(--lime); }
.breakdown-list { margin: 0; display: grid; }
.breakdown-list > div { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid #edf0ee; }
.breakdown-list > div:last-child { border-bottom: 0; }
.breakdown-list dt { color: var(--muted); font-size: 12px; }
.breakdown-list dd { margin: 0; font-size: 13px; font-weight: 750; }
.breakdown-list .subtotal { margin-top: 4px; }
.breakdown-list .subtotal dt, .breakdown-list .subtotal dd { color: var(--ink); font-weight: 850; }
.disclaimer { margin: 2px 6px 0; color: #75827d; font-size: 11px; line-height: 1.65; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 12px 17px; color: white; background: #122b24; border-radius: 12px; box-shadow: 0 16px 35px rgba(0,0,0,.22); font-size: 13px; font-weight: 750; }

@media (max-width: 960px) {
  .page-shell { width: min(760px, calc(100% - 30px)); padding-top: 38px; }
  .intro { align-items: flex-start; flex-direction: column; }
  .intro-actions { justify-content: flex-start; }
  .workspace { grid-template-columns: 1fr; }
  .saved-list { grid-auto-columns: minmax(260px, 48%); }
  .result-column { position: static; grid-row: 1; }
  .form-column { grid-row: 2; }
}

@media (max-width: 620px) {
  .topbar { min-height: 58px; padding: 0 15px; }
  .brand { font-size: 14px; }
  .brand-mark { width: 31px; height: 31px; }
  .privacy-pill { padding: 6px 8px; font-size: 10px; }
  .page-shell { width: calc(100% - 22px); padding: 28px 0 58px; }
  .intro { gap: 20px; margin-bottom: 22px; }
  h1 { font-size: 38px; }
  .intro p:not(.eyebrow) { margin-top: 13px; font-size: 14px; }
  .intro-actions { width: 100%; }
  .intro-actions .button { flex: 1; padding-inline: 10px; }
  .saved-panel { margin-bottom: 16px; padding: 18px; }
  .saved-heading { align-items: flex-start; gap: 14px; }
  .saved-heading-copy { align-items: flex-start; gap: 11px; }
  .saved-heading-copy h2 { font-size: 19px; }
  .saved-heading-copy p:not(.eyebrow) { font-size: 12px; }
  .recent-mark { width: 39px; height: 39px; border-radius: 12px; font-size: 20px; }
  .saved-heading .button { flex: 0 0 auto; min-height: 40px; padding-inline: 11px; font-size: 12px; }
  .saved-list { grid-auto-columns: minmax(245px, 88%); }
  .workspace { gap: 13px; }
  .result-column { gap: 12px; }
  .panel, .result-card { padding: 19px; border-radius: 17px; }
  .panel-heading { margin-bottom: 18px; }
  .panel-heading p { font-size: 12px; }
  .field-grid, .field-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 10px; }
  .field-grid.compact .field:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .toggle-grid { grid-template-columns: 1fr; }
  .inline-field { width: 50%; margin: -4px 0 4px auto; }
  .metric-grid span { font-size: 10px; }
  .metric-grid strong { font-size: 13px; }
}

@media (max-width: 370px) {
  .privacy-pill { display: none; }
  .field-grid, .field-grid.compact { grid-template-columns: 1fr; }
  .field.wide, .field-grid.compact .field:last-child:nth-child(odd) { grid-column: auto; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-grid > div { grid-template-columns: 1fr auto; align-items: center; }
}

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