@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Playfair+Display:ital,wght@1,700;1,800&display=swap');

:root {
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --accent: #0282cc;
  --buy: #3fb55d;
  --sell: #e10d0d;
  --warn: #d9a70e;
  --nav-bg: #0f1117;
  --nav-text: #e0e0e0;
  --card-bg: #ffffff;
  --table-stripe: #f5f7fa;
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-alt: #161b22;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --border: #30363d;
  --accent: #58a6ff;
  --buy: #3fb950;
  --sell: #f85149;
  --warn: #d29922;
  --nav-bg: #0d1117;
  --nav-text: #e6edf3;
  --card-bg: #161b22;
  --table-stripe: #1c2333;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  line-height: 1.5; min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ── Navbar ──────────────────────────────────────────── */
.navbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 1rem; background: var(--nav-bg); color: var(--nav-text);
  position: sticky; top: 0; z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-wrap: wrap; gap: 0.4rem;
}

.nav-title {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-weight: 800; font-style: italic;
  font-size: 1.15rem; letter-spacing: 0;
  background: linear-gradient(135deg, #58a6ff, #3fb950);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

[data-theme="light"] .nav-title {
  background: linear-gradient(135deg, #0282cc, #3fb55d);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-right { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.nav-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 5px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 600;
  text-decoration: none; transition: all 0.15s;
  background: rgba(255,255,255,0.08); color: var(--nav-text); white-space: nowrap;
}
.nav-link:hover { background: rgba(255,255,255,0.18); }
.nav-link.active { background: var(--accent); color: #fff; }

.market-badge {
  font-size: 0.75rem; padding: 3px 8px; border-radius: 4px;
  background: rgba(255,255,255,0.08); white-space: nowrap;
}
.market-badge.open { color: var(--buy); }
.market-badge.extended { color: var(--warn); }
.market-badge.closed { color: var(--sell); }

#theme-toggle {
  background: none; border: 1px solid rgba(255,255,255,0.2); color: var(--nav-text);
  padding: 3px 8px; border-radius: 4px; cursor: pointer; font-size: 0.95rem;
  transition: background 0.2s;
}
#theme-toggle:hover { background: rgba(255,255,255,0.1); }

/* ── Main layout ─────────────────────────────────────── */
main { max-width: 1400px; margin: 0 auto; padding: 1rem; }

/* ── Tabs ────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; margin-bottom: 1rem; border-bottom: 2px solid var(--border); overflow-x: auto; }
.tab-btn {
  padding: 0.5rem 1rem; border: none; background: none; cursor: pointer;
  font-size: 0.9rem; color: var(--text-muted); font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--text); }

/* ── Refresh info ────────────────────────────────────── */
.refresh-info {
  font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.75rem;
  padding: 5px 10px; background: var(--bg-alt); border-radius: var(--radius);
  display: inline-block; line-height: 1.4;
}

/* ── Tooltip ─────────────────────────────────────────── */
[data-tooltip] {
  position: relative; cursor: help;
  text-decoration: underline dotted var(--text-muted);
  text-underline-offset: 3px;
}
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-size: 0.72rem; font-weight: 400;
  padding: 6px 10px; border-radius: 4px; z-index: 300;
  pointer-events: none; opacity: 1; text-align: center;
  text-transform: none; letter-spacing: 0; line-height: 1.4;
  max-width: 420px; white-space: normal; word-wrap: break-word;
}
/* Tooltips near right edge: shift left */
[data-tooltip]:hover::after {
  left: auto; right: 0; transform: none;
}
@media (min-width: 900px) {
  th[data-tooltip]:hover::after,
  td[data-tooltip]:hover::after {
    left: 50%; right: auto; transform: translateX(-50%);
  }
}

/* ── Scorecard grid ──────────────────────────────────── */
.scorecard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.4rem; margin-bottom: 0.75rem;
}
.scorecard-item {
  background: var(--bg-alt); padding: 0.5rem 0.6rem; border-radius: var(--radius);
  text-align: center;
}
.scorecard-item .label {
  font-size: 0.68rem; color: var(--text-muted);
  text-decoration: underline dotted var(--text-muted);
  text-underline-offset: 2px; cursor: help;
  display: inline-block;
}
.scorecard-item .value { font-size: 1.05rem; font-weight: 700; color: var(--accent); }

/* ── Loading spinner ─────────────────────────────────── */
.spinner {
  display: flex; flex-direction: column; align-items: center; gap: 0.6rem;
  padding: 1.5rem; color: var(--text-muted);
}
.spinner-wheel {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-bar-container {
  width: 100%; max-width: 260px; height: 5px; background: var(--border);
  border-radius: 3px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--accent); border-radius: 3px;
  transition: width 0.4s ease; width: 0%;
}

/* ── Tables ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%; border-collapse: collapse;
  font-size: 0.8rem; margin-bottom: 1rem;
  background: var(--card-bg); border-radius: var(--radius);
  min-width: 600px;
}
th {
  text-align: left; padding: 0.5rem 0.6rem; background: var(--bg-alt);
  color: var(--text-muted); font-weight: 600; font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.04em; border-bottom: 1px solid var(--border);
}
td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
tr:nth-child(even) td { background: var(--table-stripe); }
tr:hover td { background: var(--bg-alt); }

.ticker-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.ticker-link:hover { text-decoration: underline; }

.signal-badge {
  display: inline-block; padding: 2px 7px; border-radius: 4px;
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
}
.signal-strong-buy { background: #d4edda; color: #155724; }
.signal-buy { background: #e8f5e9; color: #2e7d32; }
.signal-hold { background: #fff3e0; color: #e65100; }
.signal-sell, .signal-underperform { background: #ffebee; color: #c62828; }

[data-theme="dark"] .signal-strong-buy { background: #0d3320; color: #3fb950; }
[data-theme="dark"] .signal-buy { background: #1a3320; color: #56d364; }
[data-theme="dark"] .signal-hold { background: #332b00; color: #d29922; }
[data-theme="dark"] .signal-sell, [data-theme="dark"] .signal-underperform { background: #330d0d; color: #f85149; }

.flag-badge {
  display: inline-block; padding: 1px 5px; border-radius: 3px;
  font-size: 0.68rem; background: rgba(217, 167, 14, 0.15); color: var(--warn);
  margin-right: 2px; white-space: nowrap;
}

/* ── Ticker page ────────────────────────────────────── */
.ticker-search {
  display: flex; gap: 0.4rem; margin-bottom: 1rem;
}
.ticker-search input {
  flex: 1; padding: 0.5rem 0.8rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg-alt); color: var(--text);
  font-size: 0.95rem; text-transform: uppercase; min-width: 0;
}
.ticker-search input:focus { outline: none; border-color: var(--accent); }
.ticker-search button {
  padding: 0.5rem 1.2rem; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); cursor: pointer; font-weight: 600;
  font-size: 0.9rem; transition: filter 0.2s; white-space: nowrap;
}
.ticker-search button:hover { filter: brightness(1.1); }
.ticker-search button:disabled { opacity: 0.5; cursor: not-allowed; }

