/* ==========================================================
   UmbrellaApp - paleta oficial (brain-*), estilo Supabase
   Oscuro por defecto, [data-theme="light"] la sobreescribe.
   ========================================================== */
:root, html[data-theme="dark"] {
  --accent:        #7C5CFC;
  --accent-dark:   #6247E0;
  --accent-alpha:  rgba(124, 92, 252, 0.14);
  --accent-border: rgba(124, 92, 252, 0.30);

  --success:       #22C55E;
  --success-dark:  #16A34A;
  --success-alpha: rgba(34, 197, 94, 0.16);

  --danger:        #EF4444;
  --danger-dark:   #DC2626;
  --danger-alpha:  rgba(239, 68, 68, 0.16);

  --bg:          #1C1C1C;
  --bg-elevated: #242424;
  --bg-inset:    #171717;
  --bg-strong:   #101010;
  --border:      #2E2E2E;

  --text:       #EDEDED;
  --text-muted: #888888;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --topbar-h: 56px;
}

html[data-theme="light"] {
  --accent:        #6247E0;
  --accent-dark:   #4F3BC4;
  --accent-alpha:  rgba(98, 71, 224, 0.10);
  --accent-border: rgba(98, 71, 224, 0.35);

  --success:       #16A34A;
  --success-dark:  #15803D;
  --success-alpha: rgba(22, 163, 74, 0.14);

  --danger:        #DC2626;
  --danger-dark:   #B91C1C;
  --danger-alpha:  rgba(220, 38, 38, 0.12);

  --bg:          #F6F5FB;
  --bg-elevated: #FFFFFF;
  --bg-inset:    #EFEDF9;
  --bg-strong:   #E4E0F7;
  --border:      #DEDAF0;

  --text:       #1C1C24;
  --text-muted: #6B6B78;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: #000;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- Marco de app: en pantallas anchas (escritorio) la app se
   comporta como si estuviera dentro de un telefono, no se estira a
   1400px. El transform crea un "containing block" para que todos los
   position:fixed de adentro (topbar, sidebar, modales) queden confinados
   a este ancho en vez de pegarse al viewport completo. ---------- */
.app-frame {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  transform: translate(0);
  transition: background-color .2s ease, color .2s ease;
}

/* ---------- Boton de tema (sol/luna) ---------- */
.theme-toggle {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.theme-toggle:active { transform: scale(0.94); }
html[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
html[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ==========================================================
   LOGIN - pantalla completa estilo app (sin tarjeta flotante)
   ========================================================== */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-right: 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left: 24px;
  background: var(--bg);
}

.login-topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.login-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 380px;
  width: 100%;
  margin: 0 auto;
}

.login-logo {
  width: 56px; height: 56px;
  border-radius: var(--radius-md);
  background: var(--accent-alpha);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
  margin-bottom: 20px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 6px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 32px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-alpha);
}

.btn-primary {
  width: 100%;
  padding: 15px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:active { transform: scale(0.98); }

/* ---------- Toast / pill de alerta (icono + texto + accion opcional) ---------- */
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-strong);
  border-radius: 999px;
  padding: 8px 16px 8px 8px;
  margin-bottom: 20px;
  color: var(--text);
  font-size: 13.5px;
}

.toast .toast-icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.toast .toast-icon svg, .toast .toast-icon i { width: 15px; height: 15px; }

.toast.success .toast-icon { background: var(--success); }
.toast.error .toast-icon { background: #F97316; }
.toast.info .toast-icon { background: #6B7280; }

.toast .toast-text { flex: 1; }

.toast .toast-action {
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}

/* ==========================================================
   DASHBOARD - shell de app: top bar compacto + tab bar inferior
   ========================================================== */
.app-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 18px;
  padding-right: 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}

.app-topbar .brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;
}
.app-topbar .brand span { color: var(--accent); }

.app-topbar .right { display: flex; align-items: center; gap: 10px; position: relative; }

.avatar-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.avatar-btn:active { transform: scale(0.94); }

.profile-menu {
  position: absolute;
  top: 46px;
  right: 0;
  width: 240px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: none;
  z-index: 50;
}
.profile-menu.open { display: block; }

