:root {
  --bg: #040404;
  --panel: #0b0b0b;
  --panel-alt: #111111;
  --border: rgba(255, 255, 255, 0.8);
  --border-soft: rgba(255, 255, 255, 0.18);
  --text: #f5f5f5;
  --muted: rgba(255, 255, 255, 0.62);
  --dim: rgba(255, 255, 255, 0.34);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    radial-gradient(circle at top, rgba(255, 255, 255, 0.05), transparent 40%),
    var(--bg);
  background-size: 28px 28px, 28px 28px, auto, auto;
  color: var(--text);
  font-family: "IBM Plex Mono", "SFMono-Regular", "Consolas", "Courier New", monospace;
}

html {
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.32) rgba(255, 255, 255, 0.05);
}

*::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

*::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.36), rgba(255, 255, 255, 0.2));
  border: 2px solid #050505;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(255, 255, 255, 0.28));
}

*::-webkit-scrollbar-corner {
  background: rgba(255, 255, 255, 0.04);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(transparent 0%, rgba(255, 255, 255, 0.02) 50%, transparent 100%);
  background-size: 100% 5px;
  pointer-events: none;
  opacity: 0.25;
}

.terminal-shell {
  padding: 20px;
}

.topbar,
.ribbon,
.panel {
  border: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 24px;
  align-items: flex-end;
}

.eyebrow,
.panel-kicker,
.panel-note,
.detail-label,
.status-label,
.ribbon-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
}

.app-title,
.panel-title {
  margin: 6px 0 0;
  font-size: 26px;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-note {
  margin-top: 8px;
  line-height: 1.5;
}

.topbar-actions {
  display: flex;
  gap: 18px;
  align-items: flex-end;
}

.topbar-form {
  margin: 0;
}

.status-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.status-value,
.ribbon-value {
  font-size: 13px;
  color: var(--text);
}

.leverage-controls {
  min-width: 360px;
}

.summary-controls {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.leverage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.date-range-controls {
  min-width: 520px;
}

.date-range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.chart-preset-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.terminal-input-date {
  width: 150px;
}

.date-range-separator {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.terminal-button-subtle {
  border-color: var(--border-soft);
  color: var(--muted);
}

.terminal-button-subtle:hover {
  color: var(--text);
}

.terminal-range {
  width: 220px;
  accent-color: #f5f5f5;
}

.terminal-button,
.portfolio-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.terminal-button:hover,
.portfolio-button:hover,
.portfolio-button.is-active {
  background: var(--text);
  color: var(--bg);
}

.selection-mode-button {
  position: relative;
}

.selection-mode-button::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  top: calc(100% + 10px);
  width: 300px;
  padding: 10px 12px;
  background: #050505;
  color: #f5f5f5;
  border: 1px solid rgba(255, 255, 255, 0.34);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.42);
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.45;
  white-space: normal;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 20;
}

.selection-mode-button::before {
  content: "";
  position: absolute;
  left: 18px;
  top: calc(100% + 4px);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid rgba(255, 255, 255, 0.34);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 21;
}

.selection-mode-button:hover::after,
.selection-mode-button:hover::before,
.selection-mode-button:focus-visible::after,
.selection-mode-button:focus-visible::before {
  opacity: 1;
  transform: translateY(0);
}

.ribbon {
  margin-top: 14px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: 18px;
}

.portfolio-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.benchmark-toggle-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 36px;
}

.benchmark-toggle-row.compact {
  justify-content: flex-start;
}

.benchmark-label,
.benchmark-note {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.benchmark-note {
  color: var(--dim);
  letter-spacing: 0.08em;
}

.benchmark-button {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  border: 1px solid var(--border-soft);
  padding: 8px 12px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.benchmark-button:hover,
.benchmark-button.is-active {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border);
}

.benchmark-button:disabled {
  cursor: not-allowed;
  color: var(--dim);
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.015);
}

.chart-preset-button {
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  border: 1px solid var(--border-soft);
  padding: 7px 10px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.chart-preset-button:hover,
.chart-preset-button.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-color: var(--border);
}

.workspace {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
  pointer-events: none;
}

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

.split-header {
  align-items: center;
}

.sidebar {
  min-height: calc(100vh - 150px);
}

.sidebar-controls {
  margin-bottom: 14px;
}

.terminal-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  border: 1px solid var(--border-soft);
  padding: 10px 12px;
  font: inherit;
}

.terminal-input::placeholder {
  color: var(--dim);
}

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

.login-panel {
  width: min(100%, 480px);
  border: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015));
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-copy {
  color: var(--muted);
  line-height: 1.6;
  margin: 14px 0 0;
}

