/* =====================================================================
   MiesApp — LAYOUT
   El armazón: el shell (#app), las pantallas y sus modos de scroll, la
   cabecera fija, los widgets del home, el calendario, la barra inferior
   fija, y las adaptaciones a tablet/desktop. Comportamiento sutil: no
   tocar sin comparar (el scroll infinito depende de que .body-in sea su
   propio contenedor de scroll, no el viewport).
   ===================================================================== */

/* ---- Shell ---- */
#app {
  /* La app va CLAVADA al viewport visible, no al documento. Con el teclado
     abierto iOS desplaza el "visual viewport" (offsetTop) para revelar el
     campo enfocado; con position:fixed + translateY(--vvtop) la app sigue
     exactamente el área visible, y --vh le da el alto justo. Los dos valores
     los mide el JS con visualViewport (ver initTeclado). */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  max-width: var(--app-max);
  height: var(--vh, 100dvh);
  transform: translateY(var(--vvtop, 0px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Barra de la demo pública ---- */
#demo-bar { display: none; }
.modo-demo #demo-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-shrink: 0;
  background: var(--mies); color: #fff;
  padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top));
  font-size: 13px; font-weight: 500;
}
.modo-demo #demo-bar .demo-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modo-demo #demo-bar .demo-cta {
  flex-shrink: 0; width: auto; height: auto;
  border: none; background: #fff; color: var(--mies);
  font-weight: 600; font-size: 12.5px; font-family: inherit;
  border-radius: var(--rad-pill); padding: 6px 12px; cursor: pointer;
}
.modo-demo #demo-bar .demo-cta:active { transform: scale(.97); }

