/* Koparental — estilos.
   Paleta oficial (entregada por el cliente): azul confiable + verde de equilibrio, fondos limpios
   y acentos empáticos. Las variables --color-* son la paleta tal cual; los tokens cortos (--pri,
   --ok, etc.) la aplican en la interfaz. Donde hay texto sobre color se usan variantes más
   oscuras del MISMO tono para cumplir contraste WCAG AA (los tonos pastel no alcanzan 4.5:1). */
:root {
  /* ── Paleta oficial ── */
  --color-bg-primary: #F7F9FB;
  --color-bg-secondary: #FFFFFF;
  --color-bg-accent: #F5F1E8;
  --color-primary: #5B9BD5;
  --color-primary-dark: #3F7BB5;
  --color-secondary: #7FB069;
  --color-text-primary: #2D3748;
  --color-text-secondary: #4A5568;
  --color-border: #E2E8F0;
  --color-accent-soft: #C4B5D8;
  --color-accent-warm: #FAD7C8;
  --color-success: #68B684;
  --color-warning: #F6C98B;
  --color-error: #E58A8A;

  /* ── Variantes legibles derivadas (texto sobre blanco o texto blanco encima) ── */
  --color-primary-ink: #2F6496;   /* azul para enlaces y texto destacado (6.2:1) */
  --color-success-ink: #2E6B4A;   /* 6.3:1 */
  --color-warning-ink: #8A5A12;   /* 5.9:1 */
  --color-error-ink: #A94442;     /* 5.9:1 */

  /* ── Tokens de la interfaz ── */
  --bg: var(--color-bg-primary); --bg-2: #EEF2F6; --card: var(--color-bg-secondary);
  --ink: var(--color-text-primary); --muted: var(--color-text-secondary); --line: var(--color-border);
  --pri: var(--color-primary-dark); --pri-2: #E6F0FA; --pri-3: var(--color-primary-ink); --pri-claro: var(--color-primary);
  --sec: var(--color-secondary); --sec-2: #EDF5E8;
  --acc: var(--color-accent-soft); --acc-2: var(--color-accent-warm); --acc-3: var(--color-bg-accent);
  --ok: var(--color-success-ink); --ok-2: #E6F4EC; --ok-borde: var(--color-success);
  --warn: var(--color-warning-ink); --warn-2: #FDF3E4; --warn-borde: var(--color-warning);
  --bad: var(--color-error-ink); --bad-2: #FBECEC; --bad-borde: var(--color-error);
  --peligro: #B5544F;             /* fondo de botones de peligro (texto blanco 4.8:1) */
  /* Niveles de conflicto: tonos de la paleta oscurecidos para texto blanco */
  --n1: #3D7A35; --n2: #8A5A12; --n3: #B5544F; --n4: #6E5596;
  --radio: 14px; --sombra: 0 1px 2px rgba(45,55,72,.06), 0 4px 16px rgba(45,55,72,.06);
  --fuente: 'Nunito Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; --titulo: 'Fraunces', Georgia, serif;
  /* Franja de caso activo y fondo del logotipo (en oscuro el logotipo va sobre un recuadro claro
     para conservar los colores de la marca). */
  --caso-bg: var(--color-accent-soft); --caso-ink: var(--color-text-primary); --logo-fondo: transparent; --logo-pad: 0;
  color-scheme: light;
}
/* Modo oscuro: automático según el dispositivo, o elegido en Mi cuenta (atributo data-theme,
   que aplica public/js/tema.js antes de pintar). Mantener ambos bloques iguales. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161C24; --bg-2: #1E2631; --card: #1F2833; --ink: #E7ECF2; --muted: #A9B4C2; --line: #2E3A48;
    --pri: #5B9BD5; --pri-2: #22344A; --pri-3: #8DBDE6; --pri-claro: #5B9BD5;
    --sec-2: #22331F; --acc-2: #4A3329; --acc-3: #2A2620;
    --ok: #8FD0A6; --ok-2: #1F3328; --warn: #F6C98B; --warn-2: #3A321F; --bad: #F0A5A5; --bad-2: #3D2425;
    --caso-bg: #3A3350; --caso-ink: #ECE6F7;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #161C24; --bg-2: #1E2631; --card: #1F2833; --ink: #E7ECF2; --muted: #A9B4C2; --line: #2E3A48;
    --pri: #5B9BD5; --pri-2: #22344A; --pri-3: #8DBDE6; --pri-claro: #5B9BD5;
    --sec-2: #22331F; --acc-2: #4A3329; --acc-3: #2A2620;
    --ok: #8FD0A6; --ok-2: #1F3328; --warn: #F6C98B; --warn-2: #3A321F; --bad: #F0A5A5; --bad-2: #3D2425;
    --caso-bg: #3A3350; --caso-ink: #ECE6F7;
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--fuente); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--pri-3); }
h1, h2, h3 { font-family: var(--titulo); line-height: 1.2; margin: 0 0 .5rem; font-weight: 700; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.08rem; font-family: var(--fuente); font-weight: 800; }
p { margin: 0 0 .8rem; }
small, .muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
.oculto { display: none !important; }

/* ─── Layout ─── */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.app > * { min-width: 0; }
.lateral { background: var(--card); border-right: 1px solid var(--line); padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.marca { display: flex; align-items: center; gap: 10px; font-family: var(--titulo); font-size: 1.35rem; font-weight: 700; color: var(--pri-3); padding: 4px 8px 14px; text-decoration: none; }
.marca img { width: 40px; height: 40px; border-radius: 50%; }
.marca img.logo-marca, img.logo-marca { width: auto; max-width: 100%; border-radius: 0; box-shadow: none; }
.marca-chip { display: inline-flex; background: #FFFFFF; border-radius: 14px; padding: 10px 16px; margin: 0 0 18px; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.marca-grande { font-size: 1.7rem; }
.marca-grande img { width: 64px; height: 64px; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: .95rem; }
.nav a:hover { background: var(--bg-2); }
.nav a.activo { background: var(--pri-2); color: var(--pri-3); }
.nav .ico { width: 20px; text-align: center; opacity: .85; }
.nav .badge { margin-left: auto; }
.nav-sep { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 12px 4px; font-weight: 700; }
.lateral .pie { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); font-size: .85rem; }
.principal { padding: 22px clamp(16px, 3vw, 40px) 90px; max-width: 1180px; width: 100%; }
.caso-activo { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px; padding: 8px clamp(16px, 3vw, 40px); background: var(--caso-bg); color: var(--caso-ink); font-size: .9rem; border-bottom: 1px solid var(--line); }
.caso-activo .cambiar { display: flex; align-items: center; gap: 6px; font-size: .85rem; }
.caso-activo select { width: auto; max-width: 220px; padding: 4px 8px; font-size: .85rem; }
.topbar { display: none; }
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .lateral { display: none; }
  .lateral.abierta { display: flex; position: fixed; inset: 0 25% 0 0; z-index: 50; box-shadow: var(--sombra); }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .topbar .marca { padding: 0; font-size: 1.15rem; }
  .topbar .marca img { width: 32px; height: 32px; }
  .principal { padding: 16px 16px 96px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; text-align: center; padding: 8px 2px 6px; font-size: .7rem; color: var(--muted); text-decoration: none; font-weight: 700; }
  .bottom-nav a .ico { display: block; font-size: 1.15rem; }
  .bottom-nav a.activo { color: var(--pri); }
}

