/* AplicaInsulina · sistema visual
   Tema: compañero diario para controlar la diabetes con insulina.
   Audiencia: la persona con diabetes, mirando el móvil antes o después de comer.
   Trabajo: registrar rápido y leer de un vistazo si la glucosa está bien.
   Firma: la glucosa siempre con su color de rango (bajo, en rango, alto, muy alto). */

:root {
  /* Color */
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #12201d;
  --muted: #586964;
  --line: #dde5e2;
  --accent: #0a7a6e;
  --accent-ink: #ffffff;
  --accent-soft: #dff1ed;
  --danger: #c4321c;
  --danger-soft: #fdeceb;
  --ok: #157a3c;
  --info: #1f5fbf;
  --info-soft: #e8f0fc;
  --warn: #a35a00;

  /* Rangos de glucosa (texto y fondo) */
  --g-bajo: #c4321c;      --g-bajo-bg: #fde7e4;
  --g-rango: #12804a;     --g-rango-bg: #dcf3e5;
  --g-alto: #a35a00;      --g-alto-bg: #fdf0d9;
  --g-muy-alto: #7b3fc4;  --g-muy-alto-bg: #f0e7fb;

  /* Franjas */
  --f-desayuno: #b7791f;  --f-comida: #0a7a6e;  --f-merienda: #b4436c;  --f-cena: #4b5fc2;

  /* Tipografía (escala 1.25) */
  --fuente: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Helvetica Neue", sans-serif;
  --fuente-display: "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Display", Roboto, sans-serif;
  --step--2: 0.72rem;
  --step--1: 0.84rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.5rem;
  --step-3: clamp(1.7rem, 1.4rem + 1.5vw, 2.1rem);
  --step-4: clamp(2.4rem, 2rem + 2vw, 3rem);

  /* Espaciado (base 4) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --radius-s: 10px;
  --radius: 16px;
  --radius-l: 22px;
  --shadow: 0 1px 2px rgb(16 32 28 / 6%), 0 4px 14px rgb(16 32 28 / 6%);
  --shadow-alta: 0 10px 30px rgb(16 32 28 / 14%);
  --anillo: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
  --t-rapida: 160ms cubic-bezier(.2, .7, .3, 1);
  --barra-inferior: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1312;
    --surface: #151d1b;
    --surface-2: #1b2624;
    --ink: #e5eeeb;
    --muted: #93a6a0;
    --line: #26332f;
    --accent: #36c9b6;
    --accent-ink: #032420;
    --accent-soft: #11332e;
    --danger: #ff7f6e;
    --danger-soft: #3a1714;
    --ok: #5fd68f;
    --info: #8bb4ff;
    --info-soft: #172640;
    --warn: #f4b04f;
    --g-bajo: #ff8a78;      --g-bajo-bg: #3d1a15;
    --g-rango: #5fd68f;     --g-rango-bg: #123323;
    --g-alto: #f4b04f;      --g-alto-bg: #382a10;
    --g-muy-alto: #c7a1ff;  --g-muy-alto-bg: #2c1d45;
    --f-desayuno: #e6b35c;  --f-comida: #36c9b6;  --f-merienda: #f08bb0;  --f-cena: #9aa8ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
    --shadow-alta: 0 12px 34px rgb(0 0 0 / 45%);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--step-0)/1.55 var(--fuente);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--fuente-display); line-height: 1.2; margin: 0 0 var(--sp-3); }
h1 { font-size: var(--step-3); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: var(--step-1); font-weight: 650; letter-spacing: -0.01em; display: flex; align-items: center; gap: var(--sp-2); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--accent); text-underline-offset: 3px; }
code { font-size: .88em; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); }
small { font-size: .7em; font-weight: 500; color: var(--muted); }
abbr { text-decoration: none; }
:focus-visible { outline: none; box-shadow: var(--anillo); border-radius: 8px; }
[hidden] { display: none !important; }

.icono { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.25em; }
.icono-grande { width: 44px; height: 44px; color: var(--muted); opacity: .6; }

.saltar { position: absolute; left: -999px; top: 8px; z-index: 50; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.saltar:focus { left: 8px; }

/* ---------- Barra superior ---------- */
.barra {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) var(--sp-4) 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.marca { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 500 var(--step-1)/1 var(--fuente-display); letter-spacing: -0.01em; }
.marca img { border-radius: 9px; box-shadow: var(--shadow); }
.marca b { font-weight: 750; color: var(--accent); }
.acciones-barra { display: flex; align-items: center; gap: var(--sp-1); }
.acciones-barra form { margin: 0; }
.boton-icono {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  transition: background var(--t-rapida), color var(--t-rapida);
}
.boton-icono:hover, .boton-icono[aria-current="page"] { background: var(--surface-2); color: var(--accent); }

/* ---------- Navegación: barra inferior en móvil, pestañas arriba en escritorio ---------- */
.pestanas {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--barra-inferior) + env(safe-area-inset-bottom));
  padding: 6px var(--sp-2) env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--line);
}
.pestanas a {
  flex: 1; max-width: 96px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: var(--step--2); font-weight: 600;
  border-radius: 14px; transition: color var(--t-rapida), background var(--t-rapida);
}
.pestanas a .icono { width: 24px; height: 24px; }
.pestanas a[aria-current="page"] { color: var(--accent); }
.pestanas a[aria-current="page"] .icono { stroke-width: 2.4; }
.pestana-principal .icono {
  width: 46px !important; height: 46px !important; padding: 11px; margin-top: -22px;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  box-shadow: var(--shadow-alta), 0 0 0 5px var(--bg);
}
.pestanas a.pestana-principal { color: var(--ink); }
body.con-sesion { padding-bottom: calc(var(--barra-inferior) + env(safe-area-inset-bottom)); }

