:root {
  --bg: #f4f6fa; --panel: #fff; --ink: #1b2233; --muted: #6b7488; --line: #e1e5ee;
  --brand: #3b6cff; --brand-ink: #fff; --danger: #d6384a; --ok: #1fa971;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1420; --panel: #181f2f; --ink: #e8ecf5; --muted: #8f9ab3; --line: #263049; --brand: #5b86ff; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand); }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }

.btn {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

input, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); width: 100%;
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 4px; }

/* Login */
body.auth { display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; }
.auth-card h1 { margin: 0 0 4px; }
.alert { background: #fde8ea; color: #8a1f2c; padding: 8px 12px; border-radius: 8px; margin: 12px 0; font-size: 14px; }

/* Layout */
.topbar { height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .02em; }
.layout { display: grid; grid-template-columns: 260px 1fr; height: calc(100% - 54px); }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 14px; overflow: auto; }
.side h3 { margin: 6px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.nav { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; border: 0; background: none; color: var(--ink); font: inherit; cursor: pointer; }
.nav:hover { background: var(--bg); }
.nav.active { background: var(--brand); color: var(--brand-ink); }
.nav .count { float: right; opacity: .7; font-size: 12px; }
.main { padding: 22px; overflow: auto; }
.main h2 { margin: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card h4 { margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.card .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #aab; display: inline-block; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(31,169,113,.2); }
.empty { padding: 36px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }

/* Medios */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); margin-bottom: 14px; cursor: pointer; }
.drop.over { border-color: var(--brand); color: var(--brand); background: rgba(59,108,255,.06); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.media { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.thumb { aspect-ratio: 16/10; background: #000; position: relative; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.media .meta { padding: 8px 10px; font-size: 12px; }
.media .meta .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.media .meta .sub { color: var(--muted); }
.media .acts { padding: 0 10px 10px; display: flex; gap: 6px; margin-top: auto; }

.uploads { margin-bottom: 14px; }
.up { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; font-size: 13px; }
.up .bar { height: 6px; background: var(--line); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.up .bar i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }
.up.err { border-color: var(--danger); }
.up.err .msg { color: var(--danger); }

/* Diálogos */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--ink); width: min(520px, 94vw); }
dialog::backdrop { background: rgba(8,12,22,.55); }
dialog.wide { width: min(1100px, 96vw); }
.dlg-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.dlg-h h3 { margin: 0; }
.dlg-b { padding: 18px; }
.dlg-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* Editor de playlist */
.pl { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; height: min(62vh, 560px); }
.pl > div { display: flex; flex-direction: column; min-height: 0; }
.pl h4 { margin: 0 0 8px; }
.pl .scroll { overflow: auto; flex: 1; padding-right: 4px; }
.pli { display: grid; grid-template-columns: 22px 64px 1fr auto; gap: 8px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--panel); }
.pli.dragging { opacity: .4; }
.pli .grab { cursor: grab; color: var(--muted); text-align: center; user-select: none; }
.pli .t { width: 64px; height: 40px; background: #000; border-radius: 4px; overflow: hidden; }
.pli .t img, .pli .t video { width: 100%; height: 100%; object-fit: cover; }
.pli .nm { font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pli .ctl { display: flex; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }
.pli .ctl input { width: 58px; padding: 3px 6px; }
.pl-lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.pl-lib .media { cursor: pointer; }
.pl-lib .media:hover { border-color: var(--brand); }
.pl-lib .thumb { aspect-ratio: 16/10; }
.pl-lib .meta { padding: 4px 6px; }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .pl { grid-template-columns: 1fr; height: auto; }
  .pl .scroll { max-height: 40vh; }
}

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1b2233; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--danger); }
