:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-synthesis: none;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --line: #dfe4e8;
  --line-strong: #c9d1d8;
  --text: #17202a;
  --muted: #69747f;
  --quiet: #8d98a2;
  --green: #087f5b;
  --green-soft: #e7f5ef;
  --blue: #1769aa;
  --blue-soft: #eaf3fb;
  --amber: #9a5c00;
  --amber-soft: #fff5dc;
  --red: #b42318;
  --red-soft: #fff0ee;
  --shadow: 0 1px 2px rgba(20, 29, 38, 0.06);
  --brand: #16324a;
  --control: #ffffff;
  --line-soft: #edf0f2;
  --titlebar: #ffffff;
  --tag-neutral-bg: #edf1f4;
  --tag-neutral-text: #50606d;
  --status-bg: #eef1f3;
  --summary-bg: #16324a;
  --summary-text: #ffffff;
  --code-text: #33424e;
  --lab-liquid: #78e3c5;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315;
  --surface: #191c1f;
  --surface-muted: #212529;
  --line: #343a3f;
  --line-strong: #4a535a;
  --line-soft: #292e32;
  --text: #edf1f3;
  --muted: #aeb7be;
  --quiet: #89949c;
  --green: #55d6aa;
  --green-soft: #173c32;
  --blue: #72b7eb;
  --blue-soft: #17364b;
  --amber: #f0bd6a;
  --amber-soft: #45331b;
  --red: #ff8a80;
  --red-soft: #472622;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
  --brand: #285b7e;
  --control: #151719;
  --titlebar: #191c1f;
  --tag-neutral-bg: #2a3034;
  --tag-neutral-text: #bdc6cc;
  --status-bg: #292e32;
  --summary-bg: #173248;
  --summary-text: #f5f8fa;
  --code-text: #c7d0d6;
  --lab-liquid: #82e8cb;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

html { scrollbar-color: var(--line-strong) transparent; }

