:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2330;
  --muted: #5f6b7a;
  --accent: #d97706;
  --accent-strong: #b45309;
  --accent-contrast: #ffffff;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn-bg: #fff4e5;
  --warn-text: #8a4b00;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a2029;
    --surface-2: #222a35;
    --border: #2e3846;
    --text: #e7ebf0;
    --muted: #9aa6b5;
    --accent: #f59e0b;
    --accent-strong: #fbbf24;
    --accent-contrast: #1c1300;
    --danger: #ef5350;
    --ok: #66bb6a;
    --warn-bg: #3a2a0d;
    --warn-text: #ffcc80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent-strong); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }

/* ---------- topo ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-lg { font-size: 1.4rem; justify-content: center; margin-bottom: 16px; }
.logo {
  width: 28px; height: 20px; border-radius: 4px; background: var(--accent); position: relative; flex: none;
}
.logo::after {
  content: ""; position: absolute; left: 11px; top: 5px;
  border-left: 8px solid var(--surface); border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
nav { display: flex; gap: 4px; flex: 1; }
nav a {
  padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500;
}
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.active { background: var(--surface-2); color: var(--text); }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* ---------- elementos ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; font-size: 0.875rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input[type="color"] { padding: 2px; height: 36px; width: 56px; }
textarea { min-height: 110px; resize: vertical; }
label { display: block; font-weight: 500; margin-bottom: 4px; }
.hint { color: var(--muted); font-size: 0.875rem; margin: 4px 0 0; }
.error { color: var(--danger); margin: 8px 0 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .back { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty p { margin: 0 0 16px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.warn { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 8px 12px; font-size: 0.9rem; }
.warn ul { margin: 0; padding-left: 18px; }

/* ---------- telas ---------- */
.screen-card { display: flex; flex-direction: column; gap: 10px; }
.screen-card .title { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.code-box {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; word-break: break-all;
}
.code-box span { flex: 1; }
.code-box.big { font-size: 1.15rem; padding: 14px; }

.layouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.layout-option { cursor: pointer; border: 2px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--surface); }
.layout-option:has(input:checked) { border-color: var(--accent); }
.layout-option input { position: absolute; opacity: 0; }
.layout-option .name { font-size: 0.875rem; font-weight: 500; margin-top: 8px; display: block; text-align: center; }

.preview { position: relative; aspect-ratio: 16 / 9; border-radius: 6px; overflow: hidden; background: #000; }
.preview .zone {
  position: absolute; display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 0.75rem; font-weight: 600; color: #fff; overflow: hidden; padding: 2px; border: 1px solid rgb(0 0 0 / 35%);
}
.preview.large .zone { font-size: 0.95rem; }
.preview .zone.main { background: #475569; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.editor aside { position: sticky; top: 76px; }
.colors { display: flex; gap: 16px; flex-wrap: wrap; }
.colors label { font-weight: 400; font-size: 0.875rem; }

/* ---------- playlists ---------- */
.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: grid; grid-template-columns: 88px minmax(0, 1fr) auto; gap: 14px; align-items: start;
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.item + .item { margin-top: 10px; }
.item .thumb, .media-card .thumb {
  width: 88px; aspect-ratio: 16 / 9; border-radius: 6px; background: var(--surface-2); object-fit: cover; display: block;
}
.item .thumb.web { display: flex; align-items: center; justify-content: center; font-size: 1.6rem; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .fields { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.item .fields input[type="number"] { width: 110px; }
.item .fields select { width: auto; }
.item .controls { display: flex; flex-direction: column; gap: 4px; }
.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.schedule { margin-top: 10px; padding: 10px; background: var(--surface-2); border-radius: 8px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.days label {
  margin: 0; font-weight: 500; font-size: 0.85rem; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); cursor: pointer; background: var(--surface);
}
.days label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.days input { display: none; }
.schedule .row input { width: auto; }

.savebar {
  position: sticky; bottom: 0; margin: 20px -24px -24px; padding: 12px 24px;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; gap: 12px; align-items: center; justify-content: flex-end;
}
.savebar .status { margin-right: auto; color: var(--muted); font-size: 0.9rem; }
.savebar .status.dirty { color: var(--warn-text); }

/* ---------- mídias ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center;
  color: var(--muted); background: var(--surface); cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.dropzone strong { color: var(--text); }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }
.media-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.media-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.media-card .thumb { width: 100%; border-radius: 0; }
.media-card .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.media-card .name { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.media-card .meta { color: var(--muted); font-size: 0.8rem; }
.media-card .actions { display: flex; justify-content: space-between; margin-top: auto; }
.media-card.selectable { cursor: pointer; border-width: 2px; }
.media-card.selected { border-color: var(--accent); }

/* ---------- modal e avisos ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text);
  width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog .modal-body { padding: 20px; overflow: auto; max-height: calc(100vh - 160px); }
dialog .modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); }
dialog.small { width: min(440px, calc(100vw - 32px)); }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1c2330; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgb(0 0 0 / 25%); }
.toast.error { background: var(--danger); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}

@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .editor aside { position: static; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  nav { order: 3; width: 100%; }
  main { padding: 16px; }
  .savebar { margin: 20px -16px -16px; padding: 12px 16px; }
  .item { grid-template-columns: 64px minmax(0, 1fr); }
  .item .thumb { width: 64px; }
  .item .controls { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
}

/* TV em pé: prévia com proporção 9:16 */
.preview.portrait { aspect-ratio: 9 / 16; width: auto; height: 260px; margin: 0 auto; }
.preview.portrait.large { height: 440px; }
.layout-option .preview.portrait { height: 110px; }
