:root {
  --fondo: #E9EDF2;
  --superficie: #FFFFFF;
  --hundido: #DCE2EA;
  --tinta: #182132;
  --tinta-2: #4E5A6E;
  --tinta-3: #7D889A;
  --linea: #CDD5E0;
  --accion: #2C55E8;
  --accion-tinta: #FFFFFF;
  --libre: #12805A;
  --libre-fondo: #DDF3EA;
  --reservado: #9A6500;
  --reservado-fondo: #FBEFD3;
  --vendido: #364257;
  --vendido-fondo: #E4E9F1;
  --retirado: #B5372A;
  --retirado-fondo: #F8E1DE;
  --sombra: 0 1px 0 rgba(24, 33, 50, .06), 0 6px 18px -10px rgba(24, 33, 50, .25);
  --radio: 14px;
  --nav-alto: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #121722;
    --superficie: #1B2230;
    --hundido: #252E3F;
    --tinta: #E8EDF5;
    --tinta-2: #A9B4C6;
    --tinta-3: #7A869A;
    --linea: #2E384A;
    --accion: #6C8CFF;
    --accion-tinta: #0E1424;
    --libre: #4FD3A0;
    --libre-fondo: #133328;
    --reservado: #F0B84A;
    --reservado-fondo: #3A2E14;
    --vendido: #C6D0E0;
    --vendido-fondo: #2A3345;
    --retirado: #FF8A7A;
    --retirado-fondo: #3D201D;
    --sombra: 0 1px 0 rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fondo);
  color: var(--tinta);
  font-family: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accion); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Cabecera y buscador ---------- */
.cabecera {
  position: sticky; top: 0; z-index: 20;
  background: var(--fondo);
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
}
.titulo-fila { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.titulo-fila h1 {
  margin: 0; font-size: 28px; line-height: 1.1; font-weight: 800; font-stretch: 78%; letter-spacing: -.01em;
}
.titulo-fila .total { color: var(--tinta-3); font-size: 14px; }
.modo {
  display: flex; align-items: flex-start; gap: 8px; margin: -2px 0 10px; font-size: 13px; line-height: 1.35; color: var(--tinta-2);
}
.modo .punto { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--libre); }
.modo.vieja { color: var(--reservado); }
.modo.vieja .punto { background: var(--reservado); }
.buscador { position: relative; }
.buscador input {
  width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--linea);
  background: var(--superficie); padding: 0 40px 0 42px; font-size: 16px;
}
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.buscador svg { position: absolute; left: 13px; top: 13px; width: 20px; height: 20px; color: var(--tinta-3); }
.buscador .limpiar {
  position: absolute; right: 4px; top: 4px; width: 38px; height: 38px; border: 0; background: none; color: var(--tinta-3); font-size: 22px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--linea); background: var(--superficie); color: var(--tinta-2);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--tinta); border-color: var(--tinta); color: var(--fondo); }

