:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #15181d;
  --text-2: #5b6472;
  --text-3: #8a93a1;
  --border: #e3e7ed;
  --primary: #007aff;
  --primary-ink: #ffffff;
  --primary-soft: rgba(0, 122, 255, 0.1);
  --accent: #1f9d55;
  --danger: #d93025;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Devanagari", "Noto Sans", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f12;
    --surface: #17191d;
    --surface-2: #22252b;
    --text: #f2f4f7;
    --text-2: #a9b0bb;
    --text-3: #7c8490;
    --border: #2c3038;
    --primary: #2b8fff;
    --primary-soft: rgba(43, 143, 255, 0.16);
    --accent: #3ccf76;
    --danger: #ff6b5e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0f12;
  --surface: #17191d;
  --surface-2: #22252b;
  --text: #f2f4f7;
  --text-2: #a9b0bb;
  --text-3: #7c8490;
  --border: #2c3038;
  --primary: #2b8fff;
  --primary-soft: rgba(43, 143, 255, 0.16);
  --accent: #3ccf76;
  --danger: #ff6b5e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand img { border-radius: 8px; }

.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.nav a, .nav button {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 14px;
  background: none;
  border: 0;
  cursor: pointer;
}
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.is-active { background: var(--primary-soft); color: var(--primary); }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  flex: 1;
  outline: none;
}
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

/* ---------- Filters ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--text-3); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.dates { display: flex; gap: 8px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.dates label { font-size: 13px; color: var(--text-2); display: flex; gap: 6px; align-items: center; }
.dates input {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 14px;
}

/* ---------- News ---------- */
.feed { display: grid; gap: 12px; }

.card {
  display: grid;
  grid-template-columns: 1fr 168px;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card--no-thumb { grid-template-columns: 1fr; }
.card__meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--text-3); margin-bottom: 6px; }
.card__source { font-weight: 600; color: var(--primary); }
.card__ticker { font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 1px 8px; border-radius: 6px; }
.card__cat { border: 1px solid var(--border); padding: 0 8px; border-radius: 6px; }
.card h2 { font-size: 17px; line-height: 1.4; margin: 0 0 6px; font-weight: 650; }
.card h2 a { color: var(--text); }
.card h2 a:hover { color: var(--primary); text-decoration: none; }
.card__desc {
  margin: 0;
  color: var(--text-2);
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__actions { display: flex; gap: 8px; margin-top: 12px; }
.card__thumb {
  width: 168px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface-2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn--primary:hover { background: color-mix(in srgb, var(--primary) 88%, black); }
.btn--saved { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.btn--block { width: 100%; padding: 10px 14px; }
.btn svg { width: 16px; height: 16px; }

.more { display: flex; justify-content: center; margin-top: 20px; }
.count { color: var(--text-3); font-size: 13px; }

.empty, .loading, .error-box {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.error-box { color: var(--danger); }

.skeleton {
  height: 120px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border: 1px solid var(--border);
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- Forms ---------- */
.auth {
  max-width: 400px;
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.auth .sub { margin: 0 0 20px; color: var(--text-2); font-size: 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}
.field input:focus, .dates input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.form-error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }
.form-links { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; font-size: 14px; flex-wrap: wrap; }

/* ---------- Admin ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 4px; font-size: 17px; }
.panel p { margin: 0 0 14px; color: var(--text-2); font-size: 14px; }
.panel .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel .row label { font-size: 14px; color: var(--text-2); display: flex; gap: 6px; align-items: center; }
.panel .row input { width: 72px; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 5px 8px; }
.log {
  margin-top: 14px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  max-height: 260px;
  overflow: auto;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  z-index: 50;
  max-width: calc(100% - 32px);
}

.footer {
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}
.footer p { margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar__inner { gap: 8px; }
  .brand span { display: none; }
  .nav a, .nav button { padding: 6px 9px; }
  .page-head h1 { font-size: 22px; }
  .dates { margin-left: 0; }
  .card { grid-template-columns: 1fr 96px; gap: 12px; padding: 14px; }
  .card__thumb { width: 96px; aspect-ratio: 1; }
  .card h2 { font-size: 16px; }
  .card__desc { -webkit-line-clamp: 2; }
}
