/* PAPTrace — tema claro rosa pastel
 *
 * Hereda la BASE FUNCIONAL de AIRIS RX (shell, breakpoints, patrones de
 * tabla, altura de controles), no sus colores. El dark 2026 no se puede
 * teñir: esta paleta se construyó desde cero y se midió.
 *
 * Contraste: todos los tokens verificados WCAG AA sobre los 4 fondos con
 * scripts/check_contrast.py. NO cambiar un color sin volver a correrlo —
 * en tema claro los tonos suaves pierden contraste con facilidad.
 */

:root {
  /* Superficies */
  --bg: #FDFBFC;
  --surface-1: #FFFFFF;
  --surface-2: #FBF5F7;
  --surface-3: #F6EBEF;

  /* Bordes */
  --line: #F0DDE4;
  --line-2: #E3C5D0;

  /* Texto */
  --ink: #2B2229;
  --ink-2: #6B5C65;
  --ink-3: #8D7E86;

  /* Acento */
  --accent: #B9647E;
  --accent-deep: #9E4F6A;
  --glow: rgba(185, 100, 126, .12);

  /* Semáforo clínico — convención estándar, NO armonizada con el rosa.
   * Un crítico vencido debe verse inequívocamente alarmante. */
  --ok: #27865A;
  --warn: #B26A00;
  --bad: #B92E29;
  --muted: #7D747B;

  /* Geometría */
  --control-h: 40px;
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 68px;

  --shadow-1: 0 1px 2px rgba(43, 34, 41, .05);
  --shadow-2: 0 4px 16px rgba(43, 34, 41, .08);

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-ui: "DM Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.25; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width .18s ease;
}

.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
}

.sidebar .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 14.5px;
  white-space: nowrap;
  /* Sin esto el contador de 3 dígitos desborda la barra lateral. */
  min-width: 0;
  overflow: hidden;
}
.nav a > span:not(.ico):not(.count) { overflow: hidden; text-overflow: ellipsis; }
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--glow); color: var(--accent-deep); font-weight: 500; }
.nav a .ico { flex-shrink: 0; width: 18px; text-align: center; }

.nav .count {
  margin-left: auto;
  background: var(--surface-3);
  color: var(--ink-2);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.nav a.active .count { background: var(--accent); color: #fff; }
.nav .count.alert { background: var(--bad); color: #fff; }

.content { flex: 1; min-width: 0; padding: 26px 34px 60px; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 22px;
}
.topbar h1 { flex: 1; min-width: 0; }

.menu-toggle {
  display: none;
  background: none; border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  width: 40px; height: 40px;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 17px;
  flex-shrink: 0;
}

/* Pie de la barra: quién tiene la sesión abierta. `margin-top:auto` lo
 * empuja al fondo sin posicionamiento absoluto. */
.sidebar-user {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Un nombre largo corta con puntos suspensivos en vez de ensanchar la barra. */
  min-width: 0;
}
.sidebar-user .su-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar colapsada (preferencia de escritorio, persistida).
 *
 * Se ocultan las ETIQUETAS, nunca los iconos: una barra colapsada sin iconos
 * es una franja gris sin navegación. Por eso los selectores excluyen
 * `.ico` y el punto de la marca — ambos son <span> y un `.nav a span`
 * a secas se los llevaba por delante. */
.collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.collapsed .sidebar .brand span:not(.dot),
.collapsed .nav a span:not(.ico),
.collapsed .nav .count,
/* Sin esto el nombre y "Cerrar sesión" se desbordan de los 68px. */
.collapsed .sidebar-user { display: none; }
.collapsed .nav a { justify-content: center; padding: 9px; }
.collapsed .brand { justify-content: center; }

/* ---------- Paneles ---------- */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-1);
}
.panel > h2 { margin-bottom: 14px; }

.panel-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 { flex: 1; min-width: 0; }

/* ---------- Tiles ---------- *
 * Regla LUMNIA: cajas de igual altura y ancho proporcional.
 * flex column + margin-top auto en .value mantiene las cifras alineadas
 * aunque un rótulo envuelva a dos líneas. */
/* grid + stretch: todas las cajas de una fila comparten altura por
 * construcción, no por coincidencia de contenido (regla LUMNIA). */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; align-items: stretch; }
.stats.cols-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* height:100% + grid stretch = todas las cajas de la fila miden lo mismo
 * aunque una tenga el rótulo o el subtítulo en dos líneas. Sin esto, la
 * altura la define el contenido y las cajas quedan disparejas (regla
 * LUMNIA: se mide en píxeles, no se estima a ojo). */
