/* Archivo Potterfics — UI v2 */
:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e7e5e0;
  --accent: #a3584b;        /* burgundy cálido */
  --accent-ink: #7c3d33;
  --gold: #d97706;
  --glass: rgba(255,255,255,.86);
  --hover-line: #d9d3c9;
  --track: #efede8;
  --mark-bg: #fdeebd;
  --tok-bg: #fafafa;
  --th-bg: #faf9f6;
  --row-hover: #fcfbf8;
  --facets-bg: #faf9f6;
  --ok-bg: #eef9f0;  --ok-line: #bfe3c7;
  --err-bg: #fdf0ef; --err-line: #efc7c2;
  --chip-bg: #f4e8ff; --chip-ink: #5b2d91; --chip-line: #dcc8ef; --chip-hover: #ecdffc;
  --badge-done-bg: #e7f6ec;  --badge-done-ink: #1a7f37;
  --badge-wip-bg: #fef3dd;   --badge-wip-ink: #a16207;
  --badge-story-bg: #ede9fe; --badge-story-ink: #6d28d9;
  --badge-chapt-bg: #e0f2fe; --badge-chapt-ink: #0369a1;
  --badge-crawl-bg: #fff4e0; --badge-crawl-ink: #a85d00; --badge-crawl-line: #f0d9b5;
  --badge-meta-bg: #f2f1ee;
  --violet-a: #9a7fd1; --violet-b: #6a4fa3;
  --agent-hover: #b3551d;
  --ring: rgba(163, 88, 75, .28);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 36, 48, .05), 0 8px 24px -12px rgba(31, 36, 48, .12);
  --shadow-lg: 0 12px 32px -12px rgba(31, 36, 48, .18);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--glass);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  max-width: 1080px; margin: 0 auto; padding: .7rem 1.2rem;
  display: flex; gap: 1rem; align-items: center;
}
.logo {
  font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; font-size: 1.05rem;
}
.logo span { color: var(--accent-ink); }
.topbar__search {
  flex: 1; display: flex; max-width: 520px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: .15rem .25rem .15rem 1rem; transition: box-shadow .15s, border-color .15s;
}
.topbar__search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.topbar__search input {
  flex: 1; border: 0; outline: 0; background: transparent; font: inherit; color: var(--ink);
}
.topbar__search button {
  border: 0; background: var(--accent); color: #fff; width: 2.2rem; height: 2.2rem;
  border-radius: 999px; cursor: pointer; font-size: 1.05rem; line-height: 1;
  display: grid; place-items: center; transition: background .15s;
}
.topbar__search button:hover { background: var(--accent-ink); }
.topbar__link { color: var(--muted); font-size: .95rem; white-space: nowrap; }
.topbar__link:hover { color: var(--accent-ink); }
@media (max-width: 720px) { .topbar__link { display: none; } }

/* ---------- layout ---------- */
.page { max-width: 1080px; margin: 1.8rem auto 3rem; padding: 0 1.2rem; min-height: 55vh; }
.footer {
  border-top: 1px solid var(--line); color: var(--muted);
  padding: 1.4rem 1.2rem; text-align: center; font-size: .88rem;
}
.footer p { margin: .25rem auto; max-width: 720px; }

.hero h1 { margin: 0 0 .3rem; font-size: clamp(1.6rem, 3.5vw, 2.3rem); letter-spacing: -0.03em; }
.hero__sub { margin: 0 0 1.6rem; color: var(--muted); }
.hero__sub b { color: var(--ink); }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: .12rem .6rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; letter-spacing: .02em; line-height: 1.6;
}
.badge--done   { background: var(--badge-done-bg); color: var(--badge-done-ink); }
.badge--wip    { background: var(--badge-wip-bg); color: var(--badge-wip-ink); }
.badge--story  { background: var(--badge-story-bg); color: var(--badge-story-ink); }
.badge--chapter{ background: var(--badge-chapt-bg); color: var(--badge-chapt-ink); }

