/* ── GitHub-quality design system ──────────────────────────────────────── */
:root {
  --bg:          #0D1117;
  --bg-card:     #161B22;
  --bg-card-alt: #1C2130;
  --bg-input:    #0D1117;
  --border:      #30363D;
  --border-hi:   #444C56;
  --text:        #E6EDF3;
  --muted:       #7D8590;
  --accent:      #58A6FF;
  --accent-bg:   rgba(88,166,255,0.12);
  --anl:         #38BDF8;
  --anl-bg:      rgba(56,189,248,0.08);
  --success:     #3FB950;
  --warning:     #D29922;
  --danger:      #F85149;
  --radius:      8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
}
[data-theme="light"] {
  --bg:          #F6F8FA;
  --bg-card:     #FFFFFF;
  --bg-card-alt: #F6F8FA;
  --bg-input:    #FFFFFF;
  --border:      #D0D7DE;
  --border-hi:   #BFC5CC;
  --text:        #1F2328;
  --muted:       #656D76;
  --accent:      #0969DA;
  --accent-bg:   rgba(9,105,218,0.08);
  --anl:         #0550AE;
  --anl-bg:      rgba(5,80,174,0.06);
  --success:     #1A7F37;
  --warning:     #9A6700;
  --danger:      #CF222E;
  --shadow:      0 2px 12px rgba(0,0,0,0.08);
}

/* ── 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', 'Inter', sans-serif; font-size: 14px; line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top loading bar ──────────────────────────────────────────────────── */
#loading-bar {
  position: fixed; top: 0; left: 0; height: 2px; width: 0%;
  background: var(--accent); z-index: 9999;
  transition: width 0.4s ease, opacity 0.4s ease; opacity: 0;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.sov-header {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 100;
}
.anl-logo { font-size: 18px; font-weight: 700; color: var(--anl); letter-spacing: -0.3px; }
.anl-logo span { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 8px; }
.header-tag { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent); border-radius: 20px; padding: 1px 8px; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-hint { font-size: 11px; color: var(--muted); }
.header-hint kbd { background: var(--bg-card-alt); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: monospace; }
#theme-toggle { background: none; border: 1px solid var(--border); color: var(--muted); padding: 5px 10px; border-radius: var(--radius); cursor: pointer; font-size: 12px; transition: border-color 0.2s; }
#theme-toggle:hover { border-color: var(--accent); color: var(--text); }

/* ── Main ─────────────────────────────────────────────────────────────── */
.sov-main { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }

/* ── Search panel ─────────────────────────────────────────────────────── */
#search-panel {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.search-hero { margin-bottom: 20px; }
.search-input-wrap {
  display: flex; gap: 10px; align-items: center;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px 4px 4px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.search-icon { font-size: 16px; color: var(--muted); flex-shrink: 0; }
#topic-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 16px; padding: 8px 0;
}
#topic-input::placeholder { color: var(--muted); }
#search-btn {
  background: var(--accent); border: none; color: #fff;
  padding: 9px 22px; border-radius: 8px; font-size: 14px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 7px;
  transition: opacity 0.15s, transform 0.15s; white-space: nowrap; flex-shrink: 0;
}
#search-btn:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }
#search-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#search-spinner {
  width: 13px; height: 13px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Topic presets */
.topic-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.presets-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.preset-topic {
  background: var(--bg-card-alt); border: 1px solid var(--border);
  color: var(--muted); padding: 4px 12px; border-radius: 20px;
  font-size: 12px; cursor: pointer; transition: all 0.15s;
}
.preset-topic:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

/* Search history */
#search-history {
  display: none; margin-top: 10px; display: flex; flex-wrap: wrap;
  gap: 6px; align-items: center;
}
.history-label { font-size: 11px; color: var(--muted); }
.history-chip {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: 3px 10px; border-radius: 20px; font-size: 12px; cursor: pointer; transition: all 0.15s;
}
.history-chip:hover { border-color: var(--muted); color: var(--text); }