/* ─── Componentes ─── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radio); padding: 18px; box-shadow: var(--sombra); margin-bottom: 16px; }
.card.plana { box-shadow: none; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila.entre { justify-content: space-between; }
.pila > * + * { margin-top: 10px; }
.encabezado { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.encabezado p { margin: 0; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; background: var(--pri); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 700; cursor: pointer; text-decoration: none; font-size: .95rem; min-height: 42px; transition: background .15s, transform .05s; }
.btn:hover { background: var(--pri-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sec { background: var(--card); color: var(--pri-3); border-color: var(--line); }
.btn.sec:hover { background: var(--bg-2); }
.btn.suave { background: var(--pri-2); color: var(--pri-3); }
.btn.peligro { background: var(--peligro); }
.btn.acento { background: var(--sec); color: #1F3A17; }
.btn.acento:hover { background: #6E9E59; }
.btn.chico { padding: 6px 11px; min-height: 34px; font-size: .86rem; }
.btn.bloque { width: 100%; }
.btn-link { background: none; border: 0; color: var(--pri-3); cursor: pointer; padding: 0; font-weight: 700; text-decoration: underline; }

label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 5px; }
.campo { margin-bottom: 14px; }
.campo .ayuda { font-size: .82rem; color: var(--muted); margin-top: 4px; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=tel], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 42px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--pri) 35%, transparent); outline-offset: 1px; border-color: var(--pri); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.check input { margin-top: 4px; width: 18px; height: 18px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 800; background: var(--bg-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-2); color: var(--ok); } .badge.warn { background: var(--warn-2); color: var(--warn); }
.badge.bad { background: var(--bad-2); color: var(--bad); } .badge.pri { background: var(--pri-2); color: var(--pri-3); }
.badge.num { background: var(--acc); color: var(--ink); min-width: 20px; justify-content: center; }
.nivel { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: .85rem; color: #fff; }
.nivel.n1 { background: var(--n1); } .nivel.n2 { background: var(--n2); } .nivel.n3 { background: var(--n3); } .nivel.n4 { background: var(--n4); }
.banda-nivel { border-radius: var(--radio); padding: 14px 18px; margin-bottom: 16px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; border: 1px solid var(--line); background: var(--card); }
.banda-nivel.n1 { border-left: 6px solid var(--n1); } .banda-nivel.n2 { border-left: 6px solid var(--n2); } .banda-nivel.n3 { border-left: 6px solid var(--n3); } .banda-nivel.n4 { border-left: 6px solid var(--n4); }
.aviso { padding: 12px 14px; border-radius: 12px; background: var(--pri-2); color: var(--ink); margin-bottom: 14px; font-size: .94rem; }
.aviso.warn { background: var(--warn-2); border-left: 4px solid var(--warn-borde); } .aviso.bad { background: var(--bad-2); border-left: 4px solid var(--bad-borde); } .aviso.ok { background: var(--ok-2); border-left: 4px solid var(--ok-borde); } .aviso.acc { background: var(--acc-3); border-left: 4px solid var(--acc-2); }

.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radio); padding: 14px 16px; }
.kpi .v { color: var(--ink); font-size: 1.7rem; font-weight: 800; font-family: var(--titulo); }
.kpi .l { color: var(--muted); font-size: .85rem; font-weight: 700; }
.kpi .meta { font-size: .78rem; color: var(--muted); }
.barra { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.barra > i { display: block; height: 100%; background: var(--pri); border-radius: 99px; }

.lista { list-style: none; padding: 0; margin: 0; }
.lista > li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.lista > li:last-child { border-bottom: 0; }
.item { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.item .t { font-weight: 800; }
.tabla { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabla th, .tabla td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabla th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tabla-scroll { overflow-x: auto; }
.vacio { text-align: center; padding: 26px 10px; color: var(--muted); }

/* ─── Chat ─── */
.chat { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 380px; }
.chat .mensajes { flex: 1; overflow-y: auto; padding: 8px 4px; display: flex; flex-direction: column; gap: 8px; }
.burbuja { max-width: min(78%, 560px); padding: 10px 13px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); word-wrap: break-word; }
.burbuja .txt { white-space: pre-wrap; }
.burbuja.mia { align-self: flex-end; background: var(--color-primary-ink); color: #fff; border-color: var(--color-primary-ink); border-bottom-right-radius: 4px; }
.burbuja.suya { align-self: flex-start; border-bottom-left-radius: 4px; }
.burbuja.maria { align-self: flex-start; background: var(--acc-3); border-color: var(--acc-2); }
.burbuja.comunicado { border-left: 4px solid var(--n4); }
.burbuja .meta { font-size: .72rem; opacity: .75; margin-top: 4px; }
.redactor { display: flex; gap: 8px; align-items: flex-end; padding-top: 10px; border-top: 1px solid var(--line); }
.redactor textarea { min-height: 46px; max-height: 160px; }
.propuesta { border: 2px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; background: var(--card); text-align: left; width: 100%; }
.propuesta:hover, .propuesta.sel { border-color: var(--pri); background: var(--pri-2); }

/* ─── Calendario ─── */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dn { font-size: .72rem; text-transform: uppercase; color: var(--muted); font-weight: 800; text-align: center; padding: 4px 0; }
.cal .dia { min-height: 92px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 5px; font-size: .74rem; overflow: hidden; }
.cal .dia.fuera { opacity: .45; } .cal .dia.hoy { border-color: var(--pri); box-shadow: inset 0 0 0 1px var(--pri); }
.cal .num { font-weight: 800; font-size: .8rem; }
.ev { display: block; border-radius: 6px; padding: 1px 5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; background: var(--bg-2); }
.ev.cuidado.A { background: var(--pri-2); color: var(--pri-3); } .ev.cuidado.B { background: var(--sec-2); color: var(--ok); }
.ev.entrega { background: var(--warn-2); color: var(--warn); } .ev.salud { background: var(--bad-2); color: var(--bad); }
.ev.escolar { background: #F0ECF6; color: #5E4A82; } .ev.vacaciones { background: var(--ok-2); color: var(--ok); }
@media (max-width: 640px) { .cal .dia { min-height: 58px; } .cal .ev { font-size: .62rem; } }
.calor { display: flex; gap: 3px; }
.calor i { width: 14px; height: 14px; border-radius: 3px; background: var(--bg-2); display: inline-block; }

/* ─── Modal y toasts ─── */
.modal-fondo { position: fixed; inset: 0; background: rgba(45, 55, 72, .45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--card); border-radius: 18px; max-width: 640px; width: 100%; max-height: 92vh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.ancho { max-width: 860px; }
.modal .cerrar { float: right; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
#toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--sombra); font-weight: 600; font-size: .92rem; animation: entra .2s ease-out; }
.toast.error { background: var(--color-error-ink); } .toast.ok { background: var(--color-success-ink); }
@keyframes entra { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ─── Acceso ─── */
.acceso { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
/* Portada: fotografía de fondo bajo un velo azul de la marca, más denso arriba (titular) y más
   liviano abajo para que se vean las manos y el niño; el texto blanco mantiene contraste AA. */
.acceso .lado { background: linear-gradient(180deg, rgba(22,50,84,.90) 0%, rgba(28,62,100,.82) 45%, rgba(30,68,108,.82) 82%, rgba(40,86,132,.55) 100%), url("/img/portada.jpg") center 62% / cover no-repeat, var(--color-primary-dark); text-shadow: 0 1px 3px rgba(0,0,0,.35); color: #F7F9FB; padding: clamp(28px, 6vw, 72px); display: flex; flex-direction: column; justify-content: center; }
.acceso .lado h1 { font-size: clamp(2rem, 4vw, 2.8rem); color: #fff; }
.acceso .lado ul { padding-left: 1.1rem; } .acceso .lado li { margin-bottom: 8px; }
.acceso .form { padding: clamp(24px, 5vw, 64px); display: flex; flex-direction: column; justify-content: center; max-width: 520px; width: 100%; justify-self: center; }
@media (max-width: 860px) { .acceso .lado { background: linear-gradient(180deg, rgba(22,50,84,.88), rgba(32,72,114,.72)), url("/img/portada-800.jpg") center 55% / cover no-repeat, var(--color-primary-dark); }
  .acceso { grid-template-columns: 1fr; } .acceso .lado { padding: 28px 20px; } .acceso .lado ul { display: none; } }
.tabs { display: flex; gap: 4px; background: var(--bg-2); padding: 4px; border-radius: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px 12px; border-radius: 9px; font-weight: 700; cursor: pointer; color: var(--muted); }
.tabs button.activo { background: var(--card); color: var(--ink); box-shadow: var(--sombra); }

.cargando-pantalla { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.logo-grande { font-family: var(--titulo); font-size: 2.2rem; color: var(--pri-3); font-weight: 700; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--pri-2); border-top-color: var(--pri); border-radius: 50%; animation: gira .8s linear infinite; display: inline-block; }
.spinner.chico { width: 16px; height: 16px; border-width: 2px; vertical-align: middle; }
@keyframes gira { to { transform: rotate(360deg); } }
.pensando { display: inline-flex; gap: 4px; } .pensando i { width: 7px; height: 7px; border-radius: 50%; background: var(--pri-claro); animation: late 1s infinite; }
.pensando i:nth-child(2) { animation-delay: .15s; } .pensando i:nth-child(3) { animation-delay: .3s; }
@keyframes late { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* Diagnóstico */
.pregunta { padding: 14px 0; border-bottom: 1px solid var(--line); }
.opciones { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.opciones label { margin: 0; font-weight: 600; font-size: .88rem; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; background: var(--card); }
.opciones input { position: absolute; opacity: 0; pointer-events: none; }
.opciones input:checked + span { color: var(--pri-3); }
.opciones label:has(input:checked) { background: var(--pri-2); border-color: var(--pri); }
.progreso { height: 6px; background: var(--bg-2); border-radius: 99px; overflow: hidden; margin: 8px 0 16px; } .progreso i { display: block; height: 100%; background: var(--sec); }

.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 14px 18px; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--pri); border: 2px solid var(--card); }
.timeline .hash { font-family: ui-monospace, Consolas, monospace; font-size: .7rem; color: var(--muted); word-break: break-all; }
.markdown h2 { font-size: 1.05rem; margin-top: 1rem; font-family: var(--fuente); font-weight: 800; }
.markdown ul { padding-left: 1.2rem; }
.fuentes { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.sugerencia { background: var(--card); border: 1px solid var(--acc-2); border-left: 4px solid var(--color-primary); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.sugerencia .sug-texto { white-space: pre-wrap; margin-bottom: 8px; }
.fuentes a { color: var(--muted); }

/* Logotipo Koparental (horizontal): nunca se deforma, ni en la barra móvil. */
.topbar .marca img.logo-marca, .marca img.logo-marca { width: auto; height: auto; max-height: 44px; background: var(--logo-fondo); padding: var(--logo-pad); border-radius: 10px; }
.topbar .marca img.logo-marca { max-height: 32px; }
.marca-chip { align-self: flex-start; width: fit-content; }
.marca-chip img.logo-marca { max-height: 56px; }

/* App Android (pantalla de borde a borde): margen de las barras del sistema. En el navegador
   env(safe-area-inset-*) vale 0, así que estas reglas no cambian nada. */
@media (max-width: 860px) {
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .lateral.abierta { padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .acceso .lado { padding-top: calc(28px + env(safe-area-inset-top)); }
}
@media (min-width: 861px) {
  .app { padding-top: env(safe-area-inset-top); }
  .lateral { top: env(safe-area-inset-top); height: calc(100vh - env(safe-area-inset-top)); }
}
#app > div:not(.app):not(.acceso) { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

/* ═══════════ v3.0 — Koparental Mediación ═══════════
   Lenguaje visual de "despacho": tinta azul petróleo para lo procesal, papel cálido para los
   documentos y sello para los códigos de verificación. Mantener los tres bloques de tokens iguales. */
:root { --med: #1F5F6B; --med-2: #E2F0F1; --med-3: #154750; --med-tx: #FFFFFF; --papel: #FFFDF8; --papel-borde: #E8E0CF; --sello: #8C2F39; --rojo-pl: #B5544F; --amb-pl: #C98A1B; --ver-pl: #3D7A35; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --med: #6FB7C2; --med-2: #1C3438; --med-3: #9FD3DB; --med-tx: #0E1A1C; --papel: #232A30; --papel-borde: #3A4148; --sello: #E59AA2; --rojo-pl: #F0A5A5; --amb-pl: #F6C98B; --ver-pl: #8FD0A6; } }
:root[data-theme="dark"] { --med: #6FB7C2; --med-2: #1C3438; --med-3: #9FD3DB; --med-tx: #0E1A1C; --papel: #232A30; --papel-borde: #3A4148; --sello: #E59AA2; --rojo-pl: #F0A5A5; --amb-pl: #F6C98B; --ver-pl: #8FD0A6; }

.med-titulo { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.eyebrow { font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 800; color: var(--med); }
.med-titulo h1 { margin: 2px 0 4px; }
.btn.med { background: var(--med); color: var(--med-tx); } .btn.med:hover { background: var(--med-3); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--med-2); color: var(--med-3); white-space: nowrap; }
.chip.previa { background: var(--warn-2); color: var(--warn); } .chip.voluntaria { background: var(--ok-2); color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: .82rem; letter-spacing: .02em; }

/* Reloj del plazo legal (art. 110) */
.reloj { display: inline-grid; place-items: center; position: relative; }
.reloj svg { display: block; transform: rotate(-90deg); }
.reloj .cifra { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.05; }
.reloj .cifra b { font-family: var(--titulo); font-size: 1.35rem; color: var(--ink); display: block; }
.reloj .cifra small { font-size: .62rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.reloj.mini .cifra b { font-size: .74rem; font-family: var(--fuente); } .reloj.mini .cifra small { display: none; }

/* Línea de vida procesal */
.vida { display: flex; overflow-x: auto; padding: 8px 2px 4px; scrollbar-width: thin; }
.vida .paso { flex: 1 0 96px; position: relative; text-align: center; padding-top: 28px; min-width: 96px; }
.vida .paso::before { content: ''; position: absolute; top: 11px; left: -50%; width: 100%; height: 3px; background: var(--line); }
.vida .paso:first-child::before { display: none; }
.vida .paso.hecho::before, .vida .paso.actual::before, .vida .paso.bloqueado::before { background: var(--med); }
.vida .nodo { position: absolute; top: 1px; left: calc(50% - 12px); width: 24px; height: 24px; border-radius: 50%; background: var(--card); border: 3px solid var(--line); z-index: 1; display: grid; place-items: center; font-size: .72rem; font-weight: 900; color: var(--med-tx); }
.vida .hecho .nodo { background: var(--med); border-color: var(--med); }
.vida .actual .nodo { border-color: var(--med); box-shadow: 0 0 0 5px color-mix(in srgb, var(--med) 22%, transparent); animation: latido 2s ease-in-out infinite; }
.vida .bloqueado .nodo { background: var(--rojo-pl); border-color: var(--rojo-pl); color: #fff; }
.vida .t { font-size: .78rem; font-weight: 800; color: var(--ink); display: block; padding: 0 2px; }
.vida .f { font-size: .7rem; color: var(--muted); }
.vida .pendiente .t { color: var(--muted); font-weight: 700; }
@keyframes latido { 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--med) 8%, transparent); } }
@media (prefers-reduced-motion: reduce) { .vida .actual .nodo { animation: none; } }

/* Cabecera de la causa */
.causa-cab { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radio); padding: 18px; box-shadow: var(--sombra); margin-bottom: 14px; border-top: 5px solid var(--med); }
@media (max-width: 640px) { .causa-cab { grid-template-columns: 1fr; } .causa-cab .reloj { justify-self: start; } }
.causa-cab h1 { font-size: 1.45rem; margin: 2px 0 6px; }
.alertas-med { display: grid; gap: 8px; margin-bottom: 14px; }
.alerta-med { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--amb-pl); font-size: .92rem; flex-wrap: wrap; }
.alerta-med.rojo { border-left-color: var(--rojo-pl); background: var(--bad-2); }
.alerta-med > div { flex: 1 1 240px; min-width: 0; }
.alerta-med .ir { margin-left: auto; white-space: nowrap; }

/* Pestañas de la causa */
.med-tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 2px solid var(--line); margin-bottom: 16px; position: sticky; top: 0; background: var(--bg); z-index: 5; scrollbar-width: none; }
.med-tabs::-webkit-scrollbar { display: none; }
.med-tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 800; color: var(--muted); cursor: pointer; white-space: nowrap; border-bottom: 3px solid transparent; margin-bottom: -2px; font-size: .9rem; }
.med-tabs button.activo { color: var(--med); border-bottom-color: var(--med); }
.med-tabs button .badge { margin-left: 4px; }
@media (max-width: 860px) { .med-tabs { top: calc(57px + env(safe-area-inset-top)); } }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(210px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.kcol { background: var(--bg-2); border-radius: 14px; padding: 10px; min-height: 140px; }
.kcol h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; justify-content: space-between; margin: 2px 4px 10px; }
.kcard { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 11px; margin-bottom: 8px; text-decoration: none; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.04); transition: transform .12s, box-shadow .12s; }
.kcard:hover { transform: translateY(-1px); box-shadow: var(--sombra); }
.kcard .cab { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.kcard .car { font-weight: 800; margin: 3px 0 6px; font-size: .95rem; }
.kcard .pie { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 6px; font-size: .76rem; color: var(--muted); }
.kcard.roja { border-left: 4px solid var(--rojo-pl); }
.punto { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--line); flex: none; }
.punto.verde { background: var(--ver-pl); } .punto.amarillo { background: var(--amb-pl); } .punto.rojo { background: var(--rojo-pl); }

/* Documentos con aspecto de expediente */
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.doc { position: relative; background: var(--papel); border: 1px solid var(--papel-borde); border-radius: 4px 14px 4px 4px; padding: 14px 14px 12px; box-shadow: 0 1px 0 var(--papel-borde), 0 3px 10px rgba(60,48,20,.06); }
.doc::after { content: ''; position: absolute; top: -1px; right: -1px; width: 18px; height: 18px; background: linear-gradient(225deg, var(--bg) 50%, var(--papel-borde) 50%); border-radius: 0 14px 0 0; }
.doc .tit { font-family: var(--titulo); font-weight: 700; font-size: 1rem; margin: 0 18px 6px 0; }
.sello { display: inline-block; border: 1.5px solid var(--sello); color: var(--sello); border-radius: 6px; padding: 1px 7px; font-family: ui-monospace, Consolas, monospace; font-size: .74rem; font-weight: 700; transform: rotate(-1.5deg); }
.doc.anulado { opacity: .55; } .doc.anulado .tit { text-decoration: line-through; }
.doc .acciones { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.firmas-linea { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Agenda semanal */
.semana { display: grid; grid-template-columns: repeat(7, minmax(118px, 1fr)); gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.semana .dia { background: var(--card); border: 1px solid var(--line); border-radius: 12px; min-height: 180px; padding: 8px; }
.semana .dia.hoy { border-color: var(--med); box-shadow: inset 0 0 0 1px var(--med); }
.semana .dia.feriado { background: repeating-linear-gradient(135deg, var(--card), var(--card) 8px, var(--bg-2) 8px, var(--bg-2) 16px); }
.semana .dn { font-size: .74rem; font-weight: 800; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; gap: 4px; }
.bloque-ses { display: block; margin-top: 6px; padding: 6px 8px; border-radius: 9px; background: var(--med-2); color: var(--med-3); text-decoration: none; font-size: .78rem; font-weight: 700; border-left: 4px solid var(--med); }
.bloque-ses.realizada { opacity: .7; border-left-color: var(--ver-pl); } .bloque-ses.suspendida { opacity: .5; text-decoration: line-through; }

/* Gráficos simples */
.barras { display: grid; gap: 8px; }
.barras .fila-b { display: grid; grid-template-columns: minmax(110px, 40%) 1fr auto; gap: 10px; align-items: center; font-size: .86rem; }
.barras .tr { height: 12px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.barras .tr i { display: block; height: 100%; background: var(--med); border-radius: 99px; }
.columnas { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.columnas .c { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; font-size: .68rem; color: var(--muted); }
.columnas .c .par { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.columnas .c i { width: 45%; max-width: 18px; background: var(--med); border-radius: 5px 5px 1px 1px; min-height: 2px; }
.columnas .c i.b { background: var(--ver-pl); }
.leyenda { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); } .leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }

/* Asistente de ingreso */
.pasos-wiz { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.pasos-wiz span { flex: 1; min-width: 92px; text-align: center; padding: 8px 6px; border-radius: 10px; background: var(--bg-2); font-size: .78rem; font-weight: 800; color: var(--muted); }
.pasos-wiz span.activo { background: var(--med); color: var(--med-tx); } .pasos-wiz span.hecho { background: var(--med-2); color: var(--med-3); }
.materias-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.materia-op { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; background: var(--card); font-weight: 600; margin: 0; font-size: .9rem; }
.materia-op input { margin-top: 3px; }
.materia-op:has(input:checked) { border-color: var(--med); background: var(--med-2); }
.materia-op.prohibida { opacity: .65; cursor: not-allowed; background: var(--bg-2); }
.rut-ok { color: var(--ok); font-weight: 800; font-size: .8rem; } .rut-mal { color: var(--bad); font-weight: 800; font-size: .8rem; }
.tamiz { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--card); }
.tamiz.bloquea { border-left: 4px solid var(--rojo-pl); } .tamiz .q { flex: 1 1 320px; font-size: .92rem; }
.tamiz .si-no { display: flex; gap: 4px; }
.tamiz .si-no label { margin: 0; border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; cursor: pointer; font-size: .85rem; position: relative; }
.tamiz .si-no input { position: absolute; opacity: 0; pointer-events: none; }
.tamiz .si-no label:has(input:checked) { background: var(--med); color: var(--med-tx); border-color: var(--med); }
.parte-form { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; background: var(--card); }
.parte-form h3 { display: flex; justify-content: space-between; align-items: center; }

/* Onboarding */
.med-hero { background: linear-gradient(135deg, #154750, #1F5F6B 60%, #2C7A86); color: #F7FBFB; border-radius: 20px; padding: clamp(22px, 4vw, 40px); margin-bottom: 18px; position: relative; overflow: hidden; }
.med-hero h1 { color: #fff; font-size: clamp(1.6rem, 3.4vw, 2.3rem); max-width: 720px; }
.med-hero p { max-width: 680px; opacity: .93; }
.med-hero .eyebrow { color: #BFE3E7; }
.med-hero::after { content: '§'; position: absolute; right: 4%; bottom: -46px; font-family: var(--titulo); font-size: 230px; opacity: .09; line-height: 1; pointer-events: none; }
.plan { border: 2px solid var(--line); border-radius: 16px; padding: 18px; background: var(--card); }
.plan.sel { border-color: var(--med); box-shadow: 0 0 0 4px var(--med-2); }
.req { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; font-size: .92rem; }
.req .m { font-weight: 900; width: 20px; flex: none; } .req.ok .m { color: var(--ok); } .req.no .m { color: var(--bad); }

/* Portal de la parte */
.portal { max-width: 760px; margin: 0 auto; padding: 22px 16px 60px; }
.portal .cabecera { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.portal .bienvenida { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; border-top: 5px solid var(--med); margin-bottom: 14px; }
.cita-grande { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.fecha-b { width: 78px; border-radius: 14px; overflow: hidden; text-align: center; border: 1px solid var(--line); background: var(--card); }
.fecha-b .mes { background: var(--med); color: var(--med-tx); font-size: .72rem; font-weight: 800; text-transform: uppercase; padding: 3px 0; }
.fecha-b .d { font-family: var(--titulo); font-size: 1.9rem; font-weight: 700; padding: 2px 0; }
.lectura { max-height: 340px; overflow-y: auto; white-space: pre-wrap; background: var(--papel); border: 1px solid var(--papel-borde); border-radius: 10px; padding: 14px; font-size: .9rem; line-height: 1.55; }
@media print { .lateral, .topbar, .bottom-nav, .med-tabs, .no-imprimir, #toasts, .caso-activo { display: none !important; } .app { display: block; } .principal { padding: 0; max-width: none; } .card, .kpi { box-shadow: none; break-inside: avoid; } }

input[type=file] { max-width: 100%; font-size: .88rem; }
select { max-width: 100%; }

/* v3.1 — Inicio simplificado, modo unilateral y menú plegable */
.pregunta-inicio { font-family: var(--titulo); font-size: 1.25rem; margin: 18px 0 10px; }
.atajos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.atajo { display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: var(--radio); background: var(--card); border: 1px solid var(--line); box-shadow: var(--sombra); color: var(--ink); text-decoration: none; min-height: 112px; transition: border-color .15s, transform .15s; }
.atajo:hover, .atajo:focus-visible { border-color: var(--pri); transform: translateY(-1px); }
.atajo .ico { font-size: 1.5rem; }
.atajo small { color: var(--muted); line-height: 1.3; }
.card.uni { border-left: 4px solid var(--acc); }
.uni-cifras { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 10px 0; }
.uni-cifras div { background: var(--bg-2); border-radius: 10px; padding: 8px 10px; text-align: center; }
.uni-cifras strong { display: block; font-size: 1.3rem; }
.uni-cifras small { color: var(--muted); }
details.plegable > summary { cursor: pointer; list-style: none; }
details.plegable > summary::-webkit-details-marker { display: none; }
details.plegable > summary::after { content: ' ▾'; color: var(--muted); }
.nav-mas > summary { cursor: pointer; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 12px 4px; font-weight: 700; list-style: none; }
.nav-mas > summary::-webkit-details-marker { display: none; }
.nav-mas > summary::after { content: ' +'; }
.nav-mas[open] > summary::after { content: ' −'; }
@media (max-width: 600px) { .atajos { grid-template-columns: 1fr 1fr; } .atajo { min-height: 96px; padding: 12px; } }

/* v3.1 — Modo kiosco de la escucha presencial del niño */
body.kiosco { overscroll-behavior: none; }
body.kiosco .card { font-size: 1.05rem; }

/* v3.1 — Página para profesionales (#/mediadores) */
.landing { max-width: 1040px; margin: 0 auto; padding: 18px 16px 8px; background: var(--bg); }
.landing-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 6px 0 18px; }
.landing-top nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.landing-top nav a:not(.btn) { color: var(--ink); font-weight: 600; text-decoration: none; }
.landing-hero { padding: 28px 0 22px; }
.landing-hero .eyebrow { color: var(--pri-3); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; margin: 0 0 8px; }
.landing-hero h1 { font-family: var(--titulo); font-size: clamp(1.8rem, 4.5vw, 2.8rem); line-height: 1.12; margin: 0 0 12px; max-width: 18ch; }
.landing-hero .bajada { font-size: 1.1rem; color: var(--muted); max-width: 62ch; margin-bottom: 18px; }
.landing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 14px; }
.landing-grid .card h3 { margin-top: 0; }
.landing-flujo ol { padding-left: 20px; line-height: 1.7; }
.landing-familias { background: var(--acc-3); }