.tile {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: 92px;
  height: 100%;
  box-shadow: var(--shadow-1);
}
.tile .label { font-size: 12.5px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-family: var(--font-display); font-size: 30px; font-weight: 600; margin-top: auto; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }

.tile.focus { border-color: var(--accent); background: var(--glow); }
.tile.alert { border-color: var(--bad); }
.tile.alert .value { color: var(--bad); }

/* ---------- Chips de estado ---------- *
 * SIEMPRE punto + texto, nunca color solo (accesibilidad CVD). */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.chip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 32%, transparent); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.chip.muted { color: var(--muted); }
.chip.accent { color: var(--accent-deep); border-color: var(--line-2); background: var(--glow); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
  text-align: left;
  padding: 9px 12px;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
th:first-child { border-top-left-radius: var(--radius-sm); }
th:last-child { border-top-right-radius: var(--radius-sm); }

td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

td.nowrap, th.nowrap { white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.acts { white-space: nowrap; text-align: right; }

/* Ficha clave/valor */
table.kv th { background: none; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink-2); width: 42%; font-weight: 500; }
table.kv td, table.kv th { padding: 8px 0; border-bottom: 1px solid var(--line); }

/* ---------- Formularios ---------- */
/* Un formulario de captura no es un dashboard: en pantalla ancha se lee en
 * columna angosta, no estirado a 1400px. */
.form-slim { max-width: 680px; }

.field { margin-bottom: 16px; }

label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
/* El label envolvente necesita separar su campo: margin-bottom empuja lo
 * que va DESPUÉS del texto, y el reset deja el control pegado. */
label > input, label > select, label > textarea { margin-top: 8px; }

input, select, textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 12px;
  background: var(--surface-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--font-ui);
  /* 16px: bajo ese valor Safari en iOS amplía la página al enfocar. */
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.5; resize: vertical; }

/* La celda .mono es 14px; el CONTROL .mono debe seguir siendo 16px.
 * Separarlos evita el zoom de iOS sin achicar los datos de las tablas. */
input.mono, select.mono, textarea.mono { font-family: var(--font-mono); font-size: 16px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B5C65' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}

/* input[type=date] en WebKit ignora alto y ancho y usa su tamaño intrínseco:
 * queda más alto y más ancho que sus vecinos y desborda el panel. Es un
 * defecto del MOTOR, no del ancho de pantalla — un iPad de 1180px lo sufre
 * igual que un teléfono de 390px. Por eso vive en la base de la hoja y NO
 * dentro de una media query, que fue el error que lo dejó volver en el iPad.
 * Hay 12 campos de fecha en este producto. */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  /* Una fecha son 10 caracteres: heredar el 100% de los inputs la estiraba
   * al ancho completo del panel (feedback Felipe 2026-08-06). */
  width: 100%;
  max-width: 240px;
  height: var(--control-h);
}
/* Safari centra el texto arriba y deja el indicador pegado al borde. */
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="date"]::-webkit-calendar-picker-indicator { margin-inline-start: auto; }

.hint { font-size: 12.5px; color: var(--ink-3); margin-top: 6px; }

/* ---------- Casillas ---------- */
/* La casilla NO hereda el `width: 100%` de los campos: sin esto se estira al
 * ancho del panel y deja de parecer una casilla. */