/* ---------- Lista ---------- */
main { padding: 4px 16px calc(var(--nav-alto) + 90px + env(safe-area-inset-bottom)); }
.lista { display: grid; gap: 10px; }
.cuenta {
  background: var(--superficie); border-radius: var(--radio); box-shadow: var(--sombra);
  padding: 12px 12px 10px; border: 0; text-align: left; width: 100%; display: block;
}
.cuenta .juego { font-weight: 700; font-size: 17px; line-height: 1.25; }
.cuenta .email { color: var(--tinta-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cuenta .lanzamiento { color: var(--reservado); font-size: 13px; font-weight: 600; margin-top: 2px; }

/* Los tres huecos de una cuenta: el elemento distintivo del panel */
.huecos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.hueco {
  border-radius: 9px; padding: 6px 8px 7px; min-height: 48px; min-width: 0;
  background: var(--vendido-fondo); color: var(--vendido);
  border: 1.5px solid transparent;
}
.hueco .plat { font-size: 12px; font-weight: 700; font-stretch: 80%; opacity: .8; }
.hueco .quien { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hueco.libre { background: transparent; border-color: var(--libre); color: var(--libre); }
.hueco.reservado { background: var(--reservado-fondo); color: var(--reservado); }
.hueco.retirado { background: var(--retirado-fondo); color: var(--retirado); }
.hueco.retirado .quien { text-decoration: line-through; }
.hueco.na { background: transparent; border: 1.5px dashed var(--linea); color: var(--tinta-3); }

.vacio { text-align: center; color: var(--tinta-2); padding: 48px 16px; }
.vacio strong { display: block; color: var(--tinta); font-size: 18px; margin-bottom: 4px; }
.mas { margin: 14px auto 0; display: block; }
.cargando { text-align: center; color: var(--tinta-3); padding: 24px; }

/* ---------- Resultados de búsqueda ---------- */
.seccion-titulo { font-size: 15px; font-weight: 700; color: var(--tinta-2); margin: 16px 2px 8px; }
.fila-cliente {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  background: var(--superficie); border: 0; border-radius: 12px; padding: 13px 14px; box-shadow: var(--sombra);
  text-align: left; font-size: 17px; font-weight: 600; margin-bottom: 8px;
}
.fila-cliente .flecha { color: var(--tinta-3); }

/* ---------- Navegación inferior ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--superficie); border-top: 1px solid var(--linea);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  height: var(--nav-alto); border: 0; background: none; color: var(--tinta-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 600; font-stretch: 85%; position: relative;
}
.nav button svg { width: 24px; height: 24px; }
.nav button[aria-current="page"] { color: var(--accion); }
.nav button[aria-current="page"]::before {
  content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accion);
}
.nav .badge {
  position: absolute; top: 7px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--libre); color: var(--superficie); font-size: 11px; line-height: 18px;
}

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-alto) + 16px + env(safe-area-inset-bottom)); z-index: 25;
  height: 52px; padding: 0 20px 0 16px; border-radius: 26px; border: 0;
  background: var(--accion); color: var(--accion-tinta); font-weight: 700; font-size: 16px;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 8px 20px -8px rgba(44, 85, 232, .6);
}
.fab svg { width: 22px; height: 22px; }

/* ---------- Hojas (paneles que suben) ---------- */
.velo { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); z-index: 40; opacity: 0; transition: opacity .2s; }
.velo.abierto { opacity: 1; }
.hoja {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; max-height: 92dvh;
  background: var(--fondo); border-radius: 20px 20px 0 0; overflow: hidden;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.hoja.abierta { transform: translateY(0); }
@media (min-width: 720px) {
  .hoja { left: 50%; width: 640px; margin-left: -320px; }
}
.hoja-cab {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 16px 12px;
  background: var(--superficie); border-bottom: 1px solid var(--linea);
}
.hoja-cab::before {
  content: ''; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--linea);
}
.hoja-cab .txt { flex: 1; min-width: 0; padding-top: 10px; }
.hoja-cab h2 { margin: 0; font-size: 21px; line-height: 1.2; font-weight: 800; font-stretch: 82%; }
.hoja-cab .sub { color: var(--tinta-2); font-size: 14px; word-break: break-all; }
.hoja-cab .cerrar { margin-top: 6px; width: 40px; height: 40px; border-radius: 20px; border: 0; background: var(--hundido); font-size: 20px; }
.hoja-cuerpo { overflow-y: auto; padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.bloque { background: var(--superficie); border-radius: var(--radio); padding: 4px 14px; margin-bottom: 12px; box-shadow: var(--sombra); }
.bloque h3 { font-size: 15px; margin: 12px 0 4px; color: var(--tinta-2); font-weight: 700; }
.dato { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--linea); }
.dato:last-child { border-bottom: 0; }
.dato .k { color: var(--tinta-2); font-size: 14px; flex: none; }
.dato .v { text-align: right; font-weight: 600; word-break: break-all; display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.copiar { border: 0; background: var(--hundido); border-radius: 8px; padding: 5px 9px; font-size: 13px; flex: none; }

/* Huecos en detalle */
.hueco-detalle { padding: 12px 0; border-bottom: 1px solid var(--linea); }
.hueco-detalle:last-child { border-bottom: 0; }
.hueco-detalle .cab { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hueco-detalle .nombre { font-weight: 700; }
.estado {
  font-size: 13px; font-weight: 700; border-radius: 6px; padding: 2px 8px;
  background: var(--vendido-fondo); color: var(--vendido);
}
.estado.libre { background: var(--libre-fondo); color: var(--libre); }
.estado.reservado { background: var(--reservado-fondo); color: var(--reservado); }
.estado.retirado { background: var(--retirado-fondo); color: var(--retirado); }
.estado.na { background: var(--hundido); color: var(--tinta-3); }
.hueco-detalle .cliente-link { border: 0; background: none; padding: 4px 0; color: var(--accion); font-weight: 600; font-size: 16px; }
.hueco-detalle .meta { color: var(--tinta-3); font-size: 13px; }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.btn {
  border: 1px solid var(--linea); background: var(--superficie); border-radius: 10px;
  min-height: 42px; padding: 0 14px; font-weight: 600; font-size: 15px;
}
.btn.primario { background: var(--accion); border-color: var(--accion); color: var(--accion-tinta); }
.btn.peligro { color: var(--retirado); border-color: var(--retirado); background: transparent; }
.btn.ancho { width: 100%; }
.btn:disabled { opacity: .5; }

/* Formularios */
.campo { display: block; margin: 10px 0; }
.campo span { display: block; font-size: 14px; color: var(--tinta-2); margin-bottom: 4px; }
.campo input, .campo select, .campo textarea {
  width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid var(--linea);
  background: var(--superficie); padding: 9px 12px; font-size: 16px;
}
.campo textarea { min-height: 120px; resize: vertical; }
.campo.check { display: flex; align-items: center; gap: 10px; }
.campo.check input { width: 22px; min-height: 22px; height: 22px; }
.campo.check span { margin: 0; color: var(--tinta); }
.ayuda { color: var(--tinta-3); font-size: 13px; margin: 4px 0 10px; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.aviso-bloqueado {
  background: var(--retirado-fondo); color: var(--retirado); border-radius: 12px; padding: 10px 14px; font-weight: 700; margin-bottom: 12px;
}
.item-simple { padding: 10px 0; border-bottom: 1px solid var(--linea); }
.item-simple:last-child { border-bottom: 0; }
.item-simple .t { font-weight: 600; }
.item-simple .m { color: var(--tinta-2); font-size: 14px; }
.item-boton { width: 100%; background: none; border: 0; text-align: left; padding: 10px 0; border-bottom: 1px solid var(--linea); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item-boton:last-child { border-bottom: 0; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px; max-width: 420px; margin: 0 auto;
}
.login .marca { display: flex; gap: 6px; margin-bottom: 18px; }
.login .marca i { width: 26px; height: 34px; border-radius: 7px; display: block; }
.login .marca i:nth-child(1) { background: var(--libre); }
.login .marca i:nth-child(2) { background: var(--vendido-fondo); border: 1.5px solid var(--vendido); }
.login .marca i:nth-child(3) { border: 1.5px dashed var(--tinta-3); }
.login h1 { font-size: 36px; line-height: 1.05; font-weight: 800; font-stretch: 75%; margin: 0 0 6px; }
.login p { color: var(--tinta-2); margin: 0 0 20px; }
.error { color: var(--retirado); font-weight: 600; min-height: 1.4em; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-alto) + 84px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--tinta); color: var(--fondo); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  max-width: calc(100vw - 32px); transition: opacity .2s, transform .2s;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }
#toast.mal { background: var(--retirado); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .hoja, .velo, #toast { transition: none; }
}
