:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #66716a;
  --line: #dfe5e1;
  --surface: #ffffff;
  --soft: #f4f7f5;
  --canvas: #edf2ef;
  --brand: #176b4d;
  --brand-dark: #0e4f38;
  --brand-soft: #e2f1ea;
  --amber: #e9a23b;
  --amber-soft: #fff2dc;
  --red: #cf4a4a;
  --red-soft: #fdeaea;
  --blue: #367cbb;
  --shadow: 0 12px 34px rgba(24, 54, 40, 0.08);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(23, 107, 77, 0.18); outline-offset: 1px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 224px; z-index: 20; display: flex; flex-direction: column; padding: 24px 16px; background: #14231c; color: white; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 28px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; color: #14231c; background: #f3bb57; }
.brand-mark svg { width: 22px; height: 22px; }
.brand strong, .brand small, .sidebar-foot strong, .sidebar-foot small { display: block; }
.brand strong { font: 700 16px/1.2 Manrope, sans-serif; }
.brand small { margin-top: 3px; font-size: 11px; color: #96a79e; }
.main-nav { display: grid; gap: 6px; }
.nav-item { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 12px; padding: 0 12px; border: 0; border-radius: 6px; color: #aebcb5; background: transparent; text-align: left; transition: 150ms ease; }
.nav-item svg { width: 19px; height: 19px; }
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.active { color: white; background: #24543f; box-shadow: inset 3px 0 #f3bb57; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-foot strong { font-size: 11px; font-weight: 600; }
.sidebar-foot small { margin-top: 2px; font-size: 10px; color: #82958b; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #65c896; box-shadow: 0 0 0 4px rgba(101,200,150,.12); }

.main-content { grid-column: 2; min-width: 0; }
.topbar { height: 84px; position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 32px; border-bottom: 1px solid rgba(223,229,225,.9); background: rgba(255,255,255,.88); backdrop-filter: blur(14px); }
.eyebrow { margin: 0 0 3px; color: var(--brand); font: 700 10px/1 Manrope, sans-serif; letter-spacing: 0; text-transform: uppercase; }
.topbar h1 { margin: 0; font-size: 21px; line-height: 1.2; letter-spacing: 0; }
.topbar-actions, .action-group { display: flex; align-items: center; gap: 10px; }
.update-note { color: var(--muted); font-size: 12px; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: white; }
.icon-button:hover { border-color: #bac8c0; background: var(--soft); }
.icon-button.small { width: 28px; height: 28px; }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.small svg { width: 14px; height: 14px; }

.view { display: none; padding: 30px 32px 48px; }
.view.active { display: block; }
.view-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.view-intro h2, .section-heading h3, .planner-controls h3 { margin: 0; letter-spacing: 0; }
.view-intro h2 { font-size: 20px; }
.view-intro p, .section-heading p, .planner-controls p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.profit-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(310px, 350px); gap: 24px; align-items: start; }
.input-rail { grid-column: 2; grid-row: 1; display: grid; gap: 12px; }
.form-group, .band { margin: 0; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.form-group { padding: 16px; }
.form-group > h3 { margin: 0 0 12px; color: #39453f; font-size: 12px; font-weight: 700; letter-spacing: 0; }
label { min-width: 0; display: grid; gap: 6px; color: #566159; font-size: 11px; font-weight: 600; }
label > span { color: #8a948e; font-size: 9px; font-weight: 500; }
input, select { width: 100%; min-width: 0; min-height: 38px; padding: 8px 10px; border: 1px solid #d8dfdb; border-radius: 5px; color: var(--ink); background: #fbfcfb; transition: 140ms ease; }
input:hover, select:hover { border-color: #b8c5bd; }
input:focus, select:focus { border-color: var(--brand); background: white; }
.field-grid { display: grid; gap: 12px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-group > .field-grid + label, .form-group > label + .field-grid { margin-top: 12px; }
.exchange-field-row { display: grid; grid-template-columns: minmax(0, 1fr) 38px; align-items: end; gap: 8px; margin-top: 12px; }
.exchange-field-row .icon-button.loading svg { animation: spin 800ms linear infinite; }
.rate-note { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 9px; }
.rate-note .status-dot { width: 6px; height: 6px; }
.rate-note.fallback .status-dot { background: var(--amber); box-shadow: 0 0 0 4px rgba(233,162,59,.14); }
input[readonly] { color: #526059; background: #f0f4f2; cursor: default; }
@keyframes spin { to { transform: rotate(360deg); } }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.toggle-row > span:first-child { color: inherit; font-size: inherit; }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row small { margin-top: 3px; color: var(--muted); font-weight: 400; }
.toggle-row input { position: absolute; width: 1px; height: 1px; min-height: 0; opacity: 0; pointer-events: none; }
.toggle { width: 38px; height: 22px; flex: 0 0 auto; position: relative; border-radius: 12px; background: #c7cfca; transition: 150ms ease; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.22); transition: 150ms ease; }
.toggle-row input:checked + .toggle { background: var(--brand); }
.toggle-row input:checked + .toggle::after { transform: translateX(16px); }

.results-area { grid-column: 1; grid-row: 1; min-width: 0; display: grid; gap: 18px; container-type: inline-size; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.profit-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-card { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: white; box-shadow: 0 4px 15px rgba(24,54,40,.035); }
.kpi-card .kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; font-weight: 600; }
.kpi-card .kpi-icon { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 6px; color: var(--brand); background: var(--brand-soft); }
.kpi-card .kpi-icon svg { width: 14px; height: 14px; }
.kpi-card strong { display: block; margin-top: 10px; overflow-wrap: anywhere; font: 700 19px/1.15 Manrope, sans-serif; }
.kpi-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; }
.kpi-card > small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-card.positive strong { color: var(--brand); }
.kpi-card.negative strong { color: var(--red); }
.money-stack { display: flex; flex-direction: column; min-width: 0; }
.money-stack > span { overflow-wrap: anywhere; }
.money-stack > small { margin-top: 4px; color: var(--muted); font: 500 10px/1.25 "Noto Sans SC", sans-serif; }
.money-stack.compact { align-items: flex-end; }
.money-stack.compact > small { margin-top: 2px; font-size: 8px; }

.scenario-section, .cost-section { padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h3, .planner-controls h3 { font-size: 14px; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 9px; }
.key { width: 8px; height: 8px; margin-left: 7px; border-radius: 2px; }
.key.sea { background: var(--brand); }.key.air { background: var(--amber); }.key.express { background: var(--blue); }
.scenario-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.scenario { min-width: 0; padding: 16px; border-right: 1px solid var(--line); }
.scenario:last-child { border-right: 0; }
.scenario-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 15px; }
.scenario-name { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; }
.scenario-name .key { margin: 0; width: 10px; height: 10px; }
.status-badge { padding: 3px 7px; border-radius: 10px; color: var(--brand-dark); background: var(--brand-soft); font-size: 9px; font-weight: 700; }
.status-badge.no { color: #9b3737; background: var(--red-soft); }
.scenario-profit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.scenario-profit-grid > div { min-width: 0; padding: 10px; border: 1px solid #e8edea; border-radius: 5px; background: #fafcfb; }
.scenario-profit-grid > div > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 9px; }
.scenario-profit-grid strong { display: block; font: 700 16px/1.15 Manrope, sans-serif; }
.scenario-profit-grid .money-stack > small { font-size: 8px; }
.scenario-margin { margin: 5px 0 16px; color: var(--muted); font-size: 10px; }
.metric-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid #edf0ee; font-size: 10px; }
.metric-row span { color: var(--muted); }
.metric-row > strong { min-width: 92px; text-align: right; }
.cost-plan-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.cost-plan { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 6px; }
.cost-plan > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid #edf0ee; }
.cost-plan > header > span:last-child { text-align: right; font-size: 10px; font-weight: 700; }
.cost-row { display: grid; gap: 6px; margin-top: 11px; font-size: 10px; }
.cost-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cost-meta span { color: var(--muted); }
.cost-meta strong { font: 700 10px/1 Manrope, sans-serif; }
.cost-row > small { min-width: 0; color: var(--muted); font-size: 9px; }
.cost-row > small .money-stack { flex-direction: row; align-items: baseline; justify-content: space-between; gap: 8px; }
.cost-row > small .money-stack > small { margin: 0; }
.bar-track { height: 8px; overflow: hidden; border-radius: 4px; background: #edf1ef; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--brand); }
.cost-row:nth-child(2) .bar-fill { background: var(--blue); }
.cost-row:nth-child(3) .bar-fill { background: var(--amber); }
.cost-row:nth-child(4) .bar-fill { background: #8f6ab0; }
.cost-row:nth-child(5) .bar-fill { background: #a97655; }
.cost-row:nth-child(6) .bar-fill { background: #8f9c95; }
.model-note { display: flex; gap: 10px; padding: 12px 14px; border: 1px solid #ecd8b3; border-radius: 6px; color: #75531e; background: var(--amber-soft); }
.model-note svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 1px; }
.model-note p { margin: 0; font-size: 10px; line-height: 1.6; }

.primary-button, .secondary-button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 13px; border-radius: 5px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.primary-button { border: 1px solid var(--brand); color: white; background: var(--brand); }
.primary-button:hover { background: var(--brand-dark); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: white; }
.secondary-button:hover { border-color: #b9c5be; background: var(--soft); }
.primary-button svg, .secondary-button svg { width: 15px; height: 15px; }
.band { padding: 20px; margin-bottom: 18px; }
.form-band { margin-bottom: 12px; }
.logistics-fields { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.logistics-kpis { margin: 12px 0 18px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 10px; }
th { padding: 10px 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-weight: 700; text-align: left; white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid #edf0ee; vertical-align: middle; }
tbody tr:hover { background: #fafcfa; }
td input, td select { min-width: 86px; min-height: 32px; padding: 5px 7px; font-size: 10px; }
td .icon-button { width: 30px; height: 30px; border-color: transparent; background: transparent; }
tfoot td { border-top: 1px solid var(--line); border-bottom: 0; font-weight: 700; }
.timing-band { margin-bottom: 0; }
.timeline-summary { display: grid; grid-template-columns: minmax(0, 1fr) 180px; align-items: end; gap: 28px; margin-top: 22px; }
.timeline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.timeline-step { position: relative; padding-top: 18px; border-top: 3px solid var(--brand); }
.timeline-step::before { content: ""; position: absolute; top: -7px; left: 0; width: 11px; height: 11px; border: 2px solid white; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.timeline-step span, .timeline-step strong { display: block; }
.timeline-step span { color: var(--muted); font-size: 9px; }
.timeline-step strong { margin-top: 4px; font-size: 12px; }
.storage-estimate { padding: 12px 14px; border-left: 3px solid var(--amber); background: var(--amber-soft); }
.storage-estimate span, .storage-estimate strong, .storage-estimate small { display: block; }
.storage-estimate span { color: #725522; font-size: 9px; font-weight: 700; }
.storage-estimate strong { margin-top: 4px; font: 700 17px/1.2 Manrope, sans-serif; }
.storage-estimate small { margin-top: 3px; color: #876b39; font-size: 8px; }

.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.chart-band canvas { width: 100%; min-height: 280px; display: block; }
.segmented { display: inline-flex; align-items: center; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); }
.segmented button { min-height: 29px; padding: 0 10px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-size: 10px; font-weight: 600; }
.segmented button.active { color: var(--ink); background: white; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.subtabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.subtabs button { min-height: 42px; display: inline-flex; align-items: center; gap: 7px; padding: 0 14px; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; font-size: 11px; font-weight: 600; }
.subtabs button svg { width: 15px; height: 15px; }
.subtabs button.active { border-bottom-color: var(--brand); color: var(--brand-dark); }
.operations-panel { display: none; }
.operations-panel.active { display: block; }
.planner-controls { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.planner-controls label { width: 160px; }
.planner-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.planner-hour { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 11px; border: 1px solid var(--line); border-radius: 6px; background: white; }
.planner-hour strong { font: 700 15px/1.2 Manrope, sans-serif; }
.planner-hour span { color: var(--muted); font-size: 9px; }
.planner-hour input { grid-row: 1 / 3; grid-column: 2; width: 58px; min-height: 34px; text-align: center; }

.warehouse-tools { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.search-box { width: min(460px, 100%); position: relative; }
.search-box svg { position: absolute; z-index: 1; top: 11px; left: 12px; width: 17px; height: 17px; color: var(--muted); }
.search-box input { height: 40px; padding-left: 38px; background: white; }
.warehouse-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.warehouse-card { min-width: 0; min-height: 132px; display: grid; grid-template-rows: auto 1fr auto; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.warehouse-card header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.warehouse-card h3 { margin: 0; font: 700 15px/1 Manrope, sans-serif; }
.region-pill { padding: 3px 7px; border-radius: 10px; color: var(--brand-dark); background: var(--brand-soft); font-size: 9px; font-weight: 700; }
.warehouse-card address { color: #4f5b54; font-size: 10px; line-height: 1.55; font-style: normal; }
.warehouse-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 9px; }
.copy-button { padding: 0; border: 0; color: var(--brand); background: transparent; font-size: 9px; font-weight: 700; }
.load-more { display: flex; margin: 18px auto 0; }
.empty-state { grid-column: 1 / -1; padding: 60px 20px; color: var(--muted); text-align: center; }
.empty-state svg { width: 30px; height: 30px; margin-bottom: 8px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 320px; padding: 11px 14px; border-radius: 6px; color: white; background: #24352d; box-shadow: var(--shadow); font-size: 11px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.danger-text { color: var(--red) !important; }

@container (max-width: 980px) {
  .scenario-grid { grid-template-columns: 1fr; }
  .scenario { border-right: 0; border-bottom: 1px solid var(--line); }
  .scenario:last-child { border-bottom: 0; }
  .cost-plan-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profit-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cost-plan-grid { grid-template-columns: 1fr; }
  .logistics-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .warehouse-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-shell { display: block; padding-bottom: 68px; }
  .sidebar { inset: auto 0 0; width: auto; height: 64px; flex-direction: row; align-items: center; padding: 6px; border-top: 1px solid rgba(255,255,255,.12); }
  .brand, .sidebar-foot { display: none; }
  .main-nav { width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
  .nav-item { min-width: 0; min-height: 52px; flex-direction: column; justify-content: center; gap: 3px; padding: 3px; border-radius: 5px; text-align: center; font-size: 9px; }
  .nav-item.active { box-shadow: inset 0 2px #f3bb57; }
  .nav-item svg { width: 17px; height: 17px; }
  .main-content { min-width: 0; }
  .profit-layout { grid-template-columns: 1fr; }
  .input-rail, .results-area { grid-column: auto; grid-row: auto; }
  .input-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .input-rail .form-group:last-child { grid-column: 1 / -1; }
  .warehouse-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .topbar { height: 70px; padding: 0 16px; }
  .topbar h1 { font-size: 18px; }
  .update-note { display: none; }
  .view { padding: 22px 14px 34px; }
  .view-intro { align-items: stretch; flex-direction: column; gap: 14px; }
  .input-rail { grid-template-columns: 1fr; }
  .input-rail .form-group:last-child { grid-column: auto; }
  .field-grid.three { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-card { padding: 13px; }
  .kpi-card strong { font-size: 18px; }
  .scenario-grid { grid-template-columns: 1fr; }
  .scenario { border-right: 0; border-bottom: 1px solid var(--line); }
  .scenario:last-child { border-bottom: 0; }
  .logistics-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .warehouse-tools { align-items: stretch; flex-direction: column; }
  .warehouse-tools .segmented { align-self: flex-start; }
  .warehouse-list { grid-template-columns: 1fr; }
  .planner-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .planner-controls { align-items: stretch; flex-direction: column; }
  .planner-controls label { width: 100%; }
  .timeline-summary { grid-template-columns: 1fr; }
  .action-group { width: 100%; }
  .action-group > * { flex: 1; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .section-heading .primary-button { align-self: flex-start; }
  .subtabs { overflow-x: auto; }
  .subtabs button { flex: 0 0 auto; }
}
