:root {
  --ink: #14212b;
  --muted: #5b6b76;
  --line: #d7e0e6;
  --paper: #e8eef1;
  --card: #ffffff;
  --accent: #0b6e4f;
  --accent-soft: #d8f0e7;
  --blue: #0a2f5c;
  --blue-soft: #cfe4f6;
  --danger: #b42318;
  --sidebar: 300px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

a {
  color: inherit;
  text-decoration: none;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 13px;
  line-height: 1.4;
}

/* —— Login —— */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 0%, #d8f0e7 0%, transparent 50%),
    radial-gradient(ellipse at 90% 100%, #dce8f5 0%, transparent 45%),
    var(--paper);
}

.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 28px 24px;
  box-shadow: 0 8px 28px rgba(20, 33, 43, 0.06);
}

.login-card .brand,
.sidebar .brand {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.login-card h1 {
  margin: 6px 0 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.lede {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.login-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.login-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.login-form button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 8px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.login-form button:hover,
.btn:hover { filter: brightness(1.05); }

.error {
  background: #fef3f2;
  color: var(--danger);
  border: 1px solid #fecdca;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 12px;
}

/* —— Shell —— */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 16px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.user-email {
  margin: 4px 0 0;
  font-weight: 600;
  font-size: 13px;
  word-break: break-all;
}

.meta-line {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.kind-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.kind-switch-label {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}
.kind-btn,
a.btn.kind-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 0;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.kind-btn:hover,
a.btn.kind-btn:hover {
  filter: brightness(1.03);
  color: var(--blue);
  text-decoration: none;
}
.kind-btn.active,
a.btn.kind-btn.active {
  background: var(--blue);
  color: #fff;
}
.kind-btn-tv.active {
  background: #0b3a6e;
}
.month-pick {
  display: grid;
  gap: 4px;
}
.month-pick label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.month-pick select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.sidebar-actions .btn { margin-top: 6px; }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-toggle[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}
.btn-toggle[aria-pressed="false"] {
  background: #f3f6f8;
  color: var(--muted);
  border: 1px solid var(--line);
}

.hint-sm {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.prefs-panel h2 {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.seg-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.seg-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  margin-bottom: 6px;
  align-items: start;
}

.seg-toggle,
.block-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #f7fafb;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
  color: var(--muted);
}

.seg-toggle.on,
.block-toggle.on {
  background: var(--accent-soft);
  border-color: #b7dfd0;
  color: var(--ink);
  font-weight: 600;
}

.seg-toggle .dot,
.block-toggle .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c5d0d6;
  flex-shrink: 0;
}

.seg-toggle.on .dot,
.block-toggle.on .dot {
  background: var(--accent);
}

.expand {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 32px;
  height: 34px;
  cursor: pointer;
  color: var(--muted);
}

.block-list {
  grid-column: 1 / -1;
  list-style: none;
  margin: 0 0 4px 8px;
  padding: 0;
}

.block-list li { margin-bottom: 4px; }

.block-toggle {
  padding: 6px 8px;
  font-size: 12px;
}

.seg-item.is-off .block-toggle {
  opacity: 0.45;
  pointer-events: none;
}

.logout-form { margin-top: auto; }

.report-frame {
  overflow: hidden;
  background: var(--paper);
  min-height: 100vh;
}

.report-iframe {
  width: 100%;
  height: 100vh;
  border: 0;
  background: var(--paper);
  display: block;
}

.empty-state {
  margin: 48px auto;
  max-width: 420px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}

/* —— Mobile shell (drawer) —— */
.mobile-bar {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100dvh;
  }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 40;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--card);
    border-bottom: 1px solid var(--line);
  }

  .mobile-bar .brand {
    margin: 0;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .mobile-bar .meta-line {
    margin: 2px 0 0;
  }

  .mobile-bar-text {
    flex: 1;
    min-width: 0;
  }

  .mobile-menu-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .mobile-menu-btn .burger,
  .mobile-menu-btn .burger::before,
  .mobile-menu-btn .burger::after {
    display: block;
    width: 16px;
    height: 2px;
    background: var(--ink);
    border-radius: 1px;
    position: relative;
  }

  .mobile-menu-btn .burger::before,
  .mobile-menu-btn .burger::after {
    content: "";
    position: absolute;
    left: 0;
  }

  .mobile-menu-btn .burger::before { top: -5px; }
  .mobile-menu-btn .burger::after { top: 5px; }

  .mobile-pdf,
  .mobile-tv {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    flex: 0 0 auto;
  }

  .mobile-tv {
    background: var(--blue);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(20, 33, 43, 0.45);
  }

  .sidebar-backdrop[hidden] {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    width: min(320px, 88vw);
    height: 100dvh;
    height: 100vh;
    border-right: 1px solid var(--line);
    border-bottom: none;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 28px rgba(20, 33, 43, 0.18);
  }

  .report-frame {
    min-height: 0;
    height: calc(100dvh - 58px);
    height: calc(100vh - 58px);
  }

  .report-iframe {
    height: 100%;
  }
}

/* —— Admin usuarios —— */
.admin-main {
  padding: 28px 32px 48px;
  max-width: 860px;
}

.admin-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.admin-header .lede {
  margin: 6px 0 18px;
}

.admin-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px 18px;
  margin-bottom: 16px;
}