/* ---------- grid de historias ---------- */
.grid {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
}
.card {
  display: flex; flex-direction: column; gap: .3rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  color: inherit; box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover {
  text-decoration: none; transform: translateY(-2px);
  box-shadow: var(--shadow-lg); border-color: var(--hover-line);
}
.card__title { font-weight: 650; line-height: 1.35; letter-spacing: -0.01em; }
.card__author { color: var(--muted); font-size: .88rem; }
.card__meta {
  margin-top: .35rem; display: flex; flex-wrap: wrap; gap: .5rem;
  color: var(--muted); font-size: .8rem; align-items: center;
}

/* ---------- búsqueda ---------- */
.bq { display: flex; gap: .5rem; margin: 0 0 1.4rem; flex-wrap: wrap; }
.bq input[type=search] {
  flex: 1; min-width: 220px; padding: .6rem .95rem;
  border: 1px solid var(--line); border-radius: 10px; font: inherit;
  background: var(--surface);
}
.bq input:focus, .bq select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.bq select { padding: .6rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font: inherit; }
.bq button {
  border: 0; background: var(--accent); color: #fff; border-radius: 10px;
  padding: .6rem 1.3rem; font: inherit; font-weight: 600; cursor: pointer; transition: background .15s;
}
.bq button:hover { background: var(--accent-ink); }
.count { color: var(--muted); margin: 0 0 1rem; }
.count b { color: var(--ink); }
.count.small { font-size: .82rem; }

.hits { display: flex; flex-direction: column; gap: .7rem; }
.hit {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1.1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .3rem;
}
.hit__title { font-weight: 650; letter-spacing: -0.01em; }
.hit__meta { display: flex; gap: .5rem; align-items: center; color: var(--muted); font-size: .8rem; }
.hit__snippet { margin: 0; color: var(--muted); font-size: .9rem; }
.hit__snippet mark { background: var(--mark-bg); color: inherit; border-radius: 3px; padding: 0 .1em; }
.empty { color: var(--muted); text-align: center; padding: 2.5rem 0; }

/* ---------- paginador ---------- */
.pager { display: flex; justify-content: center; margin: 2rem 0 .5rem; }
.pager__list { display: flex; gap: .35rem; list-style: none; margin: 0; padding: 0; align-items: center; }
.pager__btn {
  display: inline-grid; place-items: center; min-width: 2.3rem; height: 2.3rem;
  padding: 0 .5rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
a.pager__btn:hover { border-color: var(--accent); color: var(--accent-ink); text-decoration: none; }
.pager__btn--active {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.pager__btn--disabled { opacity: .35; cursor: default; }
.pager__dots { color: var(--muted); padding: 0 .25rem; }

/* ---------- ficha de historia ---------- */
.meta { color: var(--muted); font-size: .92rem; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.sinopsis {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: var(--radius); padding: .9rem 1.1rem; box-shadow: var(--shadow);
}
.caps { padding-left: 1.4rem; margin: 1rem 0 2rem; }
.caps li { margin: .35rem 0; }
.caps small { color: var(--muted); }

/* ---------- lectura de capítulo ---------- */
.chapter {
  max-width: 720px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2.2rem 2.4rem;
}
.chapter h1 { margin: .2rem 0 .2rem; letter-spacing: -0.02em; font-size: 1.7rem; }
.chapter h2.ct { color: var(--muted); font-size: 1.05rem; font-weight: 500; margin-top: 0; }
.texto { font-size: 1.08rem; line-height: 1.9; white-space: pre-wrap; }
/* red de seguridad: textos viejos pegotes (párrafo único de 19k chars) no
   deben salirse de la pantalla NUNCA — se doblan aunque no haya espacios */
.texto, .texto mark { overflow-wrap: anywhere; word-break: break-word; }
.texto mark { background: var(--mark-bg); border-radius: 3px; padding: 0 .1em; }
.crumb { margin-bottom: 1.2rem; font-size: .95rem; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent-ink); }
.capnav {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 720px; margin: 1.4rem auto 0; gap: .5rem;
}
.capnav a, .capnav span {
  padding: .55rem 1.1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); font-size: .95rem;
}
.capnav a:hover { border-color: var(--accent); color: var(--accent-ink); text-decoration: none; }
.capnav .none { opacity: .3; border: 0; box-shadow: none; background: transparent; }

/* ---------- formularios ---------- */
form label { display: block; margin: .8rem 0; max-width: 640px; color: var(--ink); font-size: .95rem; }
form input, form select, form textarea {
  width: 100%; margin-top: .3rem; padding: .55rem .75rem;
  border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--surface);
}
form input:focus, form select:focus, form textarea:focus {
  outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}
form button {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: .6rem 1.4rem; font: inherit; font-weight: 600; cursor: pointer; transition: background .15s;
}
form button:hover { background: var(--accent-ink); }
.ok { background: var(--ok-bg); border: 1px solid var(--ok-line); border-radius: var(--radius); padding: 1rem 1.2rem; }
.err { background: var(--err-bg); border: 1px solid var(--err-line); border-radius: var(--radius); padding: .7rem 1.2rem; }
.token {
  display: block; font: .95rem ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--tok-bg); border: 1px dashed var(--accent); border-radius: 10px;
  padding: .7rem .9rem; user-select: all; margin: .8rem 0 1rem;
}
.small { color: var(--muted); font-size: .85rem; }

