:root {
  color-scheme: light;
  --bg: #f4f5f0;
  --panel: #ffffff;
  --text: #172026;
  --muted: #69737a;
  --border: #d8ddd7;
  --green: #1f7a5a;
  --blue: #285f7f;
  --amber: #b56d22;
  --red: #b24a3b;
  --market-up: #b24a3b;
  --market-down: #285f7f;
  --ink: #273036;
  --shadow: 0 12px 28px rgba(23, 32, 38, 0.08);
  --panel-shadow: 0 6px 18px rgba(23, 32, 38, 0.04);
  --input-bg: #ffffff;
  --table-head: #f8faf6;
  --sidebar-bg: #172026;
  --sidebar-text: #ffffff;
  --sidebar-muted: #d8e0df;
  --sidebar-hover: #26333a;
  --soft-blue: #e8eff2;
  --soft-red: #f5e2de;
  --code-bg: #f4f6f2;
  --backdrop: rgba(23, 32, 38, 0.52);
  --chart-axis: #d8ddd7;
  --chart-grid: #edf0ec;
  --chart-zero: #b9c2b7;
  --chart-red: #d62728;
  --chart-yellow: #f2b705;
  --chart-green: #2ca02c;
  --chart-blue: #1f77b4;
  --chart-orange: #ff7f0e;
  --chart-purple: #7b3fb2;
  --chart-mono: #111111;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1218;
  --panel: #131d27;
  --text: #e6eef3;
  --muted: #aab9c4;
  --border: #2f4150;
  --green: #39c7b5;
  --blue: #7fc7e8;
  --amber: #e0a24d;
  --red: #ff8a82;
  --market-up: #ff8a82;
  --market-down: #7fc7e8;
  --ink: #d8e4ea;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.34);
  --panel-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
  --input-bg: #182633;
  --table-head: #172633;
  --sidebar-bg: #0f1821;
  --sidebar-text: #f3f8fb;
  --sidebar-muted: #aab9c4;
  --sidebar-hover: #1b2b38;
  --soft-blue: #183041;
  --soft-red: #4d2328;
  --code-bg: #1a2a36;
  --backdrop: rgba(0, 0, 0, 0.68);
  --chart-axis: #3a4c59;
  --chart-grid: #21313e;
  --chart-zero: #526777;
  --chart-red: #ff5a5f;
  --chart-yellow: #ffd43b;
  --chart-green: #69db7c;
  --chart-blue: #4dabf7;
  --chart-orange: #ffa94d;
  --chart-purple: #b197fc;
  --chart-mono: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

button[data-busy="1"]:disabled {
  cursor: progress;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

label span {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: var(--table-head);
}

td {
  font-size: 13px;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sync-message {
  white-space: pre-wrap;
}

.diagnostic-cell {
  min-width: 240px;
  white-space: pre-wrap;
}

.validation-summary {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  line-height: 1.5;
}

.validation-summary ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.eyebrow {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-panel h1 {
  margin-top: 4px;
  font-size: 29px;
}

.stack {
  display: grid;
  gap: 15px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.check-row span {
  margin: 0;
  font-size: 13px;
  color: var(--ink);
}

.form-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
}

.brand-block h1 {
  margin-top: 4px;
  font-size: 23px;
}

.nav-list {
  display: grid;
  gap: 7px;
}

.nav-list button {
  min-height: 42px;
  border-radius: 7px;
  background: transparent;
  color: var(--sidebar-muted);
  text-align: left;
  padding: 10px 12px;
  font-weight: 750;
}

.nav-list button:hover,
.nav-list button.active {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-badge,
.user-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.mode-badge {
  background: #dfece3;
  color: #155d44;
}

.mode-badge.real {
  background: #f3dfd9;
  color: #8c3428;
}

.user-badge {
  background: var(--sidebar-hover);
  color: var(--sidebar-muted);
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar-title {
  display: grid;
  gap: 4px;
}

.topbar-title h2 {
  font-size: 24px;
}

.sync-state {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--code-bg);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.sync-state.ready {
  color: var(--green);
}

.sync-state.blocked {
  color: var(--amber);
}

.topbar-actions,
.button-row,
.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 40px;
  border-radius: 7px;
  padding: 9px 13px;
  font-weight: 800;
  white-space: nowrap;
}

.primary {
  background: var(--green);
  color: #fff;
}

.secondary {
  background: var(--soft-blue);
  color: var(--blue);
}

.ghost {
  background: transparent;
  color: var(--ink);
}

.danger {
  background: var(--soft-red);
  color: var(--red);
}

.danger-soft {
  color: var(--red);
}

.icon-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-size: 18px;
  line-height: 1;
  background: var(--soft-blue);
  color: var(--blue);
}

.icon-btn:hover,
.icon-btn.active {
  background: var(--blue);
  color: #fff;
}

.icon-btn.danger-soft {
  background: var(--soft-red);
  color: var(--red);
}

.icon-btn.danger-soft:hover {
  background: var(--red);
  color: #fff;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.full {
  width: 100%;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 11px 13px;
  color: var(--ink);
}

.status-line time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.status-line.error {
  border-color: #e9b6ad;
  color: var(--red);
}

.section {
  display: none;
}

.section.active {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.control-row {
  justify-content: space-between;
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.segmented > button,
.period-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 76px;
  min-height: 40px;
  padding: 0 12px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

.segmented > :last-child {
  border-right: 0;
}

.period-control button {
  min-width: 0;
  min-height: auto;
  padding: 0;
  background: transparent;
  color: inherit;
  font-weight: 800;
}

.segmented > button.active,
.period-control.active {
  background: var(--blue);
  color: #fff;
}

.period-count-input {
  width: 36px;
  height: 26px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-align: center;
}

.period-control.active .period-count-input {
  border-color: rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.compact-select {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compact-select span {
  margin: 0;
}

.compact-select select {
  width: 220px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

#metricGrid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

#metricGrid .metric-card {
  min-width: 0;
  padding: 14px;
}

#metricGrid .metric-card strong {
  font-size: clamp(17px, 1.45vw, 21px);
}

.market-index-grid {
  padding: 16px 16px 0;
}

.ai-market-layout {
  --ai-index-card-height: clamp(104px, 7vw, 112px);
  --ai-index-stack-height: clamp(440px, calc(28vw + 24px), 472px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 16px 16px 0;
  align-items: stretch;
}

.ai-market-layout .market-index-grid {
  padding: 0;
}

.ai-index-col {
  display: grid;
  grid-template-rows: repeat(4, var(--ai-index-card-height));
  gap: 8px;
  min-height: 0;
}

.ai-index-col .metric-card {
  height: 100%;
  min-height: 0;
}

.ai-index-col .metric-card:nth-child(1) {
  grid-row: 1;
}

.ai-index-col .metric-card:nth-child(2) {
  grid-row: 2;
}

.ai-index-col .metric-card:nth-child(3) {
  grid-row: 3;
}

.ai-index-col .metric-card:nth-child(4) {
  grid-row: 4;
}

.ai-side-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: var(--ai-index-stack-height);
  min-height: 0;
}

.market-bundle-card {
  min-height: 0;
}

.ai-index-col .market-bundle-card {
  align-content: start;
  gap: 8px;
  padding: 10px 12px;
}

.market-bundle-lines {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.market-bundle-item {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.market-bundle-item b {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.market-bundle-item strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.2;
}

.market-bundle-item small {
  font-size: 11px;
  overflow-wrap: anywhere;
}

.ai-allocation-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--panel-shadow);
  flex: 1 1 auto;
  padding: 10px 12px;
  min-height: 0;
}

.portfolio-allocation-box {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  height: 100%;
  padding: 10px 14px;
  align-content: stretch;
}

.investor-trend-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--panel-shadow);
  flex: 0 0 auto;
  padding: 10px 12px 8px;
  min-height: 0;
}

.investor-trend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}

.investor-trend-head span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.investor-trend-canvas {
  display: block;
  width: 100%;
  height: clamp(170px, 12vw, 205px);
}

.allocation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}

.allocation-head span {
  color: var(--muted);
  font-size: 12px;
}

.allocation-visual {
  display: grid;
  grid-template-columns: minmax(145px, 175px) auto;
  align-items: center;
  align-self: center;
  height: 100%;
  justify-content: center;
  gap: 24px;
}

.allocation-donut {
  display: block;
  align-self: center;
  justify-self: center;
  width: min(175px, 100%);
  aspect-ratio: 1 / 1;
  color: var(--text);
}

.allocation-donut-hole {
  fill: var(--panel);
}

.allocation-center-title,
.allocation-center-sub,
.allocation-slice-label {
  text-anchor: middle;
  dominant-baseline: middle;
  fill: currentColor;
}

.allocation-center-title {
  font-size: 17px;
  font-weight: 800;
}

.allocation-center-sub {
  font-size: 15px;
  font-weight: 700;
}

.allocation-slice-label {
  font-size: 14px;
  font-weight: 800;
  fill: rgba(0, 0, 0, 0.66);
}

.allocation-legend {
  display: grid;
  gap: 6px;
}

.allocation-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--ink);
}

.allocation-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(11, 18, 32, 0.1);
}

