/* 与 AlphaDesk（Streamlit 浅色主题）同一套视觉 */
@font-face {
  font-family: "Source Sans Pro";
  src: url("/static/fonts/SourceSansVF.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --secondary: #f0f2f6;
  --text: #31333f;
  --muted: rgba(49, 51, 63, 0.6);
  --primary: #ff4b4b;
  --border: rgba(49, 51, 63, 0.2);
  --ok: #21c354;
  --bad: #ff2b2b;
  --warn: #faca2b;
  --up: #ff2b2b;
  --down: #21c354;
  --radius: 0.5rem;
  --font: "Source Sans Pro", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --side: 21rem;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
}
.tab-radio {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.app {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: var(--side);
  flex: 0 0 var(--side);
  background: var(--secondary);
  color: var(--text);
  padding: 2rem 1.5rem 2.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.side-title {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.side-note {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 1rem 0 0;
  line-height: 1.5;
  word-break: break-word;
}

.workspace {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.topbar {
  height: 3.75rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.5rem 1rem;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
main {
  padding: 1rem 5rem 4rem;
}
main > h1 {
  margin: 0 0 0.35rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: #262730;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.75rem;
  min-height: 2.5rem;
}
.dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--warn);
}
.dot.live { background: var(--ok); }
.dot.off { background: var(--primary); }

.caption {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 1rem;
  line-height: 1.5;
}

.risk {
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  line-height: 1.35;
  margin: 0 0 0.6rem;
  background: #e6f3fb;
  color: var(--text);
}
.risk.ok { background: #e6f3fb; }
.risk.bad { background: #ffe8e6; }

.board {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0 0 0.75rem;
}
.metrics, .cashflow {
  display: grid;
  gap: 0.45rem;
}
.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cashflow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric, .cashflow article {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem 0.45rem;
}
.lm-label { color: var(--muted); font-size: 0.72rem; margin-bottom: 0.05rem; line-height: 1.2; }
.lm-value {
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--text);
}
.lm-value.sm { font-size: 1.05rem; }
.lm-cny { color: var(--muted); font-size: 0.72rem; margin-top: 0.05rem; line-height: 1.2; }
.lm-diff { font-size: 0.72rem; font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; }
.lm-diff.up, .lm-value.pos, .lm-cny.pos { color: var(--up); }
.lm-diff.down, .lm-value.neg, .lm-cny.neg { color: var(--down); }
.lm-diff.flat { display: none; }
.metric {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 0.45rem;
  align-items: end;
}
.metric .lm-label { grid-column: 1 / -1; }
.metric .lm-value { grid-column: 1; }
.metric .lm-diff { grid-column: 2; grid-row: 2; margin: 0 0 0.05rem; align-self: end; }
.metric .lm-cny { grid-column: 1 / -1; }
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.05rem;
}
.split .k { color: var(--muted); font-size: 0.75rem; margin-bottom: 0.15rem; }

.param-grid { display: flex; flex-direction: column; gap: 0.85rem; margin-bottom: 1rem; }
.param-grid label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.6rem;
  font-size: 0.875rem;
  color: var(--text);
}
.param-grid label.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 0.75rem;
  row-gap: 0.15rem;
  margin-bottom: 0.15rem;
}
.param-grid label.slider > span:last-of-type {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}
.param-grid label.check {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.4;
}
.param-grid input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 1.15rem;
  margin: 0 0 0.35rem;
  background: transparent;
  accent-color: var(--primary);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.param-grid input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg, #ff4b4b var(--p, 40%), rgba(49, 51, 63, 0.16) var(--p, 40%));
}
.param-grid input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #ff4b4b;
  box-shadow: 0 1px 2px rgba(49, 51, 63, 0.25);
}
.param-grid input[type="range"]::-moz-range-track {
  height: 4px;
  border: 0;
  border-radius: 99px;
  background: rgba(49, 51, 63, 0.16);
}
.param-grid input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 99px;
  background: #ff4b4b;
}
.param-grid input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #ff4b4b;
}
.param-grid input[type="number"],
.param-grid select,
.ladder-bar select,
.ladder-bar input[type="number"],
.calc-grid input[type="number"] {
  flex: 1 0 100%;
  width: 100%;
  min-height: 2.5rem;
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.25rem 0.75rem;
  font: inherit;
  font-size: 1rem;
}
.param-grid select,
.ladder-bar select,
.param-grid select option,
.ladder-bar select option {
  font-size: 0.8125rem;
  font-weight: 400;
}
.param-grid select,
.ladder-bar select {
  appearance: none;
  padding-right: 1.85rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.2 L6 6.2 L11 1.2' fill='none' stroke='%2331333f' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 0.7rem;
}
.param-grid input[type="number"]:focus,
.param-grid select:focus,
.ladder-bar select:focus,
.ladder-bar input[type="number"]:focus,
.calc-grid input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
}
.param-grid input[type="checkbox"],
.ladder-bar input[type="checkbox"] {
  accent-color: var(--primary);
  width: 1rem;
  height: 1rem;
  margin-top: 0.15rem;
}