.admin-card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.admin-card h2 .count {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.admin-form {
  display: grid;
  gap: 10px;
  max-width: 420px;
}

.admin-form label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.admin-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.admin-form .btn {
  width: auto;
  justify-self: start;
  margin-top: 4px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.admin-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.admin-table .muted {
  color: var(--muted);
  font-size: 12px;
}

.admin-table .actions {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}

.btn-sm {
  width: auto;
  margin-top: 0;
  padding: 6px 10px;
  font-size: 12px;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecdca;
}

.btn-danger:hover {
  background: #fef3f2;
  filter: none;
}

.admin-list {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
}

.admin-flash {
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 14px;
}

.admin-flash.ok {
  background: var(--accent-soft);
  color: var(--ink);
  border: 1px solid #b7dfd0;
}

.admin-flash.error {
  background: #fef3f2;
  color: var(--danger);
  border: 1px solid #fecdca;
}

.admin-ingest-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.admin-ingest-row .btn {
  width: auto;
  margin-top: 0;
}

/* —— Modo TV (40"+ / oficina) —— */
html.tv-mode,
html.tv-mode body.app-shell {
  background: #0c1520;
}

html.tv-mode body.app-shell {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
}

html.tv-mode .sidebar,
html.tv-mode .mobile-bar,
html.tv-mode .sidebar-backdrop {
  display: none !important;
}

html.tv-mode .report-frame {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  background: #0c1520;
}

html.tv-mode .report-iframe {
  height: 100vh;
  height: 100dvh;
  background: #0c1520;
}

.tv-hud {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 14px;
  z-index: 80;
  color: #e8eef4;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

html.tv-mode .tv-hud {
  display: block;
}

html.tv-mode.tv-hud-on .tv-hud {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.tv-hud[hidden] {
  display: none !important;
}

.tv-hud-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: rgba(10, 22, 34, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.tv-hud-brand {
  min-width: 0;
  flex: 1;
}

.tv-hud-brand .brand {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #9bb0c0;
}

.tv-hud-title {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-hud-clock {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  flex: 0 0 auto;
}

.tv-hud-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.tv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.tv-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.tv-btn-play[aria-pressed="false"] {
  background: var(--accent);
  border-color: transparent;
}

.tv-btn-exit {
  background: #b42318;
  border-color: transparent;
}

.tv-hud-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding: 0 6px;
}

.tv-dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  cursor: pointer;
}

.tv-dot.on {
  background: #5ee0b5;
  box-shadow: 0 0 0 3px rgba(94, 224, 181, 0.22);
}

.tv-hud-hint {
  margin: 8px 8px 0;
  font-size: 12px;
  color: rgba(232, 238, 244, 0.72);
}

.tv-progress-slim {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
}

.tv-progress-slim[hidden] {
  display: none !important;
}

.tv-progress-slim span {
  display: block;
  height: 100%;
  width: 0;
  background: #5ee0b5;
  transition: width 0.35s linear;
}

@media (max-width: 900px) {
  .tv-hud-bar {
    flex-wrap: wrap;
  }
  .tv-hud-clock {
    font-size: 22px;
  }
  .tv-hud-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