/* Date + labs row */
.search-options { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; padding-top: 18px; border-top: 1px solid var(--border); }
.search-dates { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-dates label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.search-dates input[type="date"] {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 7px 10px; font-size: 13px; outline: none; transition: border-color 0.2s;
}
.search-dates input[type="date"]:focus { border-color: var(--accent); }
.date-presets { display: flex; gap: 5px; }
.preset-btn {
  background: var(--bg-card-alt); border: 1px solid var(--border); color: var(--muted);
  padding: 5px 10px; border-radius: 20px; font-size: 11px; cursor: pointer; transition: all 0.15s;
}
.preset-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Lab checkboxes */
.labs-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.labs-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.labs-header label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.labs-link { background: none; border: none; color: var(--accent); font-size: 11px; cursor: pointer; text-decoration: underline; padding: 0; }
.lab-checkboxes { display: flex; flex-wrap: wrap; gap: 7px; }
.lab-checkbox-item {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card-alt); border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 12px; cursor: pointer; transition: all 0.15s; user-select: none;
}
.lab-checkbox-item.is-primary { border-color: var(--anl); background: var(--anl-bg); }
.lab-checkbox-item:hover { border-color: var(--border-hi); }
.lab-checkbox-item input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
.lab-color-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.lab-label { font-size: 12px; font-weight: 500; }

/* ── Error / no-data banners ──────────────────────────────────────────── */
#error-banner { background: rgba(248,81,73,0.1); border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 13px; display: none; }
#no-data-notice { background: rgba(210,153,34,0.1); border: 1px solid var(--warning); color: var(--warning); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 13px; display: none; }

/* ── Progress section ─────────────────────────────────────────────────── */
#progress-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px; display: none; }
.progress-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.progress-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
#elapsed-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#progress-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.progress-chip { display: flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 500; border: 1px solid var(--border); color: var(--muted); transition: all 0.25s; }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-hi); transition: background 0.25s; }
.progress-chip.loading { border-color: var(--warning); color: var(--warning); }
.progress-chip.loading .chip-dot { background: var(--warning); animation: pulse 1s ease-in-out infinite; }
.progress-chip.done { border-color: var(--success); color: var(--success); }
.progress-chip.done .chip-dot { background: var(--success); }
.progress-chip.error { border-color: var(--warning); color: var(--warning); }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