/* ---------- tablas (admin) ---------- */
table { width: 100%; border-collapse: collapse; margin: .6rem 0 2rem; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table th, table td { border-bottom: 1px solid var(--line); padding: .55rem .7rem; font-size: .88rem; text-align: left; vertical-align: top; }
table th { color: var(--muted); font-weight: 600; background: var(--th-bg); }
table tr:hover td { background: var(--row-hover); }

/* autor: link del nombre en historia */
.author-link {
  color: inherit;
  text-decoration: underline dotted;
}
.agent-link:hover {
  color: var(--agent-hover);
  text-decoration: solid;
}

/* ---------- barra de progreso de recolección (topbar) ---------- */
.progress {
  display: flex;
  flex-direction: column;   /* dos barras apiladas */
  align-items: stretch;
  gap: .3rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .35rem 1.2rem;
  font-size: .8rem;
  color: var(--muted);
}
.progress__track {
  flex: 1;
  max-width: 520px;
  height: 8px;
  background: var(--track);
  border-radius: 99px;
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-ink));
  transition: width .6s ease;
}
.progress__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress__coffee {
  white-space: nowrap;
  color: #fff;
  background: #d9600c;
  border-radius: 99px;
  padding: .18rem .7rem;
  text-decoration: none;
  font-weight: 600;
}
.progress__coffee:hover { background: #b3551d; }

/* topbar: grupo de enlaces a la derecha */
.topbar__links { display: flex; gap: 1rem; align-items: center; }

/* ---------- toolbar de orden ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  margin: 0 0 1.2rem;
  font-size: .85rem;
}
.toolbar__label { color: var(--muted); margin-right: .3rem; }
.toolbar__link {
  padding: .3rem .8rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
}
.toolbar__link:hover { border-color: var(--accent); }
.toolbar__link.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- sección de aleatorios ---------- */
.aleatorias { margin: 0 0 2.2rem; }
.section__title { font-size: 1.05rem; margin: 0 0 .8rem; }
.section__refresh { font-size: .8rem; font-weight: 400; color: var(--muted); margin-left: .4rem; }
.section__refresh:hover { color: var(--accent); }
.grid--mini { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .7rem; }
.card--mini { padding: .7rem .9rem; }
.card--mini .card__title { font-size: .9rem; }
.card--mini .card__author { font-size: .78rem; }

/* barra de progreso por-historia en las cartas */
.card__bar {
  height: 5px;
  background: var(--track);
  border-radius: 99px;
  overflow: hidden;
  margin-top: .45rem;
}
.card__bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-ink));
  border-radius: 99px;
}
.card__bar span:empty { width: 0; }

.badge--crawling { background: var(--badge-crawl-bg); color: var(--badge-crawl-ink); border: 1px solid var(--badge-crawl-line); }
.badge--meta { background: var(--badge-meta-bg); color: var(--muted); border: 1px solid var(--line); }

/* dos barras: descubrimiento (títulos) + cosecha (contenido) */
.progress__row {
  display: grid;
  grid-template-columns: minmax(140px, 520px) minmax(0, 1fr) auto;
  gap: .8rem;
  align-items: center;
}
.progress__row .progress__label { min-width: 0; }
.progress__fill--cosecha {
  background: linear-gradient(90deg, var(--violet-a), var(--violet-b));
}
@media (max-width: 760px) {
  .progress__row { grid-template-columns: 1fr; gap: .25rem; }
}

/* facetas del buscador y chips de filtro activo */
.facets {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem;
  background: var(--facets-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: .9rem 1.1rem; margin: 1rem 0;
}
.facets h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 .45rem; }
.facets ul { list-style: none; margin: 0; padding: 0; }
.facets li { padding: .18rem 0; font-size: .9rem; }
.facets li small { color: var(--muted); }
.chips { display: flex; gap: .5rem; margin: .7rem 0; flex-wrap: wrap; }
.chip {
  background: var(--chip-bg); color: var(--chip-ink); border: 1px solid var(--chip-line);
  border-radius: 99px; padding: .18rem .7rem; font-size: .82rem;
}
.chip:hover { background: var(--chip-hover); }

