:root {
  --red: #dc1c24;
  --red-dark: #b5151c;
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b72;
  --line: #e3e3e8;
  --ok: #18853a;
  --warn: #b26a00;
  --err: #d0121b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 10px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.modal-open { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
a { color: var(--red); }
code { font-size: 0.85rem; word-break: break-all; }
button, input, select { font: inherit; color: inherit; }
img { max-width: 100%; }

.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error-text { color: var(--err); }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 8px; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.section-title { margin: 24px 4px 10px; }

/* ---------- Estrutura ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; margin-right: auto; }
.brand img { height: 30px; }
.topnav { display: none; gap: 4px; }
.topnav a { padding: 8px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.topnav a.active { background: #fde8e9; color: var(--red); }

.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
}
.bottomnav a.active { color: var(--red); }

@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .topnav { display: flex; }
  .bottomnav { display: none; }
}

.page { max-width: 760px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head h1 { margin-bottom: 4px; }
.back { display: inline-flex; align-items: center; gap: 2px; text-decoration: none; font-weight: 500; margin: 0 0 8px -6px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card > h2 { margin-bottom: 8px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover { background: #f7f7f9; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.danger { color: var(--err); border-color: #f3c2c4; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 0.85rem; }
.btn.block { width: 100%; margin-top: 12px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: #f0f0f3; color: var(--text); }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* ---------- Telas ---------- */
.screen-card h2 { font-size: 1.25rem; }
.screen-card .muted { margin: 4px 0 10px; }
.badge { font-size: 0.78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge.ok { background: #e3f4e8; color: var(--ok); }
.badge.warn { background: #fff1d6; color: var(--warn); }
.status { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.95rem; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.status.on { color: var(--ok); }
.status.on .dot { background: var(--ok); box-shadow: 0 0 0 4px #d8f0df; }
.status.off { color: var(--err); }
.status.off .dot { background: var(--err); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .btn:last-child { grid-column: 1 / -1; }
@media (min-width: 560px) {
  .actions { grid-template-columns: auto auto auto; justify-content: start; }
  .actions .btn:last-child { grid-column: auto; }
}

/* ---------- Playlist ---------- */
.save-state { font-size: 0.85rem; color: var(--muted); }
.playlist { list-style: none; margin: 12px 0 0; padding: 0; }
.pl-item { border: 1px solid var(--line); border-radius: 12px; background: var(--card); margin-bottom: 8px; }
.pl-item.disabled .pl-info, .pl-item.disabled .thumb { opacity: 0.45; }
.pl-item.ghost { opacity: 0.35; background: #fde8e9; }
.pl-item.chosen { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); }
.pl-main { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 0; }
.handle {
  display: flex;
  align-items: center;
  align-self: stretch;
  padding: 0 4px 0 8px;
  color: #a0a0a8;
  cursor: grab;
  touch-action: none;
}
.pl-info { flex: 1; min-width: 0; }
.pl-info .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); }
.meta svg { width: 15px; height: 15px; }
.pl-side { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tag { font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: #ececf0; color: var(--muted); }
.tag.warn { background: #fff1d6; color: var(--warn); }
.period-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
}
.period-btn svg { width: 15px; height: 15px; }
.period-btn.active, .period-btn.future { color: var(--text); }
.period-btn.ended { color: var(--warn); }
.period-btn.bad { color: var(--err); }
.period-edit { border-top: 1px dashed var(--line); padding: 10px 12px 12px; display: grid; gap: 10px; }

/* ---------- Miniaturas / grade ---------- */
.thumb {
  position: relative;
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 9px;
  background: #1c1c1e;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb .ph { color: #bbb; font-size: 0.75rem; text-align: center; padding: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  padding: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.tile:disabled { cursor: default; opacity: 0.6; }
.tile .thumb { width: 100%; height: auto; aspect-ratio: 1 / 1; border-radius: 0; margin-bottom: 8px; }
.tile.dim .thumb, .tile.dim .tile-name { opacity: 0.45; filter: grayscale(1); }
.tile-name { padding: 0 10px; font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { padding: 0 10px; font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-warn { margin: 4px 10px 0; font-size: 0.75rem; font-weight: 600; color: var(--warn); }
.thumb-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}
.thumb-badge svg { width: 13px; height: 13px; }

/* ---------- Upload ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 16px;
  margin-bottom: 14px;
  border: 2px dashed #cfcfd6;
  border-radius: var(--radius);
  text-align: center;
  color: var(--text);
  cursor: pointer;
  background: var(--card);
}
.dropzone svg { color: var(--red); width: 28px; height: 28px; }
.dropzone.over { border-color: var(--red); background: #fdf0f0; }
.upload { padding: 8px 0; border-top: 1px solid var(--line); }
.upload:first-of-type { border-top: 0; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 8px; }
.bar { height: 6px; border-radius: 3px; background: #ececf0; overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; background: var(--red); transition: width 0.2s; }
.upload.done .bar span { background: var(--ok); }
.upload.error .bar span { background: var(--err); }

/* ---------- Formulários ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 0.9rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="datetime-local"], input:not([type]), select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #d6d6dc;
  border-radius: 10px;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--red); }
.copy-row { display: flex; align-items: center; gap: 8px; background: #f4f4f6; border-radius: 10px; padding: 8px 8px 8px 12px; }
.copy-row code { flex: 1; }

.segmented { display: inline-flex; background: #ececf0; border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 0.9rem; cursor: pointer; color: var(--muted); }
.segmented button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { position: relative; width: 46px; height: 28px; border-radius: 14px; background: #d1d1d6; transition: background 0.2s; flex: none; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track .knob { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--red); outline-offset: 2px; }
.switch-label { font-weight: 600; }

/* ---------- Aviso ---------- */
.alert-preview { background: var(--red); color: #fff; font-weight: 700; text-align: center; padding: 10px 12px; border-radius: 10px; }
.alert-card { display: grid; gap: 8px; justify-items: start; }
.alert-card .alert-preview { width: 100%; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: up 0.2s ease-out;
}
.sheet.wide { max-width: 760px; }
@media (min-width: 760px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 8px 18px; }
.sheet-body { padding: 4px 18px 18px; overflow-y: auto; }
.sheet-foot { display: flex; justify-content: space-between; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.preview { background: #1c1c1e; border-radius: 12px; overflow: hidden; display: flex; justify-content: center; margin-bottom: 14px; }
.preview video, .preview img { max-height: 46vh; max-width: 100%; display: block; }
.preview .ph { color: #ccc; padding: 40px 16px; text-align: center; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
@media (min-width: 760px) { .toasts { bottom: 24px; } }
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-radius: 12px;
  background: #1c1c1e;
  color: #fff;
  font-weight: 600;
  font-size: 0.92rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  animation: up 0.2s ease-out;
  pointer-events: auto;
}
.toast.ok::before { content: "✓"; color: #4cd964; margin-right: -4px; }
.toast.err { background: var(--err); }
.toast-action { border: 0; background: none; color: #ffb3b6; font-weight: 700; cursor: pointer; padding: 0; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login-logo { height: 64px; justify-self: center; }
.login h1 { text-align: center; font-size: 1.25rem; }
body:has(.login) { padding-bottom: 0; }

/* ---------- Ajuda ---------- */
.help ol, .help ul { padding-left: 20px; margin: 8px 0 0; }
.help li { margin-bottom: 6px; }