.check {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-size: 14.5px;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.45;
}
.check:hover { background: var(--surface-2); }
.check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  appearance: auto;
  -webkit-appearance: checkbox;
  cursor: pointer;
}
.check span { flex: 1; min-width: 0; }
.check.strong { border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.check.strong:has(input:checked) {
  border-color: var(--accent);
  background: var(--glow);
}

/* ---------- Chips de selección rápida ---------- */
/* Atajos que escriben en el campo de texto vecino. El campo sigue siendo la
 * fuente: quien no está en la lista se escribe a mano. */
.picks { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.pick {
  width: auto;
  height: auto;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--surface-1);
  color: var(--ink-2);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.3;
  cursor: pointer;
  text-align: left;
}
.pick:hover { background: var(--surface-2); color: var(--ink); }
.pick.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

/* Valor que no se pregunta porque no tiene alternativa. */
.fixed-value {
  display: flex;
  align-items: center;
  height: var(--control-h);
  padding: 0 12px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  background: var(--surface-2);
}

.panel.warn-panel { border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters .field { margin-bottom: 0; flex: 1 1 170px; min-width: 0; }
/* En la fila de filtros cada campo llena su caja: el tope de 240px de las
 * fechas dejaría "Desde/Hasta" más angostos que el select vecino. */
.filters input[type="date"] { max-width: none; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: var(--control-h);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--surface-1);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

/* ---------- Alertas ---------- */
.alert {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert a { color: inherit; text-decoration: underline; }
.alert.bad { border-color: color-mix(in srgb, var(--bad) 35%, transparent); background: color-mix(in srgb, var(--bad) 7%, transparent); color: var(--bad); }
.alert.warn { border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); color: var(--warn); }
.alert.ok { border-color: color-mix(in srgb, var(--ok) 32%, transparent); background: color-mix(in srgb, var(--ok) 7%, transparent); color: var(--ok); }

.empty { text-align: center; padding: 44px 20px; color: var(--ink-3); }

/* ---------- Barra de progreso ---------- */
.bar { height: 9px; background: var(--surface-3); border-radius: 20px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 20px; }
.bar > span.ok { background: var(--ok); }
.bar > span.warn { background: var(--warn); }
.bar > span.bad { background: var(--bad); }

/* ---------- Timeline de la ficha ---------- */
.timeline { list-style: none; padding: 0; }
.timeline li { position: relative; padding: 0 0 20px 26px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 3px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface-1); border: 2px solid var(--line-2);
}
.timeline li.done::before { background: var(--ok); border-color: var(--ok); }
.timeline li.pending::before { background: var(--surface-1); border-color: var(--ink-3); }
.timeline li.alert::before { background: var(--bad); border-color: var(--bad); }
.timeline .t-label { font-weight: 500; font-size: 14px; }
.timeline .t-meta { font-size: 13px; color: var(--ink-2); margin-top: 2px; }

/* ---------- Acceso ---------- */
/* Sin shell: quien no inició sesión no ve menú ni contadores de casos.
 * `min-height: 100dvh` y no `100vh`: en Safari móvil la barra de
 * direcciones recorta la vh y el botón queda bajo el pliegue. */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 30px 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}
.login-brand .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.login-sub { font-size: 13px; color: var(--ink-2); margin: 6px 0 22px; }
.login-card .alert { margin-bottom: 18px; }
.login-submit { width: 100%; margin-top: 4px; }
.login-legal {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  line-height: 1.45;
}

/* =====================================================================
   Responsive — dos breakpoints, heredados de AIRIS RX
   ===================================================================== */

@media (max-width: 860px) {
  .menu-toggle { display: flex; align-items: center; justify-content: center; }

  /* La preferencia .collapsed es de escritorio: en el drawer debe
   * neutralizarse, o quien colapsó el menú en el computador abre el
   * celular y encuentra un drawer sin etiquetas. */
  .collapsed .sidebar { width: min(280px, 82vw); }
  .collapsed .sidebar .brand span,
  .collapsed .nav a span,
  .collapsed .nav .count { display: revert; }
  .collapsed .nav a { justify-content: flex-start; padding: 9px 12px; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(280px, 82vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-2);
  }
  .drawer-open .sidebar { transform: translateX(0); }

  .drawer-open::after {
    content: "";
    position: fixed; inset: 0;
    background: rgba(43, 34, 41, .34);
    z-index: 40;
  }

  .content { padding: 18px 16px 48px; }
  h1 { font-size: 22px; }
  .filters .field { flex: 1 1 100%; }
}

@media (max-width: 640px) {
  /* Listados a tarjetas. Se aplica POR CLASE (.rows), nunca por
   * contenedor: las fichas .kv viven dentro del mismo .table-wrap y un
   * selector por contenedor las rompería. */
  table.rows thead { display: none; }
  table.rows, table.rows tbody, table.rows tr, table.rows td { display: block; width: 100%; }

  table.rows tr {
    background: var(--surface-1);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 6px 14px;
    box-shadow: var(--shadow-1);
  }
  table.rows tr:hover { background: var(--surface-1); }

  table.rows td {
    border-bottom: 1px solid var(--line);
    padding: 9px 0;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
  }
  table.rows td:last-child { border-bottom: none; }

  table.rows td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--ink-2);
    font-weight: 600;
  }
  table.rows td.acts { justify-content: flex-end; }
  table.rows td.acts::before { content: none; }

  /* El arreglo de input[type=date] NO va acá: es un defecto del motor, no del
   * ancho. Vive en la base de la hoja, junto a los demás controles. */

  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 13px 14px; min-height: 82px; }
  .tile .value { font-size: 25px; }

  .actions .btn { flex: 1 1 100%; }
}
