:root {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #253531;
  background: #f6f7f8;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --forest: #123f38;
  --green: #22765e;
  --mint: #dbf6e8;
  --muted: #6c7b76;
  --line: #e9edea;
  --radius: 18px;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
/* Only the content surface moves during the optional edge rebound. Floating
   navigation, the frame and modal dialogs remain outside this surface. */
.page-surface-clip { overflow: clip; }
#page-surface.is-bouncing { will-change: transform; }
body.rage-on, html:has(body.rage-on) { overscroll-behavior-y: none; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid #83c9ad; outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }
svg { flex-shrink: 0; }
.icon { width: 18px; height: 18px; vertical-align: middle; }
.container, .page-container, main { width: min(1280px, calc(100% - 80px)); margin-inline: auto; }

.topbar {
  min-height: 78px;
  border-bottom: 1px solid #e6ebe7;
  background: rgba(255, 255, 255, .88);
}
.topbar-inner {
  width: min(1280px, calc(100% - 80px));
  min-height: 78px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-icon, .logo-icon {
  width: 37px; height: 37px; display: grid; place-items: center;
  color: #fff; background: var(--forest); border-radius: 10px;
}
.brand-icon svg, .logo-icon svg { width: 21px; height: 21px; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.35px; }
.brand-subtitle { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; letter-spacing: .8px; }
.local-badge, .topbar-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 500; color: #66756d;
  border: 1px solid #e4eae5; border-radius: 6px; padding: 6px 9px; background: #fafcfb;
}
.local-badge::before, .topbar-badge::before { content: ""; width: 5px; height: 5px; background: #77a58d; border-radius: 50%; }
.local-badge:has(.status-dot)::before { display: none; }
.status-dot { width: 5px; height: 5px; flex-shrink: 0; display: inline-block; border-radius: 50%; background: #569472; }
.live-indicator { display: inline-flex; align-items: center; gap: 5px; }

.page-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 35px 0 27px; }
.overline, .eyebrow, .header-overline { font-size: 10px; font-weight: 700; letter-spacing: 1.9px; text-transform: uppercase; }
.overline, .header-overline { color: #7f9488; margin-bottom: 8px; }
.page-header .eyebrow { color: #718a7b; margin-bottom: 8px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 30px; font-weight: 700; letter-spacing: -.85px; line-height: 1.4; }
.page-subtitle, .page-header p { margin-top: 8px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.header-actions { display: flex; gap: 9px; flex-shrink: 0; }
.header-actions { flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 37px; border: 1px solid var(--forest); border-radius: 8px;
  padding: 8px 13px; color: #fff; background: var(--forest);
  font-size: 12px; font-weight: 600; transition: background .15s, border-color .15s, transform .15s;
}
.btn:hover { background: #20564b; border-color: #20564b; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: #596860; border-color: #dce4df; }
.btn.secondary:hover { background: #f1f6f3; border-color: #b9ccbf; }
.btn svg { width: 15px; height: 15px; }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid #dce4df; border-radius: 8px; color: #677970; background: white; }
.icon-button:hover { background: #f1f6f3; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 24px; align-items: stretch; }
.input-panel, .result-panel, .breakdown-panel { background: #fff; border: 1px solid #e5ebe6; border-radius: var(--radius); box-shadow: 0 3px 8px rgba(29, 55, 39, .025); }
.input-panel { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.input-panel > .input-section:last-child { flex: 1; }
.input-section, .panel-section { padding: 24px 25px; border-bottom: 1px solid var(--line); }
.input-section:last-child, .panel-section:last-child { border-bottom: 0; }
.section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 19px; }
.step-number { display: grid; place-items: center; width: 25px; height: 25px; border: 1px solid #e5ece6; border-radius: 7px; font-size: 11px; font-weight: 700; color: #63776a; background: #f8faf8; }
.section-heading h2, .breakdown-header h2 { font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.section-hint { margin-left: auto; color: var(--muted); font-size: 11px; letter-spacing: .3px; }
.field-grid { display: grid; gap: 15px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.rate-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { min-width: 0; }
.field > label, .field-label { display: flex; align-items: center; justify-content: space-between; gap: 4px; color: #58685e; font-size: 13px; line-height: 1.5; margin-bottom: 8px; }
.field-tag { color: var(--muted); font-size: 11px; white-space: nowrap; font-weight: 400; }
.input-wrap { display: flex; align-items: center; min-width: 0; min-height: 43px; border: 1px solid #dce4de; border-radius: 8px; background: #fff; transition: border-color .15s, box-shadow .15s; overflow: hidden; }
.input-wrap:focus-within { border-color: #62a98c; box-shadow: 0 0 0 3px #edf7f1; }
.input-wrap input, .input-wrap select { width: 100%; min-width: 0; height: 41px; padding: 9px 12px; border: 0; outline: 0; color: #2c4034; background: transparent; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.input-wrap select { font-size: 12px; font-weight: 500; padding-right: 28px; appearance: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23728476' stroke-width='1.7'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center; }
.prefix, .suffix, .input-prefix, .input-suffix { flex-shrink: 0; padding: 0 11px; color: #9aaba0; font-size: 12px; }
.prefix + input, .input-prefix + input { padding-left: 0; }
input:has(+ .suffix), input:has(+ .input-suffix) { padding-right: 0; }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input::placeholder { color: #a1ada4; font-weight: 400; }
.field-help { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.discount-unit-control { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-bottom: 7px; }
.discount-unit-control label { color: var(--muted); font-size: 11px; }
.discount-unit-control select { flex: 1 1 112px; min-width: 0; max-width: 100%; min-height: 32px; padding: 4px 6px; border: 1px solid #c8dbce; border-radius: 6px; background: #fff; color: #294d37; font-size: 11px; }
.discount-unit-control select:focus-visible { outline: 2px solid #83c9ad; outline-offset: 2px; }
.field-error { display: block; margin-top: 7px; color: #b83c40; font-size: 11px; line-height: 1.5; }
/* Shared intrinsic tracks keep numeric boxes level when labels, selectors,
   help text or validation messages wrap. Each responsive column group gets
   its own tracks, without measuring or reserving a fixed label height. */
.field-grid.three.pricing-fields { row-gap: 0; grid-auto-rows: auto; }
.pricing-fields > .field { display: grid; grid-template-rows: subgrid; grid-row: span 5; align-items: start; }
.pricing-fields > .field > label { grid-row: 1; }
.pricing-fields > .field > .discount-unit-control { grid-row: 2; }
.pricing-fields > .field > .input-wrap { grid-row: 3; }
.pricing-fields > .field > .field-help { grid-row: 4; }
.pricing-fields > .field > .field-error { grid-row: 5; }
.input-section > .field-grid.four, .input-section > .rate-grid { row-gap: 0; grid-auto-rows: auto; }
.input-section > .field-grid.four > .field, .input-section > .rate-grid > .field { display: grid; grid-template-rows: subgrid; grid-row: span 3; align-items: start; }
.input-section > .field-grid.four > .field > label, .input-section > .rate-grid > .field > label { grid-row: 1; }
.input-section > .field-grid.four > .field > .input-wrap, .input-section > .rate-grid > .field > .input-wrap { grid-row: 2; }
.input-section > .field-grid.four > .field > .field-error, .input-section > .rate-grid > .field > .field-error { grid-row: 3; }
.input-wrap.has-error { border-color: #d97377; box-shadow: 0 0 0 2px #fff0f0; }
.fixed-rates { display: flex; align-items: center; gap: 0; background: #f7f9f7; border: 1px solid #edf0ed; border-radius: 8px; margin-top: 17px; padding: 12px 14px; }
.fixed-rate, .fixed-rates > div, .fixed-rates > span { flex: 1; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.fixed-rates small { font-size: 11px; }
.fixed-rates > :nth-child(2) { padding-left: 18px; border-left: 1px solid #e3e9e2; }
.fixed-rates strong { color: #667c6b; font-size: 12px; font-weight: 600; margin-left: auto; }
.fixed-rates svg { width: 12px; height: 12px; }
.cost-total, .cost-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 17px; padding-top: 14px; border-top: 1px dashed #e6ebe6; font-size: 11px; color: #8c9c8f; }
.cost-total strong, .cost-summary strong { font-size: 15px; color: #566d5b; font-weight: 600; font-variant-numeric: tabular-nums; }
.pricing-preview { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-top: 17px; padding-top: 15px; border-top: 1px dashed #e6ebe6; font-size: 11px; color: var(--muted); line-height: 1.8; }
.pricing-preview > span { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.pricing-preview strong { color: #52735d; font-weight: 600; font-variant-numeric: tabular-nums; }
.cost-note { margin-top: 15px; font-size: 11px; color: var(--muted); line-height: 1.75; }

.right-column, .results-column { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 18px; min-width: 0; }
.summary-card { overflow: hidden; background: var(--forest); color: #fff; border-radius: var(--radius); padding: 24px 25px 0; box-shadow: 0 6px 16px rgba(18, 63, 56, .09); position: relative; }
.summary-card::before { content: ""; position: absolute; width: 190px; height: 190px; border: 1px solid rgba(180, 235, 206, .045); border-radius: 50%; right: -75px; top: -90px; pointer-events: none; }
.summary-card::after { content: ""; position: absolute; width: 255px; height: 255px; border: 1px solid rgba(180, 235, 206, .035); border-radius: 50%; right: -108px; top: -123px; pointer-events: none; }
.summary-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; position: relative; z-index: 1; }
.summary-top h2 { font-size: 14px; font-weight: 500; color: #c7e4d5; letter-spacing: .2px; }
.summary-pill { font-size: 11px; font-weight: 400; white-space: nowrap; padding: 4px 9px; border: 1px solid #41695c; border-radius: 20px; color: #c9e7d7; background: #ffffff08; }
.summary-top .eyebrow { color: #a0c8b9; font-weight: 500; font-size: 10px; letter-spacing: .5px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; color: #d0ecd9; background: rgba(180, 232, 204, .09); border: 1px solid rgba(200, 240, 217, .13); border-radius: 20px; padding: 4px 8px; font-size: 9px; line-height: 1.5; white-space: nowrap; }
.status-pill::before { content: ""; width: 4px; height: 4px; background: #98d6af; border-radius: 50%; }
.margin-amount { display: flex; align-items: baseline; gap: 6px; font-size: 48px; font-weight: 600; letter-spacing: -1.8px; line-height: 1.25; margin-top: 18px; font-variant-numeric: tabular-nums; }
.margin-amount .currency { font-size: 24px; font-weight: 400; letter-spacing: 0; color: #bdd9cc; }
.margin-amount small { font-size: 12px; font-weight: 400; letter-spacing: 0; color: #94b8a9; margin-left: 3px; }
.summary-description { font-size: 10px; color: #8db5a4; margin-top: 7px; line-height: 1.6; }
.summary-bottom { display: grid; grid-template-columns: 1fr 1fr; margin-top: 22px; border-top: 1px solid rgba(211, 238, 221, .13); padding: 17px 0 20px; gap: 18px; }
.summary-metric { min-width: 0; }
.summary-metric > span, .summary-metric > p, .summary-metric > div:first-child { display: block; font-size: 11px; color: #b2cdbf; margin-bottom: 5px; }
.summary-metric strong, .summary-metric output { color: #e1f1e8; font-size: 18px; font-weight: 500; letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.summary-metric small { font-size: 10px; color: #a0c0b1; font-weight: 400; margin-left: 3px; }

.result-panel { display: flex; flex-direction: column; min-width: 0; padding: 23px 24px 21px; }
.result-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.result-header h2 { font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.result-header > span { font-size: 11px; color: var(--muted); }
.linkage-caption { color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.7; }
.linked-fields { display: grid; gap: 10px; margin-top: 17px; }
.linked-field { padding: 13px 15px 11px; border: 1px solid #e4eae5; border-radius: 10px; background: #fff; transition: border-color .15s, background .15s; }
.linked-field.is-anchor { border-color: #acd9bf; background: #f1fbf5; }
.linked-field:focus-within { border-color: #71b18e; }
.linked-field.has-error { border-color: #d97377; background: #fff8f8; }
.linked-field.has-error:focus-within { box-shadow: 0 0 0 2px #fce7e7; }
.linked-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: #536d5b; }
.linked-label > label { cursor: pointer; }
.linked-label > label span { color: #99a69b; font-size: 9px; margin-left: 4px; }
.link-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; padding: 2px 6px; border-radius: 4px; color: var(--muted); background: #f5f7f5; line-height: 1.4; }
.link-badge svg { width: 10px; height: 10px; }
.is-anchor .link-badge { color: #43805a; background: #e0f2e6; }
.linked-input { display: flex; align-items: baseline; gap: 6px; min-width: 0; margin-top: 7px; }
.linked-input input { width: 100%; min-width: 0; flex: 1; color: #294d37; border: 0; outline: 0; background: transparent; padding: 0; font-size: 25px; font-weight: 600; letter-spacing: -.6px; line-height: 1.3; font-variant-numeric: tabular-nums; }
.linked-input .prefix, .linked-input .input-prefix { color: #8caa95; font-size: 16px; padding: 0; }
.linked-input .suffix, .linked-input .input-suffix { color: var(--muted); font-size: 11px; padding: 0; white-space: nowrap; }
.ad-spend-layout { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 7px; }
.ad-spend-layout .ad-spend-main { flex: 1 1 115px; margin-top: 0; }
.ad-spend-meta { display: flex; flex: 0 1 154px; flex-direction: column; min-width: 0; gap: 7px; color: var(--muted); font-size: 11px; }
.ad-spend-ratio { font-size: 11px; line-height: 1.6; }
.ad-spend-ratio output { margin-left: 5px; color: #43805a; font-weight: 600; font-variant-numeric: tabular-nums; }
.free-traffic-field { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.free-traffic-field label { font-size: 11px; line-height: 1.5; }
.free-traffic-input { flex: 0 1 68px; min-height: 29px; border-radius: 5px; }
.free-traffic-input input { width: 45px; height: 27px; padding: 4px 5px; font-size: 12px; font-weight: 500; }
.free-traffic-input > span { padding-right: 5px; font-size: 11px; }
.linked-note { color: var(--muted); font-size: 11px; line-height: 1.6; margin-top: 4px; }
.is-anchor .linked-note { color: #5f8069; }
.profit-unit-control { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 11px; padding-bottom: 9px; border-bottom: 1px solid #e0eae3; }
.profit-unit-control label { color: var(--muted); font-size: 11px; }
.profit-unit-control select { min-height: 32px; max-width: 190px; padding: 4px 9px; border: 1px solid #c8dbce; border-radius: 6px; background: #fff; color: #294d37; font-size: 12px; }
.profit-unit-control select:focus-visible { outline: 2px solid #83c9ad; outline-offset: 2px; }
.message { display: flex; gap: 7px; align-items: flex-start; border-radius: 7px; padding: 10px 12px; font-size: 11px; line-height: 1.65; margin-top: 13px; }
.message svg { width: 14px; height: 14px; margin-top: 2px; }
.message.warning { color: #8e6627; background: #fff8e8; border: 1px solid #f4e1b7; }
.message.error { color: #a54346; background: #fff2f2; border: 1px solid #f0d3d4; }
.result-footnote { display: flex; align-items: flex-start; gap: 6px; margin-top: auto; padding-top: 15px; color: var(--muted); font-size: 11px; line-height: 1.75; }
.result-footnote svg { width: 11px; height: 11px; margin-top: 2px; }
.readonly-value { font-variant-numeric: tabular-nums; }
.negative { color: #b74c4b !important; }

.breakdown-panel { margin-top: 24px; padding: 23px 25px 24px; }
.breakdown-header { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 24px; }
.breakdown-header > small, .breakdown-header > span { color: var(--muted); font-size: 11px; }
.breakdown-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 35px; }
.allocation { padding-right: 31px; border-right: 1px solid var(--line); }
.allocation h3 { margin-bottom: 16px; font-size: 12px; font-weight: 500; color: #617868; }
.allocation-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; color: #778779; font-size: 11px; }
.allocation-heading strong { color: #5b7160; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.allocation-bar { height: 20px; display: flex; overflow: hidden; gap: 2px; border-radius: 5px; background: #f1f4f0; }
.allocation-bar > span, .allocation-bar > div { min-width: 0; transition: width .25s; }
.allocation-legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 23px; margin-top: 19px; }
.legend-item, .allocation-legend > div { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); min-width: 0; }
.legend-dot, .color-dot { width: 6px; height: 6px; flex-shrink: 0; border-radius: 2px; }
.allocation-legend .legend-item > span { display: flex; align-items: center; gap: 6px; }
.allocation-legend i { display: inline-block; width: 7px; height: 7px; border-radius: 2px; flex-shrink: 0; }
.legend-item > strong, .allocation-legend > div > strong { margin-left: auto; color: #677d6b; font-weight: 500; white-space: nowrap; font-variant-numeric: tabular-nums; }
.allocation-note { margin-top: 18px; color: #a0ada2; font-size: 9px; line-height: 1.7; }
.chart-note { margin-top: 17px; color: var(--muted); font-size: 11px; line-height: 1.75; }
.ledger { min-width: 0; }
.ledger-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 0; font-size: 12px; color: #617868; line-height: 1.5; }
.ledger-row:first-child { padding-top: 0; }
.ledger-row > span:first-child { flex-shrink: 0; }
.ledger-values { display: flex; align-items: center; justify-content: flex-end; gap: 20px; min-width: 0; }
.ledger-formula { color: var(--muted); font-size: 11px; text-align: right; }
.ledger-values strong, .ledger-values output { min-width: 63px; color: #5d7663; font-size: 12px; font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
.ledger-row.subtle { color: var(--muted); }
.ledger-row.subtotal { padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px dashed #e7ece6; color: #486d55; }
.ledger-row.subtotal strong { color: #426b50; font-weight: 600; }
.ledger-row.total { margin-top: 8px; padding-top: 14px; border-top: 1px solid #e4ebe3; color: #3e6650; font-weight: 600; }
.ledger-row.total strong, .ledger-row.total output { color: #2f6547; font-weight: 700; font-size: 15px; }
.assumption-note { display: flex; align-items: flex-start; gap: 7px; color: var(--muted); font-size: 11px; line-height: 1.8; margin-top: 18px; padding: 14px 2px; }
.assumption-note svg { width: 13px; height: 13px; margin-top: 2px; color: #a5b1a7; }
.assumption-note strong { color: #87978b; font-weight: 500; }
.info-icon { display: inline-grid; place-items: center; width: 14px; height: 14px; margin-top: 3px; flex-shrink: 0; border: 1px solid #8da294; border-radius: 50%; font: 600 10px Georgia, serif; color: #6c8374; }
.page-footer { display: flex; justify-content: space-between; gap: 20px; padding: 14px 0 26px; font-size: 11px; color: #718178; border-top: 1px solid #e8ece8; line-height: 1.6; }
.page-footer span { display: inline-flex; align-items: center; gap: 5px; }
.page-footer svg { width: 11px; height: 11px; }
.toast { position: fixed; bottom: 25px; left: 50%; transform: translateX(-50%); z-index: 20; max-width: calc(100% - 32px); padding: 11px 17px; color: #fff; background: #234b3c; box-shadow: 0 5px 22px #123f3826; border: 1px solid #527461; border-radius: 9px; font-size: 12px; text-align: center; }
#copy-dialog { width: min(580px, calc(100% - 32px)); border: 1px solid #d6e2d9; border-radius: 16px; padding: 24px; color: #253531; box-shadow: 0 24px 80px #103b352e; }
#copy-dialog::backdrop { background: #133f385c; backdrop-filter: blur(2px); }
#copy-dialog h2 { font-size: 19px; }
#copy-dialog p { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.7; }
#copy-text { display: block; width: 100%; min-height: 280px; max-height: 55vh; margin: 18px 0; padding: 14px; border: 1px solid #dbe6dd; border-radius: 9px; resize: vertical; outline-color: #6fa78a; background: #f8faf8; color: #385140; font: 12px/1.7 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif; }
#copy-dialog form { display: flex; justify-content: flex-end; }
#settings-dialog { width: min(760px, calc(100% - 28px)); max-height: 88vh; padding: 0; border: 1px solid #d6e2d9; border-radius: 16px; color: #253531; box-shadow: 0 24px 80px #103b352e; overflow: hidden; }
#settings-dialog::backdrop { background: #133f385c; backdrop-filter: blur(2px); }
#settings-form { display: flex; flex-direction: column; max-height: 88vh; }
.settings-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 23px 25px 19px; border-bottom: 1px solid var(--line); }
.settings-header h2 { font-size: 20px; }
.settings-header p, .settings-storage-note { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.settings-body { padding: 20px 25px; overflow-y: auto; }
.settings-section { margin: 0 0 22px; padding: 0; border: 0; min-width: 0; }
.settings-section legend { margin-bottom: 14px; padding: 0; font-size: 14px; font-weight: 650; color: #2c5942; }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.settings-grid .field > label { min-height: 20px; font-size: 12px; }
.settings-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding: 17px 25px; border-top: 1px solid var(--line); background: #fafcfb; }
.settings-footer > div { display: flex; gap: 9px; }
.settings-storage-note { margin-top: 0; }
.page-navigation {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: calc(100vw - 32px);
}
.page-navigation button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 76px;
  min-width: 44px;
  max-width: 100%;
  min-height: 58px;
  padding: 8px 7px;
  border: 1px solid #416d58;
  border-radius: 11px;
  background: #28543f;
  color: #fff;
  box-shadow: 0 4px 16px #173d332b;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  touch-action: manipulation;
  transition: background .15s ease, box-shadow .15s ease;
}
.page-navigation button:hover { background: #1e4433; box-shadow: 0 5px 19px #173d3342; }
.page-navigation button:focus-visible { outline: 3px solid #85b99e; outline-offset: 3px; }
.page-navigation svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.page-navigation .rage-collapse {
  padding-block: 5px;
  gap: 1px;
  opacity: 0;
  transform: translateY(8px) scale(.72);
  transform-origin: center bottom;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s cubic-bezier(.2, .7, .25, 1), background .15s ease, box-shadow .15s ease;
}
.page-navigation .rage-collapse svg { width: 16px; height: 16px; }
.page-navigation .rage-collapse span { font-size: 11px; line-height: 1.1; }
.page-navigation .rage-collapse.is-visible { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
body.rage-on .page-navigation button { border-color: #b34155; background: #8b2434; box-shadow: 0 4px 16px #8b243430; }
body.rage-on .page-navigation button:hover { background: #752030; }
body.rage-on .page-navigation button:focus-visible { outline-color: #ed96a7; }

@media (min-width: 1400px) {
  .page-header { padding-top: 39px; padding-bottom: 30px; }
}
@media (max-width: 1100px) {
  .page-header { flex-wrap: wrap; }
  .container, .page-container, main, .topbar-inner { width: calc(100% - 48px); }
  .workspace { gap: 18px; }
  .input-section, .panel-section { padding: 22px 20px; }
  .field-grid.three { gap: 11px; }
  .field-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .input-section > .field-grid.four > .field:nth-child(-n+2) { margin-bottom: 14px; }
  .result-panel { padding: 22px 20px; }
  .summary-card { padding: 23px 21px 0; }
  .fixed-rates { gap: 11px; padding: 11px; }
  .fixed-rates > :nth-child(2) { padding-left: 11px; }
  .fixed-rate, .fixed-rates > div, .fixed-rates > span { flex-wrap: wrap; gap: 4px; }
  .breakdown-grid { gap: 25px; }
  .allocation { padding-right: 24px; }
  .allocation-legend { gap: 12px 14px; }
  .ledger-values { gap: 12px; }
}
@media (max-width: 899px) {
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .right-column, .results-column { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); grid-template-rows: auto; align-items: stretch; gap: 18px; }
  .field-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .input-section > .field-grid.four > .field:nth-child(-n+2) { margin-bottom: 0; }
  .input-section, .panel-section { padding: 24px; }
  .summary-bottom { grid-template-columns: 1fr; gap: 15px; }
  .summary-top { align-items: flex-start; }
  .summary-top { flex-wrap: wrap; }
  .summary-top .status-pill { font-size: 11px; padding: 3px 6px; }
  .margin-amount { font-size: 38px; letter-spacing: -1.3px; }
  .summary-card .summary-description { max-width: 185px; }
  .breakdown-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 22px; }
  .allocation { padding-right: 20px; }
  .allocation-legend { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  h1 { font-size: 27px; }
  .page-header { align-items: flex-start; }
  .header-actions { padding-top: 17px; }
  .btn { padding: 8px 10px; }
}
@media (max-width: 660px) {
  .container, .page-container, main, .topbar-inner { width: calc(100% - 32px); }
  .topbar, .topbar-inner { min-height: 66px; }
  .brand-name { font-size: 14px; }
  .brand-subtitle { font-size: 11px; }
  .brand-icon, .logo-icon { width: 33px; height: 33px; border-radius: 9px; }
  .local-badge, .topbar-badge { font-size: 11px; padding: 5px 7px; }
  .page-header { flex-wrap: wrap; gap: 16px; padding: 27px 0 22px; }
  .header-actions { padding-top: 0; }
  .right-column, .results-column { grid-template-columns: minmax(0, 1fr); align-items: start; }
  .summary-bottom { grid-template-columns: 1fr 1fr; gap: 18px; }
  .summary-card .summary-description { max-width: none; }
  .margin-amount { font-size: 44px; }
  .breakdown-panel { padding: 22px 20px; }
  .breakdown-grid { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .allocation { padding-right: 0; padding-bottom: 24px; border-right: 0; border-bottom: 1px solid var(--line); }
  .allocation-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 25px; }
  .ledger-row { padding-block: 9px; }
  .ledger-values { gap: 15px; }
  .page-footer { flex-direction: column; gap: 6px; padding-bottom: 22px; }
}
@media (max-width: 560px) {
  .page-navigation { right: calc(12px + env(safe-area-inset-right, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); gap: 7px; }
  .page-navigation button { width: 68px; min-height: 54px; padding: 7px 5px; font-size: 11px; }
  .page-navigation .rage-collapse { padding-block: 5px; }
  .settings-header { padding: 20px 17px 16px; }
  .settings-body { padding: 18px 17px; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
  .settings-footer { padding: 15px 17px; }
  h1 { font-size: 25px; letter-spacing: -.7px; }
  .page-subtitle, .page-header p { font-size: 11px; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; min-height: 39px; }
  .input-section, .panel-section { padding: 21px 19px; }
  .field-grid.three, .field-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 13px; }
  .pricing-fields > .field:nth-child(-n+2), .input-section > .field-grid.four > .field:nth-child(-n+2) { margin-bottom: 16px; }
  .rate-grid { gap: 13px; }
  .section-heading { gap: 8px; margin-bottom: 18px; }
  .section-hint { font-size: 11px; }
  .section-heading h2 { font-size: 14px; }
  .fixed-rates { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px; }
  .fixed-rates > :nth-child(2) { padding-left: 0; padding-top: 8px; border-left: 0; border-top: 1px solid #e3e9e2; }
  .fixed-rate, .fixed-rates > div, .fixed-rates > span { flex-wrap: nowrap; }
  .result-panel { padding: 22px 19px; }
  .result-header > span { font-size: 11px; }
  .breakdown-header { flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
  .breakdown-header > small, .breakdown-header > span { font-size: 11px; }
  .ledger-formula { display: none; }
  .ledger-values { gap: 10px; }
  .linked-input input { font-size: 26px; }
  .assumption-note { font-size: 11px; padding-top: 10px; margin-top: 12px; }
  .pricing-preview { gap: 10px; }
  .pricing-preview > span { display: block; }
  .pricing-preview strong { display: block; }
}
@media (max-width: 380px) {
  .local-badge, .topbar-badge { font-size: 0; gap: 0; padding: 6px; }
  .local-badge::before, .topbar-badge::before { width: 5px; height: 5px; }
  .field-tag { display: none; }
  .section-hint { display: none; }
  .rate-grid { grid-template-columns: minmax(0, 1fr); }
  .input-section > .rate-grid > .field:first-child { margin-bottom: 14px; }
  .ledger-formula { display: none; }
  .allocation-legend { gap: 13px 15px; }
  .margin-amount { font-size: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
  #page-surface { transform: none !important; will-change: auto !important; }
}
@media print {
  :root, body { background: #fff; color: #20332b; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .page-surface-clip { overflow: visible; }
  #page-surface { transform: none !important; will-change: auto !important; }
  .container, .page-container, main, .topbar-inner { width: 100%; }
  .topbar { min-height: 50px; background: white; }
  .topbar-inner { min-height: 50px; }
  .header-actions, .page-footer, .toast, .icon-button, .page-navigation { display: none !important; }
  .page-header { padding: 20px 0; }
  .workspace { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 16px; }
  .right-column, .results-column { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); align-items: stretch; gap: 12px; }
  .summary-bottom { grid-template-columns: 1fr 1fr; }
  .input-section, .panel-section { padding: 16px; }
  .field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .field-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pricing-fields > .field:nth-child(-n+2), .input-section > .field-grid.four > .field:nth-child(-n+2), .input-section > .rate-grid > .field:first-child { margin-bottom: 0; }
  .fixed-rates { display: flex; }
  .fixed-rates > :nth-child(2) { padding: 0 0 0 10px; border-top: 0; border-left: 1px solid #e3e9e2; }
  .input-panel, .result-panel, .summary-card, .breakdown-panel { box-shadow: none; break-inside: avoid; }
  .breakdown-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
  .allocation { padding-right: 20px; padding-bottom: 0; border-bottom: 0; border-right: 1px solid var(--line); }
  .allocation-legend { grid-template-columns: minmax(0, 1fr); }
  .breakdown-panel { margin-top: 16px; padding: 18px; }
  .assumption-note { font-size: 11px; }
}

/* Older browsers retain normal flow instead of creating implicit placeholder
   tracks for unsupported subgrids. Exact shared-row alignment is progressive. */
@supports not (grid-template-rows: subgrid) {
  .field-grid.three.pricing-fields,
  .input-section > .field-grid.four,
  .input-section > .rate-grid { row-gap: 15px; }
  .pricing-fields > .field,
  .input-section > .field-grid.four > .field,
  .input-section > .rate-grid > .field { display: block; grid-row: auto; }
  .pricing-fields > .field:nth-child(n),
  .input-section > .field-grid.four > .field:nth-child(n),
  .input-section > .rate-grid > .field:nth-child(n) { margin-bottom: 0; }
}