/* ── Summary cards ────────────────────────────────────────────────────── */
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.summary-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: border-color 0.2s; }
.summary-card:hover { border-color: var(--border-hi); }
.summary-card.anl-highlight { border-color: rgba(56,189,248,0.4); background: var(--anl-bg); }
.summary-card-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 8px; }
.summary-card-value { font-size: 30px; font-weight: 700; color: var(--text); line-height: 1; font-variant-numeric: tabular-nums; }
.summary-card.anl-highlight .summary-card-value { color: var(--anl); }
.summary-card-sub { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── Skeleton shimmer (while loading) ─────────────────────────────────── */
.skeleton-val {
  display: inline-block; width: 80px; height: 28px; border-radius: 4px;
  background: linear-gradient(90deg, var(--border) 25%, var(--border-hi) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Chart cards ──────────────────────────────────────────────────────── */
.charts-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.chart-card-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chart-card-title small { font-size: 11px; font-weight: 400; color: var(--muted); }
.chart-export-btn { background: none; border: 1px solid var(--border); color: var(--muted); padding: 3px 8px; border-radius: 5px; font-size: 11px; cursor: pointer; transition: all 0.15s; }
.chart-export-btn:hover { border-color: var(--accent); color: var(--accent); }
.chart-wrapper { position: relative; }
.chart-wrapper-sov    { height: 340px; }
.chart-wrapper-volume { height: 280px; }
.chart-wrapper-trend  { height: 300px; }
.chart-wrapper-donut  { height: 260px; }
.chart-full { margin-bottom: 16px; }
.donuts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-note { font-size: 11px; color: var(--muted); margin-top: 8px; }
.chart-note::before { content: 'ℹ  '; }

/* ── Results table ────────────────────────────────────────────────────── */
.table-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.table-card-title { font-size: 13px; font-weight: 600; color: var(--text); padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.table-card-title span { font-size: 11px; color: var(--muted); font-weight: 400; }
.sov-table { width: 100%; border-collapse: collapse; }
.sov-table th { background: var(--bg-card-alt); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; padding: 10px 16px; text-align: left; cursor: pointer; user-select: none; transition: color 0.15s; white-space: nowrap; }
.sov-table th:hover { color: var(--text); }
.sov-table th.text-end { text-align: right; }
.sov-table th.sort-desc::after { content: ' ↓'; color: var(--accent); }
.sov-table th.sort-asc::after  { content: ' ↑'; color: var(--accent); }
.sov-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.sov-table tr:last-child td { border-bottom: none; }
.sov-table tr:hover td { background: var(--bg-card-alt); }
.sov-table .table-primary-row td { background: var(--anl-bg); }
.sov-table .table-primary-row:hover td { background: rgba(56,189,248,0.12); }
.text-end { text-align: right; }
.font-mono { font-variant-numeric: tabular-nums; }
.lab-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.badge-primary { background: var(--anl-bg); color: var(--anl); border: 1px solid rgba(56,189,248,0.4); border-radius: 4px; padding: 1px 5px; font-size: 10px; font-weight: 700; vertical-align: middle; }
.rank-badge { background: var(--bg-card-alt); color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 2px 7px; font-size: 12px; font-weight: 600; }

/* ── Articles ─────────────────────────────────────────────────────────── */
.articles-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.articles-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.articles-card-title { font-size: 13px; font-weight: 600; color: var(--text); padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.source-badge { font-size: 10px; font-weight: 600; text-transform: uppercase; background: var(--bg-card-alt); color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; }
.article-item { padding: 10px 18px; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.article-item:last-child { border-bottom: none; }
.article-item:hover { background: var(--bg-card-alt); }
.article-title { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 4px; line-height: 1.4; }
.article-title:hover { color: var(--accent); text-decoration: none; }
.article-meta { display: flex; gap: 10px; font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.article-domain { font-weight: 500; }
.article-score { color: var(--success); }
.article-date { margin-left: auto; }
.empty-state { padding: 20px; font-size: 13px; color: var(--muted); }

/* ── Export bar ───────────────────────────────────────────────────────── */
.export-bar { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.export-bar-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.export-btn { background: var(--bg-card-alt); border: 1px solid var(--border); color: var(--text); padding: 6px 13px; border-radius: var(--radius); font-size: 12px; font-weight: 500; cursor: pointer; transition: all 0.15s; }
.export-btn:hover { border-color: var(--accent); color: var(--accent); }
.export-note { margin-left: auto; font-size: 11px; color: var(--muted); }

/* ── Toast ────────────────────────────────────────────────────────────── */
.sov-toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(12px); background: var(--bg-card); border: 1px solid var(--success); color: var(--success); padding: 9px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 500; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 9999; box-shadow: var(--shadow); }
.sov-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .charts-grid-2, .donuts-grid, .articles-grid { grid-template-columns: 1fr; }
  .chart-wrapper-sov { height: 280px; }
}
@media (max-width: 600px) {
  .sov-main { padding: 16px 12px 40px; }
  .search-options { flex-direction: column; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
}

/* ── Print ────────────────────────────────────────────────────────────── */
@media print {
  .sov-header, #search-panel, #progress-section, .export-bar, #loading-bar { display: none !important; }
  body { background: #fff; color: #000; }
  .chart-card, .table-card, .articles-card, .summary-card { border: 1px solid #ccc; }
}