.horizon-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin: 0.75rem 0; }
.horizon-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem;
}
.horizon-card h4 { margin-bottom: 0.4rem; display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; }
.horizon-card p { font-size: 0.8rem; color: var(--text-muted); }

.error-msg { color: var(--sell); font-size: 0.85rem; padding: 0.75rem; background: var(--bg-alt); border-radius: var(--radius); }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1200px) {
  main { max-width: 100%; padding: 0.75rem; }
  .horizon-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .horizon-cards { grid-template-columns: 1fr; }
  .scorecard { grid-template-columns: repeat(3, 1fr); }
  table { font-size: 0.73rem; }
  th, td { padding: 0.35rem 0.45rem; }
  .nav-title { font-size: 0.9rem; }
  .nav-link { padding: 4px 10px; font-size: 0.75rem; }
  .tabs { overflow-x: auto; }
}

@media (max-width: 600px) {
  main { padding: 0.5rem; }
  .navbar { padding: 0.4rem 0.6rem; gap: 0.3rem; }
  .nav-title { font-size: 0.8rem; }
  .scorecard { grid-template-columns: repeat(2, 1fr); }
  .ticker-search { flex-direction: column; }
  .horizon-cards { grid-template-columns: 1fr; }
  table { font-size: 0.7rem; min-width: auto; }
  th, td { padding: 0.3rem 0.35rem; }
  .nav-right { gap: 0.3rem; }
  .market-badge { font-size: 0.7rem; padding: 2px 6px; }
}

@media (max-width: 400px) {
  .scorecard { grid-template-columns: 1fr 1fr; }
  .nav-title { font-size: 0.75rem; }
}