.btn {
  appearance: none;
  cursor: pointer;
  background: var(--primary);
  color: #ffffff;
  font: inherit;
  font-weight: 400;
  font-size: 1rem;
  min-height: 2.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  line-height: 1.6;
}
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.sidebar .btn { width: 100%; }

.bar {
  margin-top: 0.3rem;
  height: 0.28rem;
  border-radius: 99px;
  background: rgba(49, 51, 63, 0.12);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.4s ease;
}

.tabbar {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.28rem;
  margin: 0.35rem 0 1rem;
  background: var(--secondary);
  border: 1px solid rgba(49, 51, 63, 0.12);
  border-radius: 0.7rem;
}
.tabbar label {
  cursor: pointer;
  padding: 0.42rem 1.15rem;
  border-radius: 0.48rem;
  color: rgba(49, 51, 63, 0.72);
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.4;
  user-select: none;
}
.tabbar label:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
}
body:has(#tabUnits:checked) .tabbar label[for="tabUnits"],
body:has(#tabLadder:checked) .tabbar label[for="tabLadder"],
body:has(#tabPos:checked) .tabbar label[for="tabPos"] {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 1px 2px rgba(255, 75, 75, 0.28);
}
.panel { display: none; }
body:has(#tabUnits:checked) #panelUnits,
body:has(#tabLadder:checked) #panelLadder,
body:has(#tabPos:checked) #panelPos { display: block; }

.sec-title {
  font-size: 1.5rem;
  margin: 0.25rem 0 0.75rem;
  font-weight: 600;
  color: #262730;
}

.ladder-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin-bottom: 0.5rem;
}
.ladder-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--text);
  font-size: 0.875rem;
}
.ladder-bar label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  padding-bottom: 0.45rem;
}
.ladder-bar select,
.ladder-bar input[type="number"] { min-width: 8rem; width: auto; }
.ladder-note { margin: 0.15rem 0 0.75rem; color: var(--muted); font-size: 0.875rem; }
.ladder-src {
  display: block;
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.unit {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1rem 0.9rem;
  margin-bottom: 0.75rem;
}
.held-opt {
  margin: 0.15rem 0 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: #e6f3fb;
  color: var(--text);
  font-size: 0.95rem;
}
.unit-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}
.unit-head strong { font-size: 1.05rem; }
.unit-head code {
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--primary);
  background: var(--secondary);
  padding: 0.05rem 0.35rem;
  border-radius: 0.25rem;
}
.unit-head .status { color: var(--muted); font-size: 0.875rem; }
.unit-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
}
.unit-grid.vig { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cell .k { color: var(--muted); font-size: 0.875rem; }
.cell .v {
  font-weight: 600;
  margin-top: 0.1rem;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
}
.cell .s { color: var(--muted); font-size: 0.8rem; margin-top: 0.1rem; }

.cushion-calc {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(49, 51, 63, 0.1);
}
.cushion-calc .calc-label { color: var(--muted); font-size: 0.875rem; margin-bottom: 0.45rem; }
.calc-step { display: inline-flex; align-items: center; gap: 0.25rem; }
.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  margin-left: 0.2rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: help;
  user-select: none;
  vertical-align: middle;
  background: #fff;
}
.help-tip:hover, .help-tip:focus { color: var(--primary); border-color: var(--primary); outline: none; }
.help-tip::after {
  content: attr(data-tip);
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.45rem);
  width: min(280px, 70vw);
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius);
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  opacity: 0;
  visibility: hidden;
  z-index: 40;
  white-space: normal;
  pointer-events: none;
}
.help-tip:hover::after, .help-tip:focus::after { opacity: 1; visibility: visible; }
.calc-grid .help-tip::after { left: 50%; right: auto; transform: translateX(-50%); }
.calc-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.2fr 0.9fr;
  gap: 0.6rem;
  align-items: end;
}
.calc-grid .field .k { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.2rem; }
.calc-grid .field .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.calc-grid .field .s { color: var(--muted); font-size: 0.75rem; margin-top: 0.12rem; }

