:root {
  --fondo: #f5f7fa; --tarjeta: #ffffff; --texto: #1a202c; --suave: #718096; --linea: #e2e8f0;
  --acento: #2b6cb0; --acento-texto: #ffffff;
  --ok: #2f855a; --alto: #b7791f; --muyalto: #dd6b20; --bajo: #c53030;
  --banda: rgba(47, 133, 90, 0.10); --banda-alta: rgba(214, 158, 46, 0.10);
  --interruptor-off: #cbd5e0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0f1620; --tarjeta: #18212d; --texto: #e2e8f0; --suave: #94a3b8; --linea: #2a3644;
    --acento: #63b3ed; --acento-texto: #0f1620;
    --ok: #48bb78; --alto: #ecc94b; --muyalto: #f6862a; --bajo: #fc8181;
    --banda: rgba(72, 187, 120, 0.12); --banda-alta: rgba(236, 201, 75, 0.10);
    --interruptor-off: #4a5568;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--fondo); color: var(--texto); min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex; justify-content: center;
}
main { width: 100%; max-width: 720px; }
/* Todas las vistas centradas en la pantalla (vertical y horizontalmente). */
.vista {
  display: grid; gap: 16px; align-content: center; justify-items: stretch;
  min-height: calc(100vh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
}
.oculto { display: none !important; }
.visualmente-oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tarjeta { background: var(--tarjeta); border-radius: 16px; padding: 24px; border: 1px solid var(--linea); }
h1 { font-size: 24px; margin-bottom: 8px; }
h2 { font-size: 15px; font-weight: 600; color: var(--suave); margin-bottom: 12px; }
.suave { color: var(--suave); }
.nota { color: var(--suave); font-size: 12px; margin-top: 16px; line-height: 1.45; }

/* Formularios */
.login, #vista-perfiles .tarjeta, #vista-vacia .tarjeta { max-width: 420px; margin: 0 auto; width: 100%; text-align: center; }
.login form { text-align: left; }
form { display: grid; gap: 14px; margin-top: 16px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--suave); }
input, select {
  font: inherit; font-size: 16px; color: var(--texto); background: var(--fondo);
  border: 1px solid var(--linea); border-radius: 10px; padding: 12px; min-height: 44px; width: 100%;
}
button {
  font: inherit; font-size: 16px; min-height: 44px; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--linea); background: var(--tarjeta); color: var(--texto);
}
button.primario { background: var(--acento); color: var(--acento-texto); border-color: transparent; font-weight: 600; }
button.peligro { color: var(--bajo); }
button:disabled { opacity: 0.6; cursor: wait; }
.error { color: var(--bajo); font-size: 14px; }
.casilla { display: flex; gap: 10px; align-items: flex-start; color: var(--texto); line-height: 1.4; }
.casilla input { width: 22px; height: 22px; min-height: 0; flex: none; margin-top: 1px; accent-color: var(--acento); }
a { color: var(--acento); }
.legal { max-width: 680px; margin: 0 auto; line-height: 1.55; }
.legal h2 { color: var(--texto); font-size: 17px; margin: 22px 0 8px; }
.legal p, .legal li { margin-bottom: 8px; }
.legal ul { padding-left: 20px; }

/* Lista de perfiles */
.perfiles { list-style: none; display: grid; gap: 10px; margin-top: 12px; }
.perfiles button { width: 100%; text-align: left; font-weight: 500; }

/* Barra superior del panel: logo a la izquierda, nombre del perfil centrado y los botones de periodo y ⋯ a la derecha.
   Las columnas laterales miden lo mismo para que el nombre quede centrado. El logo blanco se usa en modo oscuro (<picture>). */