/* últimas incorporaciones */
.feed { display: grid; gap: .55rem; max-width: 780px; margin: 0 auto; }
.feed__item {
  display: grid; gap: .15rem; padding: .7rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}

.feed__fic { font-weight: 600; }
.feed__meta { font-size: .82rem; color: var(--muted); }

/* ---------- página de prosa (acerca) ---------- */
.prose { max-width: 46rem; margin: 0 auto; }
.prose h2 { margin-top: 2.2rem; font-size: 1.15rem; }
.prose li { margin: .4rem 0; }

/* ===================== modo obscuro (accesibilidad) =====================
   Tres vías: automático (prefers-color-scheme), forzado oscuro (data-tema="oscuro")
   y forzado claro (data-tema="claro"). El toggle del topbar cicla auto→oscuro→claro. */
.tema-toggle {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; cursor: pointer; font-size: 1rem; line-height: 1;
  width: 2.3rem; height: 2.3rem; display: inline-grid; place-items: center;
  transition: border-color .15s, background .15s;
  flex: 0 0 auto;
}
.tema-toggle:hover { border-color: var(--accent); color: var(--accent-ink); }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d; --surface: #1d2029; --ink: #e8e6de; --muted: #a5a9b3;
    --line: #2c303b; --accent: #c47a6d; --accent-ink: #d68d7f; --gold: #e5a03d;
    --glass: rgba(23,25,32,.86); --hover-line: #3a3f4d; --track: #262a33;
    --mark-bg: #3a3421; --tok-bg: #17191f; --th-bg: #22252e; --row-hover: #22252e;
    --facets-bg: #1a1d25;
    --ok-bg: #182b1e;  --ok-line: #2f5c3d;
    --err-bg: #2e1917; --err-line: #6b3a34;
    --chip-bg: #33264f; --chip-ink: #cbb2ef; --chip-line: #4b3a70; --chip-hover: #3d2e5f;
    --badge-done-bg: #17301f;  --badge-done-ink: #6fdc93;
    --badge-wip-bg: #2e2410;   --badge-wip-ink: #e3b23c;
    --badge-story-bg: #241c3d; --badge-story-ink: #b49df3;
    --badge-chapt-bg: #10293a; --badge-chapt-ink: #6cc0ea;
    --badge-crawl-bg: #32230f; --badge-crawl-ink: #e6a35c; --badge-crawl-line: #4a3820;
    --badge-meta-bg: #23262e;
    --violet-a: #7e66c2; --violet-b: #5a45a0;
    --agent-hover: #d98b46;
    --ring: rgba(196, 122, 109, .38);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.5);
    --shadow-lg: 0 12px 32px -12px rgba(0,0,0,.6);
  }
}
/* forzado manual (gana sobre el media query por especificidad) */
html[data-tema="oscuro"] {
  --bg: #14161d; --surface: #1d2029; --ink: #e8e6de; --muted: #a5a9b3;
  --line: #2c303b; --accent: #c47a6d; --accent-ink: #d68d7f; --gold: #e5a03d;
  --glass: rgba(23,25,32,.86); --hover-line: #3a3f4d; --track: #262a33;
  --mark-bg: #3a3421; --tok-bg: #17191f; --th-bg: #22252e; --row-hover: #22252e;
  --facets-bg: #1a1d25;
  --ok-bg: #182b1e;  --ok-line: #2f5c3d;
  --err-bg: #2e1917; --err-line: #6b3a34;
  --chip-bg: #33264f; --chip-ink: #cbb2ef; --chip-line: #4b3a70; --chip-hover: #3d2e5f;
  --badge-done-bg: #17301f;  --badge-done-ink: #6fdc93;
  --badge-wip-bg: #2e2410;   --badge-wip-ink: #e3b23c;
  --badge-story-bg: #241c3d; --badge-story-ink: #b49df3;
  --badge-chapt-bg: #10293a; --badge-chapt-ink: #6cc0ea;
  --badge-crawl-bg: #32230f; --badge-crawl-ink: #e6a35c; --badge-crawl-line: #4a3820;
  --badge-meta-bg: #23262e;
  --violet-a: #7e66c2; --violet-b: #5a45a0;
  --agent-hover: #d98b46;
  --ring: rgba(196, 122, 109, .38);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 32px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}
html[data-tema="claro"] { color-scheme: light; }
