:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1d2433;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --amber: #d97706;
  --green: #16a34a;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; background: #eef1f5; padding: 1px 4px; border-radius: 4px; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.nav { display: flex; gap: 14px; }
.nav a { color: var(--text); }
.topbar form.inline { margin-left: auto; }
.container { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 20px 16px; }
.footer { padding: 12px 16px; color: var(--muted); font-size: 12px; text-align: center; }

h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card-wide { grid-column: 1 / -1; }
.card-switch.is-on { border-color: var(--danger); background: #fff5f5; }

.kv { list-style: none; margin: 0; padding: 0; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.kv li:last-child { border-bottom: 0; }
.kv li span:first-child { color: var(--muted); }
.list { padding-left: 20px; }
.status-line { font-size: 15px; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; background: #9ca3af; }
.dot-green { background: var(--green); }
.dot-red { background: var(--danger); }
.dot-amber { background: var(--amber); }
.dot-grey { background: #9ca3af; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
.badge-warn { background: #fef3c7; color: #92400e; }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; background: #e5e7eb; color: var(--text);
}
.btn:hover { filter: brightness(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: #e5e7eb; }
.btn-link { background: none; color: var(--primary); padding: 4px 6px; font-weight: 500; }

.form label { display: block; margin-bottom: 12px; font-weight: 500; }
.form input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #cbd2dc; border-radius: 6px; font: inherit; }
.form input:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }

.auth-box { max-width: 420px; margin: 40px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.auth-box-wide { max-width: 560px; }
.steps { padding-left: 20px; }
.qr { text-align: center; margin: 12px 0; }
.qr svg { width: 220px; height: 220px; }
.secret code { font-size: 15px; letter-spacing: 0.08em; }

.flash { padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; border: 1px solid transparent; }
.flash-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.flash-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }

.prose { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 860px; }
.prose h1 { font-size: 22px; }
.prose h2 { font-size: 18px; margin-top: 24px; }
.prose table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.prose pre { background: #eef1f5; padding: 10px; border-radius: 6px; overflow-x: auto; }
.prose img { max-width: 100%; }

@media (max-width: 600px) {
  .topbar { gap: 10px; }
  .topbar form.inline { margin-left: 0; }
  .container { padding: 14px 12px; }
  .auth-box { margin: 16px auto; padding: 18px; }
}

/* --- Phase 1: portfolios, accounts, charts --- */
.selection { display: flex; flex-wrap: wrap; gap: 24px; }
.selection fieldset { border: 0; padding: 0; margin: 0; min-width: 220px; }
.selection legend { font-weight: 600; margin-bottom: 6px; }
.check { display: block; padding: 2px 0; font-weight: 400; }
.check input { margin-right: 6px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric-label { color: var(--muted); font-size: 13px; }
.metric-value { font-size: 20px; font-weight: 600; }
.pos { color: #15803d; }
.neg { color: #b91c1c; }
.table .num, .table td.num, .table th.num { text-align: right; white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.table-monthly td, .table-monthly th { padding: 4px 6px; font-size: 13px; text-align: right; }
.table-monthly th:first-child { text-align: left; }
.table tr.total td { border-top: 2px solid var(--border); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.job-log { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: #374151; }
.form select { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #cbd2dc; border-radius: 6px; font: inherit; background: #fff; }
.inline select { padding: 4px 6px; border: 1px solid #cbd2dc; border-radius: 6px; font: inherit; }

.chart { width: 100%; height: auto; display: block; font-family: inherit; }
.chart-grid { stroke: #e3e6ea; stroke-width: 1; }
.chart-tick { stroke: #9ca3af; stroke-width: 1; }
.chart-baseline { stroke: #9ca3af; stroke-width: 1; stroke-dasharray: 4 4; }
.chart-label { fill: var(--muted); font-size: 12px; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-index .chart-line { stroke: #15803d; }
.chart-dot { fill: var(--primary); }
.chart-index .chart-dot { fill: #15803d; }
.chart-empty { fill: var(--muted); font-size: 14px; }

/* Phase 2: copy pipeline */
.badge-proposed { background: #dbeafe; color: #1e40af; }
.badge-blocked { background: #fee2e2; color: #991b1b; }
.badge-approved, .badge-executing { background: #fef3c7; color: #92400e; }
.badge-executed { background: #dcfce7; color: #166534; }
.badge-rejected, .badge-expired, .badge-failed, .badge-skipped { background: #e5e7eb; color: #374151; }
.decide-form .qty { width: 80px; padding: 6px 8px; border: 1px solid #cbd2dc; border-radius: 6px; font: inherit; margin-right: 6px; }
.table tr.is-blocked td { background: #fff7ed; }
.table tr.is-open td { background: #fff5f5; }
.pre { white-space: pre-line; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.rule-form fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; }
.rule-form legend { padding: 0 6px; color: var(--muted); font-size: 13px; }
.rule-form details { margin: 0 0 12px; }
.rule-form summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.proposal { padding: 8px 0; border-bottom: 1px solid var(--border); }
.proposal:last-child { border-bottom: 0; }
