:root {
  --bg: #0a0a0c;
  --bg-grid: rgba(255, 255, 255, 0.035);
  --surface: #17171b;
  --surface-2: #1d1d22;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f2f2f4;
  --text-dim: #a6a6ad;
  --text-faint: #737379;
  --accent: #e8591a;
  --accent-dim: rgba(232, 89, 26, 0.16);
  --ok: #35c46a;
  --off: #6b6b72;
  --danger: #e5484d;
  --radius: 16px;
  --radius-sm: 10px;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 40px 40px;
  min-height: 100vh;
  padding: 16px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}

button, input {
  font-family: inherit;
  color: inherit;
}

@media (prefers-reduced-motion: no-preference) {
  .reveal {
    animation: reveal 420ms cubic-bezier(.2,.7,.2,1) both;
  }
  @keyframes reveal {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}

/* ---------- login ---------- */
.login-screen {
  min-height: calc(100vh - 32px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.login-logo { width: 160px; height: auto; margin-bottom: 6px; filter: brightness(1.1); }
.login-card h1 { font-size: 20px; margin: 0; font-weight: 700; }
.login-sub { margin: -8px 0 8px; color: var(--text-dim); font-size: 14px; }
.field-error { color: var(--danger); font-size: 13px; margin: 0; }

.field {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 13px 14px;
  font-size: 15px;
  min-height: 48px;
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  min-height: 48px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 120ms ease, background 150ms ease, opacity 150ms ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #f16a2c; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: rgba(255,255,255,0.045); color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost.active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.btn-big { width: 100%; font-size: 15px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

/* ---------- topo ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px;
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  background: var(--bg);
}
.topbar-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.topbar-logo { height: 22px; width: auto; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.status-pill.online .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(53,196,106,0.18); }

/* ---------- layout geral (colunas em telas largas) ---------- */
.layout {
  display: block;
}
.layout-left { min-width: 0; }
.layout-right { min-width: 0; }

@media (min-width: 1100px) {
  .layout {
    display: grid;
    grid-template-columns: 440px 1fr;
    gap: 20px;
    align-items: start;
  }
  .layout-left {
    position: sticky;
    top: 72px;
  }
}

/* ---------- agora na tv ---------- */
.now-card {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
@media (max-width: 1099px) {
  .now-card {
    position: sticky;
    top: calc(52px + env(safe-area-inset-top, 0px));
    z-index: 4;
  }
}
.now-main {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}
@media (min-width: 700px) and (max-width: 1099px) {
  .now-main { max-width: 360px; }
}
.now-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}
.now-thumb-img { width: 100%; height: 100%; object-fit: contain; background: #000; }
.now-thumb-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  font-size: 14px;
  background: radial-gradient(120% 100% at 20% 0%, rgba(232,89,26,0.08), transparent 60%), #101012;
}
.live-badge {
  position: absolute; top: 10px; left: 10px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  padding: 4px 9px; border-radius: 999px;
}

.now-info { margin-top: 12px; }
.now-name { font-weight: 700; font-size: 16px; }
.now-sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.now-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}
.ctrl-btn {
  min-width: 48px; min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.ctrl-btn:active { transform: scale(0.96); background: var(--accent-dim); }
.ctrl-btn-big { flex: 1; max-width: 140px; font-size: 20px; }
.ctrl-count { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-dim); }

.now-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-top: 14px;
  padding-bottom: 4px;
  scroll-snap-type: x proximity;
}
.now-strip-item {
  flex: 0 0 auto;
  width: 72px; height: 40px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  background: #000;
  scroll-snap-align: center;
}
.now-strip-item img { width: 100%; height: 100%; object-fit: cover; }
.now-strip-item.active { border-color: var(--accent); }

.now-secondary { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.now-secondary .btn { flex: 1; min-width: 120px; font-size: 13px; }
#btnLiveSettings { flex: 0 0 auto; }
@media (min-width: 1100px) {
  .now-secondary {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .now-secondary .btn { min-width: 0; }
  #btnLiveSettings { justify-self: end; align-self: center; }
}
.live-dot-wrap { display: inline-flex; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.live-dot.on {
  background: var(--danger);
  animation: livePulse 1.4s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,72,77,0.5); }
  50% { box-shadow: 0 0 0 5px rgba(229,72,77,0); }
}
.live-signal-label { margin-top: 8px; font-size: 12px; color: var(--text-faint); text-align: center; }

.live-settings {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field-label { font-size: 12px; color: var(--text-dim); }

/* ---------- abas ---------- */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  flex: 1;
  min-height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* ---------- upload ---------- */
.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px 16px;
  text-align: center;
  background: linear-gradient(160deg, rgba(255,255,255,0.02), transparent);
  margin-bottom: 14px;
}
.upload-zone.drag-over { border-color: var(--accent); background: var(--accent-dim); }
.upload-input { display: none; }
.upload-hint { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.upload-hint strong { font-size: 15px; }
.upload-hint span { font-size: 13px; color: var(--text-dim); }
.field-presenter { margin-bottom: 12px; max-width: 340px; margin-left: auto; margin-right: auto; }

.upload-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.upload-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.upload-row-name { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.upload-row-status { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.upload-progress-track { height: 6px; border-radius: 4px; background: rgba(255,255,255,0.08); overflow: hidden; }
.upload-progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width 200ms ease; }

/* ---------- biblioteca ---------- */
.section-title { font-size: 16px; margin: 18px 0 10px; }
.library-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 640px) { .library-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .library-grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
.card-cover {
  width: 100%; aspect-ratio: 16/9;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; }
.card-cover .kind-icon { font-size: 28px; color: var(--text-faint); }
.card-badge {
  position: absolute; top: 10px; left: 10px;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  letter-spacing: 0.4px;
}
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-name { font-weight: 700; font-size: 14px; }
.card-name[contenteditable="true"] { outline: 1px dashed var(--accent); border-radius: 4px; padding: 1px 3px; }
.card-meta { font-size: 12px; color: var(--text-dim); }
.card-expiry { font-size: 11px; color: var(--text-faint); }
.card-error { font-size: 12px; color: var(--danger); margin-top: 2px; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions .btn { flex: 1; }
.card-menu-wrap { position: relative; }
.card-menu {
  position: absolute; right: 0; bottom: 46px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  min-width: 170px; overflow: hidden; z-index: 6;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.card-menu button {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  background: none; border: none; color: var(--text); font-size: 13px; min-height: 44px; cursor: pointer;
}
.card-menu button:hover { background: rgba(255,255,255,0.06); }
.card-menu button.danger { color: var(--danger); }
.confirm-row { display: flex; gap: 8px; align-items: center; padding: 10px 14px; font-size: 13px; }
.confirm-row .btn { min-height: 40px; padding: 8px 12px; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--text-dim); }
.empty-sub { font-size: 13px; color: var(--text-faint); }

/* ---------- programações ---------- */
.playlists-head { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }
.playlists-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.playlist-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.playlist-row-name { font-weight: 700; font-size: 14px; flex: 1; min-width: 140px; }
.playlist-row-meta { font-size: 12px; color: var(--text-dim); width: 100%; }
.playlist-default-badge {
  font-size: 10px; font-weight: 700; color: var(--accent);
  background: var(--accent-dim); padding: 3px 8px; border-radius: 999px;
}
.playlist-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.playlist-actions .btn { min-height: 40px; padding: 8px 12px; font-size: 12px; }

/* ---------- modais ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
@media (min-width: 720px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  width: 100%; max-width: 560px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 18px;
}
@media (min-width: 720px) { .modal { border-radius: var(--radius); } }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-title-field { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); margin-bottom: 14px; }
.checkbox-row input { width: 20px; height: 20px; }

.entries-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.entry-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px;
}
.entry-drag-handle { cursor: grab; color: var(--text-faint); padding: 4px 6px; font-size: 16px; }
.entry-thumb { width: 56px; height: 32px; border-radius: 6px; overflow: hidden; background: #000; flex: 0 0 auto; }
.entry-thumb img { width: 100%; height: 100%; object-fit: cover; }
.entry-info { flex: 1; min-width: 0; }
.entry-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-kind { font-size: 11px; color: var(--text-faint); }
.entry-duration {
  width: 56px; background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); text-align: center; padding: 8px 4px; font-size: 13px; min-height: 40px;
}
.entry-btns { display: flex; gap: 4px; }
.entry-btns button {
  width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer;
}
.entry-row.dragging { opacity: 0.4; }

.library-pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-bottom: 14px; }
.pick-card { border-radius: 10px; overflow: hidden; border: 2px solid var(--border); cursor: pointer; background: #000; position: relative; }
.pick-card.selected { border-color: var(--accent); }
.pick-card img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.pick-card-name { font-size: 11px; padding: 5px 6px; background: var(--surface-2); }
.pick-card-check {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,0.55); border: 1.5px solid #fff; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #fff;
}
.pick-card.selected .pick-card-check { background: var(--accent); border-color: var(--accent); }

.playlist-pick-list { display: flex; flex-direction: column; gap: 8px; }
.playlist-pick-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer; min-height: 48px;
}

.hint {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  margin-top: 22px;
}
