/* ============================================================
   STONKS — Main Stylesheet
   Design: Warm parchment / editorial (matches stock notes theme)
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=JetBrains+Mono:wght@300;400;500;700&family=Lora:ital,wght@0,400;0,500;1,400&display=swap');

/* ── Variables ────────────────────────────────────────────── */
:root {
  --bg:           #f5f2ed;
  --surface:      #ffffff;
  --surface2:     #ede9e2;
  --surface3:     #e6e1d8;
  --border:       #d4cec5;
  --border2:      #c4bdb3;

  --accent:       #00834f;
  --accent-dim:   #004d2e;
  --accent-glow:  rgba(0, 131, 79, 0.12);
  --accent-glow2: rgba(0, 131, 79, 0.06);

  --danger:       #c0392b;
  --danger-dim:   #7b1c1c;
  --danger-glow:  rgba(192, 57, 43, 0.1);

  --warn:         #b45309;

  --text:         #1c2333;
  --text-muted:   #5a6a7e;
  --text-faint:   #9aa5b1;

  --font-display: 'Syne', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
  --font-body:    'Lora', serif;

  --radius:       4px;
  --radius-lg:    8px;

  --ticker-height: 36px;
  --header-height: 56px;
  --table-width:   340px;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar              { width: 4px; height: 4px; }
::-webkit-scrollbar-track        { background: var(--surface2); }
::-webkit-scrollbar-thumb        { background: var(--border2); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover  { background: var(--text-faint); }

/* ── Header ───────────────────────────────────────────────── */
#header {
  height: var(--header-height);
  background: linear-gradient(180deg, #eae6df 0%, #ddd8cf 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

#header-logo {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}

#header-logo span {
  color: var(--text-faint);
  font-weight: 400;
}

#header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* ── World Clock ──────────────────────────────────────────── */
#world-clock {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.clock-city {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 52px;
}

.clock-city-name {
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.clock-city-time {
  color: var(--text);
  font-weight: 500;
  font-size: 11px;
}

.clock-sep {
  color: var(--border2);
  font-size: 16px;
  margin-top: -2px;
}

#market-state-badge {
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

#market-state-badge.open {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(0, 131, 79, 0.3);
}

#market-state-badge.closed {
  background: rgba(90, 106, 126, 0.1);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

#last-updated {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

#refresh-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
}

#refresh-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#refresh-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Ticker Bars ──────────────────────────────────────────── */
.ticker-bar {
  height: var(--ticker-height);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
}

.ticker-bar::before,
.ticker-bar::after {
  content: '';
  position: absolute;
  top: 0;
  width: 60px;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.ticker-bar::before {
  left: 0;
  background: linear-gradient(to right, var(--surface2), transparent);
}

.ticker-bar::after {
  right: 0;
  background: linear-gradient(to left, var(--surface2), transparent);
}

.ticker-label {
  position: absolute;
  left: 0;
  z-index: 3;
  background: var(--surface2);
  padding: 0 12px 0 10px;
  height: 100%;
  display: flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  min-width: 108px;
}

.ticker-label.smh       { color: #4a8fd4; }
.ticker-label.bloomberg { color: #c0392b; }
.ticker-label.ft        { color: #b45309; }

.ticker-track {
  display: flex;
  gap: 0;
  animation: marquee 60s linear infinite;
  padding-left: 120px;
  will-change: transform;
}

.ticker-bar:hover .ticker-track { animation-play-state: paused; }

@keyframes marquee {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.ticker-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 20px;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  height: var(--ticker-height);
  text-decoration: none;
  transition: color 0.15s;
}

.ticker-item:hover { color: var(--text); }

.ticker-item::before {
  content: '◆';
  font-size: 6px;
  color: var(--text-faint);
}

/* ── Main Layout ──────────────────────────────────────────── */
#main {
  display: grid;
  grid-template-columns: var(--table-width) 1fr;
  height: calc(100vh - var(--header-height) - var(--ticker-height) * 3);
}

/* ── Stock Table Panel ────────────────────────────────────── */
#table-panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#table-panel-header {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, #f0ece5 0%, #ffffff 100%);
}

#table-panel-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}

#table-panel-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
}

#stock-table-wrap {
  overflow-y: auto;
  flex: 1;
}

#stock-table {
  width: 100%;
  border-collapse: collapse;
}

#stock-table thead th {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  text-align: right;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

#stock-table thead th:first-child { text-align: left; }

#stock-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

#stock-table tbody tr:hover { background: var(--surface2); }