@media (min-width: 768px) {
  .pestanas {
    position: sticky; top: 61px; inset: auto; height: auto; z-index: 15;
    justify-content: center; gap: var(--sp-1); padding: var(--sp-2) var(--sp-4);
    border-top: 0; border-bottom: 1px solid var(--line); background: var(--bg);
  }
  .pestanas a { flex: none; max-width: none; flex-direction: row; gap: var(--sp-2); padding: 8px 14px; font-size: var(--step--1); }
  .pestanas a .icono { width: 18px; height: 18px; }
  .pestanas a[aria-current="page"] { background: var(--accent-soft); }
  .pestana-principal .icono { width: 18px !important; height: 18px !important; padding: 0; margin: 0; background: none; color: inherit; box-shadow: none; }
  .pestanas a.pestana-principal { background: var(--accent); color: var(--accent-ink); }
  body.con-sesion { padding-bottom: 0; }
}

/* ---------- Estructura ---------- */
.contenido { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: var(--sp-4) var(--sp-4) var(--sp-6); }
.pie {
  display: flex; gap: var(--sp-2); align-items: center; justify-content: center;
  text-align: center; font-size: var(--step--2); color: var(--muted);
  padding: var(--sp-4) var(--sp-4) var(--sp-5);
}
.pie .icono { width: 14px; height: 14px; color: var(--accent); }
.seccion { margin-bottom: var(--sp-5); }
.titulo-seccion { font-size: var(--step-0); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin: var(--sp-5) 0 var(--sp-3); }
.dia { font-size: var(--step--1); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin: var(--sp-5) 0 var(--sp-2); }
.secundario { color: var(--muted); font-size: var(--step--1); }
.ayuda { font-size: var(--step--1); color: var(--muted); margin: calc(-1 * var(--sp-2)) 0 var(--sp-3); }
.texto-error { color: var(--danger) !important; }
.migas { margin-bottom: var(--sp-2); font-size: var(--step--1); }
.migas a { text-decoration: none; font-weight: 600; }

