/* ── Variables ────────────────────────────────────────────────────── */
:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface2:   #1c2128;
  --border:     #30363d;
  --border2:    #21262d;
  --text:       #e6edf3;
  --muted:      #8b949e;
  --accent:     #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.12);
  --green:      #3fb950;
  --green-bg:   rgba(63, 185, 80, 0.12);
  --red:        #f85149;
  --red-bg:     rgba(248, 81, 73, 0.12);
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 8px 32px rgba(0,0,0,0.5);
}

/* ── Reset / Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

/* ── Header ───────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 64px;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.logo-icon { width: 36px; height: 36px; }
.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}
.logo-text .accent { color: var(--accent); }

.search-wrap { flex: 1; max-width: 460px; position: relative; }
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}
#searchInput {
  width: 100%;
  padding: 9px 14px 9px 38px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
#searchInput::placeholder { color: var(--muted); }
#searchInput:focus { border-color: var(--accent); }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 200;
  overflow: hidden;
}
.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.search-result:hover { background: var(--surface2); }
.search-result-sym {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  min-width: 60px;
}
.search-result-name {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.search-result-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-left: auto;
}
.last-updated { color: var(--muted); font-size: 12px; }
.market-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}
.market-badge.open  { background: var(--green-bg); color: var(--green); }
.market-badge.closed { background: var(--red-bg);  color: var(--red); }
.market-badge.pre   { background: rgba(255,200,0,0.12); color: #f0c040; }

/* ── Auth ─────────────────────────────────────────────────────────── */
.google-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.google-btn:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.signout-btn {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid var(--border2);
  transition: color 0.15s, border-color 0.15s;
}
.signout-btn:hover { color: var(--red); border-color: var(--red); }

/* syncing indicator */
.sync-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: syncPulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes syncPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Market Bar ───────────────────────────────────────────────────── */
.market-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border2);
  position: sticky;
  top: 64px;
  z-index: 90;
}
.market-bar-inner {
  display: flex;
  align-items: stretch;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 48px;
  gap: 0;
}
.index-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 0 0;
  cursor: default;
  transition: background 0.15s;
  flex-shrink: 0;
}
.idx-sep {
  width: 1px;
  background: var(--border2);
  margin: 10px 20px 10px 0;
  flex-shrink: 0;
}
.idx-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.idx-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.idx-change {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* VIX / Fear item */
.fear-item { margin-left: auto; padding-right: 0; }
.vix-label {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.vix-low      { background: rgba(63,185,80,0.18);  color: #3fb950; }
.vix-moderate { background: rgba(240,196,0,0.18);  color: #f0c040; }
.vix-high     { background: rgba(248,81,73,0.18);  color: #f85149; }
.vix-extreme  { background: rgba(248,81,73,0.35);  color: #ff8080;
                animation: vixPulse 1.8s ease-in-out infinite; }

@keyframes vixPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,81,73,0); }
  50%       { box-shadow: 0 0 8px 2px rgba(248,81,73,0.45); }
}

/* ── Main / Grid ──────────────────────────────────────────────────── */
main {
  padding: 16px 20px;
  max-width: 1600px;
  margin: 0 auto;
}

.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 10px;
}

/* ── Stock Card ───────────────────────────────────────────────────── */
.stock-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 12px 0;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
  animation: cardIn 0.25s ease both;
  overflow: hidden;
}
.stock-card:hover {
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Row 1: symbol + price + delete */
.card-row1 {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}
.card-sym {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.2px;
}
.card-price {
  font-size: 13px;
  font-weight: 700;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

.delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  flex-shrink: 0;
  margin-left: 2px;
}
.stock-card:hover .delete-btn { opacity: 1; }
.delete-btn:hover { background: var(--red-bg); color: var(--red); }

/* Row 2: company name + change badge */
.card-row2 {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}
.card-name {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.card-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.card-badge.up   { background: var(--green-bg); color: var(--green); }
.card-badge.down { background: var(--red-bg);   color: var(--red); }

/* Sparkline — edge-to-edge */
.card-spark {
  margin: 0 -12px;
  height: 44px;
  overflow: hidden;
  line-height: 0;
}
.card-spark svg {
  width: 100%;
  height: 44px;
  display: block;
}
.card-spark-empty {
  background: var(--surface2);
}

/* Row 3: meta */
.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  padding: 5px 0 8px;
}
.card-meta strong { color: var(--text); font-weight: 600; }

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

@keyframes flashGreen {
  0%   { background-color: rgba(63, 185, 80, 0.25); }
  100% { background-color: transparent; }
}
@keyframes flashRed {
  0%   { background-color: rgba(248, 81, 73, 0.25); }
  100% { background-color: transparent; }
}
.flash-up   { animation: flashGreen 0.7s ease; }
.flash-down { animation: flashRed   0.7s ease; }

/* ── Signal dot on card ───────────────────────────────────────────── */
.sig-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 1px;
}
.sig-strong-buy  { background: #3fb950; box-shadow: 0 0 5px #3fb950; }
.sig-buy         { background: #3fb950; opacity: 0.75; }
.sig-hold        { background: #f0c040; }
.sig-sell        { background: #f85149; opacity: 0.75; }
.sig-strong-sell { background: #f85149; box-shadow: 0 0 5px #f85149; }

/* ── Smart Analysis section ───────────────────────────────────────── */
.analysis-section {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  overflow: hidden;
}
.analysis-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border2);
  gap: 12px;
  flex-wrap: wrap;
}
.analysis-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.analysis-title svg { color: var(--accent); }
.analysis-disclaimer {
  font-size: 11px;
  color: var(--muted);
  background: rgba(240,196,0,0.08);
  border: 1px solid rgba(240,196,0,0.2);
  border-radius: 5px;
  padding: 3px 8px;
}

.analysis-table-wrap { overflow-x: auto; }
.analysis-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.analysis-table thead th {
  padding: 9px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border2);
  white-space: nowrap;
}
.analysis-table tbody tr {
  border-bottom: 1px solid var(--border2);
  transition: background 0.15s;
  cursor: default;
}
.analysis-table tbody tr:last-child { border-bottom: none; }
.analysis-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.analysis-table td {
  padding: 10px 14px;
  vertical-align: middle;
}

/* Column: symbol */
.at-sym { display: flex; flex-direction: column; gap: 1px; }
.at-ticker { font-weight: 800; font-size: 13px; }
.at-name   { font-size: 10px; color: var(--muted); }

/* Column: target prices */
.at-target { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Column: 52W bar */
.w52-bar-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 140px;
}
.w52-track {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  position: relative;
}
.w52-fill {
  position: absolute;
  left: 0; top: 0; height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.4s ease;
}
.w52-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--accent);
}
.w52-label { font-size: 10px; color: var(--muted); white-space: nowrap; }

