:root {
  --bg: #f4f6fb;
  --bg-soft: #eef1f8;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6b84;
  --border: #e3e8f2;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-3: #0891b2;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --bg-soft: #101830;
  --card: #151d36;
  --text: #eef2ff;
  --muted: #94a3c8;
  --border: #26304f;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

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

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

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; }
.logo { font-size: 1.3rem; }

.icon-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 1.05rem;
  transition: transform .15s, border-color .2s;
}
.icon-btn:hover { transform: translateY(-1px); border-color: var(--accent); }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 40px 20px 20px; }

.hero { text-align: center; margin-bottom: 36px; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.8rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.grad { background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin-top: 12px; color: var(--muted); font-size: 1.05rem; max-width: 620px; margin-inline: auto; }

.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; box-shadow: var(--shadow); max-width: 760px; margin: 0 auto 24px;
}
.panel h2 { font-size: 1.35rem; letter-spacing: -.02em; }
.sub { color: var(--muted); margin: 6px 0 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.chip {
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 500;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.chip.on { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }

.add-row { display: flex; gap: 10px; margin-bottom: 14px; }
.add-row input {
  flex: 1; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text); font: inherit;
}
.add-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.selected { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; font-size: .9rem; font-weight: 500;
}
.pill-x { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; }
.pill-x:hover { color: #ef4444; }

.btn {
  border: none; cursor: pointer; font: inherit; font-weight: 600;
  padding: 11px 20px; border-radius: 12px; transition: all .15s;
}
.btn.primary { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.ghost { background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.big { width: 100%; padding: 15px; font-size: 1.05rem; }
.btn.small { padding: 9px 14px; font-size: .85rem; }

.hidden { display: none !important; }

.dash-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.mode-switch { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px; padding: 4px; gap: 4px; }
.mode-btn { border: none; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 9px 18px; border-radius: 9px; cursor: pointer; transition: all .15s; }
.mode-btn.active { background: var(--card); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.08); }

.dash-controls { display: flex; gap: 10px; flex-wrap: wrap; }
.dash-controls input[type="search"] { padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-soft); color: var(--text); font: inherit; min-width: 180px; }
.dash-controls input:focus { outline: 2px solid var(--accent); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.share-box {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg-soft); border: 1px dashed var(--border); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 18px; font-size: .9rem; color: var(--muted);
}
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); font: inherit; font-size: .85rem; }

.status { color: var(--muted); font-size: .9rem; margin-bottom: 14px; min-height: 1.2em; }

.alert-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.alert-on {
  display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 12px; padding: 10px 14px; font-size: .9rem; font-weight: 500;
}
.alert-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: pulse 2s infinite; flex: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.feed { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s, box-shadow .2s, border-color .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--accent); }
.card-meta { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }
.badge { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.badge.red { background: linear-gradient(90deg, #ef4444, #f97316); }
.source { font-weight: 600; color: var(--text); }
.dot { opacity: .5; }
.card h3 { font-size: 1rem; line-height: 1.4; letter-spacing: -.01em; }
.card h3 a { color: var(--text); text-decoration: none; }
.card h3 a:hover { color: var(--accent); }
.card p { color: var(--muted); font-size: .88rem; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { margin-top: auto; }
.read { color: var(--accent); font-weight: 600; font-size: .88rem; text-decoration: none; }
.read:hover { text-decoration: underline; }

.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

.skeleton { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; height: 170px; position: relative; overflow: hidden; }
.skeleton::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--bg-soft) 90%, transparent), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(380px, calc(100vw - 40px));
}
.toast {
  position: relative;
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px;
  opacity: 0; transform: translateY(12px); transition: opacity .35s, transform .35s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.breaking { border-left-color: #ef4444; }
.toast-head { display: flex; align-items: center; gap: 8px; font-size: .75rem; font-weight: 700; letter-spacing: .04em; margin-bottom: 6px; }
.toast-head .breaking-tag { color: #ef4444; }
.toast-head .new-tag { color: var(--accent); }
.toast-topic { color: var(--muted); font-weight: 600; }
.toast a { color: var(--text); text-decoration: none; font-weight: 600; font-size: .9rem; line-height: 1.4; display: block; padding-right: 18px; }
.toast a:hover { color: var(--accent); }
.toast-x { position: absolute; top: 8px; right: 10px; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.05rem; }
.toast-x:hover { color: #ef4444; }

.footer { text-align: center; padding: 26px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); }

@media (max-width: 640px) {
  .dash-head { flex-direction: column; align-items: stretch; }
  .dash-controls { justify-content: space-between; }
  .dash-controls input[type="search"] { flex: 1; }
  main { padding: 24px 14px 14px; }
  .panel { padding: 20px; }
}