:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6b7489;
  --line: #e3e7ef;
  --primary: #1f6feb;
  --primary-ink: #ffffff;
  --success: #15803d;
  --danger: #c2410c;
  --amber: #b45309;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141d;
    --card: #171e2a;
    --text: #e6eaf2;
    --muted: #96a0b5;
    --line: #2a3344;
    --primary: #4b8df8;
    --success: #22a052;
    --danger: #ea6a3a;
    --amber: #e0a030;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code { background: color-mix(in srgb, var(--line) 60%, transparent); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
code.block { display: block; padding: .6rem; overflow-x: auto; white-space: pre; margin: .3rem 0 .6rem; }
code.copy { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.warn-text { color: var(--amber); }
[hidden] { display: none !important; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 1rem; padding: 0 16px;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; padding: .8rem 0; }
.menu { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.menu::-webkit-scrollbar { display: none; }
.menu a {
  text-decoration: none; color: var(--muted); padding: .8rem .65rem; white-space: nowrap; border-bottom: 2px solid transparent;
  display: flex; gap: .3rem; align-items: center; font-size: .92rem;
}
.menu a.on { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.menu a:hover { color: var(--text); }
.menu .logout { margin-left: auto; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 1.2rem 16px 3rem; }

/* Tarjetas y rejillas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
details.card > summary { cursor: pointer; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.between { justify-content: space-between; }
.row form { display: inline-flex; gap: .4rem; }

/* Formularios */
.form { display: grid; gap: .8rem; }
.form label { display: grid; gap: .3rem; font-weight: 500; font-size: .92rem; }
.form small { font-weight: 400; color: var(--muted); }
.form fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: .6rem 1rem; }
label.check { display: flex !important; align-items: center; gap: .5rem; font-weight: 400; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: .55rem .7rem; width: 100%; max-width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); transform: scale(1.15); }
input[type=color] { padding: 2px; height: 40px; width: 70px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
input.saved { border-color: var(--success); }
input.error { border-color: var(--danger); }
.mini-num { width: 5.5em; padding: .3rem .4rem; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 9px; padding: .55rem .95rem;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.btn.ghost { background: transparent; }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; }
.btn.big { padding: .8rem 1.2rem; font-size: 1rem; }

/* Avisos */
.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: color-mix(in srgb, var(--success) 12%, var(--card)); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.flash.err { background: color-mix(in srgb, var(--danger) 12%, var(--card)); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.flash.warn { background: color-mix(in srgb, var(--amber) 12%, var(--card)); border-color: color-mix(in srgb, var(--amber) 40%, transparent); }

/* Etiquetas */
.badge {
  --c: #2563eb; display: inline-block; font-size: .78rem; font-weight: 600; padding: .1rem .55rem; border-radius: 99px;
  background: color-mix(in srgb, var(--c) 15%, transparent); color: color-mix(in srgb, var(--c) 80%, var(--text));
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); white-space: nowrap;
}
.pill { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 99px; background: var(--line); color: var(--text); text-decoration: none; white-space: nowrap; }
.pill.green { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.pill.amber { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.pill.red { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

/* Tablas */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .5rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
tr.off, .item.off, .card.off { opacity: .5; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; flex: 1 1 160px; }
.bulkbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding-bottom: .8rem; }
.bulkbar select, .bulkbar input { width: auto; }

/* Listas */
.list { display: grid; gap: .6rem; }
.item { display: flex; justify-content: space-between; gap: .8rem; flex-wrap: wrap; padding: .7rem; border: 1px solid var(--line); border-radius: 10px; }

/* Anuncios */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.card.ad { padding: 0; overflow: hidden; margin: 0; }
.card.ad img { width: 100%; aspect-ratio: 1.4; object-fit: cover; display: block; background: var(--line); }
.card.ad .pad { padding: .9rem; display: grid; gap: .35rem; }
.card.ad h3 { margin: .2rem 0 0; }
.preview { max-width: 100%; max-height: 260px; border-radius: 10px; margin-top: .5rem; }
.variant { display: grid; gap: .4rem; padding: .7rem; border: 1px dashed var(--line); border-radius: 10px; margin-bottom: .6rem; }
.ad-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.thumb { width: 90px; height: 90px; object-fit: cover; border-radius: 10px; }

/* Barras */
.bar { height: 8px; background: var(--line); border-radius: 9px; overflow: hidden; min-width: 120px; }
.bar span { display: block; height: 100%; background: var(--primary); }
.hbar { position: relative; background: var(--line); border-radius: 6px; height: 22px; min-width: 120px; }
.hbar span { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--primary) 45%, transparent); border-radius: 6px; }
.hbar b { position: relative; padding-left: .45rem; font-size: .82rem; line-height: 22px; }

/* Indicadores */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; display: grid; }
.kpi small { color: var(--muted); font-size: .78rem; }
.kpi b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.kpi.bad b { color: var(--danger); }
.kpis.mini .kpi b { font-size: 1.15rem; }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.spark span { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .8; }
.hours { display: flex; align-items: flex-end; gap: 3px; height: 110px; }
.hours div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.hours span { width: 100%; background: var(--primary); opacity: .75; border-radius: 3px 3px 0 0; }
.hours small { font-size: .65rem; color: var(--muted); }
.heat { border-collapse: separate; border-spacing: 3px; font-size: .75rem; }
.heat th { color: var(--muted); font-weight: 500; padding: 0 .3rem; }
.heat td {
  --a: 0; width: 38px; height: 30px; text-align: center; border-radius: 5px; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--primary) calc(var(--a) * 100%), var(--line));
}

