/* =========================================================
   MARKETS WATCH — styles.css
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

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

:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface2:   #1c2330;
  --border:     #30363d;
  --border-sub: #21262d;
  --text:       #e6edf3;
  --text-muted: #8b949e;
  --text-dim:   #6e7681;
  --accent:     #2f81f7;
  --accent-dim: #1f6feb33;
  --green:      #3fb950;
  --red:        #f85149;
  --yellow:     #d29922;
  --radius:     8px;
  --radius-sm:  5px;
  --shadow:     0 4px 24px rgba(0,0,0,.45);
}

html { scroll-behavior: smooth; }

/* Desktop: lock viewport — no page scroll */
@media (min-width: 900px) {
  html, body { height: 100%; overflow: hidden; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* =========================================================
   NAVBAR
   ========================================================= */
.navbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .03em;
  color: var(--text);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar::before {
  content: '▸';
  color: var(--accent);
  font-size: 18px;
}

/* =========================================================
   MARKET TICKER BAR
   ========================================================= */
.market-ticker {
  height: 34px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  position: relative;
}

/* Fade edges */
.market-ticker::before,
.market-ticker::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 48px;
  z-index: 2;
  pointer-events: none;
}
.market-ticker::before { left:0;  background: linear-gradient(to right,  var(--surface2), transparent); }
.market-ticker::after  { right:0; background: linear-gradient(to left, var(--surface2), transparent); }

.ticker-track {
  display: flex;
  white-space: nowrap;
  will-change: transform;
}

/* Animation applied once we have real data */
.ticker-track.ticker-running {
  animation: tickerScroll var(--ticker-duration, 40s) linear infinite;
}

@keyframes tickerScroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.market-ticker:hover .ticker-track { animation-play-state: paused; }

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 20px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  border-right: 1px solid var(--border);
}

.ticker-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.ticker-price {
  color: var(--text);
  font-weight: 500;
}

.ticker-up   .ticker-price { color: var(--green); }
.ticker-down .ticker-price { color: var(--red);   }

/* =========================================================
   PAGE LAYOUT — mobile-first, 2-col desktop
   ========================================================= */
.page-container {
  padding: 16px;
  display: flex;
  justify-content: center;
}

.content-area {
  width: 100%;
  max-width: 1440px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 900px) {
  .page-container { padding: 24px; }

  .content-area {
    grid-template-columns: 1fr 400px;
    align-items: start;   /* cards sit at top; heights are explicit */
  }
}

/* =========================================================
   SHARED CARD BASE
   ========================================================= */
.chart-card,
.news-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* =========================================================
   CHART CARD
   ========================================================= */
.chart-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  position: relative;
}

#tickerInput {
  flex: 1;
  min-width: 160px;
  padding: 7px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s;
}

#tickerInput::placeholder { color: var(--text-dim); }
#tickerInput:focus { border-color: var(--accent); }

.load-btn {
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s;
  flex-shrink: 0;
}
.load-btn:hover { opacity: .85; }

/* chart-meta: ticker label + range buttons on same row */
.chart-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-ticker-label {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 15px;
  color: var(--accent);
  letter-spacing: .04em;
  flex-shrink: 0;
  min-width: 56px;
}

.range-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.range-btn {
  padding: 5px 10px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: .03em;
  transition: all .15s;
}

.range-btn:hover { border-color: var(--accent); color: var(--text); }

.range-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

#stockChart {
  width: 100% !important;
  height: 280px !important;
  display: block;
}

@media (min-width: 600px) {
  #stockChart { height: 340px !important; }
}

@media (min-width: 900px) {
  #stockChart { height: 380px !important; }
}

/* =========================================================
   SEARCH SUGGESTIONS
   ========================================================= */
#suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 320px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 1000;
}

#suggestions:empty { display: none; }

.suggestion {
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border-sub);
  transition: background .1s;
}

.suggestion:last-child { border-bottom: none; }

.suggestion:hover,
.suggestion.keyboard-selected {
  background: var(--accent-dim);
}

.ticker-symbol {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
}

.ticker-description {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   NEWS CARD
   Desktop: fixed height matching chart card, news-list scrolls.
   Mobile: natural height, stacks below chart.
   ========================================================= */
.news-card {
  display: flex;
  flex-direction: column;
}

/* Tabs */
.news-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 11px 8px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: .02em;
}

.tab:hover { color: var(--text); background: var(--surface2); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-dim);
}

/* News list: flex-grow + scroll */
#news-list {
  flex: 1;
  overflow-y: auto;
  min-height: 120px;
}

/* News row */
.news-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-sub);
  transition: background .1s;
}

.news-item:hover { background: var(--surface2); }
.news-item:last-child { border-bottom: none; }

.news-date {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  min-width: 38px;
  padding-top: 2px;
  flex-shrink: 0;
}

.news-link {
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  transition: color .1s;
}

.news-link:hover { color: var(--accent); }

/* News sources */
.news-sources {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}

.news-sources label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 3px 0;
  transition: color .1s;
}

.news-sources label:hover { color: var(--text); }

.news-sources input[type="radio"] {
  accent-color: var(--accent);
  cursor: pointer;
  transform: scale(0.85);
}

/* =========================================================
   MOBILE
   ========================================================= */
@media (max-width: 599px) {
  .chart-header { gap: 6px; }
  #tickerInput  { min-width: 120px; }
  .range-btn    { padding: 4px 8px; }
}

.news-empty {
  padding: 24px 14px;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}

/* Smooth opacity transition when switching tabs/sources */
#news-list {
  transition: opacity 0.15s ease;
}

/* ── HTMX transitions ────────────────────────────────────────────────────── */
/* Dim the list while a request is in flight */
#news-list.htmx-request {
  opacity: 0.4;
  transition: opacity 0.15s ease;
}
#news-list {
  transition: opacity 0.15s ease;
}

/* View Transitions API fade (htmx swap="innerHTML transition:true") */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.15s;
}
