:root {
  --bg: #0f1621;
  --bg-elevated: #1a2333;
  --bg-card: #151d2b;
  --border: #2a3548;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #00bfff;
  --accent-dim: #0a7ea4;
  --positive: #3dd68c;
  --negative: #f07178;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(0, 191, 255, 0.08), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(45, 90, 160, 0.12), transparent 50%),
    var(--bg);
}

a {
  color: var(--accent);
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 22, 33, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--accent);
}

.brand p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Framed inside Dunleavy: no second title */
body.is-embedded .app-header {
  display: none;
}

/*
 * Project-page preview (embed=1, no scroll=1):
 * Fixed-height iframe on the parent; THIS document scrolls inside the frame.
 * Never use overflow:hidden on the whole app — that clipped Detail charts on desktop.
 */
html.is-embedded:not(.is-scrollable),
body.is-embedded:not(.is-scrollable) {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
body.is-embedded:not(.is-scrollable) .layout {
  height: auto;
  min-height: min-content;
  padding: 0.65rem 0.75rem 1rem;
  box-sizing: border-box;
  overflow: visible;
}
body.is-embedded:not(.is-scrollable) .main {
  overflow: visible;
  display: block;
  height: auto;
}
body.is-embedded:not(.is-scrollable) #view-overview {
  display: block;
  height: auto;
}
body.is-embedded:not(.is-scrollable) #view-overview > .panel-table {
  display: block;
  overflow: visible;
  height: auto;
}
/* Overview table keeps its own scroll so the list is not endless */
body.is-embedded:not(.is-scrollable) #view-overview .table-wrap {
  max-height: min(42vh, 380px);
  min-height: 180px;
  overflow: auto;
}
body.is-embedded:not(.is-scrollable) .status {
  flex-shrink: 0;
}
body.is-embedded:not(.is-scrollable) #view-detail,
body.is-embedded:not(.is-scrollable) #view-compare {
  padding-bottom: 1rem;
}

/*
 * Full stock-dashboard.html page: natural content height only (no min-height:100%).
 * Parent page scrolls; iframe is resized to content once — avoid infinite grow loop.
 */
html.is-embedded.is-scrollable,
body.is-embedded.is-scrollable {
  height: auto !important;
  min-height: 0 !important;
  overflow: hidden; /* scroll is on the parent page, not inside the iframe */
}
body.is-embedded.is-scrollable .layout {
  height: auto !important;
  min-height: 0 !important;
  padding: 0.75rem 1rem 1.25rem;
  box-sizing: border-box;
  overflow: visible;
  max-width: none;
}
body.is-embedded.is-scrollable .main {
  overflow: visible;
  display: block;
  height: auto;
}
body.is-embedded.is-scrollable #view-overview {
  display: block;
  height: auto;
}
body.is-embedded.is-scrollable #view-overview > .panel {
  display: block;
  overflow: visible;
  height: auto;
}
/* Table list still scrolls inside a fixed max height */
body.is-embedded.is-scrollable #view-overview .table-wrap {
  max-height: 480px;
  overflow: auto;
}
body.is-embedded.is-scrollable #view-detail,
body.is-embedded.is-scrollable #view-compare {
  padding-bottom: 0.25rem;
  height: auto;
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.meta-bar strong {
  color: var(--text);
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  grid-template-areas:
    "view view"
    "side main";
  gap: 1rem;
  padding: 1rem 1.25rem 2rem;
  max-width: 1680px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  align-items: start;
}

.view-bar {
  grid-area: view;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.view-bar .view-help {
  margin: 0.55rem 0 0;
}

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-self: start;
  position: sticky;
  top: 1rem;
}

.main {
  grid-area: main;
  min-width: 0;
}

/* Mobile / narrow: data first, then filters — avoids controls-only first paint */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "view"
      "main"
      "side";
    padding: 0.65rem 0.75rem 1.25rem;
    gap: 0.75rem;
  }

  .sidebar {
    position: static;
  }

  .view-bar {
    position: sticky;
    top: 0;
    z-index: 15;
    border-radius: 10px;
    padding: 0.55rem 0.65rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }

  .view-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
  }

  .view-tabs button {
    width: 100%;
    text-align: center;
    padding: 0.55rem 0.35rem;
    font-size: 0.82rem;
  }

  .view-bar .view-help {
    font-size: 0.78rem;
    margin-top: 0.45rem;
  }

  .panel {
    padding: 0.75rem 0.85rem;
  }

  .date-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .date-row .field {
    margin-bottom: 0.5rem;
  }

  .btn-secondary {
    width: 100%;
    margin-top: 0.45rem;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
  }

  #btnClearCompare {
    width: 100%;
    margin-top: 0.5rem;
    border-radius: 8px;
  }

  .chart-box {
    min-height: 260px;
  }

  .chart-box .plot {
    min-height: 240px;
  }

  .chart-box-compare .plot {
    min-height: 280px;
  }

  .card .value {
    font-size: 1.15rem;
  }

  /* Horizontal scroll for wide tables without crushing columns */
  .table-wrap {
    max-height: min(55vh, 420px);
    -webkit-overflow-scrolling: touch;
  }

  table.data {
    min-width: 560px;
    font-size: 0.8rem;
  }
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.panel-table {
  margin-top: 1rem;
}