.profile-menu .menu-header {
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-inset);
}
.profile-menu .menu-header .name { font-size: 14px; font-weight: 700; }
.profile-menu .menu-header .role { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.profile-menu .menu-body { padding: 6px; }
.profile-menu .menu-footer {
  padding: 6px;
  border-top: 1px solid var(--border);
}

.profile-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
}
.profile-menu a:hover { background: var(--bg-inset); }
.profile-menu a.danger { color: #F87171; }
.profile-menu a svg, .profile-menu a i { width: 17px; height: 17px; }

/* ---------- Boton hamburguesa ---------- */
.hamburger-btn {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger-btn:active { transform: scale(0.94); }
.hamburger-btn svg, .hamburger-btn i { width: 20px; height: 20px; }

/* ==========================================================
   SIDEBAR - pantalla completa estilo "Settings", sin shadow
   ========================================================== */
.app-sidebar {
  position: fixed;
  inset: 0;
  width: 100%;
  background: var(--bg);
  z-index: 95;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform .25s ease;
}
.app-sidebar.open { transform: translateX(0); }

.app-sidebar .sidebar-header {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.app-sidebar .sidebar-header h3 {
  margin: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
}

.icon-circle-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg-inset);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-circle-btn:active { transform: scale(0.94); }
.icon-circle-btn svg, .icon-circle-btn i { width: 18px; height: 18px; }

.app-sidebar .sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.sidebar-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-inset);
  margin-bottom: 22px;
  color: var(--text);
}
.sidebar-profile-card .who { flex: 1; min-width: 0; }
.sidebar-profile-card .name { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-profile-card .role { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.sidebar-profile-card svg, .sidebar-profile-card i { flex-shrink: 0; width: 18px; height: 18px; color: var(--text-muted); }

.sidebar-section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 0 0 8px 4px;
}

.sidebar-group {
  background: var(--bg-inset);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 22px;
}

.sidebar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.sidebar-group .sidebar-row:last-child { border-bottom: none; }
.sidebar-row:hover { background: var(--bg-elevated); }

.sidebar-row .row-icon {
  width: 20px; height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-row .row-icon svg, .sidebar-row .row-icon i { width: 18px; height: 18px; }

.sidebar-row .row-label { flex: 1; }

.sidebar-row .row-chevron { color: var(--text-muted); flex-shrink: 0; }
.sidebar-row .row-chevron svg, .sidebar-row .row-chevron i { width: 17px; height: 17px; }

.sidebar-row.danger { color: #F87171; }
.sidebar-row.danger .row-icon { color: #F87171; }

/* ---------- Switch (modo oscuro) ---------- */
.theme-switch-track {
  width: 44px; height: 26px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  flex-shrink: 0;
  transition: background .2s ease;
  cursor: pointer;
}
.theme-switch-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s ease;
}
html[data-theme="dark"] .theme-switch-track { background: var(--accent); }
html[data-theme="dark"] .theme-switch-track::after { transform: translateX(18px); }

/* ==========================================================
   MODAL - bottom sheet con header / body / footer, sin shadow
   ========================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.open { display: flex; }

.modal-sheet {
  width: 100%;
  background: var(--bg-elevated);
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  touch-action: none;
}

.modal-sheet .modal-handle {
  width: 40px; height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 10px auto 0;
  cursor: grab;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; margin: 0; }

.modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-inset);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.modal-close svg, .modal-close i { width: 16px; height: 16px; }

.modal-body {
  padding: 18px;
  font-size: 14px;
  color: var(--text-muted);
}

.install-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 10px;
}

.install-step-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-alpha);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.modal-footer .btn-primary { margin-top: 0; flex: 1; }

.btn-secondary {
  flex: 1;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:active { transform: scale(0.98); }

/* ---------- Contenido ---------- */
.app-content {
  padding-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 18px);
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left: 18px;
  padding-right: 18px;
  max-width: 720px;
  margin: 0 auto;
}

.page-title { font-size: 21px; font-weight: 700; margin: 0 0 4px; }
.page-subtitle { color: var(--text-muted); font-size: 13.5px; margin: 0 0 22px; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 480px) {
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
  .cards-grid.cards-grid-2 { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.stat-card .icon-badge {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent-alpha);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}

.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .value { font-size: 24px; font-weight: 700; }
.stat-card .sub { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.stat-card.success {
  background: var(--success-alpha);
  border-color: rgba(34, 197, 94, 0.3);
}
.stat-card.success .icon-badge { background: var(--success); color: #fff; }
.stat-card.success .value { color: var(--success-dark); }

.stat-card.danger {
  background: var(--danger-alpha);
  border-color: rgba(239, 68, 68, 0.3);
}
.stat-card.danger .icon-badge { background: var(--danger); color: #fff; }
.stat-card.danger .value { color: var(--danger-dark); }

.section-block {
  margin-top: 26px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.section-block h2 {
  font-size: 15px;
  margin: 0 0 4px;
}
.section-block p {
  font-size: 13.5px;
  color: var(--text-muted);
  margin: 0;
}

/* ---------- Rank list (Top programas / Top campañas) ---------- */
.rank-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rank-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.rank-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.rank-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-inset);
  overflow: hidden;
}

.rank-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.rank-bar-fill.accent2 {
  background: var(--success);
}

