/* ==================================================================
   UmbrellaApp - estilos base
   Paleta del ecosistema Umbrella (misma que Umbrella Streaming).
   Tamanos de controles al estilo Supabase: compactos, 28px de alto.
   ================================================================== */

:root {
  /* Paleta */
  --fondo: #0f1012;
  --panel: #16171a;
  --superficie: #1c1d21;
  --superficie-2: #24262b;
  --borde: rgba(255, 255, 255, .07);
  --borde-2: rgba(255, 255, 255, .12);
  --borde-3: rgba(255, 255, 255, .18);
  --texto: #e8eaed;
  --suave: #9aa0a6;
  --tenue: #6b7078;
  --acento: #7c74ff;
  --acento-borde: #5f56f0;
  --rojo: #ea4335;
  --verde: #34a853;
  --ambar: #f9ab00;

  /* Tamanos (estilo Supabase) */
  --control-h: 28px;
  --control-px: 16px;
  --control-font: 13px;
  --radio: 6px;
  --radio-lg: 10px;

  /* Efectos */
  --anillo: 0 0 0 3px rgba(124, 116, 255, .28);
  --sombra-btn: 0 1px 2px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;

  /* Areas seguras: notch de iPhone, isla dinamica, barra de gestos */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* Tema claro: <html data-theme="light">. El oscuro es el predeterminado. */
:root[data-theme="light"] {
  --fondo: #f6f6f7;
  --panel: #ffffff;
  --superficie: #ffffff;
  --superficie-2: #f1f1f3;
  --borde: rgba(16, 24, 40, .08);
  --borde-2: rgba(16, 24, 40, .13);
  --borde-3: rgba(16, 24, 40, .22);
  --texto: #17181a;
  --suave: #5f646d;
  --tenue: #9aa0a6;
  --sombra-btn: 0 1px 2px rgba(16, 24, 40, .08), inset 0 -1px 0 rgba(16, 24, 40, .05);
  --sombra-tarjeta: 0 1px 2px rgba(16, 24, 40, .04);
  color-scheme: light;
}
:root { color-scheme: dark; --sombra-tarjeta: none; }

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--fondo);
  color: var(--texto);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  overscroll-behavior-y: none;
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--acento); }

.app { padding: 24px 16px; }

/* Hoja de instalacion */
html.install-sheet-open { overflow: hidden; }

.install-sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
}
.install-sheet-panel {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
}
@media (min-width: 600px) {
  .install-sheet { align-items: center; }
  .install-sheet-panel { border-radius: 16px; padding-bottom: 20px; }
}
.install-sheet-header { display: flex; gap: 14px; align-items: center; }
.install-sheet-header img { border-radius: 12px; }
.install-sheet-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.install-sheet-header p { margin: 2px 0 0; color: var(--suave); font-size: 13px; }
.install-steps { margin: 16px 0 0; padding-left: 20px; font-size: 13px; }
.install-steps li { margin-bottom: 6px; }
.install-sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.install-sheet-actions > * { flex: 1; }

/* Aviso de nueva version */
.pwa-toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  gap: 12px;
  align-items: center;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 8px 8px 8px 14px;
  background: var(--panel);
  border: 1px solid var(--borde-2);
  color: var(--texto);
  font-size: 13px;
  border-radius: var(--radio-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}

/* ==================================================================
   Botones
   Tamano estilo Supabase (28px). Acabado "raised": borde de 1px mas
   oscuro que el relleno, brillo interior arriba y sombra sutil.
   ================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 var(--control-px);
  font-size: var(--control-font);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  color: var(--texto);
  background: var(--superficie-2) linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(255, 255, 255, 0));
  border: 1px solid var(--borde-2);
  border-radius: var(--radio);
  box-shadow: var(--sombra-btn);
  cursor: pointer;
  user-select: none;
  transition: filter .15s, border-color .15s, background-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { border-color: var(--borde-3); filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--anillo); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; transform: none; }
.btn .icon { width: 14px; height: 14px; flex: none; }

.btn--primario {
  color: #fff;
  background-color: var(--acento);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, 0));
  border-color: var(--acento-borde);
  box-shadow: 0 1px 2px rgba(124, 116, 255, .35), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn--primario:hover { border-color: var(--acento-borde); filter: brightness(1.06); }

.btn--peligro {
  color: #fff;
  background-color: var(--rojo);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, 0));
  border-color: #c5301f;
  box-shadow: 0 1px 2px rgba(234, 67, 53, .3), inset 0 1px 0 rgba(255, 255, 255, .2);
}
.btn--peligro:hover { border-color: #c5301f; filter: brightness(1.06); }

.btn--fantasma {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--suave);
}
.btn--fantasma:hover { background: var(--superficie); border-color: var(--borde-2); color: var(--texto); filter: none; }

.btn--bloque { width: 100%; }
.btn--icono { width: var(--control-h); padding: 0; }

.btn[data-cargando] { pointer-events: none; }
.btn[data-cargando]::after {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: girar .6s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

/* ==================================================================
   Campos de formulario
   ================================================================== */

