:root {
  --bg: #f5f6f8; --surface: #ffffff; --text: #14171c; --muted: #5d6673; --border: #e1e5eb;
  --accent: #4f46e5; --accent-text: #ffffff; --ok: #15803d; --warn: #b45309; --danger: #dc2626;
  --log-bg: #0f1218; --log-text: #c9d3e0; --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --surface: #161a21; --text: #e8ecf2; --muted: #98a2b3; --border: #262c36;
    --accent: #7c83ff; --accent-text: #0e1116; --ok: #4ade80; --warn: #fbbf24; --danger: #f87171;
    --log-bg: #0a0c10; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 14px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 13px; word-break: break-all; }

/* Cabecera */
.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.logo { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-size: 15px; flex: none; }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { color: var(--ok); } .badge.warn { color: var(--warn); }

main { padding-block: 24px 56px; display: grid; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card[hidden] { display: none; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.sec-head h2 { margin: 0; }
.count { color: var(--muted); font-weight: 400; }

/* Formulario */
.field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }
input[type=url], input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; min-width: 0;
}
input[type=search] { width: auto; min-width: 200px; padding: 7px 12px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, summary:focus-visible, .cover:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.url-row { display: flex; gap: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; } input[type=search] { width: 100%; min-width: 0; } }
details { margin-bottom: 14px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.checks { align-content: end; gap: 8px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn[hidden] { display: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.hint { color: var(--muted); font-size: 13px; }

/* Trabajos */
.jobs { display: grid; gap: 12px; }
.job { border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: grid; gap: 6px; min-width: 0; }
.job-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-width: 0; }
.job-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.job-error { color: var(--danger); font-size: 13px; overflow-wrap: anywhere; }
.job-error[hidden], .phase[hidden] { display: none; }
.job-log summary { margin: 0; }
.status { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.status.running { color: var(--accent); } .status.done { color: var(--ok); }
.status.error { color: var(--danger); } .status.cancelled { color: var(--warn); }
.phase { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.bar { height: 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
.fill.indeterminate { width: 35% !important; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .fill.indeterminate { animation: none; width: 100% !important; opacity: .5; } }
.meta { display: flex; gap: 16px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.meta span:empty { display: none; }
.log {
  background: var(--log-bg); color: var(--log-text); border-radius: 10px; padding: 12px;
  max-height: 220px; overflow: auto; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-all; margin: 8px 0 0;
}

/* Biblioteca */
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.item { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.cover { position: relative; aspect-ratio: 16 / 9; background: #000; border: 0; padding: 0; cursor: pointer; display: grid; place-items: center; }
.cover:disabled { cursor: default; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { color: #fff; font-size: 34px; opacity: .7; }
.cover:not(:disabled):hover .ph, .cover:not(:disabled):hover img { opacity: .85; }
.dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.75); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.item-body { padding: 12px; display: grid; gap: 4px; min-width: 0; }
.item-title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.item-meta { color: var(--muted); font-size: 13px; }
.item-warn { color: var(--warn); font-size: 13px; }
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.empty { color: var(--muted); margin: 0; }
.empty[hidden] { display: none; }
.folder { color: var(--muted); font-size: 12px; margin: 14px 0 0; }

/* Reproductor */
dialog { width: min(1000px, 94vw); padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.7); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; }
.dlg-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
video { width: 100%; max-height: 75vh; background: #000; border-radius: 10px; display: block; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: min(600px, 92vw); box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 10; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.toast[hidden] { display: none; }
