:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0a58ca;
  --brand-2: #0a78c2;
  --brand-soft: #e7f0fd;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #111a2e;
    --panel-2: #0f172a;
    --line: #22304a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --brand: #4d8ff5;
    --brand-2: #3aa0e0;
    --brand-soft: #16284a;
    --ok: #4ade80;
    --ok-soft: #12321f;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --bad: #f87171;
    --bad-soft: #3b1414;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
small.hint { color: var(--muted); font-size: 12px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: #062a5e; color: #dbe7fb; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 800; color: #fff; font-size: 16px; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #9fbbe8; }
.nav { flex: 1; overflow: auto; padding: 6px 10px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #dbe7fb; text-decoration: none; margin-bottom: 2px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .08); }
.nav a.active { background: #fff; color: #062a5e; }
.nav a .count { margin-left: auto; background: #ffb321; color: #3a2400; border-radius: 99px; font-size: 11px; font-weight: 800; padding: 1px 7px; }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #86a4d6; padding: 14px 10px 6px; }
.who { padding: 12px 18px; border-top: 1px solid rgba(255, 255, 255, .1); font-size: 13px; }
.who b { display: block; color: #fff; }
.who button { background: none; border: 0; color: #9fbbe8; padding: 0; cursor: pointer; font: inherit; text-decoration: underline; margin-top: 4px; }
.main { min-width: 0; padding: 22px 28px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin-right: auto; }
.page-head .sub { flex-basis: 100%; color: var(--muted); margin-top: -8px; }
.menu-toggle { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .main { padding: 60px 16px 40px; }
  .menu-toggle { display: block; position: fixed; top: 10px; left: 10px; z-index: 30; }
}

/* ---------- componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card > header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card > header h2 { margin-right: auto; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1100px) { .grid.two { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.warn { background: #ffb321; border-color: #ffb321; color: #3a2400; }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--brand-soft); color: var(--text); }

input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 36px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.form { display: grid; gap: 12px; }
.form .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; cursor: pointer; user-select: none; }
.days input { display: none; }
.days label:has(input:checked) { background: var(--brand); color: #fff; border-color: var(--brand); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.b-gray { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.b-green { background: var(--ok-soft); color: var(--ok); }
.b-amber { background: var(--warn-soft); color: var(--warn); }
.b-red { background: var(--bad-soft); color: var(--bad); }
.b-blue { background: var(--brand-soft); color: var(--brand); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.dot.off { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .2); }
.dot.idle { background: #94a3b8; }

.stat { padding: 14px 16px; }
.stat .v { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.bad .v { color: var(--bad); }
.stat.warn .v { color: var(--warn); }
.stat.ok .v { color: var(--ok); }

.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 14px; font-weight: 600; }
.banner.red { background: var(--bad); color: #fff; }
.banner.amber { background: var(--warn-soft); color: var(--warn); border: 1px solid currentColor; }
.banner .btn { margin-left: auto; }

.screen-card { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.screen-card .top { display: flex; align-items: center; gap: 8px; }
.screen-card .top b { font-size: 15px; }
.screen-card dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font-size: 13px; }
.screen-card dt { color: var(--muted); }
.screen-card dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen-card .shot { aspect-ratio: 16/9; background: #0b1220 center/contain no-repeat; border-radius: 6px; }

/* biblioteca */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.media-card { overflow: hidden; display: flex; flex-direction: column; cursor: pointer; }
.media-card:hover { border-color: var(--brand); }
.thumb { aspect-ratio: 16/9; background: #0b1220 center/cover no-repeat; position: relative; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 28px; }
.thumb .tag { position: absolute; left: 6px; top: 6px; font-size: 11px; }
.thumb .tag2 { position: absolute; right: 6px; top: 6px; font-size: 11px; }
.thumb.w-menu { background: linear-gradient(160deg, #063e8c, #18b5d8); }
.thumb.w-combo { background: radial-gradient(circle at 50% 30%, #ffb321, #e2531c 70%); }
.thumb.w-clock { background: linear-gradient(180deg, #062a5e, #0a58ca); }
.thumb.w-countdown { background: #0a3d91; }
.thumb.w-text { background: #ff5a1f; }
.thumb.w-html { background: #334155; }
.media-card .meta { padding: 8px 10px; font-size: 12px; }
.media-card .meta b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 20px; text-align: center; color: var(--muted); transition: .15s; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.folders { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 4px 11px; cursor: pointer; font: inherit; font-size: 13px; color: var(--text); }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }

/* playlist */
.pl-items { list-style: none; margin: 0; padding: 0; }
.pl-item { display: grid; grid-template-columns: 22px 64px 1fr 110px 90px 32px; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.pl-item.dragging { opacity: .4; }
.pl-item.over { box-shadow: inset 0 3px 0 var(--brand); }
.pl-item .grip { cursor: grab; color: var(--muted); text-align: center; user-select: none; }
.pl-item .mini { width: 64px; aspect-ratio: 16/9; border-radius: 4px; font-size: 16px; }
.pl-item input { padding: 4px 6px; }
.picker { max-height: 60vh; overflow: auto; }
@media (max-width: 700px) { .pl-item { grid-template-columns: 22px 1fr 80px 32px; } .pl-item .mini, .pl-item .fitsel { display: none; } }

/* layout */
.layout-canvas { position: relative; width: 100%; aspect-ratio: 16/9; background: #0b1220; border-radius: 8px; overflow: hidden; }
.layout-canvas.portrait { aspect-ratio: 9/16; max-width: 340px; margin: 0 auto; }
.layout-canvas .z { position: absolute; border: 2px solid rgba(255, 255, 255, .7); background: rgba(10, 88, 202, .45); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; font-size: 12px; font-weight: 700; padding: 4px; overflow: hidden; }
.layout-canvas .z.sel { background: rgba(255, 179, 33, .6); border-color: #fff; }
.layout-canvas .z small { font-weight: 500; opacity: .9; }
.tpl { cursor: pointer; padding: 8px; }
.tpl:hover, .tpl.sel { border-color: var(--brand); }
.tpl .layout-canvas .z { font-size: 9px; }

/* preview */
.preview-frame { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 8px; overflow: hidden; }
.preview-frame.portrait { aspect-ratio: 9/16; max-width: 380px; margin: 0 auto; }

/* agenda */
.week { display: grid; grid-template-columns: 44px repeat(7, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 11px; }
.week .hcol { border-right: 1px solid var(--line); }
.week .hd { height: 26px; display: flex; align-items: center; justify-content: center; font-weight: 700; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.week .col { position: relative; border-right: 1px solid var(--line); height: 480px; background: repeating-linear-gradient(var(--panel), var(--panel) 39px, var(--line) 39px, var(--line) 40px); }
.week .col:last-child { border-right: 0; }
.week .hr { height: 40px; color: var(--muted); text-align: right; padding-right: 4px; }
.week .ev { position: absolute; left: 2px; right: 2px; border-radius: 4px; padding: 2px 4px; color: #fff; overflow: hidden; font-weight: 600; line-height: 1.2; border: 1px solid rgba(255, 255, 255, .5); }
.week .ev.em { background: #dc2626 !important; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(2, 8, 23, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; overflow: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal.wide { max-width: 980px; }
.modal > header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal > header h2 { margin-right: auto; }
.modal-body { padding: 18px; }
.modal > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 11px 14px; border-radius: 8px; color: #fff; background: #0f5132; box-shadow: var(--shadow); font-weight: 600; transition: opacity .3s, transform .3s; }
.toast-error { background: #b91c1c; }
.toast-info { background: #1e3a8a; }
.toast.out { opacity: 0; transform: translateY(8px); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 9px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.warnings { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.warnings li { margin-left: 16px; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #04306e, #0a78c2 60%, #18b5d8); padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login h1 img { width: 36px; }
