:root {
  --navy: #1F3B4D;
  --navy-2: #2C5266;
  --teal: #2A7F7A;
  --teal-dark: #1F6560;
  --teal-soft: #E6F2EF;
  --mint-line: #CFE3DE;
  --ink: #1D2B33;
  --muted: #5E6E76;
  --line: #DCE4E7;
  --bg: #F5F8F8;
  --card: #FFFFFF;
  --in: #1F7A55;
  --out: #A8432B;
  --warn-bg: #FFF6E5;
  --warn-line: #F0C980;
  --warn-ink: #7A4E0B;
  --danger-bg: #FDEEEA;
  --danger-line: #EDB3A5;
  --danger-ink: #8E2F1B;
  --focus: #1A73E8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 40, 50, .06), 0 4px 16px rgba(20, 40, 50, .05);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.5; font-size: 16px; font-feature-settings: "tnum" 1, "cv11" 1; }
[hidden] { display: none !important; }
a { color: var(--teal-dark); }
h1, h2, h3 { color: var(--navy); line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--navy); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Top bar */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; color: var(--navy); font-size: 1.02rem; white-space: nowrap; }
.brand-sub { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--teal); font-weight: 600; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.plan-select { max-width: 220px; }
.badge-btn { border: 1px solid var(--mint-line); background: var(--teal-soft); color: var(--teal-dark); font: inherit; font-size: .85rem; font-weight: 600; padding: 7px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.badge-btn.full { background: var(--navy); border-color: var(--navy); color: #fff; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 20px; height: 20px; fill: var(--navy); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 40px; outline: none; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label, .label { font-weight: 600; font-size: .9rem; color: var(--navy); }
input, select { font: inherit; color: var(--ink); background: #fff; border: 1px solid #C5D1D5; border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
input:focus, select:focus { border-color: var(--teal); outline: 3px solid rgba(42, 127, 122, .25); outline-offset: 0; }
input[aria-invalid="true"] { border-color: var(--out); }
.hint { font-size: .82rem; color: var(--muted); margin: 0; }
.form-error { background: var(--danger-bg); border: 1px solid var(--danger-line); color: var(--danger-ink); padding: 10px 12px; border-radius: 10px; font-size: .92rem; }
.success-msg { background: var(--teal-soft); border: 1px solid var(--mint-line); color: var(--teal-dark); padding: 12px 14px; border-radius: 10px; font-weight: 600; }

/* Buttons */
.btn { font: inherit; font-weight: 600; font-size: .95rem; border-radius: 10px; padding: 10px 16px; min-height: 44px; border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.primary[disabled] { opacity: .6; cursor: progress; }
.btn.secondary { background: #fff; color: var(--navy); border-color: #C5D1D5; }
.btn.secondary:hover { border-color: var(--navy); }
.btn.text { background: none; color: var(--teal-dark); padding: 8px 10px; }
.btn.text:hover { background: var(--teal-soft); }
.btn.danger { background: var(--out); color: #fff; }
.btn.danger-text { background: none; color: var(--out); padding: 8px 10px; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--teal-dark); text-decoration: underline; cursor: pointer; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head p { margin: 0; }

/* Welcome */
.welcome { display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: start; padding-top: 24px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; font-weight: 700; color: var(--teal-dark); margin-bottom: 10px; }
.welcome h1 { font-size: clamp(1.9rem, 1.2rem + 2.6vw, 2.9rem); margin-bottom: 16px; }
.lede { font-size: 1.1rem; color: #3D4F58; max-width: 34em; }
.ticks { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 8px; }
.ticks li { position: relative; padding-left: 28px; }
.ticks li::before { content: ""; position: absolute; left: 0; top: .3em; width: 18px; height: 18px; border-radius: 50%; background: var(--teal-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 10.5l3 3 7-7' fill='none' stroke='%232A7F7A' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat; }
.start-card h2, .example-card h2 { margin-bottom: 14px; }
.example-card p { color: var(--muted); }

/* Workspace */
.plan-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.plan-meta { color: var(--muted); margin: 6px 0 0; }
.plan-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.example-tag { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); padding: 2px 8px; border-radius: 999px; vertical-align: middle; margin-left: 8px; }

.controls { display: flex; flex-wrap: wrap; gap: 18px 28px; align-items: flex-end; padding: 16px 20px; }
.control { display: flex; flex-direction: column; gap: 6px; min-width: 170px; }
.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0; }
.seg legend { font-weight: 600; font-size: .9rem; color: var(--navy); margin-bottom: 6px; padding: 0; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.seg span { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; min-height: 44px; border: 1px solid #C5D1D5; background: #fff; color: var(--navy); font-weight: 600; font-size: .92rem; cursor: pointer; margin-left: -1px; }
.seg label:first-of-type span { border-radius: 10px 0 0 10px; margin-left: 0; }
.seg label:last-of-type span { border-radius: 0 10px 10px 0; }
.seg input:checked + span { background: var(--navy); border-color: var(--navy); color: #fff; position: relative; z-index: 1; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 2; }
.seg .lock { width: 13px; height: 13px; fill: currentColor; opacity: .7; }
.seg.big { width: 100%; margin-bottom: 16px; }
.seg.big label { flex: 1; }
.seg.big span { width: 100%; justify-content: center; }
.scenario-hint { flex-basis: 100%; margin: -6px 0 0; color: var(--muted); font-size: .88rem; }

.alert { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; border: 1px solid; display: flex; gap: 12px; align-items: flex-start; }
.alert strong { display: block; }
.alert.ok { background: var(--teal-soft); border-color: var(--mint-line); color: var(--teal-dark); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.alert.danger { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger-ink); }
.alert p { margin: 2px 0 0; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.metric .m-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; color: var(--muted); }
.metric .m-value { font-size: clamp(1.25rem, 1rem + 1vw, 1.7rem); font-weight: 700; color: var(--navy); margin: 4px 0 2px; overflow-wrap: anywhere; }
.metric .m-sub { font-size: .85rem; color: var(--muted); margin: 0; }
.metric.negative .m-value { color: var(--out); }
.metric.accent { border-top: 4px solid var(--teal); }

.chart { width: 100%; min-height: 240px; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg .gridline { stroke: #E6ECEE; stroke-width: 1; }
.chart-svg .zero { stroke: #9AABB2; stroke-width: 1.5; }
.chart-svg .axis { font-size: 12px; fill: var(--muted); font-family: var(--font); }
.chart-svg .line { fill: none; stroke: var(--teal); stroke-width: 2.5; stroke-linejoin: round; }
.chart-svg .area { fill: rgba(42, 127, 122, .10); }
.chart-svg .cushion { stroke: #C98A1D; stroke-width: 1.5; stroke-dasharray: 6 5; }
.chart-svg .cushion-label { fill: #9A6A12; font-weight: 600; }
.chart-svg .marker { fill: #fff; stroke: var(--navy); stroke-width: 3; }
.chart-svg .marker.danger { stroke: var(--out); }
.legend { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 8px; margin: 0; }
.key { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--teal); margin-left: 6px; }
.key-cushion { border-top: 2px dashed #C98A1D; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.forecast-table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 680px; }
.forecast-table th, .forecast-table td { padding: 10px 12px; text-align: right; border-bottom: 1px solid #EDF1F2; white-space: nowrap; }
.forecast-table thead th { background: #F3F7F7; color: var(--navy); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0; }
.forecast-table th[scope="row"], .forecast-table thead th:first-child { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; }
.forecast-table thead th:first-child { background: #F3F7F7; z-index: 2; }
.forecast-table tbody tr:hover td, .forecast-table tbody tr:hover th { background: #FAFCFC; }
.forecast-table .pos { color: var(--in); }
.forecast-table .neg { color: var(--out); }
.forecast-table tr.below td.closing { color: var(--warn-ink); font-weight: 700; }
.forecast-table tr.short td.closing, .forecast-table td.short { color: var(--out); font-weight: 700; }
.forecast-table tfoot td, .forecast-table tfoot th { font-weight: 700; background: #F8FAFA; border-top: 2px solid var(--line); }
.period-sub { display: block; font-size: .78rem; color: var(--muted); font-weight: 400; }

.items-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.items-col-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 4px; }
.item-list { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 4px; border-bottom: 1px solid #EEF2F3; }
.item.off { opacity: .55; }
.item .i-main { min-width: 0; }
.item .i-name { font-weight: 600; color: var(--ink); background: none; border: 0; padding: 0; font: inherit; font-weight: 600; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.item .i-name:hover { text-decoration: underline; }
.item .i-meta { font-size: .84rem; color: var(--muted); margin: 2px 0 0; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.item .i-amt { font-weight: 700; text-align: right; white-space: nowrap; }
.item.in .i-amt { color: var(--in); }
.item.out .i-amt { color: var(--out); }
.chip { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid; text-transform: uppercase; letter-spacing: .04em; }
.chip.confirmed { color: var(--teal-dark); border-color: var(--mint-line); background: var(--teal-soft); }
.chip.expected { color: #31506A; border-color: #C9D7E3; background: #EEF3F8; }
.chip.possible { color: var(--warn-ink); border-color: var(--warn-line); background: var(--warn-bg); }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; min-height: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; background: #C5D1D5; border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + span { background: var(--teal); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.empty { color: var(--muted); padding: 16px 4px; font-size: .92rem; }

/* Dialogs */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 24px 64px rgba(15, 30, 40, .28); color: var(--ink); }
dialog::backdrop { background: rgba(20, 35, 45, .45); }
dialog form, .dialog-pad { padding: 22px 22px 18px; }
dialog h2 { margin-bottom: 14px; font-size: 1.25rem; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.spacer { flex: 1; }
.radio-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.radio-card { position: relative; }
.radio-card input { position: absolute; opacity: 0; min-height: 0; width: 1px; height: 1px; }
.radio-card span { display: block; border: 1px solid #C5D1D5; border-radius: 10px; padding: 10px; cursor: pointer; height: 100%; }
.radio-card strong { display: block; font-size: .92rem; color: var(--navy); }
.radio-card small { color: var(--muted); font-size: .76rem; line-height: 1.35; display: block; margin-top: 2px; }
.radio-card input:checked + span { border-color: var(--teal); background: var(--teal-soft); box-shadow: inset 0 0 0 1px var(--teal); }
.radio-card input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.help-details { margin: 6px 0 12px; font-size: .92rem; }
.help-details summary { cursor: pointer; color: var(--teal-dark); font-weight: 600; }
.help-details ul { padding-left: 20px; margin: 8px 0 0; }
.menu-dialog { width: min(380px, calc(100vw - 24px)); }
.menu-list { display: flex; flex-direction: column; }
.menu-list button { font: inherit; text-align: left; background: none; border: 0; padding: 12px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
.menu-list button:hover { background: var(--teal-soft); }
.menu-list .pro { font-size: .72rem; font-weight: 700; color: var(--teal-dark); background: var(--teal-soft); padding: 2px 8px; border-radius: 999px; }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; width: 100%; }
.price-line { font-size: 1.05rem; color: var(--navy); }
.prose ol { padding-left: 20px; }
.prose li { margin-bottom: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 32px); font-size: .95rem; }

.footer { max-width: 1180px; margin: 0 auto; padding: 8px 20px 40px; color: var(--muted); font-size: .88rem; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.disclaimer { font-size: .8rem; }
.noscript { padding: 20px; text-align: center; }
.print-only { display: none; }

@media (max-width: 900px) {
  .welcome { grid-template-columns: 1fr; gap: 24px; padding-top: 4px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .items-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar-inner { padding: 8px 14px; }
  .brand-sub { display: none; }
  .plan-select { max-width: 120px; padding: 8px; }
  main { padding: 16px 14px 32px; }
  .card { padding: 16px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .radio-cards { grid-template-columns: 1fr; }
  .plan-head-actions { width: 100%; }
  .plan-head-actions .btn { flex: 1; }
  .controls { gap: 14px; }
  .control { min-width: 0; width: 100%; }
  .seg { width: 100%; }
  .seg label { flex: 1; }
  .seg span { width: 100%; justify-content: center; padding: 9px 6px; }
  .metric { padding: 12px 14px; }
  dialog form, .dialog-pad { padding: 18px 16px 14px; }
  .badge-btn { padding: 6px 10px; font-size: .78rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@media print {
  body { background: #fff; font-size: 11pt; }
  .topbar, .controls, .plan-head-actions, .footer-links, .items-col-head .btn, .switch, #toast, .skip, .item-list { display: none !important; }
  main { padding: 0; max-width: none; }
  .card, .metric { box-shadow: none; break-inside: avoid; }
  .table-wrap { overflow: visible; border: 0; }
  .forecast-table { min-width: 0; font-size: 9pt; }
  .forecast-table th, .forecast-table td { padding: 4px 6px; }
  .print-only { display: block; }
  .items-grid { display: none; }
}