/* ---------- Tarjetas ---------- */
.tarjeta {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: var(--sp-5); margin-bottom: var(--sp-4); box-shadow: var(--shadow);
}
.tarjeta-plana { box-shadow: none; background: transparent; }
.tarjeta.estrecha { max-width: 440px; margin: var(--sp-5) auto; }
.zona-peligro { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.vacio { text-align: center; padding: var(--sp-6) var(--sp-4); color: var(--muted); border: 1.5px dashed var(--line); border-radius: var(--radius-l); }
.vacio p { margin: var(--sp-2) 0 0; }

/* ---------- Avisos ---------- */
.aviso {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); margin-bottom: var(--sp-3);
  background: var(--surface); border: 1px solid var(--line); font-size: var(--step--1); font-weight: 500;
  animation: entrar 220ms ease-out;
}
.aviso .icono { margin-top: 1px; }
.aviso-ok { background: var(--g-rango-bg); border-color: transparent; color: var(--ok); }
.aviso-error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.aviso-info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.aviso-alerta { background: #b42318; border-color: #b42318; color: #fff; font-weight: 650; font-size: var(--step-0); }
.aviso a { color: inherit; font-weight: 650; }
@keyframes entrar { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- Botones ---------- */
.boton {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  width: 100%; min-height: 50px; padding: 12px 18px; margin-bottom: var(--sp-3);
  font: 650 var(--step-0)/1.2 var(--fuente); text-align: center; text-decoration: none;
  border: 1.5px solid var(--accent); border-radius: 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  transition: transform var(--t-rapida), filter var(--t-rapida), background var(--t-rapida);
}
.boton:hover { filter: brightness(1.06); }
.boton:active { transform: scale(.98); }
.boton:disabled { opacity: .55; cursor: progress; }
form .boton { margin-bottom: 0; margin-top: var(--sp-2); }
.boton-secundario { background: transparent; color: var(--accent); }
.boton-secundario:hover { background: var(--accent-soft); filter: none; }
.boton-peligro { background: var(--danger); border-color: var(--danger); color: #fff; }
.boton-pequeno { width: auto; min-height: 40px; padding: 8px 16px; margin: 0; font-size: var(--step--1); border-radius: 12px; }
.boton-enlace { background: none; border: 0; color: var(--accent); font: 600 var(--step--1) var(--fuente); cursor: pointer; padding: 6px; }
.botones-fila { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.botones-fila .boton { flex: 1; min-width: 140px; }
.peligro { text-align: center; margin: var(--sp-2) 0 var(--sp-5); }

/* ---------- Formularios ---------- */
.campo { margin-bottom: var(--sp-4); }
.campo > label { display: block; font-size: var(--step--1); font-weight: 650; margin-bottom: 6px; }
.campo input:not([type=checkbox]), .campo select, .campo textarea,
.en-linea input, .form-en-linea input[type=number], .entrada-codigo, .tabla-alimentos input {
  width: 100%; min-height: 48px; padding: 11px 14px;
  font: 500 var(--step-0)/1.3 var(--fuente); color: var(--ink);
  background: var(--surface-2); border: 1.5px solid transparent; border-radius: 12px;
  transition: border-color var(--t-rapida), background var(--t-rapida), box-shadow var(--t-rapida);
  appearance: none; -webkit-appearance: none;
}
.campo select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23889a95' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
.campo textarea { min-height: 80px; resize: vertical; }
.campo input:hover, .campo select:hover, .campo textarea:hover { border-color: var(--line); }
.campo input:focus, .campo select:focus, .campo textarea:focus,
.en-linea input:focus, .entrada-codigo:focus, .tabla-alimentos input:focus, .form-en-linea input:focus {
  outline: none; border-color: var(--accent); background: var(--surface); box-shadow: var(--anillo);
}
.con-error input, .con-error select { border-color: var(--danger) !important; }
.error { color: var(--danger); font-size: var(--step--1); font-weight: 550; margin: 6px 0 0; }
.casilla { display: flex !important; gap: var(--sp-3); align-items: flex-start; font-weight: 450 !important; font-size: var(--step--1); line-height: 1.45; cursor: pointer; }
.casilla input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.rejilla { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 var(--sp-3); }
fieldset { border: 0; border-top: 1px solid var(--line); padding: var(--sp-4) 0 0; margin: var(--sp-4) 0 0; }
legend { font: 700 var(--step--1) var(--fuente); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 var(--sp-2) 0 0; }
.en-linea { display: inline-flex !important; align-items: center; gap: 6px; font-weight: 500 !important; margin: 0 !important; }
.en-linea input { width: 96px; min-height: 38px; padding: 6px 10px; }
.form-en-linea { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.form-en-linea label { display: flex; align-items: center; gap: var(--sp-2); font-weight: 600; }
.form-en-linea input[type=number] { width: 96px; min-height: 40px; }
.entrada-codigo { flex: 1; min-width: 150px; text-transform: uppercase; letter-spacing: .14em; font-weight: 650; }

/* ---------- Etiquetas y glucosa ---------- */
.etiqueta {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--step--2); font-weight: 750; text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.etiqueta::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.etiqueta-desayuno { color: var(--f-desayuno); background: color-mix(in srgb, var(--f-desayuno) 13%, transparent); }
.etiqueta-comida { color: var(--f-comida); background: color-mix(in srgb, var(--f-comida) 13%, transparent); }
.etiqueta-merienda { color: var(--f-merienda); background: color-mix(in srgb, var(--f-merienda) 13%, transparent); }
.etiqueta-cena { color: var(--f-cena); background: color-mix(in srgb, var(--f-cena) 13%, transparent); }
.etiqueta-alerta { color: var(--danger); background: var(--danger-soft); }
.etiqueta-alerta::before { display: none; }

.gluc { display: inline-block; padding: 2px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.gluc-bajo { color: var(--g-bajo); background: var(--g-bajo-bg); }
.gluc-rango { color: var(--g-rango); background: var(--g-rango-bg); }
.gluc-alto { color: var(--g-alto); background: var(--g-alto-bg); }
.gluc-muy-alto { color: var(--g-muy-alto); background: var(--g-muy-alto-bg); }
.gluc-vacio { color: var(--muted); padding: 0; }
.pendiente-dato { font-size: var(--step--1); font-weight: 600; color: var(--muted); font-style: italic; }

.punto { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.punto-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--g-rango-bg); }
.punto-error { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* ---------- Hoy: resumen del día con medidor de glucosa ---------- */
.resumen-dia {
  display: grid; grid-template-columns: 1fr; gap: var(--sp-3);
  padding: var(--sp-5); margin-bottom: var(--sp-4); border-radius: 28px;
  background:
    radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.resumen-texto h1 { font-size: var(--step-3); margin: 0; }
.sobretitulo { margin: 0 0 2px; font-size: var(--step--1); font-weight: 650; color: var(--muted); }
.medidor { position: relative; width: min(100%, 300px); margin: var(--sp-2) auto 0; }
.medidor svg { display: block; width: 100%; overflow: visible; }
.arco { fill: none; stroke-width: 14; stroke-linecap: butt; }
.arco-bajo { stroke: var(--g-bajo); }
.arco-rango { stroke: var(--g-rango); }
.arco-alto { stroke: var(--g-alto); }
.arco-muy-alto { stroke: var(--g-muy-alto); }
.arco-vacio { stroke: var(--line); stroke-linecap: round; }
.medidor .arco { opacity: .28; }
.medidor.nivel-bajo .arco-bajo, .medidor.nivel-rango .arco-rango,
.medidor.nivel-alto .arco-alto, .medidor.nivel-muy-alto .arco-muy-alto { opacity: 1; }
.aguja { fill: var(--surface); stroke: var(--ink); stroke-width: 4; filter: drop-shadow(0 2px 4px rgb(0 0 0 / 25%)); }
.medidor-valor { position: absolute; inset: auto 0 0 0; text-align: center; line-height: 1; }
.medidor-valor strong { display: block; font: 750 var(--step-4)/1 var(--fuente-display); letter-spacing: -0.04em; }
.medidor-valor span { display: block; margin-top: 6px; font-size: var(--step--1); color: var(--muted); font-weight: 600; }
.medidor.nivel-bajo .medidor-valor strong { color: var(--g-bajo); }
.medidor.nivel-rango .medidor-valor strong { color: var(--g-rango); }
.medidor.nivel-alto .medidor-valor strong { color: var(--g-alto); }
.medidor.nivel-muy-alto .medidor-valor strong { color: var(--g-muy-alto); }
.cifras-dia { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); margin: var(--sp-2) 0 0; }
.cifras-dia div { background: var(--surface-2); border-radius: var(--radius); padding: var(--sp-3); text-align: center; }
.cifras-dia dt { font-size: var(--step--2); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cifras-dia dd { margin: 2px 0 0; font: 700 var(--step-2)/1.1 var(--fuente-display); letter-spacing: -0.02em; }
@media (min-width: 640px) {
  .resumen-dia { grid-template-columns: 1fr 260px; align-items: center; }
  .resumen-texto { align-self: start; }
  .medidor { grid-row: span 2; grid-column: 2; margin: 0; }
}

.acciones-rapidas { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.accion-rapida {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: var(--sp-3);
  min-height: 92px; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-l);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none; font-weight: 650; font-size: var(--step--1);
  transition: transform var(--t-rapida), box-shadow var(--t-rapida);
}
.accion-rapida .icono { width: 26px; height: 26px; color: var(--accent); }
.accion-rapida:hover { transform: translateY(-2px); box-shadow: var(--shadow-alta); }
.accion-principal { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.accion-principal .icono { color: var(--accent-ink); }

.pendiente { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); }
.pendiente-texto { flex: 1; min-width: 0; }
.pendiente p { margin: 2px 0 0; }
.pendiente-icono { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--muted); flex: none; }
.pendiente.toca { border-color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), var(--surface) 70%); }
.pendiente.toca .pendiente-icono { background: var(--accent); color: var(--accent-ink); animation: latido 2.4s ease-in-out infinite; }
@keyframes latido { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 18%, transparent); } }
.estado-ia { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; font-size: var(--step--1); color: var(--muted); margin: var(--sp-3) 0 0; }

/* ---------- Filas de comida, basal, pacientes ---------- */
.fila-comida, .fila-paciente, .fila-simple {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: var(--sp-4); margin-bottom: var(--sp-2); color: var(--ink); text-decoration: none;
  box-shadow: var(--shadow); transition: transform var(--t-rapida), border-color var(--t-rapida);
}
.fila-comida:hover, .fila-paciente:hover, .fila-simple:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); transform: translateY(-1px); }
.fila-cabecera { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.hora { display: inline-flex; align-items: center; gap: 5px; font-size: var(--step--1); font-weight: 600; color: var(--muted); }
.hora .icono { width: 15px; height: 15px; }
.datos { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2); margin: 0; }
.datos dt { font-size: var(--step--2); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.datos dd { margin: 0; font-weight: 700; font-size: var(--step--1); }
.datos dd.cifra { font: 700 var(--step-1)/1.1 var(--fuente-display); }
.datos .gluc { font-size: var(--step--1); padding: 2px 7px; }
.incidencias { display: flex; align-items: center; gap: 6px; margin: var(--sp-3) 0 0; font-size: var(--step--2); font-weight: 600; color: var(--warn); }
.incidencias .icono { width: 14px; height: 14px; }
.fila-simple { display: flex; gap: var(--sp-3); align-items: baseline; padding: var(--sp-3) var(--sp-4); box-shadow: none; }
.fila-basal { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); }
@media (max-width: 420px) {
  .datos { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: var(--sp-3); }
  .acciones-rapidas { grid-template-columns: 1fr 1fr; }
  .accion-principal { grid-column: 1 / -1; min-height: 64px; flex-direction: row; align-items: center; justify-content: flex-start; }
}