/* Panel de publicación */
.statusbar { display: flex; flex-wrap: wrap; gap: 1rem 1.6rem; align-items: center; }
.stat { display: grid; }
.stat small { color: var(--muted); font-size: .75rem; }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat.grow { flex: 1; min-width: 220px; }
.grid-runner { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.item-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.item-head h2 { margin: .4rem 0 .1rem; font-size: 1.3rem; }
.wait { text-align: center; background: color-mix(in srgb, var(--amber) 14%, var(--card)); border-radius: 10px; padding: .5rem .9rem; display: grid; }
.wait b { font-size: 1.6rem; font-variant-numeric: tabular-nums; color: var(--amber); }
.wait small { font-size: .72rem; color: var(--muted); max-width: 160px; }
.post-preview { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1rem; margin: 1rem 0; }
.post-preview img { width: 100%; border-radius: 10px; object-fit: cover; }
.post-preview pre {
  margin: 0; white-space: pre-wrap; word-break: break-word; font: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .8rem; max-height: 320px; overflow: auto;
}
.steps { display: flex; flex-wrap: wrap; gap: .5rem; margin: .7rem 0; }
.queue { padding-left: 1.3rem; margin: 0; display: grid; gap: .35rem; font-size: .88rem; max-height: 420px; overflow: auto; }
ul.queue { list-style: none; padding-left: 0; }
.empty { text-align: center; padding: 2rem 0; }

dialog.card { max-width: 520px; width: calc(100% - 32px); color: var(--text); }
dialog::backdrop { background: rgba(10, 15, 25, .55); }

/* Páginas sin menú */
body.bare { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card.narrow { width: 100%; max-width: 440px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; margin: 1rem 0; }
.codes code { text-align: center; padding: .5rem; font-size: 1.05rem; letter-spacing: .05em; }
.qr { display: flex; justify-content: center; padding: .8rem; background: #fff; border-radius: 10px; margin: .5rem 0; }
.secret { word-break: break-all; }
.pager { justify-content: center; margin-top: 1rem; }

@media (max-width: 860px) {
  .grid-runner { grid-template-columns: 1fr; }
  .post-preview { grid-template-columns: 1fr; }
  .post-preview img { max-height: 260px; }
  .brand { display: none; }
  .menu a { padding: .75rem .5rem; font-size: .85rem; }
  .steps .btn { flex: 1 1 100%; }
  h1 { font-size: 1.3rem; }
  .grid2 { grid-template-columns: 1fr; }
}