.prem-sum {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 0 0 0.85rem;
}
.prem-sum:empty { display: none; }
.prem-stat {
  background: #fff5f5;
  border: 1px solid rgba(255, 75, 75, 0.35);
  border-radius: 0.7rem;
  padding: 0.55rem 0.85rem 0.65rem;
}
.prem-stat.keep {
  background: #f3fbf6;
  border-color: rgba(33, 195, 84, 0.45);
}
.prem-stat.assign {
  background: #fff8eb;
  border-color: rgba(214, 158, 46, 0.55);
}
.prem-stat .k {
  color: rgba(49, 51, 63, 0.72);
  font-size: 0.8rem;
  font-weight: 650;
}
.prem-stat .v {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}
.prem-stat.assign .v { color: #9a6700; }
.prem-stat .s {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 860px) {
  .prem-sum { grid-template-columns: 1fr; }
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td {
  padding: 0.45rem 0.65rem;
  text-align: right;
  border-bottom: 1px solid rgba(49, 51, 63, 0.12);
  font-variant-numeric: tabular-nums;
  background: #ffffff;
}
th:first-child, td:first-child,
th:nth-child(2), td:nth-child(2) { text-align: left; }
th {
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  background: var(--secondary);
}
tbody tr:hover td { background: #f7f8fa; }
.pos { color: var(--up); }
.neg { color: var(--down); }
.cost-cell { color: rgba(49, 51, 63, 0.72); }
.px-cell { font-weight: 700; }
.quote-sub {
  font-weight: 650;
  font-size: 0.75rem;
  margin-top: 0.08rem;
  line-height: 1.3;
}
.pnl-cny {
  color: inherit;
  opacity: 0.75;
  font-size: 0.75rem;
  margin-top: 0.1rem;
}
.th-sum {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  font-weight: 650;
}
.th-sum-cny { display: block; margin-top: 0.05rem; font-size: 0.7rem; font-weight: 600; opacity: 0.8; }

@media (max-width: 1100px) {
  main { padding: 1rem 1.5rem 3rem; }
  .metrics, .cashflow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .unit-grid, .unit-grid.vig, .calc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-basis: auto;
    height: auto;
    position: static;
  }
  main { padding: 1rem; }
  .metrics, .cashflow { grid-template-columns: 1fr; }
}

.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-right: 0.75rem;
}
.text-link {
  color: var(--text);
  font-size: 0.875rem;
  text-decoration: none;
}
.text-link:hover { color: var(--primary); }
.btn.ghost {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--secondary);
}
.auth-card {
  width: min(28rem, 100%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem 1.75rem;
}
.auth-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}
.auth-card .caption { margin: 0 0 1.25rem; }
.auth-card label {
  display: block;
  margin: 0 0 0.85rem;
  font-size: 0.875rem;
  color: var(--muted);
}
.auth-card input[type="text"],
.auth-card input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 2.5rem;
  padding: 0.25rem 0.75rem;
}
.auth-card .btn { width: 100%; margin-top: 0.4rem; }
.auth-error { color: var(--bad); min-height: 1.4rem; margin: 0.6rem 0 0; font-size: 0.875rem; }

.users-page { max-width: 52rem; }
.user-form, .user-row {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr auto;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.6rem;
}
.user-row { grid-template-columns: 1.2fr 1.2fr auto auto; }
.users-page input[type="text"],
.users-page input[type="password"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 2.5rem;
  padding: 0.25rem 0.75rem;
  width: 100%;
}
.user-meta { color: var(--muted); font-size: 0.8rem; margin: 0 0 1rem; }
.btn.danger {
  background: var(--bg);
  color: var(--bad);
  border-color: rgba(255, 43, 43, 0.45);
}
@media (max-width: 720px) {
  .user-form, .user-row { grid-template-columns: 1fr; }
}
