/* ============================================================
   MARKET PULSE TERMINAL — Bloomberg-style, flat & dense.
   No gradients, no rounded corners, no shadows, no glow.
   ============================================================ */

:root {
  --bg: #000000;
  --panel: #0d0d0d;
  --line: #262626;
  --text: #e8e8e8;
  --muted: #8a8a8a;
  --amber: #ffa028;
  --up: #26d07c;
  --down: #f6465d;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: var(--mono); }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------------- screen flash ---------------- */
#flash {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0;
  background: var(--down);
  transition: opacity 0.18s linear;
}
#flash.show-down { background: var(--down); opacity: 0.22; }
#flash.show-amber { background: var(--amber); opacity: 0.16; }

/* ---------------- command bar ---------------- */
#cmdbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 34px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: #050300;
  white-space: nowrap;
}
.cmd-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand { color: var(--amber); font-weight: 700; letter-spacing: 0.12em; }
.cmd-sep { color: var(--line); }
.cmd-line { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.prompt { color: var(--amber); }
#cmd-text { color: var(--text); }
.caret { color: var(--amber); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.fkeys { display: flex; gap: 2px; }
.fkey {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.05em;
  padding: 4px 8px;
  cursor: pointer;
}
.fkey span { color: var(--amber); margin-right: 4px; }
.fkey:hover { border-color: var(--amber); color: var(--text); }
.clock { color: var(--amber); letter-spacing: 0.08em; }

/* ---------------- grid ---------------- */
#grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: minmax(0, 1.6fr) minmax(0, 1fr) auto;
  gap: 1px;
  background: var(--line); /* gaps read as hairline rules */
}
#chart-panel { grid-column: 1; grid-row: 1; }
#sentiment-panel { grid-column: 2; grid-row: 1; }
#watchlist-panel { grid-column: 1; grid-row: 2; }
#positions-panel { grid-column: 2; grid-row: 2; }
#ticker { grid-column: 1 / -1; grid-row: 3; }

/* ---------------- panels ---------------- */
.panel {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 26px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: #0a0a0a;
}
.panel-title {
  color: var(--amber);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.16em;
}
.panel-meta { display: flex; align-items: center; gap: 10px; font-size: 11px; }
.panel-tools { margin-left: auto; }
.tool {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  cursor: pointer;
}
.tool[aria-pressed="true"] { border-color: var(--amber); color: var(--amber); }
.panel-body { flex: 1 1 auto; min-height: 0; overflow: auto; }

/* ---------------- chart ---------------- */
.chart-body { overflow: hidden; padding: 0; position: relative; }
#chart { position: absolute; inset: 0; }
#chart-symbol { color: var(--amber); font-weight: 700; }

/* ---------------- sentiment / face ---------------- */
.sentiment-body { display: flex; flex-direction: column; padding: 8px; gap: 8px; }
.feed {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  background: #000;
  overflow: hidden;
}
.feed > div[data-mirror], .feed video, .feed canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#video { object-fit: cover; transform: scaleX(-1); }
#overlay { transform: scaleX(-1); }
.feed-status {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  text-align: center;
  background: rgba(0, 0, 0, 0.78);
}
.feed-status.hidden { display: none; }
.consent { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 0; max-width: 30ch; }
.start-btn, .start-btn:focus-visible {
  background: var(--amber);
  color: #000;
  border: 1px solid var(--amber);
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 7px 14px;
  cursor: pointer;
}
.start-btn:hover { background: #ffb24f; }
.feed-msg { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; }

.readout { display: flex; flex-direction: column; gap: 6px; }
.readout-row { display: flex; align-items: baseline; justify-content: space-between; }
.readout-row .k { color: var(--muted); font-size: 10px; letter-spacing: 0.12em; }
.readout-row .v { font-size: 14px; }
#expr-name { text-transform: uppercase; color: var(--amber); font-weight: 700; }
.bar { height: 6px; background: #1a1a1a; border: 1px solid var(--line); position: relative; }
.bar::after {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: var(--fill, 0%);
  background: var(--amber);
}
.sentiment-meter {
  position: relative; height: 8px; background: #1a1a1a; border: 1px solid var(--line);
}
.meter-mid { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--muted); }
.meter-fill {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 0;
  background: var(--up);
}
.hint { color: var(--muted); font-size: 10px; margin: 2px 0 0; letter-spacing: 0.04em; }

/* ---------------- tables ---------------- */
.table-body { padding: 0; }
.grid-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.grid-table th {
  position: sticky; top: 0;
  background: #0a0a0a;
  color: var(--muted);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-align: right;
  padding: 5px 10px;
  border-bottom: 1px solid var(--line);
}
.grid-table th.l { text-align: left; }
.grid-table td { padding: 5px 10px; text-align: right; border-bottom: 1px solid #161616; }
.grid-table td.l { text-align: left; }
.grid-table tbody tr { cursor: pointer; }
.grid-table tbody tr:hover { background: #141414; }
.grid-table tbody tr.sel { background: #1c1505; }
.grid-table tbody tr.sel td:first-child { box-shadow: inset 2px 0 0 var(--amber); }
.sym { color: var(--text); font-weight: 700; }
td.empty { text-align: center; color: var(--muted); padding: 14px; cursor: default; }

/* price-tick flash */
@keyframes flashUp { from { background: rgba(38, 208, 124, 0.32); } to { background: transparent; } }
@keyframes flashDown { from { background: rgba(246, 70, 93, 0.32); } to { background: transparent; } }
.flash-up { animation: flashUp 0.5s linear; }
.flash-down { animation: flashDown 0.5s linear; }

/* ---------------- portfolio ---------------- */
.positions-body { display: flex; flex-direction: column; gap: 10px; padding: 10px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.stat { background: var(--panel); padding: 7px 9px; display: flex; flex-direction: column; gap: 3px; }
.stat .k { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; }
.stat .v { font-size: 15px; }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.goal-head .k { color: var(--amber); font-size: 10px; letter-spacing: 0.14em; }
.goal-head .v { color: var(--amber); font-size: 12px; }
.goal-track { height: 8px; background: #1a1a1a; border: 1px solid var(--line); }
.goal-fill { height: 100%; width: 0; background: var(--amber); }
.trade { border: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.trade-sel { display: flex; justify-content: space-between; align-items: baseline; }
.trade-sel .k { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; }
.trade-sel .v { color: var(--amber); font-weight: 700; }
.trade-controls { display: flex; gap: 6px; align-items: stretch; }
.qty { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; letter-spacing: 0.08em; }
.qty input {
  width: 64px; background: #000; border: 1px solid var(--line); color: var(--text);
  padding: 5px 7px; font-size: 13px; text-align: right;
}
.t-buy, .t-sell {
  flex: 1; border: 1px solid var(--line); background: #000; cursor: pointer;
  font-weight: 700; letter-spacing: 0.08em; padding: 6px 0;
}
.t-buy { color: var(--up); } .t-buy:hover { border-color: var(--up); background: rgba(38,208,124,0.08); }
.t-sell { color: var(--down); } .t-sell:hover { border-color: var(--down); background: rgba(246,70,93,0.08); }
.auto { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; letter-spacing: 0.04em; cursor: pointer; }
.auto input { accent-color: var(--amber); }

/* ---------------- ticker ---------------- */
#ticker {
  display: flex; align-items: center; height: 26px;
  background: #0a0a0a; border-top: 1px solid var(--line); overflow: hidden;
}
.tick-label {
  flex: 0 0 auto; background: var(--amber); color: #000; font-weight: 700;
  font-size: 10px; letter-spacing: 0.14em; padding: 0 10px; height: 100%;
  display: flex; align-items: center;
}
.tick-viewport { flex: 1 1 auto; overflow: hidden; height: 100%; }
.tick-track {
  display: inline-flex; align-items: center; height: 100%; white-space: nowrap;
  will-change: transform; animation: ticker 38s linear infinite;
}
.tick-track:hover { animation-play-state: paused; }
.tick-item { padding: 0 22px; font-size: 12px; border-right: 1px solid var(--line); }
.tick-time { color: var(--muted); margin-right: 8px; }
.tick-sev-crash { color: var(--down); font-weight: 700; }
.tick-sev-whale { color: var(--amber); font-weight: 700; }
.tick-sev-info { color: var(--text); }
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  #grid {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-rows: min-content;
  }
  #chart-panel, #sentiment-panel, #watchlist-panel, #positions-panel {
    grid-column: 1;
    grid-row: auto;
  }
  .chart-body { height: 260px; }
  #cmdbar { gap: 6px; overflow: hidden; }
  #cmdbar .cmd-line,
  #cmdbar .brand,
  #cmdbar .cmd-sep,
  #cmdbar .clock { display: none; }
  .fkeys { flex: 1 1 auto; justify-content: space-between; }
  .fkeys .fkey { padding: 4px 5px; font-size: 10px; letter-spacing: 0.01em; }
}

/* ---------------- reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  .caret { animation: none; }
  .tick-track { animation: none; }
  .flash-up, .flash-down { animation: none; }
  #flash { transition: none; }
}