#stock-table tbody tr.active {
  background: var(--accent-glow2);
  border-left: 2px solid var(--accent);
}

#stock-table tbody td {
  padding: 9px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
  vertical-align: middle;
}

#stock-table tbody td:first-child {
  text-align: left;
  padding-left: 14px;
}

.cell-label {
  font-weight: 500;
  color: var(--text);
  font-size: 12px;
  display: block;
  line-height: 1.3;
}

.cell-type {
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cell-price {
  font-weight: 500;
  color: var(--text);
}

.cell-currency {
  font-size: 9px;
  color: var(--text-faint);
  display: block;
}

.cell-change { font-weight: 500; }
.cell-change.up   { color: var(--accent); }
.cell-change.down { color: var(--danger); }
.cell-change.flat { color: var(--text-muted); }

.cell-vol {
  color: var(--text-muted);
  font-size: 11px;
}

.loading-row td {
  color: var(--text-faint);
  text-align: center !important;
  padding: 24px 0 !important;
  font-size: 11px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.9; }
}

.error-row td {
  color: var(--danger);
  text-align: center !important;
  padding: 20px 0 !important;
  font-size: 11px;
}

/* ── Tooltip ──────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  min-width: 200px;
  max-width: 260px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s, transform 0.12s;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

#tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.tt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 3px 0;
  font-family: var(--font-mono);
  font-size: 11px;
}

.tt-label { color: var(--text-faint); }
.tt-value { color: var(--text); font-weight: 500; }
.tt-value.up   { color: var(--accent); }
.tt-value.down { color: var(--danger); }

.tt-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* ── Notes Panel ──────────────────────────────────────────── */
#notes-panel {
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

#notes-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-faint);
  pointer-events: none;
}

#notes-placeholder .ph-icon {
  font-size: 48px;
  opacity: 0.2;
}

#notes-placeholder p {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.4;
}

#notes-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: none;
}

/* ── Loading bar for iframe ───────────────────────────────── */
#notes-loader {
  position: absolute;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s ease;
  z-index: 10;
  box-shadow: 0 0 8px rgba(0,131,79,0.4);
}

/* ── No-notes placeholder ─────────────────────────────────── */
.no-notes-page {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Mobile Bottom Sheet ──────────────────────────────────── */
#mobile-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s;
}

#mobile-sheet-backdrop.visible { opacity: 1; }

#mobile-sheet {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 92vh;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border2);
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#mobile-sheet.open { transform: translateY(0); }

#mobile-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border2);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

#mobile-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(180deg, #f0ece5 0%, #ffffff 100%);
}

#mobile-sheet-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

#mobile-sheet-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}

#mobile-sheet-iframe {
  flex: 1;
  border: none;
  width: 100%;
}

/* ── Mobile Inline Expand ─────────────────────────────────── */
.mobile-expand {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  animation: expandIn 0.15s ease;
}

@keyframes expandIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mobile-expand-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-bottom: 12px;
}

.mobile-expand-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-expand-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mobile-expand-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.mobile-expand-value.up   { color: var(--accent); }
.mobile-expand-value.down { color: var(--danger); }

.view-notes-btn {
  display: block;
  width: 100%;
  padding: 9px 0;
  background: var(--accent-glow);
  border: 1px solid rgba(0, 131, 79, 0.3);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: center;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.view-notes-btn:hover { background: rgba(0, 131, 79, 0.18); }

/* ── 52-week range bar ────────────────────────────────────── */
.range-bar-wrap { margin: 10px 0 4px; }

.range-bar-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.range-bar-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  position: relative;
}

.range-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: linear-gradient(to right, var(--danger-dim), var(--accent-dim));
  border-radius: 2px;
}

.range-bar-dot {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0,131,79,0.4);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1023px) {
  #main {
    display: block;
    height: auto;
  }

  #notes-panel { display: none; }
  #tooltip     { display: none !important; }

  #table-panel {
    border-right: none;
    height: auto;
    overflow: visible;
  }

  #stock-table-wrap { overflow-y: visible; }
  .col-vol, .col-avgvol { display: none; }
}

@media (max-width: 768px) {
  #world-clock .clock-city:nth-child(n+3) { display: none; }
  #world-clock .clock-sep:nth-child(n+4)  { display: none; }
}

@media (max-width: 479px) {
  :root { --header-height: 48px; }
  #header-logo { font-size: 16px; }
  #header-meta { gap: 8px; }
  #world-clock, #refresh-btn { display: none; }
  #stock-table tbody td { padding: 8px 10px; }
  #stock-table thead th { padding: 6px 10px 5px; }
}