:root {
  --bg: #f4f6f9; --surface: #fff; --surface-2: #f0f2f5; --border: #dde2e8;
  --text: #1c2430; --muted: #66727f; --primary: #1565c0; --primary-ink: #fff;
  --ok: #2e7d32; --bad: #c62828; --warn: #b26a00; --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318; --surface: #171c23; --surface-2: #1e252e; --border: #2b343f;
    --text: #e6eaef; --muted: #96a1ad; --primary: #64a5f0; --primary-ink: #0b1a2c;
    --ok: #66bb6a; --bad: #ef5350; --warn: #ffb74d; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow-x: hidden; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--warn); }
.hidden { display: none !important; }

/* layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.brand svg { width: 26px; height: 26px; color: var(--primary); }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font-weight: 600; }
.main { padding: 20px 24px 60px; min-width: 0; overflow-x: hidden; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .btn.menu-btn { display: inline-flex; }
  #userBtn .role { display: none; }
  #pageActions { order: 5; width: 100%; flex-wrap: wrap; }
  .main { padding: 14px 16px 60px; }
}

/* componentes */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.icon { padding: 6px 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.media { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--bad); flex: none; }
.dot.ok { background: var(--ok); }
.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; background: var(--surface); color: var(--text); padding: 7px 14px; cursor: pointer; font: inherit; }
.tabs button + button { border-left: 1px solid var(--border); }
.tabs button.on { background: var(--primary); color: var(--primary-ink); }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.actions { display: flex; gap: 4px; justify-content: flex-end; }

.screen-card .head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.screen-card .head strong { flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 2px 8px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.media-card { overflow: hidden; display: flex; flex-direction: column; }
.media-card .thumb { aspect-ratio: 16/10; background: #000; display: grid; place-items: center; overflow: hidden; }
.media-card .thumb img, .media-card .thumb video { width: 100%; height: 100%; object-fit: contain; }
.media-card .body { padding: 10px 12px; display: flex; gap: 6px; align-items: flex-start; }
.media-card .body > div { flex: 1; min-width: 0; }
.media-card .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pl-items { list-style: none; margin: 0; padding: 0; }
.pl-items li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.pl-items li:last-child { border-bottom: 0; }
.pl-items li.dragging { opacity: .4; }
.pl-items li.over { box-shadow: inset 0 2px 0 var(--primary); }
.pl-items .handle { cursor: grab; color: var(--muted); user-select: none; font-size: 18px; }
.pl-items .pos { width: 22px; color: var(--muted); text-align: right; }
.pl-items .thumb { width: 64px; height: 40px; background: #000; border-radius: 4px; overflow: hidden; flex: none; }
.pl-items .thumb img, .pl-items .thumb video { width: 100%; height: 100%; object-fit: cover; }
.pl-items .info { flex: 1; min-width: 0; }
.pl-items .info .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-items input[type=number] { width: 80px; flex: none; }
@media (max-width: 800px) { .pl-items .thumb, .pl-items .pos { display: none; } .pl-items li { flex-wrap: wrap; } }

/* formularios */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], input[type=date], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 99px; cursor: pointer; user-select: none; }
.chip input { margin: 0; }
.chip:has(input:checked) { background: color-mix(in srgb, var(--primary) 15%, transparent); border-color: var(--primary); }
.code-input { font-size: 30px !important; letter-spacing: 10px; text-align: center; font-variant-numeric: tabular-nums; }

/* modal */
dialog#modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog#modal::backdrop { background: rgba(10,14,20,.5); }
.modal-h { padding: 16px 20px 0; display: flex; align-items: center; }
.modal-h h2 { margin: 0; flex: 1; }
.modal-b { padding: 16px 20px; max-height: 70vh; overflow: auto; }
.modal-f { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--border); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }

/* toast */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #222b36; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; white-space: pre-line; }
.toast.err { background: var(--bad); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .brand { justify-content: center; font-size: 20px; padding-bottom: 20px; }
.login .btn.primary { width: 100%; justify-content: center; padding: 10px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* multi-cliente */
.acc-name { margin: -8px 10px 14px; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-sep { margin: 16px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.banner .btn { margin-left: auto; }
.banner.info { background: color-mix(in srgb, var(--primary) 10%, transparent); border-color: color-mix(in srgb, var(--primary) 40%, transparent); }
.banner.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.banner.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.badge.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
details summary { cursor: pointer; color: var(--bad); margin-top: 8px; }