button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-header {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1680px) / 2));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand-block { display: flex; align-items: center; gap: 11px; }
.brand-mark, .empty-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: var(--summary-text);
  border-radius: 6px;
  font-weight: 700;
}
.brand-mark svg { width: 23px; height: 23px; overflow: visible; }
.brand-flask { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.brand-liquid, .brand-bubble { fill: var(--lab-liquid); }
.brand-liquid { opacity: 0.72; }
.brand-bubble {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: lab-bubble-rise 2.8s ease-out infinite;
}
.bubble-two { animation-delay: -1.15s; }
.bubble-three { animation-delay: -2.05s; }

@keyframes lab-bubble-rise {
  0%, 18% { opacity: 0; transform: translateY(1.5px) scale(0.75); }
  35% { opacity: 0.95; }
  78% { opacity: 0.65; }
  100% { opacity: 0; transform: translateY(-6px) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .brand-bubble { animation: none; opacity: 0.8; }
}
.brand-block h1 { margin: 0; font-size: 17px; line-height: 1.25; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.sync-status { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.sync-status.warning { color: var(--amber); font-weight: 650; }
.theme-toggle {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}
.theme-toggle:hover { border-color: var(--blue); background: var(--blue-soft); }
.theme-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.workspace {
  width: min(1680px, calc(100% - 48px));
  height: calc(100vh - 66px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
}

.bond-browser {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.browser-tools { padding: 16px; border-bottom: 1px solid var(--line); }
.search-box {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--control);
  color: var(--quiet);
}
.search-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }
.segmented {
  height: 34px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 10px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}
.segmented button { border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 12px; }
.segmented button.active { background: var(--control); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.list-summary { display: flex; justify-content: space-between; padding: 10px 16px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.list-summary label { display: flex; gap: 5px; align-items: center; }
.bond-list { min-height: 0; flex: 1 1 auto; overflow-y: auto; }
.bond-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
  color: inherit;
  text-align: left;
}
.bond-item:hover { background: var(--surface-muted); }
.bond-item.active { background: var(--blue-soft); box-shadow: inset 3px 0 var(--blue); }
.bond-name { min-width: 0; display: flex; align-items: center; gap: 7px; font-weight: 650; }
.bond-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.market-tag, .status-tag, .data-tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.market-tag.sh { background: var(--red-soft); color: var(--red); }
.market-tag.sz { background: var(--blue-soft); color: var(--blue); }
.status-tag { justify-self: end; background: var(--status-bg); color: var(--muted); }
.bond-meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bond-price { color: var(--text); font-variant-numeric: tabular-nums; font-size: 12px; }

.analysis-panel { min-width: 0; min-height: 0; overflow-y: auto; padding: 22px 26px 36px; }
.empty-state { min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.empty-state h2 { margin: 16px 0 4px; color: var(--text); font-size: 17px; }
.empty-state p { margin: 0; }
.error-state .empty-icon { background: var(--red); }
.command-button { margin-top: 16px; padding: 8px 13px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--control); color: var(--text); }

.analysis-titlebar {
  position: sticky;
  top: -22px;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin: -22px -26px 17px;
  padding: 16px 26px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--titlebar);
  box-shadow: 0 1px 2px rgba(20, 29, 38, 0.04);
}
.analysis-titlebar h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.analysis-titlebar p { margin: 5px 0 0; color: var(--muted); }
.title-tags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.data-tag.official { background: var(--green-soft); color: var(--green); }
.data-tag.estimated { background: var(--amber-soft); color: var(--amber); }
.data-tag.neutral { background: var(--tag-neutral-bg); color: var(--tag-neutral-text); }

.metrics-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; border: 1px solid var(--line); border-radius: 7px; background: var(--line); box-shadow: var(--shadow); overflow: hidden; }
.metric { min-width: 0; padding: 13px 14px; background: var(--surface); }
.metric-label { color: var(--muted); font-size: 12px; }
.metric-value { margin-top: 5px; font-size: 18px; font-weight: 680; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-note { margin-top: 3px; color: var(--quiet); font-size: 12px; line-height: 1.4; }

.section-band { margin-top: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 13px; }
.section-heading h3 { margin: 0; font-size: 14px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.assumptions { display: grid; grid-template-columns: 1fr 1.4fr 1.4fr; gap: 18px; }
.assumptions.two-column { grid-template-columns: 1fr 1fr; }
.field-label { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.field-label output { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.number-field { height: 38px; display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.number-field input { width: 100%; height: 100%; border: 0; padding: 0 10px; outline: 0; color: var(--text); background: var(--control); }
.number-field span { padding: 0 10px; color: var(--muted); border-left: 1px solid var(--line); }
input[type="range"] { width: 100%; accent-color: var(--blue); }
.field-help { margin: 5px 0 0; color: var(--quiet); font-size: 12px; line-height: 1.5; }
.valuation-anchors { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.valuation-anchors button { min-width: 0; padding: 6px 7px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-muted); color: var(--muted); text-align: left; }
.valuation-anchors button:hover { border-color: var(--blue); background: var(--blue-soft); }
.valuation-anchors span, .valuation-anchors strong { display: block; overflow-wrap: anywhere; }
.valuation-anchors span { font-size: 11px; }
.valuation-anchors strong { margin-top: 2px; color: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; }

.plans-wrap { overflow-x: auto; }
.plans-table { width: 100%; min-width: 880px; border-collapse: collapse; }
.plans-table.sh { min-width: 700px; }
.plans-table.sz { min-width: 820px; }
.plans-table th { padding: 9px 10px; color: var(--muted); background: var(--surface-muted); border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 650; text-align: right; white-space: nowrap; }
.plans-table th[rowspan] { vertical-align: middle; }
.plans-table .scenario-group { color: var(--muted); text-align: center; }
.plans-table .scenario-group.group-extra { color: var(--amber); }
.plans-table .scenario-labels .extra-label { color: var(--muted); }
.plans-table .scenario-labels th:first-child { text-align: right; }
.plans-table th:first-child, .plans-table td:first-child { text-align: left; }
.plans-table td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plans-table tr:last-child td { border-bottom: 0; }
.plans-table tbody tr { cursor: pointer; }
.plans-table tbody tr:hover { background: var(--surface-muted); }
.plans-table tbody tr.selected { background: var(--blue-soft); box-shadow: inset 3px 0 var(--blue); }
.plan-label { display: block; color: var(--text); font-weight: 650; }
.plan-note { display: block; max-width: 210px; margin-top: 3px; color: var(--quiet); font-size: 12px; white-space: normal; line-height: 1.45; }
.positive { color: var(--green); font-weight: 650; }
.negative { color: var(--red); font-weight: 650; }
.uncertain { color: var(--amber); }

.selected-summary { display: grid; grid-template-columns: 1.3fr repeat(4, 1fr); margin-top: 13px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.selected-summary.sh { grid-template-columns: 1.3fr repeat(6, 1fr); }
.selected-summary.sz { grid-template-columns: 1.3fr repeat(5, 1fr); }
.summary-intro { padding: 13px; background: var(--summary-bg); color: var(--summary-text); }
.summary-intro span { display: block; font-size: 12px; opacity: 0.7; }
.summary-intro strong { display: block; margin-top: 4px; font-size: 17px; }
.summary-cell { padding: 13px; background: var(--surface); border-left: 1px solid var(--line); }
.summary-cell span { display: block; color: var(--muted); font-size: 12px; }
.summary-cell strong { display: block; margin-top: 5px; font-size: 15px; font-variant-numeric: tabular-nums; }

.audit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.audit-box { padding: 13px; background: var(--surface-muted); border: 1px solid var(--line); border-radius: 6px; }
.audit-box h4 { margin: 0 0 8px; font-size: 13px; }
.audit-box code { display: block; color: var(--code-text); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; line-height: 1.65; white-space: normal; overflow-wrap: anywhere; }
.audit-box p { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.warning { color: var(--amber); }
.source-line { margin-top: 13px; color: var(--quiet); font-size: 12px; line-height: 1.5; }
.source-line a { color: var(--blue); }

@media (max-width: 1300px) {
  .metrics-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 320px minmax(0, 1fr); }
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .assumptions { grid-template-columns: 1fr 1fr; }
  .assumptions > :first-child { grid-column: 1 / -1; }
  .assumptions.two-column > :first-child { grid-column: auto; }
  .selected-summary { grid-template-columns: repeat(2, 1fr); }
  .selected-summary.sh { grid-template-columns: repeat(2, 1fr); }
  .selected-summary.sz { grid-template-columns: repeat(2, 1fr); }
  .summary-intro { grid-column: 1 / -1; }
  .summary-cell:nth-child(2n) { border-left: 0; }
  .summary-cell { border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .app-header { height: 60px; padding: 0 14px; }
  .sync-status { font-size: 11px; }
  .workspace { width: 100%; height: auto; display: block; }
  .bond-browser { height: 390px; border-right: 0; border-bottom: 1px solid var(--line); }
  .analysis-panel { padding: 18px 14px 30px; overflow: visible; }
  .analysis-titlebar { top: 0; display: block; margin: -18px -14px 17px; padding: 13px 14px 12px; }
  .title-tags { justify-content: flex-start; margin-top: 10px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .metric:last-child { grid-column: 1 / -1; }
  .assumptions, .audit-grid { grid-template-columns: 1fr; }
  .assumptions > :first-child { grid-column: auto; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
}

@media (max-width: 390px) {
  .brand-block p { display: none; }
  .list-summary { padding-left: 12px; padding-right: 12px; }
  .browser-tools { padding: 12px; }
  .analysis-panel { padding-left: 10px; padding-right: 10px; }
  .analysis-titlebar { margin-left: -10px; margin-right: -10px; padding-left: 10px; padding-right: 10px; }
  .section-band { padding: 12px; }
}
