:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --danger: #dc2626;
  --star: #f59e0b;
  --topbar-h: 52px;
}
:root:not([data-theme="light"]) {
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel-2: #172033;
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --line: #334155;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --danger: #f87171;
    --star: #fbbf24;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #172033;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #60a5fa;
  --accent-soft: #1e3a5f;
  --danger: #f87171;
  --star: #fbbf24;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button, input, select { font: inherit; color: var(--ink); }
button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn { border: 0; background: none; font-size: 18px; padding: 4px 8px; line-height: 1; }
.btn-link {
  text-decoration: none; color: var(--muted);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 12px;
}
input[type="url"], input[type="text"], input[type="number"], input[type="password"], select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.only-mobile { display: none; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; width: 320px; max-width: 100%;
}
.login-card h1 { margin: 0 0 18px; font-size: 20px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.login-card input { width: 100%; margin-top: 4px; }
.login-card button { width: 100%; margin-top: 6px; padding: 10px; }
.login-error { background: rgba(220, 38, 38, .12); color: var(--danger); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 0 0 14px; }

/* ── Barra superior ────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; white-space: nowrap; }
.topbar .status { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar .actions { display: flex; gap: 6px; align-items: center; }

/* ── Layout 3 columnas ────────────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 264px 400px 1fr; height: calc(100vh - var(--topbar-h)); }
.sidebar, .list, .reader { overflow-y: auto; }
.reader { overflow-x: hidden; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 12px; }
.list { border-right: 1px solid var(--line); }
.reader { padding: 24px 40px; }
.scrim { display: none; }

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.filters { display: flex; gap: 4px; margin-bottom: 12px; }
.filters button { flex: 1; padding: 6px 0; font-size: 12px; }
.filters button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#tree .stream {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: 13px;
}
#tree .stream:hover { background: var(--bg); }
#tree .stream.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#tree .cat-head { margin-top: 10px; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
#tree .feed { padding-left: 16px; }
#tree .feed.muted { opacity: .5; }
#tree .feed.err .count::after { content: " !"; color: var(--danger); }
#tree .count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#tree .stream.active .count { color: var(--accent); }

/* ── Lista ────────────────────────────────────────────────────────────── */
.listhead {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; background: var(--bg); border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.listhead button { padding: 4px 10px; font-size: 12px; }
.row-wrap { position: relative; overflow: hidden; }
.row-wrap.collapsing { transition: height .2s ease; }
.row-action {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end;
  padding-right: 22px; background: var(--muted); color: #fff; font-size: 13px; font-weight: 700;
}
.row-action.armed { background: var(--accent); }
.row {
  position: relative; background: var(--bg);
  display: flex; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer;
  transition: transform .18s ease;
}
.row.swiping { transition: none; }
.row:hover { background: var(--panel); }
.row.current { background: var(--accent-soft); }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; margin-bottom: 2px; }
.row.unread .row-title::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px;
  border-radius: 50%; background: var(--accent); vertical-align: middle;
}
.row:not(.unread) .row-title { font-weight: 400; color: var(--muted); }
.row-meta { font-size: 11px; color: var(--muted); }
.row-meta .badge {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 10px;
  background: var(--line); color: var(--muted); font-size: 10px;
}
.row-meta .badge.prio { background: var(--accent-soft); color: var(--accent); }
.row-snippet {
  font-size: 12px; color: var(--muted); margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.star { border: 0; background: none; color: var(--line); font-size: 18px; line-height: 1; padding: 0 2px; align-self: flex-start; }
.star:hover, .star.on { color: var(--star); }

/* ── Lector ───────────────────────────────────────────────────────────── */
.reader-nav { display: flex; gap: 8px; margin-bottom: 14px; }
.reader-nav button { padding: 5px 12px; }
.reader-head { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 20px; }
.reader-head h1 { font-size: 24px; line-height: 1.25; margin: 0 0 8px; }
.reader-meta { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.reader-actions a, .reader-actions button { display: inline-flex; align-items: center; gap: 6px; }
.reader-actions a { color: var(--accent); text-decoration: none; border: 1px solid var(--line); border-radius: 7px; padding: 5px 12px; }
.reader-actions .ico { font-size: 15px; line-height: 1; }
.ai-box { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 12px 14px; margin-bottom: 20px; }
.ai-box h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.ai-box p { margin: 0; white-space: pre-wrap; }
.reader-body { max-width: 680px; font-size: 15px; line-height: 1.7; }
.reader-body img { max-width: 100%; height: auto; border-radius: 8px; }
.reader-body pre { overflow-x: auto; background: var(--panel-2); padding: 12px; border-radius: 8px; }
.reader-body a { color: var(--accent); }
.empty { color: var(--muted); padding: 24px 14px; }

/* Transicion al pasar de un articulo a otro (swipe / flechas / botones) */
@keyframes slide-from-right { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-from-left  { from { transform: translateX(-32px); opacity: 0; } to { transform: none; opacity: 1; } }
#reader-body.slide-next { animation: slide-from-right .2s ease both; }
#reader-body.slide-prev { animation: slide-from-left .2s ease both; }
@media (prefers-reduced-motion: reduce) {
  #reader-body.slide-next, #reader-body.slide-prev { animation-duration: .01ms; }
}

/* ── Modal de ajustes ─────────────────────────────────────────────────── */
#settings-modal {
  width: 620px; max-width: calc(100vw - 24px); max-height: calc(100vh - 48px);
  border: 0; border-radius: 14px; padding: 0; color: var(--ink); background: var(--panel);
  overflow: auto;
}
#settings-modal::backdrop { background: rgba(15, 23, 42, .5); }
.modal-head { position: sticky; top: 0; background: var(--panel); display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-section { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-section h3 { margin: 0 0 10px; font-size: 13px; }
.modal-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.modal-row input[type="url"], .rule-form #rule-pattern { flex: 1; min-width: 140px; }
.filelabel { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.items-list { border: 1px solid var(--line); border-radius: 8px; max-height: 34vh; overflow-y: auto; }
.items-list:empty::after { content: "Nada todavia."; display: block; padding: 12px; color: var(--muted); font-size: 13px; }
.item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.item:last-child { border-bottom: 0; }
.item .it-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.off .it-main { color: var(--muted); text-decoration: line-through; }
.item .it-status { font-size: 11px; color: var(--danger); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item button { padding: 3px 8px; font-size: 12px; }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .3px; padding: 1px 6px; border-radius: 4px; background: var(--line); color: var(--muted); }
.tag.exclude { background: rgba(220,38,38,.15); color: var(--danger); }
.tag.include { background: rgba(37,99,235,.15); color: var(--accent); }
.tag.priority { background: var(--accent-soft); color: var(--accent); }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; max-width: 80vw; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); z-index: 100;
}
.toast.error { background: var(--danger); }

/* ── Movil ────────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .only-mobile { display: inline-flex; }
  .layout { grid-template-columns: 1fr; position: relative; }
  .topbar .brand { display: none; }
  .topbar .actions .btn-link { padding: 6px 8px; }

  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: 82vw; max-width: 320px;
    transform: translateX(-100%); transition: transform .2s ease; z-index: 30;
  }
  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(15, 23, 42, .4); z-index: 20; }

  .list { border-right: 0; }
  .reader {
    position: fixed; inset: var(--topbar-h) 0 0 0; background: var(--bg);
    padding: 16px; transform: translateX(100%); transition: transform .2s ease; z-index: 25;
  }
  body.reading .reader { transform: translateX(0); }

  /* Acciones del lector: solo iconos, en una linea */
  .reader-actions { gap: 6px; flex-wrap: nowrap; }
  .reader-actions .lbl { display: none; }
  .reader-actions a, .reader-actions button { padding: 9px 13px; }
  .reader-actions .ico { font-size: 18px; }
}