.allocation-dot-cash {
  background: #9ab34c;
}

.allocation-dot-stock {
  background: #1f88a8;
}

.allocation-dot-fund {
  background: #70609d;
}

.allocation-dot-bond {
  background: #f47a22;
}

.allocation-legend-item strong {
  overflow-wrap: anywhere;
  font-size: 14px;
  flex: 0 1 auto;
  min-width: 0;
}

.allocation-legend-item b {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.allocation-empty {
  color: var(--muted);
}

.market-events-box {
  display: grid;
  gap: 10px;
  margin: 14px 16px 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
}

.diversification-box {
  display: grid;
  gap: 8px;
  margin: 12px 16px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
}

.diversification-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.diversification-head span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.diversification-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}

.diversification-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px 8px;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.diversification-item div {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.diversification-item span,
.diversification-item small {
  color: var(--muted);
  font-size: 11px;
}

.diversification-item strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.diversification-item p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.diversification-item b {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  color: var(--green);
  font-size: 12px;
  white-space: nowrap;
}

.reference-treemap-box {
  display: grid;
  gap: 12px;
  margin: 14px 16px 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
}

.reference-treemap-head,
.reference-treemap-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reference-treemap-head span,
.reference-treemap-title span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.reference-treemap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.reference-treemap-card {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.reference-treemap-image {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.reference-treemap-image img {
  display: block;
  width: 100%;
  aspect-ratio: 80 / 46;
  object-fit: contain;
}

.reference-treemap-sectors {
  display: grid;
  gap: 7px;
}

.reference-treemap-sectors div {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  gap: 6px 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
}

.reference-treemap-sectors b,
.reference-treemap-sectors span {
  font-size: 13px;
}

.reference-treemap-sectors small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.market-events-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.market-events-head span {
  color: var(--muted);
  font-size: 12px;
}

.market-events-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.market-events-list li {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.market-events-list span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.market-events-list strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.market-events-list small {
  color: var(--muted);
  font-size: 12px;
}

.summary-evidence {
  display: grid;
  gap: 8px;
  margin: 10px 0 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--input-bg);
  white-space: normal;
}

.summary-evidence strong {
  color: var(--text);
  font-size: 13px;
}

.summary-evidence-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.summary-evidence-tags span {
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink);
  background: var(--panel);
  font-size: 12px;
}

.summary-evidence p {
  margin: 0;
  color: var(--amber);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.summary-evidence.warning {
  border-color: color-mix(in srgb, var(--amber) 45%, var(--border));
}

.metric-card,
.panel,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--panel-shadow);
}

.metric-card {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 14px;
  padding: 16px;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  font-size: 21px;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.metric-card small {
  color: var(--muted);
}

.metric-card.positive strong,
.positive {
  color: var(--market-up);
}

.metric-card.negative strong,
.negative {
  color: var(--market-down);
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  padding: 16px;
}

.ops-card {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  padding: 14px;
}

.ops-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ops-card strong {
  color: var(--ink);
  font-size: 19px;
  overflow-wrap: anywhere;
}

.ops-card small {
  color: var(--muted);
  line-height: 1.45;
}

.ops-card.ok strong {
  color: var(--green);
}

.ops-card.warn strong {
  color: var(--amber);
}

.ops-card.bad strong {
  color: var(--red);
}

.chart-grid,
.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.panel {
  min-width: 0;
}

.panel.narrow {
  max-width: 920px;
}

.panel-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-head h3 {
  font-size: 15px;
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-actions select {
  width: auto;
  min-width: 120px;
}

.chart-canvas {
  display: block;
  width: 100%;
  height: 278px;
}

.ai-summary-box {
  padding: 16px;
  color: var(--ink);
  overflow-wrap: anywhere;
  line-height: 1.6;
}

.ai-summary-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--text);
}

.ai-summary-meta {
  float: right;
  margin: -30px 0 8px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-align: right;
}

.ai-summary-text {
  clear: both;
  white-space: pre-wrap;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
}

.empty-state h3 {
  font-size: 17px;
}

.empty-state p {
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 14px;
  padding: 16px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.settings-preview {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
  color: var(--muted);
  font-size: 13px;
}

.settings-preview code {
  color: var(--ink);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
}

.manual-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(920px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  margin: 0;
  transform: translate(-50%, -50%);
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.manual-dialog::backdrop {
  background: var(--backdrop);
}

.manual-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: calc(100dvh - 24px);
}

.manual-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.manual-header h3 {
  margin-top: 4px;
  font-size: 19px;
}

.manual-content {
  display: grid;
  gap: 16px;
  overflow: auto;
  padding: 16px;
}

.manual-section {
  display: grid;
  gap: 8px;
}

.manual-section h4 {
  font-size: 15px;
}

.manual-section ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
}

.manual-section li {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.manual-section code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 5px;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    padding: 16px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
  }

  .nav-list button {
    min-width: 112px;
    text-align: center;
  }

  .sidebar-footer {
    margin-left: auto;
    margin-top: 0;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  #metricGrid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .chart-grid,
  .two-column {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar-title {
    min-width: 0;
    flex: 1 1 180px;
  }

  .sync-state {
    width: 100%;
  }

  .topbar-title h2 {
    font-size: 22px;
    overflow-wrap: anywhere;
  }

  .topbar-actions {
    margin-left: auto;
    justify-content: flex-end;
    gap: 8px;
  }

  .topbar-actions .icon-btn {
    flex: 0 0 38px;
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
  }

  .metric-grid,
  #metricGrid,
  .ops-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .ai-market-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .ai-index-col {
    grid-template-rows: auto;
  }

  .ai-side-col,
  .portfolio-allocation-box,
  .allocation-visual {
    height: auto;
  }

  .ai-index-col .metric-card,
  .ai-allocation-card,
  .investor-trend-card,
  .market-bundle-card {
    grid-column: 1;
    grid-row: auto;
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
  }

  .allocation-visual {
    grid-template-columns: 1fr;
  }

  .allocation-donut {
    justify-self: center;
    width: min(180px, 100%);
  }

  .investor-trend-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .investor-trend-head span {
    text-align: left;
  }

  .investor-trend-canvas {
    height: 170px;
  }

  .allocation-legend-item strong,
  .allocation-legend-item b {
    font-size: 14px;
  }

  .market-events-list li {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .market-events-list small {
    grid-column: 2;
  }

  .reference-treemap-head,
  .reference-treemap-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .reference-treemap-head span,
  .reference-treemap-title span {
    text-align: left;
  }

  .status-line {
    align-items: flex-start;
    flex-direction: column;
  }

  .compact-select {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .compact-select select {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .segmented > button,
  .period-control {
    flex: 1;
    min-width: 0;
    padding-left: 6px;
    padding-right: 6px;
  }

  .panel-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .chart-canvas {
    height: 230px;
  }

  table {
    min-width: 640px;
  }

  th,
  td {
    padding: 9px 8px;
  }

  .manual-dialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .manual-shell {
    max-height: calc(100dvh - 16px);
  }

  .manual-header,
  .manual-content {
    padding: 14px;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding: 10px;
  }

  .nav-list button {
    min-width: 96px;
  }

  .topbar-actions {
    width: 100%;
  }

  .chart-canvas {
    height: 210px;
  }
}

.ai-summary-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.ai-freshness {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
}

.ai-freshness.fresh {
  background: rgba(46, 160, 67, 0.18);
  color: rgb(63, 185, 80);
}

.ai-freshness.aging {
  background: rgba(217, 162, 0, 0.18);
  color: rgb(241, 196, 64);
}

.ai-freshness.stale {
  background: rgba(248, 81, 73, 0.18);
  color: rgb(255, 123, 114);
}

.ai-feedback-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid rgba(140, 140, 160, 0.15);
}

.ai-feedback-btn {
  background: rgba(120, 130, 160, 0.12);
  border: 1px solid rgba(140, 140, 160, 0.2);
  color: inherit;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.ai-feedback-btn:hover:not(:disabled) {
  background: rgba(120, 130, 160, 0.22);
}

.ai-feedback-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-feedback-stat {
  margin-left: auto;
  font-size: 12px;
  color: rgba(180, 180, 200, 0.75);
}

.reference-error {
  margin: 6px 0 10px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(248, 81, 73, 0.12);
  color: rgb(255, 138, 128);
  font-size: 12px;
  border: 1px solid rgba(248, 81, 73, 0.25);
}

.reference-held {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(140, 140, 160, 0.2);
  color: rgba(220, 220, 235, 0.85);
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
}

.diversification-item.is-held {
  opacity: 0.6;
}

.diversification-item.is-held b {
  text-decoration: line-through;
  text-decoration-color: rgba(255, 138, 128, 0.7);
}

.muted.small {
  font-size: 11px;
}

.event-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(120, 130, 160, 0.18);
  color: rgba(220, 220, 235, 0.85);
  font-size: 10px;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: middle;
}

.event-tag.holding {
  background: rgba(63, 185, 80, 0.22);
  color: rgb(120, 215, 130);
}

.market-events-list li.is-holding {
  border-left: 2px solid rgba(63, 185, 80, 0.6);
  padding-left: 8px;
}

.market-events-list a {
  color: inherit;
  text-decoration: none;
}

.market-events-list a:hover {
  text-decoration: underline;
}