.login-error {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.login-form {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-input {
  height: 46px;
}

.login-submit {
  margin-top: 4px;
  width: 100%;
}

.login-footnote {
  margin-top: 16px;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.fund-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 260px);
  overflow-y: auto;
  padding-right: 6px;
}

.fund-card {
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.015);
  padding: 12px;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.fund-card:hover,
.fund-card.is-active {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.06);
}

.fund-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.fund-name {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.fund-weight,
.fund-date {
  color: var(--muted);
  font-size: 11px;
}

.fund-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  align-items: center;
}

.fund-sharpe {
  color: var(--text);
  font-size: 11px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.fund-signal-summary {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.main-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.summary-panel {
  grid-column: span 12;
}

.chart-panel {
  grid-column: span 6;
}

.third-panel {
  grid-column: span 4;
}

.wide-panel {
  grid-column: span 12;
}

.fund-detail-panel {
  grid-column: span 12;
}

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

.stat-card {
  border: 1px solid var(--border-soft);
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.stat-value {
  margin-top: 10px;
  font-size: 22px;
  letter-spacing: 0.04em;
}

.chart-host {
  width: 100%;
}

.large-chart {
  height: 360px;
}

.medium-chart {
  height: 290px;
}

#portfolio-correlation-matrix-chart,
#portfolio-weight-history-chart,
#portfolio-constituents-chart,
#portfolio-comparison-chart {
  height: 420px;
}

.allocation-breakdown {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 14px;
  align-items: stretch;
  height: 100%;
}

.allocation-pie-canvas {
  min-width: 0;
  height: 100%;
}

.allocation-breakdown-list {
  border-left: 1px solid var(--border-soft);
  padding-left: 12px;
  overflow-y: auto;
}

.allocation-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.allocation-swatch {
  width: 10px;
  height: 10px;
  margin-top: 4px;
}

.allocation-row-name {
  font-size: 12px;
  line-height: 1.35;
}

.allocation-row-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.allocation-row-share {
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.weight-badge {
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.fund-detail-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.detail-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

.wide-column {
  height: 100%;
  min-width: 0;
}

.detail-block,
.chart-card {
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.018);
  padding: 14px;
}

.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.chart-card-header .detail-label {
  margin-top: 2px;
}

.detail-copy {
  margin: 10px 0 0;
  color: var(--text);
  line-height: 1.6;
  font-size: 13px;
}

.signal-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  font-size: 12px;
}

.signal-list li {
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
  padding: 9px 10px;
  line-height: 1.55;
}

.signal-list li.signal-emphasis {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.055);
}

.terminal-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.terminal-table td {
  border-bottom: 1px solid var(--border-soft);
  padding: 8px 0;
  font-size: 12px;
  vertical-align: top;
}

.terminal-table td:first-child {
  color: var(--muted);
  padding-right: 14px;
  width: 42%;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.terminal-table td:last-child {
  text-align: right;
}

.detail-chart-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  flex: 1 1 0;
  min-height: 0;
}

.full-width-card {
  flex: 1 1 0;
  margin-top: 14px;
  min-height: 0;
}

.fund-detail-panel .wide-column {
  display: flex;
  flex-direction: column;
}

.fund-detail-panel .chart-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.fund-detail-panel .detail-chart-row .chart-card {
  min-height: 360px;
}

.fund-detail-panel .full-width-card {
  min-height: 360px;
}

.fund-detail-panel .chart-card .chart-host {
  flex: 1 1 auto;
  min-height: 0;
}

.fund-detail-panel .medium-chart {
  height: 100%;
  min-height: 300px;
}

.fund-detail-panel .large-chart {
  height: 100%;
  min-height: 360px;
}

.image-block {
  margin-top: 18px;
}

.chart-gallery {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.gallery-card {
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.gallery-label {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.gallery-card img {
  display: block;
  width: 100%;
  padding: 12px;
  object-fit: contain;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.05), transparent 45%),
    #020202;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.empty-state {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .fund-detail-grid {
    grid-template-columns: 1fr;
  }

  .chart-gallery,
  .allocation-breakdown,
  .detail-chart-row,
  .stats-grid,
  .ribbon {
    grid-template-columns: 1fr;
  }

  .allocation-breakdown-list {
    border-left: 0;
    border-top: 1px solid var(--border-soft);
    padding-left: 0;
    padding-top: 12px;
    max-height: 220px;
  }

  .leverage-controls {
    min-width: 0;
    width: 100%;
  }

  .date-range-controls {
    min-width: 0;
    width: 100%;
  }

  .leverage-row {
    flex-wrap: wrap;
  }

  .date-range-row {
    flex-wrap: wrap;
  }

  .terminal-range {
    width: 100%;
  }

  .chart-panel,
  .third-panel,
  .summary-panel,
  .fund-detail-panel {
    grid-column: span 12;
  }
}
