:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --sidebar: #efede8;
  --text: #1f1d1a;
  --muted: #6d6860;
  --line: #e2dfd8;
  --hover: #e7e4dd;
  --active: #fde9dc;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --hidden-bg: #fff4e0;
  --hidden-line: #f1c27d;
  --star: #e8a400;
  --ok-bg: #e6f6ea;
  --ok-line: #8fd3a0;
  --mark: #ffe08a;
  --shadow: 0 10px 40px rgba(0, 0, 0, .18);
  --radius: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Charter", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181a; --panel: #1e1f22; --sidebar: #141517; --text: #e8e6e1; --muted: #9a968e;
    --line: #2e3034; --hover: #282a2e; --active: #3a2a20; --accent: #ff7a3d; --accent-text: #1a0f08;
    --danger: #ff6b6b; --hidden-bg: #2e2617; --hidden-line: #6b5121; --star: #ffc53d;
    --ok-bg: #16291c; --ok-line: #2f6b3f; --mark: #6b5212;
    --shadow: 0 10px 40px rgba(0, 0, 0, .6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17181a; --panel: #1e1f22; --sidebar: #141517; --text: #e8e6e1; --muted: #9a968e;
  --line: #2e3034; --hover: #282a2e; --active: #3a2a20; --accent: #ff7a3d; --accent-text: #1a0f08;
  --danger: #ff6b6b; --hidden-bg: #2e2617; --hidden-line: #6b5121; --star: #ffc53d;
  --ok-bg: #16291c; --ok-line: #2f6b3f; --mark: #6b5212;
  --shadow: 0 10px 40px rgba(0, 0, 0, .6); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.break { word-break: break-all; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0; font-size: 13px; }
kbd { font: 11px/1 ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 2px 4px; }

input, select, textarea {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
label { display: block; font-weight: 500; margin: 10px 0 0; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; text-decoration: none; white-space: nowrap; margin: 0;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; justify-content: flex-start; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.link { background: none; border: none; color: var(--accent); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: progress; }
.icon-btn {
  border: none; background: transparent; color: var(--muted); font-size: 17px; width: 32px; height: 32px;
  border-radius: 6px; cursor: pointer; display: inline-grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--star); }
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.logo {
  display: inline-block; width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='9' cy='23' r='3' fill='white'/%3E%3Cpath d='M6 13a13 13 0 0 1 13 13M6 6a20 20 0 0 1 20 20' stroke='white' stroke-width='3.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center/100% no-repeat;
}
.logo.huge { width: 56px; height: 56px; border-radius: 14px; opacity: .25; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand.big { font-size: 26px; }
.brand.big .logo { width: 34px; height: 34px; border-radius: 9px; }

/* ---------- acceso ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.auth-card .btn.primary { width: 100%; margin-top: 8px; padding: 10px; }
.auth-card .btn.link { margin-top: 8px; }
.auth-card h2 { margin: 18px 0 6px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; margin: 18px 0 4px; }
.auth-tabs button { font: inherit; font-weight: 600; border: none; background: none; color: var(--muted); padding: 7px; border-radius: 6px; cursor: pointer; }
.auth-tabs button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.center { text-align: center; }
.code-input { font: 600 28px/1 ui-monospace, Consolas, monospace; letter-spacing: .35em; text-align: center; padding: 12px 8px; margin-top: 12px; }
.code-input.small-code { font-size: 18px; width: 150px; flex: none; margin-top: 0; padding: 7px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.turnstile:not(:empty) { margin-top: 12px; min-height: 65px; }
.notice { font: inherit; font-size: 12.5px; text-align: left; border: 1px solid var(--hidden-line); background: var(--hidden-bg); color: var(--text); border-radius: 6px; padding: 7px 9px; cursor: pointer; margin-bottom: 4px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--text); }
.badge.warn { background: var(--hidden-bg); border-color: var(--hidden-line); color: var(--text); }
.admin-table tr.pending td { color: var(--muted); }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.device-row:last-child { border-bottom: 0; }
.device-row .btn { flex: none; }
.ok-text { color: var(--text); }

/* ---------- disposición ---------- */
.layout { display: grid; grid-template-columns: 260px minmax(320px, 420px) 1fr; height: 100vh; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 10px; min-height: 0; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 6px 6px; }
.views a, .feeds a {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px;
  color: var(--text); text-decoration: none; min-width: 0;
}
.views a:hover, .feeds a:hover { background: var(--hover); }
.views a.active, .feeds a.active { background: var(--active); font-weight: 600; }
.views .ico { width: 18px; text-align: center; color: var(--muted); }
.count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.feeds-title { font-size: 11.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); padding: 8px 8px 0; }
.feeds { overflow-y: auto; flex: 1; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.folder > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; font-weight: 600; }
.folder > summary::-webkit-details-marker { display: none; }
.folder > summary::before { content: "▸"; color: var(--muted); font-size: 11px; width: 12px; transition: transform .15s; }
.folder[open] > summary::before { transform: rotate(90deg); }
.folder > summary:hover { background: var(--hover); }
.folder > summary.active { background: var(--active); }
.folder .feed-link { padding-left: 26px; }
.feed-link .fav { width: 16px; height: 16px; border-radius: 3px; flex: none; background: var(--line) center/cover; }
.feed-link .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.feed-link .warn { color: var(--danger); font-size: 12px; }
.feed-link .more { opacity: 0; width: 22px; height: 22px; font-size: 14px; }
.feed-link:hover .more, .feed-link.active .more { opacity: 1; }
.feed-link .count { margin-left: 0; }
.empty-feeds { padding: 10px; color: var(--muted); font-size: 13px; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 2px; }

.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.list-head { display: flex; align-items: center; gap: 6px; padding: 12px 10px 6px 16px; }
.list-head h1 { font-size: 18px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-tools { display: flex; gap: 2px; }
.search-row { padding: 0 12px 8px 16px; }
.hidden-banner { margin: 0 12px 8px 16px; padding: 8px 10px; background: var(--hidden-bg); border: 1px solid var(--hidden-line); border-radius: var(--radius); font-size: 12.5px; display: grid; gap: 6px; }
.entries { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; border-top: 1px solid var(--line); }
.entry { padding: 11px 14px 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.entry:hover { background: var(--hover); }
.entry.selected { background: var(--active); box-shadow: inset 3px 0 0 var(--accent); }
.entry.read .e-title { color: var(--muted); font-weight: 400; }
.entry .e-meta { display: flex; gap: 6px; font-size: 12px; color: var(--muted); align-items: center; min-width: 0; }
.entry .e-feed { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .e-date { margin-left: auto; flex: none; }
.entry .e-title { font-weight: 600; margin: 3px 0; font-size: 14.5px; }
.entry .e-snippet { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry .e-star { color: var(--star); }
.entry:not(.read) .e-title::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: 2px; }
.why { display: inline-block; margin-top: 6px; font-size: 11.5px; padding: 2px 7px; border-radius: 999px; background: var(--hidden-bg); border: 1px solid var(--hidden-line); }
.list-foot { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.reader { overflow-y: auto; min-width: 0; background: var(--bg); }
.reader-empty { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); padding: 20px; gap: 4px; }
.reader-body { max-width: 760px; margin: 0 auto; padding: 18px 32px 80px; }
.reader-bar { position: sticky; top: 0; display: flex; gap: 4px; align-items: center; padding: 8px 0; background: var(--bg); z-index: 1; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.reader-bar .spacer { flex: 1; }
.reader h1.r-title { font-family: var(--serif); font-size: 30px; line-height: 1.2; margin-bottom: 10px; letter-spacing: -.01em; }
.reader h1.r-title a { color: inherit; text-decoration: none; }
.reader h1.r-title a:hover { text-decoration: underline; }
.r-meta { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.r-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--panel); cursor: pointer; }
.tag:hover { border-color: var(--accent); color: var(--accent); }
.r-hidden { background: var(--hidden-bg); border: 1px solid var(--hidden-line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 18px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.r-hidden span { flex: 1; min-width: 200px; }
.r-content { font-family: var(--serif); font-size: 18px; line-height: 1.65; overflow-wrap: break-word; }
.r-content img, .r-content video, .r-content iframe { max-width: 100%; height: auto; border-radius: 6px; }
.r-content pre { overflow-x: auto; background: var(--panel); padding: 12px; border-radius: 6px; font-size: 14px; }
.r-content blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 16px; color: var(--muted); }
.r-content table { border-collapse: collapse; display: block; overflow-x: auto; }
.r-content td, .r-content th { border: 1px solid var(--line); padding: 4px 8px; }
.r-original { margin-top: 30px; }

/* ---------- diálogos ---------- */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text); box-shadow: var(--shadow); width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog.wide-dlg { width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dlg { padding: 22px; }
.dlg-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.dlg-actions.spread { justify-content: space-between; }
.dlg-actions span { display: flex; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.wrap input:not([type="checkbox"]) { flex: 1 1 160px; width: auto; }
.row.spread { justify-content: space-between; }
.row select { width: auto; }

.rule-form { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px 14px; margin-top: 12px; background: var(--bg); }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checks { border: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.checks legend { font-weight: 500; padding: 0; margin-bottom: 4px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; margin: 0; font-weight: 400; }
.checks .sep { margin-left: auto; }
.preview { font-size: 13px; padding: 8px 10px; border-radius: 6px; background: var(--hidden-bg); border: 1px solid var(--hidden-line); }
.preview ul { margin: 6px 0 0; padding-left: 18px; }
.rules { list-style: none; margin: 0; padding: 0; }
.rule { display: flex; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.rule.off .r-term { text-decoration: line-through; color: var(--muted); }
.rule .r-main { flex: 1; min-width: 0; }
.rule .r-term { font-weight: 600; word-break: break-word; }
.rule .r-info { font-size: 12px; color: var(--muted); }
.rule .r-count { font-size: 12px; white-space: nowrap; }
.rules .list-empty { padding: 20px; }

/* ---------- excepciones y búsqueda ---------- */
.why.allowed, .r-hidden.allowed { background: var(--ok-bg); border-color: var(--ok-line); }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }

/* ---------- administración ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 12px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--bg); }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.admin-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.admin-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .you { font-size: 11px; color: var(--muted); margin-left: 4px; }
.admin-table td:last-child { text-align: right; }
.failing { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.failing li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.failing .f-main { flex: 1; min-width: 0; }
.failing .f-url { word-break: break-all; color: var(--muted); font-size: 12px; }
.failing .error { margin: 2px 0 0; min-height: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(30px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 10; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--danger); color: #fff; }

.only-mobile { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 230px minmax(280px, 360px) 1fr; }
  .reader-body { padding: 14px 22px 60px; }
}
@media (max-width: 820px) {
  .only-mobile { display: inline-grid; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 5; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .layout.sidebar-open .sidebar { transform: none; }
  .list-pane { border-right: none; }
  /* Cerrado, el lector sigue dentro de la pantalla pero recortado: si se desplazara
     fuera (translateX), algunos móviles permitirían arrastrar la página de lado. */
  .reader { position: fixed; inset: 0; z-index: 4; clip-path: inset(0 0 0 100%); visibility: hidden;
            transition: clip-path .2s, visibility 0s .2s; }
  .layout.reading .reader { clip-path: inset(0); visibility: visible; transition: clip-path .2s; }
  .reader-body { padding: 0 16px 60px; }
  .reader h1.r-title { font-size: 24px; }
  .r-content { font-size: 17px; }
  .rule-grid { grid-template-columns: 1fr; }
  .checks .sep { margin-left: 0; }
}
