:root {
  --bg: #0b0b0c;
  --surface: #151517;
  --surface-2: #1d1d20;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f6f3ec;
  --dim: #a9a59c;
  --faint: #6f6c66;
  --brand: #ffc824;
  --brand-ink: #1a1400;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #93c5fd;
  --radius: 16px;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background-image: radial-gradient(900px 500px at 10% -10%, rgba(255, 200, 36, 0.08), transparent 60%);
  background-attachment: fixed;
}
[hidden] { display: none !important; }
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }
h2, h3 { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: 0.01em; margin: 0; }
h2 { font-size: 28px; line-height: 1; }
h3 { font-size: 26px; margin-bottom: 16px; }

/* ---------- botões */
.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: #ffd34f; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; color: var(--dim);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.danger:hover { color: var(--bad); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; padding: 32px 24px;
  display: grid; gap: 16px;
}
.login-logo { width: 220px; margin: 0 auto; }
.login-sub { text-align: center; color: var(--dim); margin: -8px 0 4px; letter-spacing: 0.2em; text-transform: uppercase; font-size: 13px; font-weight: 600; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(11, 11, 12, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { height: 34px; width: auto; }
.brand-pill {
  font-family: var(--display); font-weight: 800; font-size: 15px;
  background: var(--brand); color: var(--brand-ink);
  padding: 2px 8px; border-radius: 6px; letter-spacing: 0.06em;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 16px 16px 64px; display: grid; gap: 16px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: grid; gap: 2px;
}
.stat-label { color: var(--dim); font-size: 13px; }
.stat strong { font-family: var(--display); font-size: 30px; font-weight: 800; line-height: 1.05; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 20px 16px;
}
.card-head { margin-bottom: 16px; }
.card-head p { margin: 6px 0 0; color: var(--dim); font-size: 15px; }
.empty { color: var(--dim); text-align: center; padding: 16px 8px; margin: 0; }

/* ---------- formulário */
.upload { display: grid; gap: 16px; }
.drop {
  position: relative;
  display: grid; justify-items: center; gap: 4px; text-align: center;
  padding: 26px 16px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop:hover, .drop.has-file { border-color: var(--brand); background: rgba(255, 200, 36, 0.05); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-icon { color: var(--brand); }
.drop-text { font-weight: 600; word-break: break-word; }
.drop-hint { color: var(--dim); font-size: 14px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: span 2; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 14px; color: var(--dim); font-weight: 500; }
.field em { font-style: normal; color: var(--faint); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input:not([type]) {
  width: 100%; min-width: 0;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 12px 14px; outline: none;
  -webkit-appearance: none; appearance: none;
  min-height: 48px;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255, 200, 36, 0.18); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: block; text-align: center; padding: 9px 6px; border-radius: 9px; font-weight: 600; color: var(--dim); }
.segmented input:checked + span { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); }

.form-error { color: var(--bad); margin: 0; font-size: 15px; }

.progress { display: grid; gap: 6px; }
.progress-bar { height: 10px; background: var(--bg); border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.progress-bar > div { height: 100%; width: 0; background: var(--brand); transition: width 0.2s ease; }
.progress span { color: var(--dim); font-size: 14px; }

/* ---------- itens */
.items, .devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 132px 1fr; gap: 12px;
  padding: 10px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
}
.item.off { opacity: 0.6; }
.thumb {
  position: relative; width: 132px; aspect-ratio: 16 / 9;
  border-radius: 10px; overflow: hidden; background: #000;
  border: 0; padding: 0; cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .dur {
  position: absolute; right: 5px; bottom: 5px;
  background: rgba(0, 0, 0, 0.75); color: #fff;
  font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 6px;
}
.thumb .pos {
  position: absolute; left: 5px; top: 5px;
  background: rgba(0, 0, 0, 0.75); color: #fff;
  font-size: 12px; font-weight: 700; min-width: 22px; text-align: center; padding: 1px 6px; border-radius: 6px;
}
.thumb.processing { display: grid; place-items: center; color: var(--dim); font-size: 13px; cursor: default; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.item-body { min-width: 0; display: grid; gap: 6px; align-content: start; }
.item-title { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.06); color: var(--dim);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.live { color: var(--ok); border-color: rgba(74, 222, 128, 0.35); background: rgba(74, 222, 128, 0.08); }
.chip.sched { color: var(--info); border-color: rgba(147, 197, 253, 0.35); background: rgba(147, 197, 253, 0.08); }
.chip.expired, .chip.error { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.08); }
.chip.proc { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }
.chip.ad { color: var(--text); }
.item-error { color: var(--bad); font-size: 13.5px; margin: 0; }
.item-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; padding-top: 4px; border-top: 1px solid var(--line); }
.item-actions .spacer { flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--dim); cursor: pointer; padding-right: 4px; }

/* switch */
.switch {
  -webkit-appearance: none; appearance: none;
  width: 46px; height: 28px; border-radius: 28px;
  background: var(--line-strong); position: relative; cursor: pointer;
  transition: background 0.2s ease; flex: none; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform 0.2s ease;
}
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(18px); background: var(--brand-ink); }
.switch:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- TVs */
.device {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.15); }
.device-body { flex: 1; min-width: 0; }
.device-body strong { display: block; }
.device-body small { color: var(--dim); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- configurações */
.settings { display: grid; gap: 14px; }
.row-switch, .row-field {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line);
}
.row-switch > span, .row-field > span { display: grid; gap: 2px; }
.row-switch small, .row-field small { color: var(--dim); }
.row-field input { width: 96px; flex: none; text-align: center; }
.config-box { display: grid; gap: 10px; padding: 14px 12px; border-radius: var(--radius); border: 1px dashed var(--line-strong); }
.config-box > button { justify-self: start; }
.config-row { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 10px; }
.config-row > span { color: var(--dim); font-size: 14px; }
.config-row code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; overflow-x: auto; white-space: nowrap; user-select: all;
}
.ffmpeg-warn { color: var(--warn); margin: 0; }

/* ---------- dialogs */
.dialog {
  width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 20px; padding: 20px 16px;
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(3px); }
.dialog-media { width: min(960px, calc(100vw - 32px)); gap: 12px; }
.dialog-media[open] { display: grid; }
#preview-body video, #preview-body img { width: 100%; max-height: 70vh; object-fit: contain; background: #000; border-radius: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
#edit-form .form-error { margin-top: 12px; }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: calc(100vw - 32px); z-index: 50;
}

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px; }
  .stat strong { font-size: 24px; }
  .stat-label { font-size: 12px; }
  .item { grid-template-columns: 112px 1fr; }
  .thumb { width: 112px; }
  .config-row { grid-template-columns: 1fr auto; }
  .config-row > span { grid-column: 1 / -1; }
}
