:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1c1d24;
  --muted: #6b6f80;
  --line: #e3e5ee;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 4px 16px rgba(20, 20, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1016;
    --card: #191a23;
    --text: #ececf3;
    --muted: #9699ab;
    --line: #2a2c39;
    --primary: #7c74ff;
    --success: #4ade80;
    --success-bg: #11321f;
    --warn: #fbbf24;
    --warn-bg: #3a2b0a;
    --danger: #f87171;
    --danger-bg: #3b1515;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.noscroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0 0 .4rem; }
h2 { font-size: 1.05rem; margin: 1rem 0 .5rem; }
h1:first-child, h2:first-child { margin-top: 0; }
code { background: var(--line); padding: .1em .35em; border-radius: 5px; }

/* ---------- Layout ---------- */
:root { --nav-offset: calc(96px + env(safe-area-inset-top)); }
/* Al bajar en la página se esconde el menú de arriba (topbar + mainnav) para
   dejar más pantalla útil; los .sticky-top (ej. cabecera de Publicar) se
   sincronizan con --nav-offset para subir hasta pegarse al borde. */
html.nav-hidden { --nav-offset: 0px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
  max-height: 80px; overflow: hidden;
  transition: max-height .25s ease, padding .25s ease, opacity .2s ease;
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.who { margin-left: auto; color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-link { font-size: 1.2rem; color: var(--muted); padding: .2rem .35rem; }
.mainnav {
  display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none;
  padding: .4rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: calc(49px + env(safe-area-inset-top)); z-index: 19;
  max-height: 60px;
  transition: max-height .25s ease, padding .25s ease, opacity .2s ease;
}
.mainnav::-webkit-scrollbar { display: none; }
html.nav-hidden .topbar, html.nav-hidden .mainnav {
  max-height: 0; padding-top: 0; padding-bottom: 0; opacity: 0; border-bottom-color: transparent;
}
.mainnav a {
  white-space: nowrap; padding: .4rem .75rem; border-radius: 999px;
  color: var(--muted); font-size: .92rem;
}
.mainnav a.on { background: var(--primary); color: var(--primary-ink); }
.badge { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 .4rem; font-size: .75rem; }

.wrap { max-width: 980px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.empty { text-align: center; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 160px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strong { font-weight: 600; }
.warn { color: var(--warn); }
.err-text { color: var(--danger); font-weight: 600; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; width: 100%;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.num { width: 5.5rem; flex: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-size: .92rem; font-weight: 500;
  padding: .55rem .9rem; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  min-height: 40px; text-align: center; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.success { background: var(--success-bg); border-color: transparent; color: var(--success); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: .35rem .65rem; font-size: .85rem; min-height: 34px; }
.btn.big { padding: .85rem 1rem; font-size: 1.02rem; font-weight: 600; min-height: 52px; }
.btn.block { width: 100%; }
.btn.copy.copied { background: var(--success-bg); color: var(--success); border-color: transparent; }
.thumb-fix.busy { opacity: .55; pointer-events: none; }

/* ---------- Status ---------- */
.pill { display: inline-block; padding: .12rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.pub { background: var(--success-bg); color: var(--success); }
.pill.pend { background: var(--danger-bg); color: var(--danger); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.partial { background: var(--warn-bg); color: var(--warn); }
.role-buttons { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.role-buttons .btn { justify-content: space-between; flex: 1 1 130px; min-height: 40px; padding: .4rem .65rem; font-size: .85rem; }
.prompt-text { white-space: pre-wrap; flex: 1 1 240px; }
.since { color: var(--muted); font-size: .82rem; }
.tag { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }

.progress-pill { font-size: .9rem; color: var(--muted); }
.progress-pill b { color: var(--text); font-size: 1.15rem; }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: .5rem 0; }
.bar.big { height: 12px; }
.bar span { display: block; height: 100%; background: var(--primary); transition: width .2s; }

/* ---------- Cuentas ---------- */
.acc-card { padding: .25rem 1rem; }
.acc-row { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; justify-content: space-between; padding: .75rem 0; border-top: 1px solid var(--line); }
.acc-row:first-child { border-top: 0; }
.acc-row.is-page { padding-left: .9rem; }
.acc-main { flex: 1 1 240px; min-width: 0; }
.acc-name { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.acc-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.plain-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.plain-list li { padding: .4rem 0; border-top: 1px solid var(--line); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-green { background: var(--success); }
.dot-red { background: var(--danger); }
a.link-row, a.link-row * { color: inherit; }
a.link-row:hover { background: var(--card); }
.quota-line { display: flex; gap: .5rem; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.quota-item.ok { color: var(--success); font-weight: 600; }
.profile-head { display: flex; align-items: center; gap: .4rem; padding: .6rem 1rem .2rem; font-size: .82rem; color: var(--muted); font-weight: 600; }
.acc-card > summary { cursor: pointer; font-weight: 600; padding: .75rem 0; list-style: none; }
.acc-card > summary::-webkit-details-marker { display: none; }
.acc-card > summary::after { content: '▾'; float: right; color: var(--muted); }
.acc-card[open] > summary::after { content: '▴'; }
.acc-card[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: .25rem; }

.publish-head { padding: .55rem 1rem; }
.publish-head-row { flex-wrap: wrap; row-gap: .35rem; }
.publish-head .copy-grid { display: flex; gap: .4rem; flex-wrap: wrap; }
.publish-head .copy-grid .btn { min-height: 34px; padding: .35rem .65rem; font-size: .85rem; }
.caption-preview { background: var(--bg); border-radius: 10px; padding: .6rem .8rem; font-size: .9rem; white-space: pre-wrap; }
.sep { border: 0; border-top: 1px solid var(--line); margin: .9rem 0; }
.sticky-top { position: sticky; top: var(--nav-offset); z-index: 15; transition: top .25s ease; }

/* ---------- Stock ---------- */
.stock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.stock { display: flex; flex-direction: column; gap: .1rem; padding: .7rem; border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.stock b { font-size: 1.5rem; }
.stock.low { border-color: var(--warn); background: var(--warn-bg); }
.stock.low .small:last-child { color: var(--warn); font-weight: 600; }

/* ---------- Media ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin-top: .75rem; }
.media { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.media-thumb { position: relative; aspect-ratio: 9 / 16; max-height: 260px; width: 100%; border: 0; padding: 0; background: #000; cursor: pointer; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .noimg { font-size: 2.2rem; display: grid; place-items: center; height: 100%; }
.media-thumb .play { position: absolute; inset: auto auto .4rem .4rem; background: rgba(0,0,0,.6); color: #fff; border-radius: 999px; width: 28px; height: 28px; display: grid; place-items: center; font-size: .75rem; }
.media-info { padding: .45rem .55rem 0; min-width: 0; }
.media-actions { display: flex; gap: .35rem; padding: .5rem .55rem .6rem; margin-top: auto; }
.media-actions .btn { flex: 1 1 0; padding-left: .3rem; padding-right: .3rem; }
.media-actions .btn.primary { flex: 3 1 0; font-size: 1.05rem; }
.media-actions .btn.restore { flex: 2 1 0; }

.tabs { display: flex; gap: .3rem; margin: .8rem 0 .4rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.pager { display: flex; gap: .75rem; justify-content: center; align-items: center; margin-top: 1rem; }

/* ---------- Subida ---------- */
.dropzone {
  margin-top: .8rem; border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 2rem 1rem; align-items: center; text-align: center; cursor: pointer; color: var(--text);
}
.dropzone.over { border-color: var(--primary); background: var(--bg); }
.dz-icon { font-size: 2rem; color: var(--primary); }
.queue { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; }
.q-item { border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
.q-item.done { border-color: var(--success); }
.q-item.done .bar span { background: var(--success); }
.q-item.failed { border-color: var(--danger); }
.q-item.failed .q-status { color: var(--danger); }

/* ---------- Categorías ---------- */
.cat-list { list-style: none; padding: 0; margin: .6rem 0; }
.cat-list li { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; padding: .45rem 0; border-top: 1px solid var(--line); }
.cat-list li > form.row { flex: 1 1 300px; }
.add-row { margin: .5rem 0; }
.add-row select { width: auto; }

/* ---------- Tabla ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: .75rem; }
.table th, .table td { text-align: left; padding: .5rem .4rem; border-top: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: .8rem; }

/* ---------- Mensajes ---------- */
.flash { padding: .7rem .9rem; border-radius: 10px; margin-bottom: .8rem; font-size: .92rem; }
.flash.ok { background: var(--success-bg); color: var(--success); }
.flash.err { background: var(--danger-bg); color: var(--danger); }
.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1c1d24; color: #fff; padding: .6rem 1rem; border-radius: 999px; z-index: 100; font-size: .92rem;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100% - 2rem);
}
.toast.err { background: var(--danger); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(8, 8, 15, .65); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-card {
  position: relative; background: var(--card); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 1.2rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 18px; }
}
.modal-x { position: absolute; top: .5rem; right: .5rem; border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: .4rem; }
.modal-card h2 { padding-right: 2rem; }
.preview { display: block; width: 100%; max-height: 70vh; object-fit: contain; background: #000; border-radius: 10px; margin: .5rem 0 .8rem; }
.preview.small { max-height: 38vh; }
.preview.tiny { max-height: 200px; margin: 0; }

/* ---------- Resultado de descarga (video + foto de portada) ---------- */
.dl-media { display: flex; gap: .6rem; margin: .5rem 0 .8rem; }
.dl-media > .preview { flex: 1 1 0; min-width: 0; }
.dl-group { border: 1px solid var(--line); border-radius: 12px; padding: .7rem; background: var(--bg); margin-bottom: .6rem; }
.dl-group:last-child { margin-bottom: 0; }
.dl-group-title { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .5rem; }
.dl-actions { display: flex; gap: .4rem; margin-top: .5rem; }
.dl-actions .btn { flex: 1 1 0; }

/* ---------- Login / instalación ---------- */
.auth-box { max-width: 400px; margin: 8vh auto 2rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.auth-box.wide { max-width: 560px; margin-top: 2rem; }
.auth-box h1 { text-align: center; margin-bottom: 1rem; }
.or-sep { display: flex; align-items: center; gap: .6rem; margin: .9rem 0; color: var(--muted); font-size: .82rem; }
.or-sep::before, .or-sep::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.google-btn { background: var(--card); }
body.auth { padding: 0 1rem; }
.checks { list-style: none; padding: 0; }
.checks .ok { color: var(--success); }
.checks .bad { color: var(--danger); font-weight: 600; }

@media (min-width: 720px) {
  .publish-head .copy-grid { grid-template-columns: repeat(2, 1fr); }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}