/* ---- Pantallas ---- */
.scr {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
}
/* Pantallas simples (formularios de un paso, wizards): scrollea la .scr entera. */
.scr.on {
  display: flex;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
.grow { flex: 1; min-height: 24px; }

/* Pantallas "split": título fijo arriba (.hdr), botones fijos abajo
   (.sticky-bottom), y en el medio el único bloque que scrollea (.body-in).
   La .scr deja de scrollear, así los botones nunca quedan tapados ni el
   rebote se escapa al resto de la pantalla. */
.scr.split.on { overflow: hidden; }
.scr.split    { padding-bottom: 0; }
.body-in {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

/* ---- Cabecera fija ---- */
.hdr {
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: -18px;                     /* compensa el padding de la pantalla */
  background-color: var(--bg);
  z-index: var(--z-header);
  padding: 18px 0 10px 0;
  margin: -18px 0 16px 0;
}

.bk {
  border: 1px solid var(--border);
  background: var(--bg);
  width: 38px;
  height: 38px;
  border-radius: var(--rad-round);
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bk:disabled { opacity: .35; cursor: default; }

.bell-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: var(--rad-pill);
  background: var(--bad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  display: none;
}

.dots { display: flex; gap: 5px; margin-left: auto; }
.dots i    { width: 7px; height: 7px; border-radius: var(--rad-round); background: var(--border2); }
.dots i.on { background: var(--primary); }

/* ---- Helpers de layout ---- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mb8  { margin-bottom: 8px; }
.mb14 { margin-bottom: 14px; }
.mt0  { margin-top: 0; }
.gap8 { gap: 8px; }
.sentinel { height: 1px; }

/* ---- Home ---- */
#s-home { overflow: hidden; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.home-hdr { display: flex; align-items: flex-start; justify-content: space-between; flex-shrink: 0; margin-bottom: 12px; }
.home-hdr h1 { margin-bottom: 0; }

.home-widgets { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 10px; margin-bottom: 12px; }
.widget { display: flex; flex-direction: column; min-height: 0; margin-bottom: 0; padding: 14px 14px 10px; }
.widget .wtitle { font-size: 13.5px; font-weight: 600; color: var(--sec); margin: 0 0 8px; flex-shrink: 0; }

#card-agenda   { flex: 1 0 50%; min-height: 50%; padding-bottom: 14px; }
#card-deben    { flex: 0 1 auto; max-height: 50%; padding-bottom: 14px; }
#card-resumen  { flex: 0 0 auto; }
#home-mes-title { text-transform: capitalize; }

/* Cabecera del resumen: mes centrado + flechitas a los lados */
.resumen-hdr { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.resumen-hdr .wtitle { flex: 1; text-align: center; margin: 0; }
.mnav { width: 30px; height: 30px; flex-shrink: 0; border: none; background: none; padding: 0; border-radius: var(--rad-round); color: var(--sec); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.mnav:active { background: var(--surf); }
.mnav:disabled { opacity: .3; cursor: default; }
.mnav .ico { width: 20px; height: 20px; }

.wscroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  mask-image: linear-gradient(to bottom, black 88%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, black 88%, transparent);
}

#home-ses { padding-bottom: 14px; }
#home-ses .sesrow { margin-bottom: 6px; }
/* "Deben" es una lista corta y acotada: sin el fade (que parecía "sigue la
   lista") y con aire abajo para que el último no quede pegado al borde. */
#home-deben { -webkit-mask-image: none; mask-image: none; padding-bottom: 8px; }
#home-deben .mrow { padding: 10px 2px; }

/* Resumen de Caja: sin etiquetas, flecha ↑ verde (ingreso), ↓ roja (egreso),
   saldo en negro sin flecha. */
#home-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; }
#home-summary .ms { display: flex; align-items: center; justify-content: center; gap: 3px; font-weight: 600; font-size: 15px; }
#home-summary .ms .ico { width: 15px; height: 15px; }
#home-summary .ms-sal { color: var(--text); }

/* Caja: mes con flechas y card de resumen, fijos arriba de la lista. */
/* La card de resumen vive dentro de .cal-fixed-top, debajo del cal-hdr. */
.mov-resumen { padding: 10px 14px; margin: 0; }

.home-nav { flex-shrink: 0; }

/* ---- Movimientos: tabs fijas arriba de la lista ---- */
#s-movs .tabbar { position: sticky; top: 0; z-index: var(--z-sticky); }

/* ---- Calendario ---- */
.cal-fixed-top {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: var(--z-cal);
  margin: -16px -16px 10px -16px;
  padding: 0 16px 5px 16px;
  border-bottom: 1px solid var(--border);
}
.cal-hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 600; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.cal-dow { text-align: center; font-size: 11.5px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal span:not(.cal-dow) { aspect-ratio: 1; }

.cal-d {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--rad-sm);
  background: none;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 6px 0;
  transition: all var(--tr);
}
.cal-d:active { transform: scale(.95); }
.cal-d i {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  background: transparent;
  color: var(--acento);
  font-style: normal;
  font-weight: 800;
  font-size: 10px;
  margin: 0;
}
.cal-hoy { border-color: var(--primary); font-weight: 700; }
.cal-con { background: var(--surf); }
.cal-d.cal-sel   { background: var(--primary); color: var(--onprimary); border-color: var(--primary); }
.cal-d.cal-sel i { color: var(--onprimary); }
/* La lista de sesiones del día no queda pegada al mes: se le da un margen
   claro respecto de la grilla del calendario que tiene arriba. */
#cal-dia { padding-top: 18px; margin-top: 4px; }

/* ---- Splash ---- (marca Mies: fondo azul, logo blanco, "hecho por dfrnt")
   El logo va por CÓDIGO: SVG inline, no una imagen raster. */
#splash {
  position: fixed;
  inset: 0;
  background: #fff;             /* splash BLANCO → barras del navegador blancas */
  z-index: var(--z-splash);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Reserva el alto del bloque "hecho por" abajo, así "mies" queda centrado
     en el espacio que queda arriba, no en toda la pantalla. */
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  transition: opacity .4s;
}
#splash .splash-logo { width: 150px; height: auto; display: block; }
#splash .splash-logo path { fill: var(--mies); }   /* mies en azul mies */
#splash .splash-by {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(38px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--sec);            /* "hecho por" en gris */
}
#splash .splash-by .by-txt {
  font-size: 11px;
  margin-bottom: 5px;
  letter-spacing: .02em;
}
#splash .splash-by .by-dfrnt {
  width: 62px;
  height: auto;
  display: block;
  margin: 0 auto;
}
#splash .splash-by .by-dfrnt path { fill: #f91a2a; }   /* dfrnt en rojo */