.barra { display: grid; grid-template-columns: minmax(112px, 1fr) minmax(0, auto) minmax(112px, 1fr); gap: 10px; align-items: center; }
.logo { display: flex; align-items: center; justify-self: start; }
.logo img { display: block; height: 30px; width: auto; }
.logo-login { display: flex; justify-content: center; margin-bottom: 12px; }
.logo-login img { display: block; height: 48px; width: auto; }
.acciones { display: flex; gap: 10px; justify-content: flex-end; }
.titulo-perfil {
  margin: 0; text-align: center; font-size: 20px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; font-size: 22px; line-height: 1; min-width: 44px; min-height: 44px;
  display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--linea); background: var(--tarjeta);
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary .icono { width: 22px; height: 22px; }
.menu[open] summary { border-color: var(--suave); }
.menu-lista {
  position: absolute; right: 0; top: 52px; z-index: 10; width: min(320px, calc(100vw - 32px)); display: grid; gap: 6px; padding: 10px;
  background: var(--tarjeta); border: 1px solid var(--linea); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
/* El menú de periodo se abre hacia la derecha, alineado con su botón. */
/* El menú de periodo se abre bajo su botón, alineado a su derecha. */
.menu-periodo .menu-lista { width: min(260px, calc(100vw - 32px)); }
.menu-lista button { text-align: left; border: none; width: 100%; }
.menu-seccion { font-size: 12px; color: var(--suave); padding: 4px 16px 2px; text-transform: uppercase; letter-spacing: 0.04em; }
.menu-cuenta { text-transform: none; letter-spacing: 0; font-size: 13px; word-break: break-all; padding-bottom: 6px; }
.menu-perfiles { padding-bottom: 6px; border-bottom: 1px solid var(--linea); }
.menu-lista button[role="menuitemradio"][aria-checked="true"] { font-weight: 600; color: var(--acento); }
.menu-lista button[role="menuitemradio"][aria-checked="true"]::after { content: "✓"; float: right; }
/* Interruptor tipo iOS dentro del menú */
.menu-lista .menu-interruptor { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.interruptor {
  position: relative; flex: none; width: 42px; height: 26px; border-radius: 13px;
  background: var(--interruptor-off); transition: background 0.2s;
}
.interruptor::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s;
}
.menu-interruptor[aria-checked="true"] .interruptor { background: var(--ok); }
.menu-interruptor[aria-checked="true"] .interruptor::before { transform: translateX(16px); }

/* Valor actual */
.actual { text-align: center; }
.valor { font-size: clamp(64px, 18vw, 112px); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.valor small { font-size: 0.22em; font-weight: 500; color: var(--suave); margin-left: 6px; }
.flecha { font-size: 0.6em; margin-left: 8px; vertical-align: 0.12em; }
.meta { margin-top: 10px; color: var(--suave); font-size: 15px; }
.ok { color: var(--ok); } .alto { color: var(--alto); } .muyalto { color: var(--muyalto); } .bajo { color: var(--bajo); }
.viejo { opacity: 0.45; }
.aviso { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--bajo); color: var(--bajo); }
svg { width: 100%; height: auto; display: block; }
.eje { fill: var(--suave); font-size: 11px; }
/* El dedo desliza en horizontal por la gráfica sin impedir el desplazamiento vertical de la página. */
#grafica { touch-action: pan-y; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.pie { color: var(--suave); font-size: 12px; text-align: center; }
.cabecera-grafica { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; min-height: 24px; }
.titulo-periodo { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lectura-cursor { font-size: 15px; color: var(--suave); font-variant-numeric: tabular-nums; white-space: nowrap; }
.resumen { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-top: 10px; font-size: 13px;
  color: var(--suave); font-variant-numeric: tabular-nums; }
.resumen span:first-child { color: var(--texto); font-weight: 600; }

/* Diálogo */
dialog {
  margin: auto; border: 1px solid var(--linea); border-radius: 16px; padding: 24px; width: min(420px, calc(100vw - 32px));
  background: var(--tarjeta); color: var(--texto);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog form { margin-top: 0; }
.botones { display: flex; gap: 10px; justify-content: flex-end; }
