:root {
  --bg: #eceef1;
  --surface: #ffffff;
  --ink: #18202b;
  --muted: #5a6472;
  --line: #d4d9e0;
  --bezel: #222a35;
  --glass: #2c3642;
  --shelf: #c3cad3;
  --accent: #2d5be3;
  --accent-ink: #ffffff;
  --accent-soft: #e3e9fc;
  --ok: #1e8a57;
  --warn: #a86f0c;
  --bad: #c0392b;
  --idle: #7d8794;
  --tv: 220px; /* largura de uma TV horizontal no mural */

  color-scheme: light;
  font-family: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161b22;
    --surface: #1f262f;
    --ink: #e8ecf1;
    --muted: #9aa4b1;
    --line: #333d49;
    --bezel: #0d1116;
    --glass: #252d37;
    --shelf: #3a4552;
    --accent: #6b8cf0;
    --accent-ink: #0e1420;
    --accent-soft: #24304d;
    --ok: #4cc28a;
    --warn: #e0a640;
    --bad: #f07163;
    --idle: #8a94a1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; font-weight: 700; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.brand {
  font-size: 1.45rem;
  font-weight: 800;
  font-stretch: 112%;
  letter-spacing: -0.01em;
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger, .btn.ghost.danger { color: var(--bad); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 0.87rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.linkish {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--accent); font-size: 0.85rem; font-weight: 600;
}
.linkish:hover { text-decoration: underline; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login-card .brand { font-size: 1.9rem; line-height: 1.15; }
.login-lead { margin: 0 0 12px; color: var(--muted); }

/* Estrutura */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar-actions { display: flex; gap: 8px; }
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  padding: 24px 28px 48px;
  align-items: start;
}
.side { position: sticky; top: 16px; display: grid; gap: 16px; }

/* Mural de telas */
.wall-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.wall-head h2 { font-size: 1.5rem; font-weight: 800; font-stretch: 112%; }
.wall-summary { margin: 2px 0 0; color: var(--muted); }
.wall-tools { display: flex; gap: 4px; }
.wall-hint { margin: 6px 0 20px; color: var(--muted); font-size: 0.9rem; }

/* Marca > loja > TVs */
.brand-group { padding-top: 22px; border-top: 1px solid var(--line); }
.brand-group:first-child { padding-top: 0; border-top: 0; }
.brand-group + .brand-group { margin-top: 8px; }
.brand-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.brand-head h3 { font-size: 1.35rem; font-weight: 800; font-stretch: 112%; letter-spacing: -0.01em; }
.brand-count { margin: 2px 0 0; color: var(--muted); font-size: 0.87rem; }

.store { margin-bottom: 32px; }
.store-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.store-head h4 { margin: 0; font-size: 1rem; font-weight: 700; }
.store-count { color: var(--muted); font-size: 0.87rem; }

/* As TVs ficam "apoiadas" na base da vitrine */
.shelf {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 28px 24px;
  padding-bottom: 14px;
  border-bottom: 6px solid var(--shelf);
}

/* Área fixa para a TV: todas apoiam na mesma linha, com o nome logo abaixo */
.shelf { --stage: calc(var(--tv) * 9 / 16 + 12px); }
.shelf.has-portrait { --stage: calc(var(--tv) + 12px); }
.screen { width: var(--tv); display: grid; grid-template-rows: var(--stage) auto; gap: 8px; }
.screen-face { align-self: end; }
.screen.is-portrait { width: max(calc(var(--tv) * 9 / 16 + 12px), calc(var(--tv) * 0.72)); }
.is-portrait .screen-face { width: calc(var(--tv) * 9 / 16 + 12px); }

.screen-face {
  position: relative;
  display: block;
  width: 100%;
  padding: 6px;
  border: 0;
  border-radius: 7px;
  background: var(--bezel);
  cursor: pointer;
  box-shadow: 0 0 0 0 var(--accent);
  transition: box-shadow 0.12s ease;
}
.screen-face:hover { box-shadow: 0 0 0 2px var(--muted); }
.is-selected .screen-face,
.is-selected .screen-face:hover { box-shadow: 0 0 0 3px var(--accent); }

.glass {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  background: var(--glass);
  overflow: hidden;
  border-radius: 2px;
}
.is-portrait .glass { aspect-ratio: 9 / 16; }
.glass video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.glass-empty { color: #8893a1; font-size: 0.85rem; }

.tick {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  display: none;
  place-items: center;
}
.tick::after {
  content: '';
  width: 10px;
  height: 5px;
  border-left: 2px solid var(--accent-ink);
  border-bottom: 2px solid var(--accent-ink);
  transform: translateY(-1px) rotate(-45deg);
}
.is-selected .tick { display: grid; }

.playlist-badge {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(13, 17, 22, 0.78);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  pointer-events: none;
}

.screen-meta { display: grid; gap: 2px; justify-items: start; }
.screen-name { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.screen-status {
  margin: 0;
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.screen-status::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tone, var(--idle));
  transform: translateY(-1px);
}
.tone-ok { --tone: var(--ok); }
.tone-warn { --tone: var(--warn); }
.tone-bad { --tone: var(--bad); color: var(--bad); }
.tone-idle { --tone: var(--idle); }

.empty {
  padding: 40px 28px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  max-width: 560px;
}
.empty p { margin: 0 0 8px; }
.empty p + p { color: var(--muted); margin-bottom: 18px; }

/* Painel lateral */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  display: grid;
  gap: 16px;
}
.field { display: grid; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label, legend { font-weight: 600; font-size: 0.9rem; }
legend { padding: 0; margin-bottom: 6px; }
input[type='text'], input[type='password'], input:not([type]), select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.hint { margin: 0; color: var(--muted); font-size: 0.84rem; }
.hint:empty { display: none; }

.upload { position: relative; }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.upload span {
  display: block;
  padding: 10px;
  border: 1px dashed var(--muted);
  border-radius: 6px;
  text-align: center;
  color: var(--accent);
  font-weight: 600;
}
.upload:hover span, .upload input:focus-visible + span { background: var(--accent-soft); }
.upload input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.progress-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.progress-text { margin: 4px 0 0; font-size: 0.84rem; color: var(--muted); }


label.check { font-weight: 500; display: flex; align-items: center; gap: 8px; cursor: pointer; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.targets {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--bg);
  font-size: 0.88rem;
  color: var(--muted);
}
.targets strong { color: var(--ink); }
.targets-warn { display: block; margin-top: 6px; color: var(--warn); font-weight: 600; }

/* Vídeos para marcar */
.pick-list { list-style: none; margin: 0; padding: 0; max-height: 230px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; }
.pick-list li + li { border-top: 1px solid var(--line); }
.pick-list .empty-line { padding: 10px 12px; color: var(--muted); font-size: 0.88rem; }
.pick {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 8px 10px;
  font-weight: 500;
  cursor: pointer;
}
.pick:hover { background: var(--bg); }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick-order {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 700;
}
.pick input:checked + .pick-order { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pick input:focus-visible + .pick-order { outline: 3px solid var(--accent); outline-offset: 2px; }
.pick input:disabled ~ * { opacity: 0.45; }
.pick:has(input:disabled) { cursor: not-allowed; }
.pick-text { font-size: 0.88rem; overflow-wrap: anywhere; }
.pick-text small { display: block; color: var(--muted); font-size: 0.78rem; }

/* Ordem que a TV vai passar */
.playlist { padding: 10px 12px; border-radius: 6px; background: var(--accent-soft); font-size: 0.88rem; }
.playlist-lead { margin: 0 0 6px; font-weight: 600; }
.playlist ol { margin: 0; padding-left: 1.4em; display: grid; gap: 4px; }
.playlist li::marker { font-weight: 700; color: var(--accent); }
.playlist li > * { vertical-align: middle; }
.playlist li { overflow-wrap: anywhere; }
.playlist-tools { display: inline-flex; gap: 2px; margin-left: 4px; }
.icon-btn {
  width: 24px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  line-height: 1;
  color: var(--muted);
}
.icon-btn:hover { border-color: var(--line); background: var(--surface); color: var(--ink); }

.form-msg, .form-error { margin: 0; font-size: 0.88rem; min-height: 1.2em; }
.form-error { color: var(--bad); }
.form-error:empty, .form-msg:empty { display: none; }

/* Bloco final do envio: vídeo + telas + botão */
.send-step { display: grid; gap: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.send-step .field { gap: 8px; }

/* Marcas */
.brands { display: flex; flex-wrap: wrap; gap: 6px; }
.brands label { font-weight: 500; }
.brands input { position: absolute; opacity: 0; pointer-events: none; }
.brands span {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.88rem;
}
.brands span small { color: var(--muted); font-size: 0.78rem; }
.brands input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.brands input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.brands .unbranded span { border-style: dashed; }

/* Biblioteca */
.video-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 340px; overflow-y: auto; }
.video-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.video-list li:first-child { border-top: 0; }
.video-name { margin: 0; font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.video-meta { margin: 0; color: var(--muted); font-size: 0.8rem; }
.video-move { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.video-move select { width: auto; min-height: 28px; padding: 0 6px; font-size: 0.8rem; }
.video-list .empty-line { color: var(--muted); font-size: 0.88rem; display: block; border: 0; }

/* Diálogos */
.dialog {
  width: min(700px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(16, 22, 30, 0.55); }
.dialog-body { display: grid; gap: 14px; padding: 24px; }
.dialog-body p { margin: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.dialog-actions.spread { justify-content: space-between; }
.steps { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.d-status { font-weight: 600; }
.d-tools { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; font-size: 0.9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 20px 16px 40px; }
  .side { position: static; }
  .topbar { padding: 14px 16px; }
}
@media (max-width: 560px) {
  :root { --tv: 150px; }
  .shelf { gap: 22px 16px; }
  .topbar { flex-wrap: wrap; }
  .topbar .brand { font-size: 1.15rem; }
  .topbar-actions .btn { padding: 0 10px; }
  .field-row { grid-template-columns: 1fr; }
  .brand-head { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
