/* Finviz-inspired dense financial-dashboard theme:
   dark navy top nav, light dense body, monospace numerics, green/red deltas */

:root {
  --navy: #0b1220;
  --navy-2: #131c2e;
  --border: #d8dde3;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1c2431;
  --text-dim: #5b6675;
  --accent: #2f6fed;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
}

/* ---------------- Top nav ---------------- */
.topnav {
  background: var(--navy);
  color: #e7ecf3;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  height: 44px;
  border-bottom: 3px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topnav .brand {
  font-weight: 800;
  letter-spacing: 0.3px;
  font-size: 15px;
  color: #ffffff;
  white-space: nowrap;
}
.topnav .brand span { color: var(--accent); }
.topnav .tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.topnav .tab {
  padding: 12px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #aab4c4;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  margin-bottom: -3px;
}
.topnav .tab:hover { color: #ffffff; }
.topnav .tab.active { color: #ffffff; border-bottom-color: var(--accent); }
.topnav .status {
  font-size: 11px;
  color: #7c8aa0;
  white-space: nowrap;
  font-family: var(--mono);
}
.topnav .status .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); margin-right: 5px;
}

/* ---------------- Control bar (time window) ---------------- */
.controlbar {
  background: var(--navy-2);
  color: #cfd8e6;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  font-size: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid #223049;
}
.controlbar label { color: #9aa6ba; margin-right: 4px; }
.controlbar input[type="date"] {
  background: #0e1626;
  color: #e7ecf3;
  border: 1px solid #2a374f;
  border-radius: 3px;
  padding: 4px 6px;
  font-family: var(--mono);
  font-size: 12px;
}
.presetBtns { display: flex; gap: 6px; }
.presetBtn, .applyBtn {
  background: #1a2436;
  color: #dbe3ee;
  border: 1px solid #2a374f;
  border-radius: 3px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.presetBtn:hover { background: #223049; }
.presetBtn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.applyBtn { background: var(--accent); border-color: var(--accent); color: #fff; }
.applyBtn:hover { filter: brightness(1.1); }
.windowInfo { margin-left: auto; font-family: var(--mono); color: #8fa0bd; font-size: 11px; }

/* ---------------- Layout ---------------- */
.page { display: none; padding: 14px 16px 40px; max-width: 1500px; margin: 0 auto; }
.page.active { display: block; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px 6px;
  display: flex;
  flex-direction: column;
}
.panel h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
/* Grid rows stretch panels to match their tallest sibling (e.g. a table
   panel next to a chart panel); without flex-grow the chart div would just
   sit at its min-height and leave the rest of the taller panel blank. */
.panel .chart { width: 100%; min-height: 260px; flex: 1 1 auto; }
.panel .chart.tall { min-height: 420px; }
.panel .note {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.5;
}
.panel .note b { color: var(--text); }

/* ---------------- Heatmap (sector treemap area) ---------------- */
.heatmap-wrap .chart { min-height: 480px; }

/* ---------------- Per-stock table ticker filter ---------------- */
.tableSearch { margin-bottom: 6px; }
.tableSearch input[type="text"] {
  background: #0e1626;
  color: #e7ecf3;
  border: 1px solid #2a374f;
  border-radius: 3px;
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 12px;
  width: 200px;
}
.tableSearch input[type="text"]:focus { outline: 1px solid var(--accent); }
.filter-empty-msg { font-size: 11px; color: var(--text-dim); padding: 8px 2px; }

/* ---------------- Tables ---------------- */
table.data {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--mono);
  font-size: 11.5px;
}
table.data th {
  text-align: right;
  background: #eef1f5;
  color: var(--text-dim);
  font-weight: 700;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td {
  text-align: right;
  padding: 4px 8px;
  border-bottom: 1px solid #eef0f3;
  white-space: nowrap;
}
table.data tbody tr:hover { background: #f5f8ff; }
.table-scroll { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 3px; }

.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }

/* ---------------- KPI strip ---------------- */
.kpis { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 14px;
  min-width: 140px;
}
.kpi .label { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.3px; }
.kpi .value { font-family: var(--mono); font-size: 18px; font-weight: 700; margin-top: 2px; }
.kpi .value.small { font-size: 14px; }

/* ---------------- Loading overlay ---------------- */
#loadingOverlay {
  position: fixed; inset: 0; background: rgba(11,18,32,0.92);
  color: #cfd8e6; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 10px; z-index: 999; font-family: var(--mono); font-size: 13px;
}
#loadingOverlay .spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid #2a374f; border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#computeBadge {
  position: fixed; bottom: 12px; right: 14px; z-index: 60;
  background: var(--navy); color: #cfd8e6; font-family: var(--mono); font-size: 11px;
  padding: 6px 10px; border-radius: 4px; border: 1px solid #2a374f; opacity: 0; transition: opacity .2s;
}
#computeBadge.show { opacity: 1; }

footer.foot {
  text-align: center; color: var(--text-dim); font-size: 11px; padding: 18px; font-family: var(--mono);
}