.panel-table-hint {
  margin-top: -0.35rem;
}

.date-row {
  display: block;
}

.btn-secondary {
  width: 100%;
  margin-top: 0.5rem;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}

#btnClearCompare {
  width: 100%;
  margin-top: 0.5rem;
  border-radius: 8px;
}

.chart-grid {
  margin-top: 1rem;
}

.view-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.view-tabs button,
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.view-tabs button.active {
  border-color: var(--accent);
  background: rgba(0, 191, 255, 0.12);
  color: var(--accent);
}

.view-tabs button:hover,
.btn:hover {
  border-color: var(--accent-dim);
}

.btn-primary {
  background: rgba(0, 191, 255, 0.18);
  border-color: var(--accent);
  color: var(--accent);
  width: 100%;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-weight: 600;
}

label.field {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

label.field input,
label.field select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.ticker-list {
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 0.35rem;
}

.ticker-list label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.28rem 0.4rem;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.ticker-list label:hover {
  background: rgba(0, 191, 255, 0.08);
}

.ticker-list input {
  accent-color: var(--accent);
}

.main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 0.9rem;
}

.status.error {
  border-color: rgba(240, 113, 120, 0.5);
  color: #ffc4c7;
  background: rgba(240, 113, 120, 0.08);
}

.status.ok {
  border-color: rgba(0, 191, 255, 0.35);
}

.help-text {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.selection-summary {
  margin: 0.55rem 0 0;
  font-size: 0.8rem;
  color: var(--accent);
  min-height: 1.2em;
}

.view-banner {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  margin-bottom: 0.25rem;
}

.view-banner strong {
  color: var(--text);
}

.ticker-list label.focus-ticker {
  outline: 1px solid rgba(0, 191, 255, 0.45);
  background: rgba(0, 191, 255, 0.1);
}

.picker-panel.hidden {
  display: none !important;
}

#panelComparePicker .ticker-list {
  max-height: 320px;
  border-color: rgba(61, 214, 140, 0.35);
}
body.is-embedded.is-scrollable #panelComparePicker .ticker-list {
  max-height: min(420px, 50vh);
}

.cards {
  display: grid;
  gap: 0.65rem;
  /* Default: even rows — avoid one lonely card on a third row */
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.cards[data-count="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.cards[data-count="6"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (min-width: 1100px) {
  .cards[data-count="4"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .cards[data-count="6"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (min-width: 1400px) {
  .cards[data-count="6"] {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.9rem;
  min-width: 0;
}

.card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.card .value {
  font-size: 1.35rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.card .sub {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.pos {
  color: var(--positive);
}

.neg {
  color: var(--negative);
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.chart-grid.two {
  grid-template-columns: 1.2fr 1fr;
}

@media (max-width: 900px) {
  .chart-grid.two {
    grid-template-columns: 1fr;
  }
}

.chart-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.5rem 0.25rem;
  min-height: 320px;
}

.chart-box h3 {
  margin: 0.4rem 0.6rem 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.chart-box .plot {
  width: 100%;
  min-height: 280px;
}

.chart-box-compare {
  min-height: 320px;
  border: none;
  padding: 0;
}

.chart-box-compare .plot {
  min-height: 300px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 520px;
  /* Keep scrollbar gutter so header/body widths stay aligned */
  scrollbar-gutter: stable;
}

table.data {
  width: 100%;
  /* Fixed layout keeps headers glued to their columns */
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* Column widths (7 cols) — shared by header + body */
table.data th:nth-child(1),
table.data td:nth-child(1) {
  width: 12%;
}
table.data th:nth-child(2),
table.data td:nth-child(2) {
  width: 14%;
}
table.data th:nth-child(3),
table.data td:nth-child(3) {
  width: 14%;
}
table.data th:nth-child(4),
table.data td:nth-child(4) {
  width: 12%;
}
table.data th:nth-child(5),
table.data td:nth-child(5) {
  width: 16%;
}
table.data th:nth-child(6),
table.data td:nth-child(6) {
  width: 16%;
}
table.data th:nth-child(7),
table.data td:nth-child(7) {
  width: 16%;
}

table.data th,
table.data td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  box-sizing: border-box;
}

table.data th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1c2738;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  /* Opaque bar so rows don’t show through when scrolling */
  box-shadow: 0 1px 0 var(--border);
}

/* Numeric headers AND cells both right-aligned (was body-only — caused “floating” labels) */
table.data th.num,
table.data td.num {
  text-align: right;
}

table.data th.sortable {
  cursor: pointer;
  user-select: none;
}

table.data th.sortable:hover {
  color: var(--accent);
}

table.data th.sortable .sort-ind {
  display: inline-block;
  width: 0.85em;
  margin-left: 0.15em;
  opacity: 0.9;
  font-size: 0.7rem;
  text-align: center;
}

table.data th.sortable.is-active {
  color: var(--accent);
}

table.data tbody tr {
  cursor: pointer;
}

table.data tbody tr:hover td {
  background: rgba(0, 191, 255, 0.06);
}

table.data tbody tr.selected td {
  background: rgba(0, 191, 255, 0.12);
}

.hidden {
  display: none !important;
}