/* ---- Barra inferior fija ---- */
.sticky-bottom {
  flex-shrink: 0;                 /* nunca se achica ni scrollea: vive fuera de .body-in */
  background: var(--bg);
  padding: 10px 0 calc(12px + env(safe-area-inset-bottom));
}
/* Con el teclado abierto no hay barra de gestos abajo: ese margen sobra y
   deja un hueco feo debajo del campo de texto. */
.kb-open .sticky-bottom { padding-bottom: 10px; }

.optscroll { overflow-y: auto; max-height: 55dvh; }

/* ---- Pantalla de acceso (enrolamiento + PIN) ----
   Vive fuera de #app: cubre la ventana hasta que la profesional entra. Usa
   los tokens y las clases del sistema; no inventa componentes nuevos. */
#auth {
  position: fixed;
  inset: 0;
  z-index: 900;                 /* sobre #app, bajo splash/loader/toast */
  background: var(--bg);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px calc(24px + env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}
#auth.on { display: flex; }
.auth-box { width: 100%; max-width: 320px; }
/* Logo Mies (SVG inline) en la pantalla de acceso, en el azul de la marca. */
.auth-logo { width: 120px; height: auto; display: block; margin: 0 auto 22px; }
.auth-logo path { fill: var(--mies); }
.auth-sub { text-align: center; margin: 0 0 20px; }
.auth-scr { display: none; }
.auth-scr.on { display: block; }
.auth-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--sec);
  margin: 0 2px 14px;
  cursor: pointer;
}
.auth-check input {
  width: 18px; height: 18px; margin: 0; padding: 0;
  flex-shrink: 0;
  appearance: auto; -webkit-appearance: checkbox;
  accent-color: var(--mies);
}
/* Campo de código/PIN: números grandes y centrados, cómodos en el pulgar. */
.auth-pin {
  text-align: center;
  letter-spacing: 8px;
  font-size: 22px;
  font-weight: 600;
}

/* =====================================================================
   TABLET (≥768px)
   ===================================================================== */
@media (min-width: 768px) {
  #app { max-width: var(--app-max-tablet); }
  .scr { padding: 26px; }
  h1 { font-size: 30px; }
  h2 { font-size: 24px; }
  .card { border-radius: var(--rad-xl); }
  .hc3 { min-height: 115px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
  .bigopt { min-height: 62px; }
  .appbtn { min-height: 56px; }
  .ghostbtn { min-height: 54px; }
  input, select { height: 54px; }
  #s-home { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .home-widgets { gap: 16px; }
  #card-deben { max-height: 42%; }

  .hdr { top: -26px; margin-top: -26px; padding-top: 26px; }

  #agenda-list {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
  }
}

/* =====================================================================
   DESKTOP (≥1200px)
   ===================================================================== */
@media (min-width: 1200px) {
  #app { max-width: var(--app-max-desk); }
  .scr { padding: 34px; }
  .home-widgets { grid-template-columns: 7fr 3fr; }

  .hdr { top: -34px; margin-top: -34px; padding-top: 34px; }
  #agenda-list {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
  }

  /* Vista Calendario en desktop: 2 columnas, calendario a la izquierda y la
     lista del día a la derecha con su propio scroll. .cal-fixed-top pierde el
     "sangrado" negativo (era para pegarse al borde en mobile) y deja de ser
     sticky: acá ya está fijo en su columna. */
  #agenda-list.is-cal {
    display: grid;
    grid-template-columns: 340px 1fr;
    column-gap: 32px;
    align-items: start;
  }
  #agenda-list.is-cal .cal-fixed-top {
    grid-column: 1;
    position: static;
    margin: 0;
    padding: 0;
    border-bottom: none;
  }
  #agenda-list.is-cal #cal-dia {
    grid-column: 2;
    align-self: stretch;
    max-height: 100%;
    overflow-y: auto;
    padding-top: 0;
  }
}

/* =====================================================================
   HOVER (solo donde hay puntero real)
   ===================================================================== */
@media (hover: hover) {
  .appbtn:hover { background: #2b2b2e; }
  .ghostbtn:hover, .bk:hover, .hc3:hover, .bigopt:hover { background: var(--surf); }
  .prow:hover, .mrow:hover, .sesrow:hover { background: var(--surf); }
  .tab:hover:not(.sel) { color: var(--text); }
  .cal-d:hover:not(.cal-sel) { background: var(--border); }
}