.campo { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.campo label { font-size: 12px; font-weight: 500; color: var(--suave); }

.input {
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--control-px);
  font-size: var(--control-font);
  color: var(--texto);
  background: var(--superficie);
  border: 1px solid var(--borde-2);
  border-radius: var(--radio);
  box-shadow: 0 1px 1px rgba(0, 0, 0, .25);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--tenue); }
.input:hover { border-color: var(--borde-3); }
.input:focus { outline: none; border-color: var(--acento); box-shadow: var(--anillo); }
.input:disabled, .input[readonly] { background: var(--panel); color: var(--tenue); }
.input.is-invalid { border-color: var(--rojo); box-shadow: 0 0 0 3px rgba(234, 67, 53, .18); }

/* Autocompletado de Chrome/Safari: mantener la paleta oscura */
.input:-webkit-autofill {
  -webkit-text-fill-color: var(--texto);
  -webkit-box-shadow: 0 0 0 40px var(--superficie) inset;
  caret-color: var(--texto);
}

/* Iconos (Feather, ver includes/icons.php). El <i> reserva el espacio
   mientras feather.replace() lo convierte en SVG. */
.icon { display: inline-block; flex: none; vertical-align: middle; }
i.icon[width="12"] { width: 12px; height: 12px; }
i.icon[width="14"] { width: 14px; height: 14px; }
i.icon[width="16"] { width: 16px; height: 16px; }
i.icon[width="18"] { width: 18px; height: 18px; }
i.icon[width="20"] { width: 20px; height: 20px; }
i.icon[width="22"] { width: 22px; height: 22px; }

/* Input con icono a la izquierda y accion a la derecha */
.input-grupo { position: relative; }
.input-grupo .input-icono {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--tenue); pointer-events: none;
}
.input-grupo .input-icono ~ .input { padding-left: 32px; }
.input-grupo .input-accion ~ .input,
.input-grupo .input:has(~ .input-accion) { padding-right: 34px; }
.input-accion {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 22px; height: 22px; padding: 0;
  background: none; border: 0; border-radius: 4px;
  color: var(--tenue); cursor: pointer;
  transition: color .15s, background-color .15s;
}
.input-accion:hover { color: var(--texto); background: var(--superficie-2); }
.input-accion:focus-visible { outline: none; box-shadow: var(--anillo); }
.input-accion .si-visible, .input-accion.es-visible .si-oculta { display: none; }
.input-accion.es-visible .si-visible { display: block; }

