/* ============================================================
   RealTimeStocks — Terminal Dark Theme
   ============================================================ */

:root {
  --bg:           #080c14;
  --bg-surface:   #0e2240;
  --bg-hover:     #111c2e;
  --border:       #1e3350;
  --text:         #e8f0f8;
  --text-dim:     #7090b0;
  --text-header:  #b8d0e8;
  --green:        #00ff88;
  --red:          #ff4444;
  --yellow:       #ffd700;
  --blue:         #4499ff;
  --font-mono:    'Courier New', Courier, monospace;
  --row-height:   44px;
  --clock: #f1ce05;
  --app-title: #f1ce05;
  --company-name: #c3c3c3;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  overflow-x: hidden;
}

/* ---- App shell ---- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 16px;
  font-size: 1.5rem;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.app-title {
  font-weight: bold;
  letter-spacing: 0.12em;
  color: var(--app-title);
  text-transform: uppercase;
  font-size: 2rem;
  font-family: sans-serif;
}

/* Market status badge */
.market-status {
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 2px;
  border: 1px solid currentColor;
  font-size: 1.1rem;
}
.market-status.open  { color: var(--green); }
.market-status.closed { color: var(--red); }

/* Sort buttons */
.sort-controls {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.sort-btn {
  background: transparent;
  border: none;
  border-right: 1px solid var(--text-dim);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  letter-spacing: 0.06em;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.sort-btn:last-child { border-right: none; }
.sort-btn:hover { background: var(--bg-hover); color: var(--text); }
.sort-btn.active { background: var(--bg-hover); color: var(--blue); }

/* Reconnect badge */
.reconnect-badge {
  display: none;
  color: var(--yellow);
  letter-spacing: 0.06em;
  animation: blink 1s step-end infinite;
}
.reconnect-badge.visible { display: inline; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* Settings gear button */
.settings-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-dim);
  width: 32px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s, border-color 0.1s;
  font-size: 2.2rem;
}
.settings-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* Clock */
.clock {
  color: var(--clock);
  letter-spacing: 0.06em;
  min-width: 110px;
  text-align: right;
}

/* ---- Main content ---- */
.main {
  flex: 1;
  overflow: visible;
  padding: 0;
  font-size: 1.2rem;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: visible;
}

/* ---- Stock table ---- */
.stock-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.stock-table th {
  padding: 10px 12px;
  text-align: right;
  font-weight: normal;
  letter-spacing: 0.1em;
  color: var(--text-header);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 1;
}
.stock-table th:first-child { text-align: left; }

/* Column widths */
.stock-table th:nth-child(1)  { width: 160px; } /* TICKER */
.stock-table th:nth-child(2)  { width: 90px;  } /* PRICE */
.stock-table th:nth-child(3)  { width: 80px;  } /* CHG$ */
.stock-table th:nth-child(4)  { width: 75px;  } /* CHG% */
.stock-table th:nth-child(5)  { width: 70px;  } /* P/E */
.stock-table th:nth-child(6)  { width: 70px;  } /* EPS */
.stock-table th:nth-child(7)  { width: 65px;  } /* BETA */
.stock-table th:nth-child(8)  { width: 80px;  } /* DIV YIELD */
.stock-table th:nth-child(9)  { width: 80px;  } /* REV YoY */
.stock-table th:nth-child(10) { width: 110px; text-align: center; } /* 52W H/L */

/* Table rows */
.stock-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  border-left: 3px solid var(--border);
  cursor: grab;
}
.stock-table tbody tr:hover { background: var(--bg-hover); }
.stock-table tbody tr.positive { border-left-color: var(--green); }
.stock-table tbody tr.negative { border-left-color: var(--red); }

.stock-table td {
  padding: 0 12px;
  height: var(--row-height);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}
.stock-table td:first-child { text-align: left; }
.stock-table td:nth-child(10) { text-align: center; }

/* Ticker cell */
.ticker-symbol {
  font-weight: bold;
  color: var(--text);
  letter-spacing: 0.04em;
}
.ticker-name {
  font-size: small;
  display: block;
  color: var(--company-name);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Price & CHG% flash animations */
@keyframes flash-green {
  0%   { background: rgba(0, 255, 136, 0.18); }
  100% { background: transparent; }
}
@keyframes flash-red {
  0%   { background: rgba(255, 68, 68, 0.18); }
  100% { background: transparent; }
}

.flash-up   { animation: flash-green 0.6s ease-out forwards; }
.flash-down { animation: flash-red   0.6s ease-out forwards; }

/* Positive / negative value coloring */
.positive-val { color: var(--green); }
.negative-val { color: var(--red); }

/* Dim cells for missing data */
.data-missing { color: var(--text-dim); }


/* Empty state */
.empty-state {
  display: none;
  text-align: center;
  color: var(--text-dim);
  padding: 60px 24px;
  letter-spacing: 0.04em;
}
.empty-state.visible { display: block; }

/* ---- Settings drawer ---- */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10;
}
.drawer-backdrop.open { display: block; }

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 11;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.settings-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title {
  font-weight: bold;
  letter-spacing: 0.12em;
  color: var(--text-header);
}
.drawer-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  transition: color 0.1s;
}
.drawer-close:hover { color: var(--text); }

.drawer-add {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ticker-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  padding: 7px 10px;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.15s;
}
.ticker-input:focus { border-color: var(--blue); }
.ticker-input::placeholder { color: var(--text-dim); }

.add-btn {
  background: var(--blue);
  border: none;
  border-radius: 2px;
  color: var(--bg);
  font-family: var(--font-mono);
  font-weight: bold;
  letter-spacing: 0.08em;
  padding: 7px 14px;
  cursor: pointer;
  transition: opacity 0.1s;
  white-space: nowrap;
}
.add-btn:hover { opacity: 0.85; }
.add-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.drawer-error {
  min-height: 20px;
  padding: 0 20px 8px;
  color: var(--red);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.ticker-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.ticker-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.ticker-list li:hover { background: var(--bg-hover); }
.ticker-list-symbol {
  font-weight: bold;
  letter-spacing: 0.04em;
}
.ticker-remove-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-dim);
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s, border-color 0.1s;
}
.ticker-remove-btn:hover { color: var(--red); border-color: var(--red); }

/* ---- Scrollbar styling ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---- Drag and drop ---- */
.stock-table tbody tr.dragging {
  opacity: 0.3;
  cursor: grabbing;
  user-select: none;
  transition: none;
}

.stock-table tbody tr.drop-line td {
  padding: 0;
  height: 2px;
  background: var(--blue);
  box-shadow: 0 0 6px var(--blue);
  cursor: default;
}