.paginacion { display: flex; justify-content: space-between; margin: var(--sp-4) 0; font-weight: 600; }
.paginacion a { text-decoration: none; }

/* ---------- Fotos e IA ---------- */
.selector-fotos { cursor: pointer; }
.miniaturas { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.miniatura { position: relative; width: 84px; height: 84px; }
.miniatura img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius); box-shadow: var(--shadow); }
.miniatura button {
  position: absolute; top: -7px; right: -7px; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--ink); color: var(--bg); cursor: pointer; line-height: 1; font-weight: 700;
}
.tabla-alimentos { width: 100%; border-collapse: separate; border-spacing: 0; margin-bottom: var(--sp-2); font-size: var(--step--1); }
.tabla-alimentos th { text-align: left; font-size: var(--step--2); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 6px 4px; }
.tabla-alimentos td { padding: 6px 4px; vertical-align: top; border-top: 1px solid var(--line); }
.tabla-alimentos input { min-height: 40px; padding: 8px 10px; font-size: var(--step--1); }
.tabla-alimentos td:nth-child(2), .tabla-alimentos td:nth-child(3) { width: 72px; }
.tabla-alimentos td.hc { width: 44px; padding-top: 16px; font-weight: 750; text-align: right; }
.tabla-alimentos tfoot td { font-weight: 750; text-align: right; border-top: 2px solid var(--line); }
.tabla-alimentos tfoot td:first-child { text-align: left; }
.info-alimento { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; align-items: center; }
.marca-fuente, .confianza { font-size: var(--step--2); font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.fuente-usda, .fuente-bedca { background: var(--g-rango-bg); color: var(--g-rango); }
.fuente-modelo { background: var(--g-alto-bg); color: var(--g-alto); }
.confianza-baja { background: var(--danger-soft); color: var(--danger); }
.descripcion-fuente { font-size: var(--step--2); color: var(--muted); }

/* ---------- Ratios, sensibilidad e informes ---------- */
.ratios { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-2); margin-bottom: var(--sp-3); }
.ratio { display: flex; flex-direction: column; gap: 6px; padding: var(--sp-4); border-radius: var(--radius); background: var(--surface-2); }
.ratio strong { font: 750 var(--step-2)/1.1 var(--fuente-display); letter-spacing: -0.02em; }
.ratio.insuficiente strong { color: var(--muted); }
.ratio .secundario { font-size: var(--step--2); margin: 0; }
.cabecera-seccion { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.cabecera-seccion h2 { margin: 0; }
.periodo { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); }
.periodo a { padding: 5px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-size: var(--step--1); font-weight: 650; }
.periodo a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.resumen-tir { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2); margin: var(--sp-3) 0 var(--sp-2); }
.resumen-tir div { padding: var(--sp-3); border-radius: var(--radius); background: var(--surface-2); }
.resumen-tir dt { font-size: var(--step--2); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.resumen-tir dd { margin: 2px 0 0; font: 750 var(--step-1)/1.15 var(--fuente-display); white-space: nowrap; }
@media (max-width: 480px) { .resumen-tir { grid-template-columns: repeat(2, 1fr); } }
.valor-grande { font: 750 var(--step-3)/1.1 var(--fuente-display); letter-spacing: -0.02em; margin: var(--sp-1) 0 var(--sp-2); }
.valor-grande .secundario { font: 500 var(--step--1) var(--fuente); letter-spacing: 0; }
.metodos-fsi { margin: var(--sp-4) 0; display: grid; gap: var(--sp-2); }
.metodos-fsi div { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); background: var(--surface-2); }
.metodos-fsi dt { font-size: var(--step--2); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.metodos-fsi dd { margin: 2px 0 0; font-weight: 600; font-size: var(--step--1); }

.grafica { margin: var(--sp-3) 0 0; }
.grafica > svg { width: 100%; height: auto; display: block; }
.banda-rango { fill: var(--g-rango); opacity: .1; }
.rejilla-linea { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.eje { fill: var(--muted); font: 600 13px var(--fuente); }
.punto-pre { fill: var(--accent); }
.punto-post { fill: var(--surface); stroke: var(--f-desayuno); stroke-width: 2.5; }
.leyenda { display: flex; gap: var(--sp-4); flex-wrap: wrap; font-size: var(--step--2); font-weight: 600; color: var(--muted); margin-top: var(--sp-2); }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.muestra-rango { display: inline-block; width: 16px; height: 10px; border-radius: 3px; background: var(--g-rango); opacity: .3; }

.acciones-informe { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.acciones-informe .boton { width: auto; margin: 0; }
.acciones-paciente { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.acciones-paciente form { margin: 0; }
.informe { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: var(--sp-5); box-shadow: var(--shadow); }
.informe header h1 { font-size: var(--step-2); }
.informe section { margin: var(--sp-5) 0; }
.tabla-informe { width: 100%; border-collapse: collapse; font-size: var(--step--1); display: block; overflow-x: auto; }
.tabla-informe th { text-align: left; font-size: var(--step--2); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 6px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tabla-informe td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabla-informe tr.excluida td { color: var(--muted); }

/* ---------- Médico ---------- */
.fila-paciente.con-alertas { border-left: 5px solid var(--danger); }
.ratios-linea { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); margin: var(--sp-3) 0 0; font-size: var(--step--1); font-weight: 600; color: var(--muted); }
.alertas { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--sp-3) 0 0; }
.codigo-grande {
  font: 750 clamp(1.8rem, 1.4rem + 3vw, 2.6rem)/1 var(--fuente-display); letter-spacing: .18em; text-align: center;
  margin: var(--sp-4) 0; padding: var(--sp-4); border-radius: var(--radius); background: var(--accent-soft); color: var(--accent);
}
.enlace-copiable code { display: block; word-break: break-all; padding: var(--sp-3); }
.fila-medico { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
.acceso { margin: 6px 0; font-size: var(--step--1); }
.acceso span { color: var(--muted); margin-right: 6px; font-weight: 600; }

/* ---------- Accesibilidad y movimiento ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Impresión (informe) ---------- */
@media print {
  .solo-pantalla, .pie, .aviso, .pestanas, .barra { display: none !important; }
  :root { --bg: #fff; --surface: #fff; --surface-2: #f2f4f3; --ink: #000; --muted: #444; --line: #ccc; color-scheme: light; }
  body { background: #fff; font-size: 10.5pt; padding: 0 !important; }
  .contenido { max-width: none; padding: 0; }
  .informe { border: 0; padding: 0; box-shadow: none; }
  .tabla-informe { display: table; }
  .tabla-informe tr, .ratio { break-inside: avoid; }
}

.bienvenida { text-align: center; margin: var(--sp-6) auto 0; max-width: 440px; }
.bienvenida img { border-radius: 18px; box-shadow: var(--shadow-alta); }
.bienvenida p { margin: var(--sp-3) 0 0; color: var(--muted); font-weight: 550; }

.boton-ia {
  margin-top: 4px; width: 100%; min-height: 28px; padding: 2px 6px;
  font: 750 var(--step--2) var(--fuente); letter-spacing: .04em; color: var(--accent);
  background: var(--accent-soft); border: 0; border-radius: 8px; cursor: pointer;
}
.boton-ia:hover { filter: brightness(.97); }
.boton-ia:disabled { opacity: .6; cursor: progress; }

/* --- Sensor --- */
.linea-sensor { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; opacity: .55; }
.muestra-sensor { display: inline-block; width: 16px; height: 2px; background: var(--accent); opacity: .7; }
.pasos { margin: 0 0 var(--sp-3); padding-left: 20px; font-size: var(--step--1); }
.pasos li { margin-bottom: 6px; }
.entrada-archivo { flex: 1; min-width: 200px; font: inherit; font-size: var(--step--1); }
.de-sensor { font-size: var(--step--2); font-weight: 700; color: var(--accent); margin-left: 4px; }
.fila-enlace { align-items: center; margin-bottom: var(--sp-4); }
.fila-enlace > span { flex: 1; }
.fila-enlace .icono { color: var(--accent); }

/* --- Medicación --- */
.fila-med { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
.fila-med:last-child { border-bottom: 0; }
.fila-med form { margin: 0; }
.med-icono { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); flex: none; }
.med-texto { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.med-texto a { color: var(--ink); text-decoration: none; }
.fila-med.atrasada .med-icono { background: var(--g-alto-bg); color: var(--g-alto); }
.fila-med.atrasada .secundario { color: var(--g-alto); font-weight: 600; }
.subtitulo { font-size: var(--step-0); font-weight: 700; margin: var(--sp-5) 0 var(--sp-2); }
#libre .subtitulo:first-of-type { margin-top: var(--sp-2); }

.persona-leida { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); background: var(--accent-soft); font-size: var(--step--1); }
.persona-leida .icono { color: var(--accent); }
.opciones { display: grid; gap: var(--sp-2); margin: var(--sp-4) 0; }
.opcion { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1.5px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.opcion:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opcion input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.opcion-icono { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.dato-sensor { display: flex; align-items: center; gap: 6px; margin-top: calc(-1 * var(--sp-3)); color: var(--accent); font-weight: 600; }
.dato-sensor .icono { width: 14px; height: 14px; }

/* --- Perfiles de insulina --- */
.perfiles-insulina { display: grid; gap: var(--sp-3); margin: 0 0 var(--sp-3); }
.perfiles-insulina > div { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); background: var(--surface-2); }
.perfiles-insulina dt { font-weight: 700; margin-bottom: 4px; }
.perfiles-insulina dd { margin: 0 0 4px; font-size: var(--step--1); }
.curva-insulina { width: 100%; max-width: 320px; height: auto; display: block; margin-top: var(--sp-2); overflow: visible; }
.curva-insulina path { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.curva-insulina text { fill: var(--muted); font: 600 11px var(--fuente); }

/* --- Visor de glucosa 12 h / 24 h / 7 d --- */
.visor-svg { width: 100%; height: auto; display: block; margin-top: var(--sp-2); overflow: visible; }
.rejilla-vertical { stroke: var(--line); stroke-width: 1; opacity: .6; }
.linea-sensor-visor { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.punto-medida { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.marca line { stroke: var(--f-desayuno); stroke-width: 1.2; stroke-dasharray: 3 3; opacity: .7; }
.marca-comida circle { fill: var(--f-desayuno); }
.marca-comida text { fill: #fff; font: 700 10px var(--fuente); }
.marca-rapida rect { fill: var(--info); }
.marca-lenta rect { fill: var(--g-muy-alto); }
.marca-rapida text, .marca-lenta text { fill: #fff; font: 700 10px var(--fuente); }
.muestra { display: inline-block; width: 12px; height: 10px; border-radius: 3px; }
.muestra-comida { background: var(--f-desayuno); border-radius: 50%; width: 10px; }
.muestra-rapida { background: var(--info); }
.muestra-lenta { background: var(--g-muy-alto); }

/* --- Guía --- */
.guia-cabecera { margin-bottom: var(--sp-4); }
.guia-cabecera .sobretitulo { display: flex; align-items: center; gap: 6px; color: var(--accent); }
.guia h3 { font-size: var(--step-0); margin: var(--sp-4) 0 var(--sp-2); }
.guia ul, .guia ol { padding-left: 22px; margin: 0 0 var(--sp-3); }
.guia li { margin-bottom: 6px; }
.indice ol { columns: 2 220px; column-gap: var(--sp-5); margin: 0; }
.indice a { text-decoration: none; font-weight: 600; }
.guia section { scroll-margin-top: 80px; }
.pasos-guia > li::marker { font-weight: 750; color: var(--accent); }
.definiciones dt { font-weight: 700; margin-top: var(--sp-3); }
.definiciones dd { margin: 2px 0 0; color: var(--ink); }
.formula { padding: var(--sp-3) var(--sp-4); border-left: 4px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; background: var(--accent-soft); margin: var(--sp-3) 0; }
.formula p { margin: 4px 0; }
.tabla-desplazable { overflow-x: auto; }
.tabla-perfiles { display: table; }
.guia details { border-top: 1px solid var(--line); padding: var(--sp-3) 0; }
.guia summary { cursor: pointer; font-weight: 650; }
.guia details p { margin: var(--sp-2) 0 0; color: var(--muted); }
.boton-ia-muestra { display: inline-block; width: auto; min-height: 0; margin: 0; padding: 1px 8px; }
.tabla-tramos { width: 100%; border-collapse: collapse; margin-bottom: var(--sp-3); }
.tabla-tramos th { text-align: left; font-size: var(--step--2); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px; }
.tabla-tramos td { padding: 4px; }
.tabla-tramos input { width: 100%; min-height: 42px; padding: 8px 10px; font: 500 var(--step-0) var(--fuente); color: var(--ink); background: var(--surface-2); border: 1.5px solid transparent; border-radius: 10px; }
.tabla-tramos input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.tramos-resumen { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-2); }
.tramos-resumen span { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: var(--step--1); }
.visor .periodo { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.visor .periodo a { white-space: nowrap; padding: 5px 10px; }

/* --- Estimación vs real --- */
.pestanas-seccion { display: flex; gap: 4px; padding: 4px; margin-bottom: var(--sp-4); border-radius: 14px; background: var(--surface-2); }
.pestanas-seccion a { flex: 1; text-align: center; padding: 9px 10px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 650; font-size: var(--step--1); }
.pestanas-seccion a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.resumen-estimacion { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-2); margin: var(--sp-3) 0; }
.desvio-encima { color: var(--g-alto); }
.desvio-debajo { color: var(--g-bajo); }
.desvio-acorde { color: var(--g-rango); }
.comparacion { padding: var(--sp-4); }
.comparacion.clase-por-encima { border-left: 5px solid var(--g-alto); }
.comparacion.clase-por-debajo { border-left: 5px solid var(--g-bajo); }
.comparacion.clase-acorde { border-left: 5px solid var(--g-rango); }
.mini-grafica { width: 100%; max-width: 520px; height: auto; display: block; margin: var(--sp-2) 0; overflow: visible; }
.linea-esperada { fill: none; stroke: var(--muted); stroke-width: 2; stroke-dasharray: 6 5; }
.linea-real { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; }
.linea-2h { stroke: var(--line); stroke-width: 1.5; }
.desvio { margin: 0; font-size: var(--step--1); }
.chip-desvio { display: inline-block; padding: 2px 9px; border-radius: 999px; font-weight: 700; }
.chip-desvio.por-encima { background: var(--g-alto-bg); color: var(--g-alto); }
.chip-desvio.por-debajo { background: var(--g-bajo-bg); color: var(--g-bajo); }
.chip-desvio.acorde { background: var(--g-rango-bg); color: var(--g-rango); }
.muestra-esperada { display: inline-block; width: 18px; border-top: 2px dashed var(--muted); }

.fuente { border-top: 1px solid var(--line); padding: var(--sp-3) 0; }
.fuente:first-of-type { border-top: 0; }
.fuente summary { cursor: pointer; font-size: var(--step-0); padding: 4px 0; }
.fuente[open] summary { margin-bottom: var(--sp-3); }
.estado-fuente { font-size: var(--step--2); font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--g-rango-bg); color: var(--g-rango); margin-left: 6px; }
.tras { font-size: var(--step--2); font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabla-sensores { display: table; min-width: 560px; }
.tabla-sensores td { font-size: var(--step--1); }
