    /* ═══════════════════════════════════════════
       VARIABLES DE COLOR
       ═══════════════════════════════════════════ */
    :root {
      --bg:       #f1f5f9;
      --surface:  #ffffff;
      --surface2: #f8fafc;
      --border:   #e2e8f0;
      --text:     #0f172a;
      --text2:    #64748b;
      /* La accion es morada y la define marca.css. Se deja el azul como
         color de dato (--left, pecho izquierdo), que es cosa distinta.

         Dos tokens y no uno porque hacen trabajos opuestos:
           --primary     es FONDO, y lleva texto blanco encima
           --primary-txt es TEXTO, y va sobre la superficie
         En claro coinciden; en oscuro tiran en direcciones contrarias y
         con un solo token uno de los dos se queda sin contraste. */
      --primary:    var(--m-700);   /* blanco encima: 7,1:1  */
      --primary-h:  var(--m-800);   /* blanco encima: 9,0:1  */
      --primary-txt:var(--m-700);   /* sobre papel:   7,1:1  */
      --danger:   #dc2626;
      --left:     #2563eb;   /* pecho izquierdo: azul   */
      --right:    #dc2626;   /* pecho derecho:  rojo    */
      --weight:   #059669;   /* peso:           verde   */
      --caca:     #8a5a34;   /* caca:           marrón  */
      --pipi:     #38bdf8;   /* pipí:           celeste */
      --target:   #f59e0b;   /* mínimo 20 g/día: ámbar  */
      --ok:       #059669;   /* va bien:         verde  */
      --r:        14px;
    }

    /* Modo oscuro automático (sigue el sistema operativo) */
    @media (prefers-color-scheme: dark) {
      :root:not([data-theme="light"]) {
        --primary:    var(--m-600);
        --primary-h:  var(--m-700);
        --primary-txt:var(--m-400);
        --bg:       #0f172a;
        --surface:  #1e293b;
        --surface2: #334155;
        --border:   #475569;
        --text:     #f1f5f9;
        --text2:    #94a3b8;
      }
    }

    /* Modo oscuro forzado por el usuario */
    :root[data-theme="dark"] {
      --primary:    var(--m-600);   /* blanco encima: 5,7:1 */
      --primary-h:  var(--m-700);
      --primary-txt:var(--m-400);   /* sobre superficie: 5,4:1 */
      --bg:       #0f172a;
      --surface:  #1e293b;
      --surface2: #334155;
      --border:   #475569;
      --text:     #f1f5f9;
      --text2:    #94a3b8;
    }

    /* ═══════════════════════════════════════════
       BASE
       ═══════════════════════════════════════════ */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      background: var(--bg);
      color: var(--text);
      min-height: 100dvh;
      -webkit-font-smoothing: antialiased;
      -webkit-tap-highlight-color: transparent;
    }

    /* ═══════════════════════════════════════════
       CABECERA
       El título ya NO usa position:absolute, así que nunca
       puede solaparse con los botones en pantallas estrechas
       (era el fallo que se veía en Android).
       ═══════════════════════════════════════════ */
    .header {
      position: sticky;
      top: 0;
      z-index: 50;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      padding: env(safe-area-inset-top, 0px) 12px 0;
      height: calc(56px + env(safe-area-inset-top, 0px));
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    .header-title {
      flex: 1;
      min-width: 0;              /* necesario para que funcione el ellipsis */
      font-size: 1.05rem;
      font-weight: 700;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .header-right {
      display: flex;
      gap: 6px;
      flex-shrink: 0;            /* los botones nunca se comprimen */
    }

    .icon-btn {
      background: none;
      border: 1px solid var(--border);
      border-radius: 8px;
      min-width: 44px;           /* objetivo táctil cómodo */
      min-height: 40px;
      padding: 6px 10px;
      color: var(--text);
      cursor: pointer;
      font-size: 1rem;
      font-family: inherit;
      line-height: 1;
    }

    /* En pantallas muy estrechas acortamos el título */
    @media (max-width: 380px) {
      .hide-narrow { display: none; }
    }

    /* ═══════════════════════════════════════════
       MODAL DE EDICIÓN
       ═══════════════════════════════════════════ */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.5);
      z-index: 200;
      display: flex;
      align-items: flex-end;
      padding: 16px;
    }

    .modal-box {
      background: var(--surface);
      border-radius: var(--r);
      padding: 20px;
      width: 100%;
      max-width: 500px;
      margin: 0 auto;
      max-height: 85vh;
      overflow-y: auto;
    }

    .modal-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }
    .modal-btns  { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }

    .btn-edit-sm {
      display: inline-block;
      padding: 5px 10px;
      background: var(--surface2);
      color: var(--text);
      border: 1px solid var(--border);
      border-radius: 6px;
      font-size: 0.8rem;
      font-family: inherit;
      cursor: pointer;
    }

    /* ═══════════════════════════════════════════
       PANTALLA DE LOGIN
       ═══════════════════════════════════════════ */
    .login-wrap  { padding: 48px 16px 32px; max-width: 420px; margin: 0 auto; }
    .login-title { text-align: center; font-size: 2rem; margin-bottom: 6px; }
    .login-sub {
      text-align: center;
      color: var(--text2);
      margin-bottom: 28px;
      font-size: 0.9rem;
    }

    /* ═══════════════════════════════════════════
       TARJETA
       ═══════════════════════════════════════════ */
    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--r);
      padding: 20px;
      margin-bottom: 16px;
    }

    .card-title { font-size: 1rem;   font-weight: 600; margin-bottom: 2px; }
    .card-sub   { font-size: 0.8rem; color: var(--text2); margin-bottom: 16px; }

    /* ═══════════════════════════════════════════
       RESUMEN DE HOY
       ═══════════════════════════════════════════ */
    /* Las columnas las fija renderResumen() segun cuantas casillas
       queden encendidas: con 4 fijas, apagar un modulo dejaba un
       hueco vacio a la derecha. */
    .sum-grid {
      display: grid;
      grid-template-columns: repeat(var(--sum-cols-estrecho, 2), 1fr);
      gap: 10px;
    }

    @media (min-width: 480px) {
      .sum-grid { grid-template-columns: repeat(var(--sum-cols, 4), 1fr); }
    }

    .sum-item {
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 10px 12px;
    }

    .sum-val   { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
    .sum-lbl   { font-size: 0.72rem; color: var(--text2); margin-top: 2px; }
    .sum-extra { font-size: 0.7rem;  color: var(--text2); margin-top: 3px; }

    /* Ganancia de peso al día, justo debajo del peso actual */
    .sum-trend {
      font-size: 0.82rem;
      font-weight: 600;
      line-height: 1.2;
      margin-top: 3px;
    }

    /* ok    = mantiene percentil
       justo = pasa los 20 g/día de la pediatra pero bajará de percentil
       bajo  = por debajo del suelo de la pediatra */
    .sum-trend.ok    { color: var(--ok); }
    .sum-trend.justo { color: var(--target); }
    .sum-trend.bajo  { color: var(--danger); }
    .sum-trend.nd    { color: var(--text2); font-weight: 500; }

    /* Lo que pide su percentil a día de hoy */
    .sum-need {
      font-size: 0.7rem;
      color: var(--text2);
      line-height: 1.2;
      margin-top: 1px;
    }

    /* Percentil OMS, debajo de la ganancia diaria */
    .sum-pct {
      font-size: 0.78rem;
      font-weight: 600;
      color: var(--text);
      line-height: 1.2;
      margin-top: 2px;
    }

    .sum-pct-lbl { font-weight: 500; color: var(--text2); font-size: 0.68rem; }
    .sum-pct.nd  { font-weight: 500; color: var(--text2); font-size: 0.7rem; }

    /* ═══════════════════════════════════════════
       FORMULARIOS
       ═══════════════════════════════════════════ */
    .field { margin-bottom: 16px; }

    label {
      display: block;
      font-size: 0.875rem;
      font-weight: 500;
      color: var(--text2);
      margin-bottom: 6px;
    }

    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="text"],
    input[type="datetime-local"],
    input[type="date"],
    textarea {
      display: block;
      width: 100%;
      padding: 14px 12px;
      border: 1.5px solid var(--border);
      border-radius: 10px;
      background: var(--surface);
      color: var(--text);
      font-size: 1rem;
      font-family: inherit;
      appearance: none;
      -webkit-appearance: none;
      outline: none;
      transition: border-color .2s;
    }

    textarea { resize: vertical; min-height: 44px; }

    input:focus, textarea:focus { border-color: var(--primary); }

    /* ═══════════════════════════════════════════
       BOTONES
       ═══════════════════════════════════════════ */
    .btn {
      display: block;
      width: 100%;
      padding: 15px;
      border: none;
      border-radius: 10px;
      font-size: 1rem;
      font-weight: 600;
      font-family: inherit;
      cursor: pointer;
      transition: opacity .2s, background .2s;
    }

    .btn:disabled { opacity: .55; cursor: not-allowed; }

    .btn-primary { background: var(--primary); color: #fff; }
    .btn-primary:hover:not(:disabled) { background: var(--primary-h); }

    .btn-danger-sm {
      display: inline-block;
      padding: 5px 10px;
      background: var(--danger);
      color: #fff;
      border: none;
      border-radius: 6px;
      font-size: 0.8rem;
      font-family: inherit;
      cursor: pointer;
    }

    .error-txt { color: var(--danger); font-size: 0.85rem; margin-top: 8px; }

    .hint-txt {
      font-size: 0.75rem;
      color: var(--text2);
      margin: -8px 0 16px;
      line-height: 1.4;
    }

    /* ═══════════════════════════════════════════
       SELECTOR DE DOS OPCIONES (pecho, transparente)
       ═══════════════════════════════════════════ */
    .toggle-row { display: flex; gap: 10px; }

    .toggle-opt {
      flex: 1;
      padding: 14px 8px;
      border: 2px solid var(--border);
      border-radius: 10px;
      background: var(--surface2);
      color: var(--text2);
      font-size: 0.95rem;
      font-weight: 500;
      font-family: inherit;
      cursor: pointer;
      text-align: center;
      transition: all .2s;
    }

    .toggle-opt.sel {
      border-color: var(--primary);
      background: var(--primary);
      color: #fff;
    }

    /* ═══════════════════════════════════════════
       SELECTOR DE CANTIDAD 0-10
       11 botones en lugar de un input numérico: en el móvil
       se registra de un toque y sin abrir el teclado.
       ═══════════════════════════════════════════ */
    .qty-row { display: flex; flex-wrap: wrap; gap: 6px; }

    .qty-btn {
      flex: 1 0 calc(16.66% - 6px);
      min-width: 42px;
      padding: 11px 0;
      border: 2px solid var(--border);
      border-radius: 9px;
      background: var(--surface2);
      color: var(--text2);
      font-size: 0.95rem;
      font-weight: 600;
      font-family: inherit;
      cursor: pointer;
      transition: all .15s;
    }

    .qty-btn.sel {
      border-color: var(--primary);
      background: var(--primary);
      color: #fff;
    }

    /* ═══════════════════════════════════════════
       SELECTOR DE COLOR DE CACA
       ═══════════════════════════════════════════ */
    /* Rejilla de 8 columnas y no flex: con un ancho fijo las muestras se
       partian en dos filas en cuanto el movil era un poco mas estrecho.
       Asi se encogen juntas y siempre caben en una. */
    .color-row {
      display: grid;
      grid-template-columns: repeat(8, 1fr);
      gap: 6px;
      /* Tope de ancho: con 8 columnas elasticas, en un escritorio de 900 px
         cada muestra se iba a 90 px y parecian globos. Asi se encogen en el
         movil y se quedan en ~44 px en pantalla grande. */
      max-width: 400px;
    }

    .color-btn {
      display: flex;
      align-items: center;
      gap: 7px;
      padding: 10px 8px;
      border: 2px solid var(--border);
      border-radius: 9px;
      background: var(--surface2);
      color: var(--text2);
      font-size: 0.74rem;
      font-family: inherit;
      text-align: left;
      cursor: pointer;
      transition: all .15s;
    }

    .color-btn.sel {
      border-color: var(--primary);
      color: var(--text);
      font-weight: 600;
    }

    .color-swatch {
      width: 16px;
      height: 16px;
      border-radius: 50%;
      flex-shrink: 0;
      /* borde propio: si no, el blanquecino desaparece sobre fondo claro */
      border: 1px solid rgba(128,128,128,.55);
    }

    /* ═══════════════════════════════════════════
       CONTENIDO PRINCIPAL Y TABS
       ═══════════════════════════════════════════ */
    main {
      max-width: 640px;
      margin: 0 auto;
      padding: 16px 16px 96px; /* hueco para la barra de tabs */
    }

    .tab-panel        { display: none; }
    .tab-panel.active { display: block; }

    .tab-bar {
      position: fixed;
      bottom: 0; left: 0; right: 0;
      background: var(--surface);
      border-top: 1px solid var(--border);
      display: flex;
      z-index: 50;
      padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .tab-btn {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
      padding: 10px 8px 8px;
      background: none;
      border: none;
      color: var(--text2);
      font-size: 0.7rem;
      font-family: inherit;
      cursor: pointer;
      transition: color .2s;
    }

    .tab-btn.active { color: var(--primary-txt); }
    .tab-icon { font-size: 1.35rem; }

    /* ═══════════════════════════════════════════
       GRÁFICAS
       ═══════════════════════════════════════════ */
    .chart-wrap { position: relative; height: 230px; margin-top: 12px; }

    .legend {
      display: flex;
      flex-wrap: wrap;
      gap: 14px;
      margin: 10px 0 4px;
      font-size: 0.82rem;
      color: var(--text2);
    }

    .legend-item { display: flex; align-items: center; gap: 6px; }

    .legend-dot {
      width: 11px; height: 11px;
      border-radius: 50%;
      flex-shrink: 0;
      border: 1px solid rgba(128,128,128,.35);
    }

    /* Guion para las series que se dibujan como línea discontinua.
       El patrón de rayas llega en el atributo style de cada leyenda. */
    .legend-dash {
      width: 18px;
      height: 3px;
      border-radius: 2px;
      flex-shrink: 0;
    }

    /* Muestra de las curvas de percentiles: tres rayitas apiladas */
    .legend-band {
      width: 18px;
      height: 10px;
      flex-shrink: 0;
      background:
        linear-gradient(rgba(100,116,139,.45) 0 0) 0 1px  / 18px 1px no-repeat,
        linear-gradient(rgba(100,116,139,.45) 0 0) 0 5px  / 18px 1px no-repeat,
        linear-gradient(rgba(100,116,139,.45) 0 0) 0 9px  / 18px 1px no-repeat;
    }

    /* ═══════════════════════════════════════════
       HISTORIAL
       ═══════════════════════════════════════════ */
    .chip-row {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      margin-bottom: 12px;
    }

    .chip {
      padding: 8px 13px;
      border: 1.5px solid var(--border);
      border-radius: 999px;
      background: var(--surface);
      color: var(--text2);
      font-size: 0.82rem;
      font-family: inherit;
      cursor: pointer;
      transition: all .15s;
    }

    .chip.sel {
      border-color: var(--primary);
      background: var(--primary);
      color: #fff;
    }

    .card-no-pad { padding: 0; overflow: hidden; }
    .table-wrap  { overflow-x: auto; }

    table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

    thead th {
      text-align: left;
      padding: 10px 12px;
      background: var(--surface2);
      color: var(--text2);
      font-size: 0.75rem;
      text-transform: uppercase;
      letter-spacing: .05em;
      font-weight: 600;
    }

    tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
    tbody tr:last-child td { border-bottom: none; }

    .nota-txt {
      display: block;
      font-size: 0.75rem;
      color: var(--text2);
      margin-top: 3px;
      font-style: italic;
    }

    .empty-state {
      text-align: center;
      padding: 32px;
      color: var(--text2);
      font-size: 0.9rem;
    }

    /* ═══════════════════════════════════════════
       TOAST (notificación flotante)
       ═══════════════════════════════════════════ */
    .toast {
      position: fixed;
      top: calc(64px + env(safe-area-inset-top, 0px));
      left: 50%;
      transform: translateX(-50%);
      background: var(--text);
      color: var(--bg);
      padding: 10px 18px;
      border-radius: 10px;
      font-size: 0.9rem;
      z-index: 999;
      pointer-events: none;
      max-width: calc(100vw - 32px);
      text-align: center;
      opacity: 0;
      transition: opacity .25s;
    }

    .toast.show { opacity: 1; }

    /* ═══════════════════════════════════════════
       PESTAÑA COMIDA
       ═══════════════════════════════════════════ */

    /* Checklist de señales de que está listo */
    .check-list { display: flex; flex-direction: column; gap: 8px; }

    .check-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 12px;
      border: 2px solid var(--border);
      border-radius: 10px;
      background: var(--surface2);
      color: var(--text2);
      font-size: 0.88rem;
      font-family: inherit;
      text-align: left;
      cursor: pointer;
      transition: all .15s;
    }

    .check-item.sel { border-color: var(--ok); color: var(--text); }

    .check-box {
      width: 22px; height: 22px;
      flex-shrink: 0;
      border: 2px solid var(--border);
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 700;
      color: #fff;
    }

    .check-item.sel .check-box { background: var(--ok); border-color: var(--ok); }

    .check-inline { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }

    /* Avisos, por nivel de gravedad */
    .aviso {
      border-radius: 10px;
      padding: 12px 14px;
      font-size: 0.85rem;
      line-height: 1.45;
      border: 1px solid;
      margin-bottom: 12px;
    }

    .aviso-stop   { background: rgba(220,38,38,.08);  border-color: rgba(220,38,38,.45);  color: var(--text); }
    .aviso-ojo    { background: rgba(245,158,11,.10); border-color: rgba(245,158,11,.5);  color: var(--text); }
    .aviso-espera { background: rgba(245,158,11,.10); border-color: rgba(245,158,11,.5);  color: var(--text); }
    .aviso-suave  { background: var(--surface2);      border-color: var(--border);        color: var(--text2); }
    .aviso-ok     { background: rgba(5,150,105,.10);  border-color: rgba(5,150,105,.45);  color: var(--text); }

    .aviso-fuente { font-size: 0.72rem; color: var(--text2); margin-top: 6px; }

    /* Distintivos */
    .tag {
      display: inline-block;
      padding: 2px 7px;
      border-radius: 999px;
      font-size: 0.65rem;
      font-weight: 600;
      white-space: nowrap;
      vertical-align: middle;
    }

    .tag-hierro   { background: rgba(220,38,38,.14);  color: #dc2626; }
    .tag-alergeno { background: rgba(245,158,11,.16); color: #b45309; }
    .tag-stop     { background: rgba(220,38,38,.14);  color: #dc2626; }
    .tag-pronto   { background: var(--surface2);      color: var(--text2); }

    @media (prefers-color-scheme: dark) {
      :root:not([data-theme="light"]) .tag-hierro   { color: #f87171; }
      :root:not([data-theme="light"]) .tag-alergeno { color: #fbbf24; }
      :root:not([data-theme="light"]) .tag-stop     { color: #f87171; }
    }

    :root[data-theme="dark"] .tag-hierro   { color: #f87171; }
    :root[data-theme="dark"] .tag-alergeno { color: #fbbf24; }
    :root[data-theme="dark"] .tag-stop     { color: #f87171; }

    /* Cola de "qué toca" */
    .cola-item {
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 12px;
      margin-bottom: 10px;
      background: var(--surface2);
    }

    .cola-item.cola-espera { opacity: .72; }

    .cola-nom {
      font-size: 0.98rem;
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 6px;
      flex-wrap: wrap;
    }

    .cola-aviso { font-size: 0.75rem; color: var(--text2); margin-top: 4px; }

    .cola-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

    .btn-mini {
      padding: 8px 12px;
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--surface);
      color: var(--text);
      font-size: 0.8rem;
      font-family: inherit;
      cursor: pointer;
    }

    .btn-mini-pri { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

    /* Catálogo plegable */
    .cat-cab {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      padding: 13px 12px;
      margin-top: 8px;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: var(--surface2);
      color: var(--text);
      font-size: 0.92rem;
      font-weight: 600;
      font-family: inherit;
      cursor: pointer;
    }

    .cat-cuenta { font-size: 0.78rem; color: var(--text2); font-weight: 500; }

    .cat-lista { padding: 4px 0 8px; }

    .ali-fila {
      display: flex;
      align-items: center;
      gap: 7px;
      width: 100%;
      padding: 11px 10px;
      border: none;
      border-bottom: 1px solid var(--border);
      background: none;
      color: var(--text);
      font-size: 0.87rem;
      font-family: inherit;
      text-align: left;
      cursor: pointer;
    }

    .ali-nom   { flex: 1; min-width: 0; }
    .ali-veces { font-size: 0.72rem; color: var(--text2); }

    .pt { width: 14px; flex-shrink: 0; font-weight: 700; text-align: center; }
    .pt-ok  { color: var(--ok); }
    .pt-med { color: var(--text2); }
    .pt-mal { color: var(--danger); }

    /* Texto de las fichas */
    .ficha-txt {
      font-size: 0.87rem;
      line-height: 1.5;
      color: var(--text);
      margin: 0;
    }

    /* Alimentos añadidos por la familia */
    .tag-mio { background: rgba(37,99,235,.14); color: #2563eb; }

    @media (prefers-color-scheme: dark) {
      :root:not([data-theme="light"]) .tag-mio { color: #93c5fd; }
    }
    :root[data-theme="dark"] .tag-mio { color: #93c5fd; }

    /* ═══════════════════════════════════════════
       LOGIN, ALTA Y CABECERA CON HIJO
       ═══════════════════════════════════════════ */
    .btn-google {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      background: var(--surface);
      color: var(--text);
      border: 1.5px solid var(--border);
    }

    .btn-google:hover { background: var(--surface2); }

    .btn-secundario {
      background: var(--surface2);
      color: var(--text);
      border: 1px solid var(--border);
    }

    /* "o con tu correo" con una línea a cada lado */
    .separador {
      display: flex;
      align-items: center;
      gap: 10px;
      margin: 16px 0;
      color: var(--text2);
      font-size: 0.78rem;
    }

    .separador::before,
    .separador::after {
      content: '';
      flex: 1;
      height: 1px;
      background: var(--border);
    }

    /* Nombre del hijo en la cabecera */
    .hijo-nombre { font-weight: 700; }

    .hijo-select {
      background: none;
      border: none;
      color: var(--text);
      font-size: 1.05rem;
      font-weight: 700;
      font-family: inherit;
      padding: 2px 18px 2px 4px;
      margin-left: -4px;
      cursor: pointer;
      max-width: 42vw;
      appearance: none;
      -webkit-appearance: none;
      /* flechita dibujada, que la nativa no se puede teñir */
      background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                        linear-gradient(135deg, currentColor 50%, transparent 50%);
      background-position: right 7px center, right 2px center;
      background-size: 5px 5px, 5px 5px;
      background-repeat: no-repeat;
    }

    .hijo-select option { background: var(--surface); color: var(--text); }

    /* ═══════════════════════════════════════════
       BOTÓN DE COMPARTIR EN LAS TARJETAS
       ═══════════════════════════════════════════ */
    .btn-compartir {
      position: absolute;
      top: 14px;
      right: 14px;
      width: 36px;
      height: 36px;
      padding: 0;
      border: 1px solid var(--border);
      border-radius: 9px;
      background: var(--surface2);
      color: var(--text);
      font-size: 1rem;
      line-height: 1;
      cursor: pointer;
      opacity: .6;
      transition: opacity .15s;
    }

    .btn-compartir:hover  { opacity: 1; }
    .btn-compartir:active { opacity: 1; }
    .btn-compartir:disabled { cursor: wait; opacity: .4; }

    /* Que el título no se meta debajo del botón */
    [data-captura] .card-title { padding-right: 44px; }

    /* ═══════════════════════════════════════════
       INTERRUPTORES DE MÓDULOS (ajustes)
       ═══════════════════════════════════════════ */
    .modulo-fila {
      display: flex;
      align-items: flex-start;
      gap: 10px;
      padding: 10px 12px;
      margin-bottom: 8px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 10px;
      cursor: pointer;
    }

    .modulo-fila input { margin-top: 3px; flex: none; width: 18px; height: 18px; }

    .modulo-txt  { display: flex; flex-direction: column; gap: 2px; }
    .modulo-nom  { font-size: .9rem; font-weight: 600; }
    .modulo-desc { font-size: .78rem; color: var(--text2); line-height: 1.35; }

    /* Leyenda de la grafica de pipis: separador y textos sueltos */
    .legend-sep {
      flex-basis: 100%;
      height: 0;
      margin: -6px 0 0;
    }

    .legend-nota { font-size: 0.78rem; opacity: .85; }

    /* ═══════════════════════════════════════════
       MARCA EN LA PANTALLA DE ENTRADA
       ═══════════════════════════════════════════ */
    .login-logo {
      display: block;
      margin: 0 auto 14px;
      border-radius: 20px;
      box-shadow: 0 8px 24px rgba(109, 40, 217, .28);
    }

    .login-nombre {
      text-align: center;
      font-size: 1.45rem;
      font-weight: 680;
      letter-spacing: -0.025em;
      margin-bottom: 6px;
    }

    .login-nombre em { font-style: normal; color: var(--marca); }

    /* ═══════════════════════════════════════════
       «MÁS OPCIONES» EN LOS FORMULARIOS

       La fecha ya viene puesta en «ahora» y la nota es opcional: entre
       las dos ocupaban 180 px de los ~600 reales que tiene un móvil con
       la barra del navegador, y dejaban el botón de Guardar fuera de
       pantalla. Plegadas, siguen a un toque de distancia.
       ═══════════════════════════════════════════ */
    .mas {
      border: 1px solid var(--border);
      border-radius: 10px;
      margin-bottom: 16px;
      background: var(--surface2);
    }

    .mas > summary {
      list-style: none;
      cursor: pointer;
      padding: 11px 14px;
      font-size: 0.85rem;
      color: var(--text2);
      display: flex;
      align-items: center;
      gap: 8px;
      user-select: none;
    }

    .mas > summary::-webkit-details-marker { display: none; }

    /* Flecha propia, para que gire igual en todos los navegadores */
    .mas > summary::before {
      content: "›";
      font-size: 1.1rem;
      line-height: 1;
      transition: transform .15s ease;
      color: var(--primary-txt);
    }

    .mas[open] > summary::before { transform: rotate(90deg); }

    .mas[open] > summary { border-bottom: 1px solid var(--border); }

    /* El momento que se va a guardar, escrito al lado del título.
       En ámbar cuando NO es ahora mismo: es justo el caso que hay que
       cazar — una hora vieja heredada de haber dejado la pestaña
       abierta, o una que se cambió a mano y se olvidó. */
    .eco-fecha {
      font-weight: 600;
      color: var(--primary-txt);
      white-space: nowrap;
    }

    .eco-fecha.viejo { color: #b45309; }

    @media (prefers-color-scheme: dark) {
      :root:not([data-theme="light"]) .eco-fecha.viejo { color: #fbbf24; }
    }

    :root[data-theme="dark"] .eco-fecha.viejo { color: #fbbf24; }

    .mas > summary .eco-fecha { margin-left: auto; }

    .mas > .field { padding: 0 14px; }
    .mas > .field:first-of-type { padding-top: 14px; }
    .mas > .field:last-child     { padding-bottom: 14px; }

    /* ═══════════════════════════════════════════
       HISTORIAL EN PANTALLA ESTRECHA

       La tabla medía 380 px dentro de un hueco de 341: se desbordaba y
       el botón de borrar quedaba cortado por el borde. Cuatro columnas
       no caben en un móvil, así que ahí deja de ser tabla y pasa a ser
       una lista. El HTML no cambia; sólo cómo se dibuja.
       ═══════════════════════════════════════════ */
    @media (max-width: 560px) {
      #tab-historial thead { display: none; }

      #tab-historial table,
      #tab-historial tbody,
      #tab-historial tr,
      #tab-historial td { display: block; width: auto; }

      #tab-historial tr {
        position: relative;
        padding: 12px 92px 12px 14px;   /* hueco a la derecha para los botones */
        border-bottom: 1px solid var(--border);
      }

      #tab-historial tr:last-child { border-bottom: none; }

      #tab-historial td {
        border: none;
        padding: 0;
        white-space: normal !important;
      }

      /* 1ª fecha y 2ª tipo, juntas arriba y en pequeño */
      #tab-historial td:nth-child(1),
      #tab-historial td:nth-child(2) {
        display: inline;
        font-size: 0.78rem;
        color: var(--text2);
      }

      #tab-historial td:nth-child(1)::after {
        content: " · ";
        color: var(--border);
      }

      /* 3ª el detalle, que es lo que se lee */
      #tab-historial td:nth-child(3) {
        margin-top: 3px;
        font-size: 0.95rem;
      }

      /* 4ª los botones, anclados a la derecha y centrados */
      #tab-historial td:nth-child(4) {
        position: absolute;
        top: 50%;
        right: 12px;
        transform: translateY(-50%);
        margin: 0;
      }

      /* El estado vacío ocupa toda la fila, sin el hueco de los botones */
      #tab-historial td.empty-state {
        position: static;
        transform: none;
        padding: 26px 14px;
        text-align: center;
      }

      #tab-historial tr:has(.empty-state) { padding: 0; }
    }

    /* ═══════════════════════════════════════════
       SECCIONES DE AJUSTES

       Eran ocho bloques seguidos, todos con el mismo peso visual, en un
       contenido de 1.222 px dentro de un modal de 690: para encontrar
       cualquier cosa había que leérselo entero. Ahora son tres secciones
       y sólo la primera viene abierta.
       ═══════════════════════════════════════════ */
    .secc {
      border: 1px solid var(--border);
      border-radius: 12px;
      margin-bottom: 10px;
      background: var(--surface2);
      overflow: hidden;
    }

    .secc > summary {
      list-style: none;
      cursor: pointer;
      padding: 13px 15px;
      font-size: 0.95rem;
      font-weight: 620;
      display: flex;
      align-items: center;
      gap: 9px;
      user-select: none;
    }

    .secc > summary::-webkit-details-marker { display: none; }

    /* La flecha va al final, empujada por el margen automático */
    .secc > summary::after {
      content: "›";
      margin-left: auto;
      font-size: 1.25rem;
      line-height: 1;
      color: var(--text2);
      transition: transform .15s ease;
    }

    .secc[open] > summary::after { transform: rotate(90deg); }

    .secc[open] > summary { border-bottom: 1px solid var(--border); }

    /* El contenido respira dentro de la sección */
    .secc > .field,
    .secc > details.mas { margin: 14px 15px; }

    .secc > .field:last-child { margin-bottom: 15px; }

    /* Dentro de una sección, las tarjetas interiores usan el fondo de la
       tarjeta para que se distingan del fondo de la propia sección */
    .secc .ali-fila,
    .secc .modulo-fila,
    .secc .mas { background: var(--surface); }

    /* ═══════════════════════════════════════════
       MUESTRAS DE COLOR
       ═══════════════════════════════════════════ */
    .color-btn {
      position: relative;
      width: 100%;
      aspect-ratio: 1;
      padding: 0;
      border-radius: 50%;
      border: 2px solid var(--border);
      background: var(--muestra);
      cursor: pointer;
      transition: transform .12s ease, box-shadow .12s ease;
    }

    .color-btn:hover { transform: scale(1.08); }

    /* La elegida: anillo del color de acción, separado por un hueco del
       propio fondo para que se vea también sobre un color claro */
    .color-btn.sel {
      border-color: var(--surface);
      box-shadow: 0 0 0 3px var(--primary);
    }

    /* El ⚠️ de blanquecino y rojizo: la advertencia no puede depender
       de reconocer un tono */
    .color-ojo {
      position: absolute;
      right: -3px;
      bottom: -3px;
      font-size: 0.6rem;
      line-height: 1;
      pointer-events: none;
    }

    /* El nombre de la elegida ocupa toda la fila, debajo de las muestras */
    .color-nombre {
      grid-column: 1 / -1;
      font-size: 0.82rem;
      color: var(--text);
      font-weight: 560;
      margin-top: 2px;
    }

    /* Enlace discreto bajo los botones de entrar */
    .enlace-sutil {
      font-size: 0.85rem;
      color: var(--text2);
      text-decoration: none;
      border-bottom: 1px solid var(--border);
      padding-bottom: 1px;
    }

    .enlace-sutil:hover { color: var(--primary-txt); border-bottom-color: var(--primary-txt); }
