:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --bg-input: #0f172a;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: rgba(59,130,246,0.15);
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-input: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: rgba(37,99,235,0.1);
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

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

/* ── Navbar ── */
.navbar {
  height: 60px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.navbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.navbar-brand .logo { font-size: 1.3rem; }
.navbar-spacer { flex: 1; }
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* ── Layout ── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.add-stock-form {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.add-stock-form input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s;
}
.add-stock-form input::placeholder { text-transform: none; color: var(--text-muted); }
.add-stock-form input:focus { border-color: var(--accent); }
.btn-add {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 700;
  transition: background 0.2s;
}
.btn-add:hover { background: var(--accent-hover); }
.btn-add:disabled { opacity: 0.5; cursor: not-allowed; }

.stock-list { flex: 1; overflow-y: auto; padding: 8px; }
.stock-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 10px;
  border: 1px solid transparent;
}
.stock-item:hover { background: var(--accent-light); border-color: var(--border); }
.stock-item.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.stock-symbol {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
}
.stock-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}
.stock-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
  opacity: 0;
  transition: all 0.15s;
}
.stock-item:hover .stock-remove { opacity: 1; }
.stock-remove:hover { background: var(--danger); color: white; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}
.api-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.api-status span { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }

/* ── Main Content ── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.toolbar {
  padding: 14px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.date-range { display: flex; align-items: center; gap: 8px; }
.date-range label { font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; }
.date-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.date-input:focus { border-color: var(--accent); }
.toolbar-spacer { flex: 1; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { filter: brightness(0.9); }

/* ── News Feed ── */
.news-feed {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}
.empty-state .icon { font-size: 3rem; opacity: 0.5; }
.empty-state p { font-size: 1rem; }
.empty-state small { font-size: 0.85rem; }

.stock-section { margin-bottom: 40px; }
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent);
}
.section-symbol {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.05em;
}
.section-count {
  background: var(--accent-light);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.section-refresh {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
  margin-left: auto;
}
.section-refresh:hover { border-color: var(--accent); color: var(--accent); }

.news-grid { display: flex; flex-direction: column; gap: 12px; }

.news-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  gap: 16px;
  transition: box-shadow 0.2s, border-color 0.2s;
  animation: fadeIn 0.3s ease;
}
.news-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.news-thumb {
  width: 110px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-input);
}
.news-body { flex: 1; min-width: 0; }
.news-headline {
  font-size: 0.97rem;
  font-weight: 600;
  line-height: 1.45;
  margin-bottom: 8px;
  color: var(--text);
}
.news-headline a { color: inherit; text-decoration: none; }
.news-headline a:hover { color: var(--accent); text-decoration: underline; }
.news-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.8rem;
}
.news-source { color: var(--accent); font-weight: 600; }
.news-date { color: var(--text-muted); }
.badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-high { background: rgba(34,197,94,0.15); color: #22c55e; }
.badge-medium { background: rgba(245,158,11,0.15); color: #f59e0b; }
.badge-low { background: rgba(239,68,68,0.15); color: #ef4444; }
.news-summary {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  margin-top: 8px;
}
.news-link:hover { text-decoration: underline; }

/* ── Loading Skeleton ── */
.skeleton { background: linear-gradient(90deg, var(--bg-card) 25%, var(--border) 50%, var(--bg-card) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; gap: 16px; margin-bottom: 12px; }
.skeleton-thumb { width: 110px; height: 72px; flex-shrink: 0; }
.skeleton-body { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.skeleton-line { height: 12px; }
.skeleton-line.wide { width: 90%; }
.skeleton-line.medium { width: 60%; }
.skeleton-line.short { width: 35%; }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease;
  max-width: 320px;
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: #2563eb; }
.toast-warning { background: #d97706; }

/* ── Source Filter ── */
.source-filter {
  display: flex;
  align-items: center;
  gap: 6px;
}
.source-filter select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.source-filter select:focus { border-color: var(--accent); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Spinner ── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  max-width: 520px;
  width: 90%;
  box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 16px; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { width: 220px; }
  .toolbar { gap: 8px; }
  .news-thumb { display: none; }
  .date-range { flex-wrap: wrap; }
}
@media (max-width: 576px) {
  .sidebar { display: none; }
  .layout { flex-direction: column; }
}