/* Column: key factor */
.at-reason { color: var(--muted); font-size: 12px; max-width: 240px; }

/* Signal badges */
.signal-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.signal-badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.signal-strong-buy  { background: rgba(63,185,80,0.2);  color: #3fb950; border: 1px solid rgba(63,185,80,0.35); }
.signal-buy         { background: rgba(63,185,80,0.12); color: #3fb950; border: 1px solid rgba(63,185,80,0.2); }
.signal-hold        { background: rgba(240,196,0,0.12); color: #f0c040; border: 1px solid rgba(240,196,0,0.25); }
.signal-sell        { background: rgba(248,81,73,0.12); color: #f85149; border: 1px solid rgba(248,81,73,0.2); }
.signal-strong-sell { background: rgba(248,81,73,0.22); color: #f85149; border: 1px solid rgba(248,81,73,0.4); }

/* ── Empty State ──────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;
  color: var(--muted);
  gap: 12px;
}
.empty-icon { width: 72px; height: 72px; opacity: 0.25; }
.empty-state h2 { font-size: 20px; color: var(--text); }
.empty-state p  { font-size: 14px; max-width: 340px; }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 860px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
  animation: slideUp 0.25s ease;
  box-shadow: var(--shadow);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* scrollbar */
.modal::-webkit-scrollbar { width: 6px; }
.modal::-webkit-scrollbar-track { background: transparent; }
.modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.modal-close {
  position: absolute;
  top: 20px; right: 20px;
  width: 32px; height: 32px;
  border: none;
  background: var(--surface2);
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--red-bg); color: var(--red); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  padding-right: 40px;
}
.modal-symbol-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.modal-symbol { font-size: 22px; font-weight: 800; }
.modal-exchange {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.modal-market-state {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  letter-spacing: 0.5px;
}
.modal-name { color: var(--muted); font-size: 14px; }

.modal-price-block { text-align: right; }
.modal-price { font-size: 30px; font-weight: 800; }
.modal-change { font-size: 14px; font-weight: 600; margin-top: 2px; }

/* ── Stats bar ────────────────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 20px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--surface2);
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-val   { font-size: 13px; font-weight: 600; }

/* ── Chart ────────────────────────────────────────────────────────── */
.chart-section { margin-bottom: 24px; }
.chart-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.period-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.period-btn:hover { border-color: var(--accent); color: var(--accent); }
.period-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.chart-wrap {
  position: relative;
  height: 220px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  padding: 12px;
}
.chart-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
}

/* ── News ─────────────────────────────────────────────────────────── */
.news-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.news-col {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  overflow: hidden;
}
.news-col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border2);
}
.news-pro .news-col-header { color: var(--green); }
.news-con .news-col-header { color: var(--red); }
.news-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-pro  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-con  { background: var(--red);   box-shadow: 0 0 6px var(--red); }

.news-list { display: flex; flex-direction: column; }
.news-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border2);
  text-decoration: none;
  transition: background 0.15s;
}
.news-item:last-child { border-bottom: none; }
.news-item:hover { background: rgba(255,255,255,0.03); }
.news-title {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}
.news-empty {
  padding: 20px 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ── Utilities ────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 700px) {
  header { padding: 0 16px; gap: 10px; }
  .logo-text { font-size: 17px; }
  main { padding: 12px; }

  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .news-section { grid-template-columns: 1fr; }
  .modal { padding: 20px 16px; }
  .modal-header { flex-direction: column; gap: 8px; }
  .modal-price-block { text-align: left; }
  .last-updated { display: none; }
}
