/* Lista de Espera Estrabismo — diseño "mobile-first": las reglas base son para teléfonos
   y las pantallas más grandes se ajustan con min-width (tabla completa desde 960 px).
   Estética de libro de registro: papel crema, tinta azul-negra y filete doble rojo. */

/* ------------------------------------------------------------------ Fuentes */

/* Títulos: Hanken Grotesk */
@font-face {
  font-family: 'Hanken Grotesk';
  src: url('/fonts/hanken-grotesk.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
/* Lista: Atkinson Hyperlegible, diseñada por el Braille Institute para lectores con baja visión */
@font-face {
  font-family: 'Atkinson Next';
  src: url('/fonts/atkinson-next.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Atkinson Next';
  src: url('/fonts/atkinson-next-ext.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Atkinson Mono';
  src: url('/fonts/atkinson-mono.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
}

/* ------------------------------------------------------------------ Tokens */

:root {
  --cream: #FFFDF2;
  --ivory: #FAF5E9;
  --ivory-deep: #F3ECDB;
  --paper-hover: #FCF8EC;
  --edge: #E8DFCA;
  --rule: #E7DECA;
  --rule-strong: #D3C8AE;

  --ink: #1D2327;
  --ink-soft: #50565C;
  --ink-faint: #8A8578;
  --dim: #6E6E6E;

  --accent: #1F4F5F;
  --accent-deep: #163C49;
  --oxblood: #8E3026;
  --margin-rule: rgba(142, 48, 38, 0.42);
  --warn: #86600F;
  --ok: #2F6B4F;

  /* Complejidad: punto de color, texto y fondo suave por nivel */
  --alta: #B4493B;
  --alta-ink: #7E2B22;
  --alta-wash: #FAEBE7;
  --mediana: #C4962B;
  --mediana-ink: #6E5211;
  --mediana-wash: #FAF1DC;
  --baja: #3F8A63;
  --baja-ink: #265C41;
  --baja-wash: #E8F1EB;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%2350565C' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --dot-vacio: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='4.1' fill='none' stroke='%23B9B1A0' stroke-width='1.4'/%3E%3C/svg%3E");
  --dot-alta: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='5' fill='%23B4493B'/%3E%3C/svg%3E");
  --dot-mediana: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='5' fill='%23C4962B'/%3E%3C/svg%3E");
  --dot-baja: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='5' fill='%233F8A63'/%3E%3C/svg%3E");

  --font-title: 'Hanken Grotesk', 'Helvetica Neue', Arial, sans-serif;
  --font-text: 'Atkinson Next', 'Avenir Next', 'Segoe UI', sans-serif;
  --font-mono: 'Atkinson Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --page: 1240px;
  --gutter: 16px;
  --dock-h: 112px; /* dos filas: filtro + botones */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 1px 2px rgba(70, 55, 20, 0.05),
    0 14px 34px -22px rgba(70, 55, 20, 0.28);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ------------------------------------------------------------------ Base */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background-color: var(--cream);
  /* grano de papel muy sutil */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)' opacity='.035'/%3E%3C/svg%3E");
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.i {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.emblem { width: 64px; height: 32px; fill: none; stroke: var(--accent); stroke-width: 1.3; }
.emblem .pupil { fill: var(--accent); stroke: none; }

:focus-visible { outline: 3px solid rgba(31, 79, 95, 0.35); outline-offset: 2px; }

.label-long { display: none; }

/* ------------------------------------------------------------------ Campos y botones */

.field { display: grid; gap: 6px; min-width: 0; }

.field-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* 16 px como mínimo: así el iPhone no hace zoom al escribir */
input:not([type='checkbox']),
select.select {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background-color: var(--cream);
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
select.select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 40px;
  cursor: pointer;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}
/* Desplegable de complejidad: punto de color a la izquierda y fondo suave según el nivel elegido */
select.select-nivel {
  padding-left: 36px;
  color: var(--ink-faint);
  background-image: var(--dot-vacio), var(--chevron);
  background-position: left 15px center, right 14px center;
  background-size: 10px 10px, 12px 8px;
}
select.select-nivel option { color: var(--ink); }
select.select-nivel[data-nivel='alta'],
select.select-nivel[data-nivel='alta']:focus {
  color: var(--alta-ink);
  background-color: var(--alta-wash);
  background-image: var(--dot-alta), var(--chevron);
  border-color: rgba(180, 73, 59, 0.4);
}
select.select-nivel[data-nivel='mediana'],
select.select-nivel[data-nivel='mediana']:focus {
  color: var(--mediana-ink);
  background-color: var(--mediana-wash);
  background-image: var(--dot-mediana), var(--chevron);
  border-color: rgba(196, 150, 43, 0.45);
}
select.select-nivel[data-nivel='baja'],
select.select-nivel[data-nivel='baja']:focus {
  color: var(--baja-ink);
  background-color: var(--baja-wash);
  background-image: var(--dot-baja), var(--chevron);
  border-color: rgba(63, 138, 99, 0.4);
}
input::placeholder { color: #A59F90; opacity: 1; }
input:focus, select.select:focus { outline: none; border-color: var(--accent); background-color: #fff; box-shadow: 0 0 0 3px rgba(31, 79, 95, 0.16); }
input[aria-invalid='true'] { border-color: var(--oxblood); box-shadow: 0 0 0 3px rgba(142, 48, 38, 0.13); }
input.mono { letter-spacing: 0.02em; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:disabled { opacity: 0.42; cursor: not-allowed; box-shadow: none; }

.btn-primary {
  background: var(--accent);
  color: var(--cream);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 8px 18px -10px rgba(22, 60, 73, 0.7);
}
.btn-primary:active:not(:disabled) { background: var(--accent-deep); }

.btn-ghost { background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.btn-ghost:active:not(:disabled) { background: var(--ivory-deep); }

.btn-danger { background: var(--oxblood); color: var(--cream); }
.btn-danger:active { background: #74261E; }

.btn-wide { width: 100%; }

.link-quiet {
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 3px;
  white-space: nowrap;
}

.form-msg { margin: 0; font-size: 0.92rem; line-height: 1.4; }
.form-msg:empty { display: none; }
.form-msg.is-error { color: var(--oxblood); }
.form-msg.is-warn { color: var(--warn); }

/* ------------------------------------------------------------------ Acceso (solo si hay clave) */

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(410px, 100%);
  display: grid;
  gap: 18px;
  padding: 34px 24px 28px;
  text-align: center;
  background: var(--ivory);
  border: 1px solid var(--edge);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
}
.login-card .emblem { justify-self: center; }
.login-card .field { text-align: left; }
.login-title { margin: 0; font-family: var(--font-title); font-weight: 700; font-size: 1.9rem; line-height: 1.1; letter-spacing: -0.02em; color: var(--accent); }
.login-title .accent { display: block; }
.login-lead { margin: -6px 0 4px; color: var(--ink-soft); }

/* ------------------------------------------------------------------ Cabecera */

.masthead {
  max-width: var(--page);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 0
    max(var(--gutter), env(safe-area-inset-left));
}
.masthead-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.95rem;
  line-height: 1.05;
  letter-spacing: -0.022em;
  color: var(--accent);
}
.title .accent { display: block; } /* en teléfonos, "Estrabismo" pasa a la segunda línea */
.subtitle { margin: 8px 0 0; font-family: var(--font-title); font-size: 0.95rem; color: var(--ink-soft); }
.folio { margin: 0; display: grid; justify-items: end; gap: 5px; flex: none; }
.folio-num {
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 2.7rem;
  line-height: 0.82;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.folio-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink-soft);
}
.double-rule { height: 6px; margin-top: 16px; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); }

/* ------------------------------------------------------------------ Hoja */

.sheet {
  max-width: var(--page);
  margin: 0 auto;
  padding: 18px max(var(--gutter), env(safe-area-inset-right)) calc(var(--dock-h) + var(--safe-bottom) + 28px)
    max(var(--gutter), env(safe-area-inset-left));
  display: grid;
  gap: 18px;
}

.card { background: var(--ivory); border: 1px solid var(--edge); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.card-title { margin: 0; font-family: var(--font-title); font-weight: 600; font-size: 1.2rem; line-height: 1.25; letter-spacing: -0.01em; }

/* Formulario: en teléfonos se despliega con un toque */
.entry-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 10px 14px 10px 16px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  text-align: left;
}
.entry-toggle-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--cream);
  transition: transform 0.15s ease;
}
.entry.is-open .entry-toggle-icon { transform: rotate(45deg); }
.entry-title { display: none; }
.entry-form { display: none; gap: 14px; padding: 2px 16px 18px; }
.entry.is-open .entry-form { display: grid; }
.f-submit { width: 100%; }

/* Lista */
.ledger { overflow: clip; }
.ledger-head { display: grid; gap: 12px; padding: 16px 16px 14px; }
.ledger-meta { margin: 2px 0 0; font-size: 0.9rem; color: var(--ink-soft); }

.search { position: relative; }
.search .i { position: absolute; left: 14px; top: 50%; translate: 0 -50%; color: var(--ink-faint); pointer-events: none; }
.search input { padding-left: 42px; border-radius: 999px; }

/* Teléfonos: cada paciente es una ficha */
.table { display: block; width: 100%; border-collapse: separate; border-spacing: 0; }
.table colgroup, .table thead { display: none; }
.table tbody { display: block; }
.table tr {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: 'nombre accion' 'rut accion' 'plan plan' 'complejidad complejidad' 'notas notas' 'fecha fecha';
  gap: 2px 12px;
  padding: 14px 16px 15px;
  background: var(--cream);
  border-top: 1px solid var(--rule);
  touch-action: manipulation;
}
.table td { display: block; min-width: 0; padding: 0; overflow-wrap: anywhere; }
.table td.c-nombre { grid-area: nombre; }
.table td.c-rut { grid-area: rut; }
.table td.c-plan { grid-area: plan; margin-top: 8px; }
.table td.c-complejidad { grid-area: complejidad; margin: 3px 0; }
.table td.c-notas { grid-area: notas; }
.table td.c-fecha { grid-area: fecha; margin-top: 8px; }
.table td.c-accion { grid-area: accion; align-self: start; }
/* etiqueta a la izquierda; el texto sigue siendo "inline" para que el tachado lo siga línea a línea */
.table td.c-complejidad, .table td.c-plan, .table td.c-notas, .table td.c-fecha {
  position: relative;
  padding-left: 6rem;
  line-height: 1.45rem;
}
.table td[data-label]::before {
  content: attr(data-label);
  position: absolute;
  top: 0;
  left: 0;
  line-height: 1.45rem;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.c-nombre .t { font-weight: 700; font-size: 1.06rem; line-height: 1.35; }
.c-rut .t { font-family: var(--font-mono); font-size: 0.95rem; letter-spacing: 0.02em; white-space: nowrap; }
.c-plan { font-size: 0.97rem; }
.c-notas { color: var(--ink-soft); font-size: 0.95rem; }
.c-fecha .t { font-family: var(--font-mono); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.espera { margin-left: 6px; font-size: 0.82rem; color: var(--ink-faint); }
.espera::before { content: '· '; }
.nada { color: var(--rule-strong); }

/* Complejidad: etiqueta suave con punto de color */
.nivel {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px 0 9px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.65rem;
  vertical-align: middle;
}
.nivel::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, currentColor); }
.nivel-alta { background-color: var(--alta-wash); color: var(--alta-ink); --dot: var(--alta); }
.nivel-mediana { background-color: var(--mediana-wash); color: var(--mediana-ink); --dot: var(--mediana); }
.nivel-baja { background-color: var(--baja-wash); color: var(--baja-ink); --dot: var(--baja); }
.is-done .nivel { background-color: transparent; color: var(--dim); box-shadow: inset 0 0 0 1px var(--rule-strong); --dot: var(--dim); }

/* Botón pequeño y cuadrado: × para tachar, ↺ para deshacer */
.c-accion { line-height: 0; }
.done-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.done-btn::after { content: ''; position: absolute; inset: -8px; } /* área táctil de 48 px */
.done-btn .i { width: 16px; height: 16px; stroke-width: 2.2; }
.done-btn:active { background: var(--ivory-deep); }
.is-done .done-btn { color: var(--dim); }

/* Completado: gris, tachado y atenuado — sin animación */
.t {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 56%;
  background-size: 0 0;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.is-done td { color: var(--dim); }
.is-done td:not(.c-accion) > * { opacity: 0.78; }
.is-done .t { background-size: 100% 1.5px; }
.is-done .c-nombre .t { font-weight: 600; }

/* Edición en la celda */
.cell-input,
select.select.cell-input { height: 42px; padding: 0 10px; font-size: 1rem; }
select.select-nivel.cell-input { padding: 0 30px 0 29px; background-position: left 11px center, right 10px center; }
.c-rut .cell-input { font-family: var(--font-mono); }

/* Estado vacío */
.table.is-empty { display: none; }
.empty { display: grid; justify-items: center; gap: 6px; padding: 40px 20px 44px; text-align: center; background: var(--cream); border-top: 1px solid var(--edge); }
.empty .emblem { opacity: 0.55; margin-bottom: 8px; }
.empty-title { margin: 0; font-family: var(--font-title); font-weight: 600; font-size: 1.2rem; }
.empty-text { margin: 0; color: var(--ink-soft); }

.ledger-foot {
  margin: 0;
  padding: 11px 16px 13px;
  font-size: 0.8rem;
  color: var(--ink-faint);
  background: var(--ivory);
  border-top: 1px solid var(--edge);
}
.hint-touch { display: none; }
@media (hover: none) {
  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
}

/* ------------------------------------------------------------------ Pie fijo */

.dock {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 253, 242, 0.94);
  -webkit-backdrop-filter: saturate(1.1) blur(12px);
  backdrop-filter: saturate(1.1) blur(12px);
  border-top: 1px solid var(--rule-strong);
  box-shadow: 0 -12px 30px -24px rgba(70, 55, 20, 0.45);
}
/* En teléfonos y tablets el pie tiene dos filas: el filtro arriba y los botones abajo */
.dock-row {
  max-width: var(--page);
  min-height: var(--dock-h);
  margin: 0 auto;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 10px;
}
.dock-status { display: flex; align-items: center; gap: 16px; min-width: 0; }
.dock-actions { display: flex; align-items: center; gap: 8px; }
.dock .btn { height: 44px; padding: 0 15px; font-size: 0.92rem; }

/* Filtro por complejidad: selector segmentado (radios nativos, un toque para cambiar).
   En teléfonos ocupa su propia fila del pie, sobre los botones. */
.filtro {
  order: -1;
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--ivory-deep);
}
.filtro-label {
  display: none;
  padding: 0 10px 0 12px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.filtro label { position: relative; flex: 1; }
.filtro input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.filtro label span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--ink-soft);
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.filtro label span::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.filtro input[value=''] + span::before { content: none; }
.filtro input[value='alta'] + span { --dot: var(--alta); }
.filtro input[value='mediana'] + span { --dot: var(--mediana); }
.filtro input[value='baja'] + span { --dot: var(--baja); }
.filtro input:checked + span { background: var(--cream); color: var(--ink); box-shadow: 0 1px 3px rgba(70, 55, 20, 0.14), 0 0 0 1px var(--edge); }
.filtro input[value='alta']:checked + span { background: var(--alta-wash); color: var(--alta-ink); box-shadow: 0 0 0 1px rgba(180, 73, 59, 0.35); }
.filtro input[value='mediana']:checked + span { background: var(--mediana-wash); color: var(--mediana-ink); box-shadow: 0 0 0 1px rgba(196, 150, 43, 0.4); }
.filtro input[value='baja']:checked + span { background: var(--baja-wash); color: var(--baja-ink); box-shadow: 0 0 0 1px rgba(63, 138, 99, 0.35); }
.filtro input:focus-visible + span { outline: 3px solid rgba(31, 79, 95, 0.35); outline-offset: 1px; }

.sync { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 0.82rem; color: var(--ink-soft); white-space: nowrap; }
.sync-label { display: none; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(47, 107, 79, 0.16); }
.sync[data-status='offline'] { color: var(--oxblood); }
.sync[data-status='offline'] .sync-dot { background: var(--oxblood); box-shadow: 0 0 0 3px rgba(142, 48, 38, 0.16); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ Diálogo */

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 26px 22px 20px;
  border: 1px solid var(--edge);
  border-radius: 18px;
  background: var(--ivory);
  color: var(--ink);
  box-shadow: 0 40px 90px -40px rgba(40, 30, 10, 0.55);
}
.dialog::backdrop { background: rgba(38, 32, 20, 0.3); }
.dialog-title { margin: 0 0 8px; font-family: var(--font-title); font-weight: 700; font-size: 1.4rem; letter-spacing: -0.015em; }
.dialog-text { margin: 0; color: var(--ink-soft); }
.dialog-actions { display: flex; gap: 10px; margin-top: 24px; }
.dialog-actions .btn { flex: 1; }

/* ------------------------------------------------------------------ Avisos */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + var(--safe-bottom) + 14px);
  z-index: 20;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  translate: -50% 0;
  pointer-events: none;
}
.toast {
  padding: 11px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.94rem;
  text-align: center;
  box-shadow: 0 16px 34px -18px rgba(20, 20, 20, 0.6);
  animation: toast-in 0.2s var(--ease) both;
}
.toast.is-error { background: var(--oxblood); }
.toast.is-leaving { animation: toast-out 0.2s ease forwards; }

tr.is-new { animation: ink-flash 1.6s ease-out; }
tr.is-leaving { animation: leave 0.3s ease forwards; }

@keyframes ink-flash { 0%, 25% { background-color: #F1E7CD; } 100% { background-color: var(--cream); } }
@keyframes leave { to { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ------------------------------------------------------------------ Mouse */

@media (hover: hover) {
  input:hover:not(:focus), select.select:hover:not(:focus) { border-color: #BFB396; }
  .filtro input:not(:checked):hover + span { background: rgba(255, 253, 242, 0.7); color: var(--ink); }
  .btn-primary:hover:not(:disabled) { background: var(--accent-deep); }
  .btn-ghost:hover:not(:disabled) { background: var(--ivory-deep); border-color: #BFB396; }
  .btn-danger:hover { background: #74261E; }
  .link-quiet:hover { color: var(--ink); text-decoration-color: currentColor; }
  .done-btn:hover { border-color: var(--ink-soft); color: var(--ink); background: var(--ivory-deep); }
  .table td[title] { cursor: text; }
}

/* ------------------------------------------------------------------ Teléfonos grandes y tablets */

@media (min-width: 640px) {
  :root { --gutter: 28px; --dock-h: 116px; }

  .label-long { display: inline; }
  .label-short { display: none; }

  .masthead { padding-top: max(36px, env(safe-area-inset-top)); }
  .title { font-size: 2.6rem; }
  .title .accent { display: inline; }
  .subtitle { font-size: 1.05rem; }
  .folio-num { font-size: 3.5rem; }
  .double-rule { margin-top: 20px; }
  .sheet { padding-top: 26px; gap: 24px; }

  .entry { padding: 20px 22px 22px; }
  .entry-toggle { display: none; }
  .entry-title { display: block; margin-bottom: 14px; }
  .entry-form,
  .entry.is-open .entry-form {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    padding: 0;
    align-items: end;
  }
  /* Nombre | RUT, Plan | Complejidad, Notas a lo ancho */
  .f-nombre { grid-area: 1 / 1; }
  .f-rut { grid-area: 1 / 2; }
  .f-plan { grid-area: 2 / 1; }
  .f-complejidad { grid-area: 2 / 2; }
  .f-notas { grid-area: 3 / 1 / 4 / 3; }
  .f-submit { grid-area: 4 / 1 / 5 / 3; justify-self: end; width: auto; padding: 0 22px; }
  .f-msg { grid-column: 1 / -1; }

  .filtro-label { display: inline; }
  .filtro label span { padding: 0 16px; }

  .ledger-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 14px 24px; padding: 20px 22px 16px; }
  .search { width: min(360px, 100%); }
  .table tr { padding: 14px 22px 15px; }
  .ledger-foot { padding: 12px 22px 14px; }

  .dock-row { padding: 8px max(var(--gutter), env(safe-area-inset-right)) 8px max(var(--gutter), env(safe-area-inset-left)); }
  .dock-actions { gap: 12px; }
  .dock .btn { height: 46px; padding: 0 20px; }
  .sync { font-size: 0.86rem; }
  .sync-label { display: inline; }

  .dialog { padding: 30px 30px 24px; }
  .dialog-actions { justify-content: flex-end; }
  .dialog-actions .btn { flex: none; }
}

/* ------------------------------------------------------------------ Computador: tabla completa */

@media (min-width: 960px), print {
  :root { --gutter: 40px; }

  .masthead { padding-top: 48px; }
  .title { font-size: clamp(2.8rem, 1.6rem + 2.2vw, 3.6rem); }
  .subtitle { font-size: 1.1rem; margin-top: 12px; }
  .folio-num { font-size: 4.2rem; }
  .double-rule { margin-top: 22px; }
  .sheet { padding-top: 30px; gap: 28px; }
  .card-title { font-size: 1.35rem; }
  .entry { padding: 22px 26px 24px; }
  .ledger-head { padding: 22px 26px 18px; }
  .ledger-foot { padding: 12px 26px 14px; }

  .table { display: table; table-layout: fixed; }
  .table colgroup { display: table-column-group; }
  .table thead { display: table-header-group; }
  .table tbody { display: table-row-group; }
  .table tr { display: table-row; padding: 0; background: none; border: 0; }
  .table.is-empty { display: none; }

  /* Plan y Notas (texto libre) se reparten por igual el espacio restante */
  .w-fecha { width: 140px; }
  .w-nombre { width: 18%; }
  .w-rut { width: 140px; }
  .w-complejidad { width: 142px; }
  .w-accion { width: 56px; }

  .table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 0;
    text-align: left;
    background: var(--ivory-deep);
    border-top: 1px solid var(--edge);
    border-bottom: 1px solid var(--rule-strong);
  }
  .table th button {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 11px 16px;
    border: 0;
    background: none;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    text-align: left;
  }
  .table th button:hover { color: var(--ink); }
  .sort { font-size: 0.85rem; letter-spacing: 0; color: var(--accent); }
  th[aria-sort='ascending'] .sort::before { content: '↑'; }
  th[aria-sort='descending'] .sort::before { content: '↓'; }
  th[aria-sort] button { color: var(--ink); }

  .table td,
  .table td.c-complejidad,
  .table td.c-plan,
  .table td.c-notas,
  .table td.c-fecha,
  .table td.is-editing {
    display: table-cell;
    margin: 0;
    padding: 15px 16px;
    line-height: 1.5;
    vertical-align: top;
    background: var(--cream);
    border-bottom: 1px solid var(--rule);
  }
  .table td[data-label]::before { content: none; }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover td { background: var(--paper-hover); }
  .table td.is-editing { padding-top: 9px; padding-bottom: 9px; background: #fff; }

  /* filete doble rojo, como el margen de un libro de registro */
  .table .c-fecha { border-right: 3px double var(--margin-rule); }
  .espera { display: block; margin: 2px 0 0; font-size: 0.8rem; }
  .espera::before { content: none; }
  .c-accion { text-align: center; }

  tr.is-new { animation: none; }
  tr.is-new td { animation: ink-flash 1.6s ease-out; }
}

/* ------------------------------------------------------------------ Pie en una sola fila */

@media (min-width: 1040px) {
  :root { --dock-h: 76px; }
  .dock-row { padding-top: 0; padding-bottom: 0; flex-wrap: nowrap; gap: 16px; }
  .filtro { order: 0; flex: none; }
}

/* ------------------------------------------------------------------ Pantallas anchas: formulario en una fila */

@media (min-width: 1180px) {
  .entry-form,
  .entry.is-open .entry-form {
    grid-template-columns: minmax(0, 1.5fr) 150px minmax(0, 1.8fr) 170px minmax(0, 1.8fr) auto;
  }
  .f-nombre, .f-rut, .f-complejidad, .f-plan, .f-notas, .f-submit { grid-area: auto; }
}

/* ------------------------------------------------------------------ Impresión directa (Cmd/Ctrl + P) */

/* Siempre se imprime en blanco y negro: negro puro, sin fondos ni grises */
@media print {
  * { color: #000 !important; background: none !important; box-shadow: none !important; }
  .entry, .dock, .search, .ledger-foot, .toasts, .c-accion, .w-accion, .sort { display: none !important; }
  .masthead, .sheet { padding: 0; max-width: none; }
  .double-rule { border-color: #000; }
  .card { border: 0; }
  .table th { position: static; border-top: 0; border-bottom: 1px solid #000; }
  .table td { padding: 8px 10px; border-bottom: 0.5pt solid #000; }
  .table .c-fecha { border-right: 0; }
  tr.is-done { display: none; }
}