.campo-cabecera { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.enlace-suave { font-size: 12px; color: var(--suave); text-decoration: none; }
.enlace-suave:hover { color: var(--texto); }

/* Avisos */
.aviso {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 8px 12px; margin-bottom: 14px;
  font-size: 13px; border-radius: var(--radio);
  border: 1px solid var(--borde-2); background: var(--superficie);
}
.aviso .icon { margin-top: 2px; }
:root[data-theme="light"] .aviso--error { color: #c5221f; }
.aviso--error { color: #f28b82; border-color: rgba(234, 67, 53, .35); background: rgba(234, 67, 53, .08); }

/* ==================================================================
   Login
   ================================================================== */

.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%; max-width: 360px;
  padding: 28px 24px 24px;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
:root[data-theme="light"] .auth-card { box-shadow: 0 12px 32px rgba(16, 24, 40, .08); }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; margin-bottom: 14px;
  color: var(--acento);
  background: var(--superficie);
  border: 1px solid var(--borde-2);
  border-radius: 10px;
  box-shadow: var(--sombra-btn);
}
.auth-brand h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.auth-brand p { margin: 4px 0 0; font-size: 13px; color: var(--suave); }
.auth form .btn--primario { margin-top: 6px; }
.auth-instalar { margin-top: 10px; }
.auth-pie { margin: 18px 0 0; font-size: 12px; color: var(--tenue); }

/* ==================================================================
   Estructura de paginas internas: barra superior + menu lateral
   ================================================================== */

:root { --sidebar-w: 320px; --topbar-h: 56px; --bottomnav-h: 58px; }

body.con-shell { padding: 0; }

/* Boton circular (atras / menu) */
.btn-circulo {
  display: grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  color: var(--texto);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 50%;
  box-shadow: var(--sombra-tarjeta);
  cursor: pointer;
  transition: border-color .15s, background-color .15s, transform .05s;
}
.btn-circulo:hover { border-color: var(--borde-3); }
.btn-circulo:active { transform: scale(.96); }
.btn-circulo:focus-visible { outline: none; box-shadow: var(--anillo); }
.btn-circulo-espacio { width: 36px; height: 36px; }

/* Barra superior: boton a la izquierda, titulo centrado */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; gap: 12px;
  min-height: calc(var(--topbar-h) + var(--safe-top));
  padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  background: color-mix(in srgb, var(--fondo) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
}
.topbar-titulo {
  margin: 0; text-align: center;
  font-size: 17px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.contenido { padding: 8px calc(16px + var(--safe-right)) 24px calc(16px + var(--safe-left)); }

/* Menu lateral (en movil ocupa la pantalla, como una vista de ajustes) */
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 900;
  width: min(100%, 420px);
  display: flex; flex-direction: column;
  background: var(--fondo);
  border-right: 1px solid var(--borde-2);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform .28s cubic-bezier(.32, .72, 0, 1), visibility 0s linear .28s;
}
html.sidebar-abierto .sidebar { transform: none; visibility: visible; transition: transform .28s cubic-bezier(.32, .72, 0, 1); }
html.sidebar-abierto { overflow: hidden; }

/* Fondo del menu: efecto vidrio (oscurece y desenfoca lo de atras) */
.sidebar-fondo {
  position: fixed; inset: 0; z-index: 899;
  background: rgba(0, 0, 0, .35);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
  opacity: 0; pointer-events: none;
  transition: opacity .28s;
}
html.sidebar-abierto .sidebar-fondo { opacity: 1; pointer-events: auto; }
:root[data-theme="light"] .sidebar-fondo { background: rgba(16, 24, 40, .16); }

.sidebar-cabecera {
  display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px calc(16px + var(--safe-left));
  min-height: calc(var(--topbar-h) + var(--safe-top));
}
.sidebar-cabecera h2 { margin: 0; text-align: center; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }

.sidebar-cuerpo {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 16px calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

/* Tarjeta de perfil */
.perfil-tarjeta {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  color: var(--texto); text-decoration: none;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 10px;
  box-shadow: var(--sombra-tarjeta);
  transition: border-color .15s;
}
.perfil-tarjeta:hover { border-color: var(--borde-2); }
.avatar {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px;
  font-size: 13px; font-weight: 600; color: var(--acento);
  background: var(--superficie-2);
  border: 1px solid var(--borde-2);
  border-radius: 50%;
}
.perfil-texto { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.perfil-texto strong { font-size: 14px; font-weight: 600; }
.perfil-texto small { font-size: 12px; color: var(--suave); }

.seccion-titulo { margin: 22px 0 8px; font-size: 12px; font-weight: 500; color: var(--suave); }

/* Grupo de filas con divisores (estilo lista de ajustes) */
.grupo {
  padding: 2px 12px;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 10px;
  box-shadow: var(--sombra-tarjeta);
}
.seccion-titulo + .grupo { margin-top: 0; }
.grupo + .grupo { margin-top: 16px; }

.fila {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 46px; padding: 0;
  font-size: 14px; text-align: left; text-decoration: none;
  color: var(--texto);
  background: none; border: 0;
  cursor: pointer;
}
/* Divisor solo entre filas visibles */
.fila:not([hidden]) ~ .fila::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0;
  border-top: 1px solid var(--borde);
}
.fila-icono { color: var(--texto); }
.fila-texto { flex: 1; min-width: 0; transition: color .15s; }
.fila-flecha { color: var(--tenue); transition: transform .15s, color .15s; }
.fila:hover .fila-flecha { color: var(--suave); transform: translateX(2px); }
.fila:focus-visible { outline: none; box-shadow: var(--anillo); border-radius: 6px; }
.fila.activa .fila-texto, .fila.activa .fila-icono { color: var(--acento); }
.fila.activa .fila-texto { font-weight: 500; }
.fila--peligro .fila-icono, .fila--peligro .fila-texto { color: var(--rojo); }

/* Interruptor (modo oscuro) */
.switch {
  position: relative; flex: none;
  width: 34px; height: 20px;
  border: 1.5px solid var(--texto);
  border-radius: 999px;
  transition: background-color .2s;
}
.switch::after {
  content: ""; position: absolute; top: 2.5px; left: 3px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--texto);
  transition: transform .2s;
}
[aria-checked="true"] > .switch::after { transform: translateX(13px); }

/* Icono del tema: luna en oscuro, sol en claro */
.icono-tema-claro { display: none !important; }
:root[data-theme="light"] .icono-tema-oscuro { display: none !important; }
:root[data-theme="light"] .icono-tema-claro { display: inline-block !important; }

.sidebar-version { margin: 20px 0 0; text-align: center; font-size: 12px; color: var(--tenue); }

/* Estado vacio */
.vacio {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 48px 16px; text-align: center; color: var(--suave);
  background: var(--superficie); border: 1px dashed var(--borde-2); border-radius: 12px;
}
.vacio h2 { margin: 6px 0 0; font-size: 15px; font-weight: 600; color: var(--texto); }
.vacio p { margin: 0; font-size: 13px; }

/* Escritorio: menu fijo a la izquierda */
@media (min-width: 1024px) {
  .sidebar {
    width: var(--sidebar-w);
    transform: none; visibility: visible;
    background: var(--panel);
  }
  .sidebar-fondo, .sidebar-cerrar, .topbar-menu { display: none; }
  .sidebar-cabecera { grid-template-columns: 1fr; }
  .sidebar-cabecera .btn-circulo-espacio { display: none; }
  html.sidebar-abierto { overflow: auto; }
  body.con-shell { padding-left: var(--sidebar-w); }
  .topbar { grid-template-columns: 0 1fr 0; }
  .contenido { max-width: 1100px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
}

/* ==================================================================
   Barra de navegacion inferior (movil y tablet)
   ================================================================== */

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px calc(8px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(8px + var(--safe-left));
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--borde);
}
.bottomnav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 46px; padding: 0;
  font-size: 11px; font-weight: 500; text-decoration: none;
  color: var(--tenue);
  background: none; border: 0; border-radius: 8px;
  cursor: pointer;
  transition: color .15s;
}
.bottomnav-item:hover { color: var(--suave); }
.bottomnav-item:active .icon { transform: scale(.92); }
.bottomnav-item:focus-visible { outline: none; box-shadow: var(--anillo); }
.bottomnav-item .icon { transition: transform .1s; }
.bottomnav-item.activa { color: var(--acento); }
.bottomnav-item span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Espacio para que el contenido no quede debajo de la barra */
body.con-shell .contenido { padding-bottom: calc(var(--bottomnav-h) + 24px + var(--safe-bottom)); }
body.con-shell .pwa-toast { bottom: calc(var(--bottomnav-h) + 12px + var(--safe-bottom)); }

@media (min-width: 1024px) {
  .bottomnav { display: none; }
  body.con-shell .contenido { padding-bottom: 32px; }
  body.con-shell .pwa-toast { bottom: 16px; }
}

/* Sin conexion */
.vacio--offline .btn { margin-top: 12px; }
.aviso-conexion {
  position: fixed; left: 50%; top: calc(8px + var(--safe-top)); z-index: 1200;
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  font-size: 12px; font-weight: 500; color: #fff;
  background: var(--rojo);
  border: 1px solid #c5301f;
  border-radius: var(--radio-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
body.con-shell .aviso-conexion { top: calc(var(--topbar-h) + var(--safe-top) + 4px); }
