/* ==========================================================================
   EquiSalud · Demo — styles.css
   Enfoque MOBILE-FIRST: los estilos base son para celular (375px).
   Los @media (min-width) añaden lo que cambia en pantallas grandes.
   Sin frameworks ni fuentes externas (carga rápida en conexiones lentas de campo).
   ========================================================================== */

/* ---- 1. TOKENS: todos los colores y medidas en un solo lugar ---------------
   Colores tomados del logo: azul marino #11334e y verde.
   El verde del logo (#589144) no pasa contraste AA como texto sobre blanco,
   por eso para texto y botones usamos una versión más oscura (--green). */
:root {
  --navy: #11334e;
  --navy-2: #1c4a6e;
  --green: #2f7a3d;          /* texto/botones: contraste ≥ 4.5:1 sobre blanco */
  --green-logo: #589144;     /* solo decoración (barras, acentos) */
  --green-soft: #e5f2e7;
  --amber: #8a4b00;          /* texto de advertencia */
  --amber-soft: #fff1d6;
  --red: #b42318;
  --red-soft: #fde8e6;
  --blue-soft: #e3eef7;
  --ink: #14212b;
  --muted: #4f5f6b;
  --line: #d9e2e7;
  --bg: #f3f6f5;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 51, 78, .06), 0 4px 14px rgba(17, 51, 78, .06);
  --nav-h: 64px;
  --top-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ---- 2. BASE ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
/* El atributo hidden debe ganar siempre, aunque el elemento tenga display:flex/grid */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3 { color: var(--navy); line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--green); }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { margin: 0; padding: 0; list-style: none; }

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

/* Foco visible para quien navega con teclado */
:focus-visible { outline: 3px solid #1a73e8; outline-offset: 2px; border-radius: 6px; }

.skip { position: absolute; left: -999px; top: 8px; background: #fff; color: var(--navy); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---- 3. LAYOUT ------------------------------------------------------------
   Móvil: encabezado arriba + contenido + barra de navegación fija abajo.
   PC (≥ 900px): barra lateral a la izquierda (CSS Grid con áreas con nombre). */
.app {
  min-height: 100vh; min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top" "main";
}

.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 16px;
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; margin-right: auto; border-radius: 10px; }
.brand img { border-radius: 50%; background: #fff; }
.brand__text { display: flex; flex-direction: column; line-height: 1.1; }
.brand__text strong { font-size: 1.125rem; letter-spacing: .2px; }
.brand__text strong span { color: #8fd19e; }
.brand__text small { font-size: .72rem; opacity: .85; }

/* Selector de rol (segmentado) */
.role { display: flex; background: rgba(255, 255, 255, .14); border-radius: 999px; padding: 3px; order: 3; width: 100%; }
.role__btn { flex: 1; min-height: 40px; border: 0; background: transparent; color: #fff; border-radius: 999px; padding: 0 12px; font-weight: 600; font-size: .9rem; }
.role__btn[aria-pressed="true"] { background: #fff; color: var(--navy); }

.bell { position: relative; display: grid; place-items: center; width: 44px; height: 44px; color: #fff; border-radius: 50%; }
.bell__count { position: absolute; top: 2px; right: 0; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: #d92d20; color: #fff; font-size: .75rem; font-weight: 700; display: grid; place-items: center; }

.main { grid-area: main; min-width: 0; padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); outline: none; }
#view { max-width: 1100px; margin: 0 auto; display: grid; gap: 16px; }

/* Navegación inferior (móvil) */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.nav__list { display: flex; }
.nav__item { flex: 1; min-width: 0; }
.nav__link {
  width: 100%; min-height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; text-decoration: none; color: var(--muted);
  font-size: .72rem; font-weight: 600; padding: 6px 2px;
}
.nav__link[aria-current="page"] { color: var(--green); }
.nav__link[aria-current="page"] .ic { stroke-width: 2.3; }
.nav__item--secondary { display: none; }   /* en móvil van dentro de "Más" */
.nav__item--more { display: block; }

/* ---- 4. COMPONENTES ------------------------------------------------------ */
.page-head { display: grid; gap: 4px; }
.page-head .sub { color: var(--muted); font-size: .95rem; }
.ecg { width: 120px; height: 18px; margin-top: 4px; stroke: var(--green-logo); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card--pad0 { padding: 0; overflow: hidden; }

.grid { display: grid; gap: 16px; }
.cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; }
.kpi__num { display: block; font-size: 1.75rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.kpi__label { font-size: .82rem; color: var(--muted); }
.kpi--bad .kpi__num { color: var(--red); }
.kpi--warn .kpi__num { color: var(--amber); }

/* Semáforo ICA */
.sem { display: grid; gap: 12px; }
.sem__top { display: flex; align-items: center; gap: 16px; }
.sem__pct { font-size: 3rem; font-weight: 800; line-height: 1; color: var(--navy); }
.sem__pct small { font-size: 1.25rem; }
.sem__txt { display: grid; gap: 6px; }
.progress { height: 12px; background: #e6ecef; border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--green-logo); border-radius: 999px; transition: width .4s ease; }
.progress--warn .progress__bar { background: #d98a00; }
.progress--bad .progress__bar { background: #d92d20; }

/* Chips de estado: siempre texto + color (no depender solo del color) */
/* white-space normal: una etiqueta larga baja de línea en vez de empujar la página (desbordaba a 375px) */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: normal; max-width: 100%; background: var(--blue-soft); color: var(--navy); }
.chip--ok { background: var(--green-soft); color: #1d5a2a; }
.chip--warn { background: var(--amber-soft); color: var(--amber); }
.chip--bad { background: var(--red-soft); color: var(--red); }
.chip--muted { background: #eceff1; color: var(--muted); }
.chip .ic { width: 14px; height: 14px; stroke-width: 2.4; }

/* Botones (alto táctil ≥ 44px) */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent; background: var(--green); color: #fff; font-weight: 700; text-decoration: none; }
.btn:hover { background: #276733; }
.btn--ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn--ghost:hover { background: #f1f5f7; }
.btn--sm { min-height: 40px; padding: 0 12px; font-size: .9rem; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--navy); }
.icon-btn:hover { background: #f1f5f7; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Listas */
.list { display: grid; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); min-width: 0; }
.row:first-child { border-top: 0; }
.row__main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row__title { font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.row__sub { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.row__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
a.row { text-decoration: none; color: inherit; }
a.row:hover { background: #f7faf9; }

.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; font-size: 1.1rem; }
.avatar--lg { width: 64px; height: 64px; font-size: 1.6rem; }

/* Búsqueda y pestañas-filtro */
.search { position: relative; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 20px; height: 20px; }
.search .input { padding-left: 40px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.tab { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-weight: 600; white-space: nowrap; color: var(--navy); }
.tab[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }

/* Formularios */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label, .field .label { font-weight: 700; font-size: .9rem; color: var(--navy); }
.input, .select, .textarea { width: 100%; min-height: 46px; padding: 8px 12px; border: 1px solid #9fb0ba; border-radius: 10px; background: #fff; }
.textarea { min-height: 84px; resize: vertical; }
.hint { font-size: .8rem; color: var(--muted); }
.error { font-size: .85rem; color: var(--red); font-weight: 600; }

/* Ficha del caballo */
.profile { display: flex; gap: 14px; align-items: center; }
.profile__name { font-size: 1.4rem; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin: 0; }
.facts dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.status-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.status { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 4px; min-width: 0; justify-items: start; }
.status__name { font-weight: 700; font-size: .9rem; }
.status__date { font-size: .8rem; color: var(--muted); }

.timeline { display: grid; gap: 0; }
.tl { display: grid; grid-template-columns: 14px 1fr; gap: 12px; padding-bottom: 14px; position: relative; }
.tl::before { content: ""; position: absolute; left: 6px; top: 16px; bottom: -2px; width: 2px; background: var(--line); }
.tl:last-child::before { display: none; }
.tl__dot { width: 14px; height: 14px; border-radius: 50%; background: var(--green-logo); margin-top: 4px; }
.tl__title { font-weight: 700; }
.tl__meta { font-size: .82rem; color: var(--muted); }
.tl__note { font-size: .9rem; margin-top: 2px; overflow-wrap: anywhere; }

/* QR de demostración + escáner simulado */
.qr { width: 132px; height: 132px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: #fff; flex: none; }
.qr svg { width: 100%; height: 100%; display: block; }
.scanner { position: relative; height: 200px; border-radius: var(--radius); background: #0c1f2e; overflow: hidden; display: grid; place-items: center; color: #cfe6d6; text-align: center; padding: 16px; }
.scanner__frame { position: absolute; inset: 28px; border: 2px dashed rgba(143, 209, 158, .55); border-radius: 12px; }
.scanner__line { position: absolute; left: 36px; right: 36px; height: 3px; background: #8fd19e; box-shadow: 0 0 12px #8fd19e; animation: scan 2.4s ease-in-out infinite alternate; top: 40px; }
@keyframes scan { to { top: calc(100% - 44px); } }

/* Bioseguridad */
.check { display: flex; gap: 12px; align-items: center; min-height: 48px; padding: 6px 0; border-top: 1px solid var(--line); }
.check:first-of-type { border-top: 0; }
.check input { width: 24px; height: 24px; accent-color: var(--green); flex: none; }
.check label { flex: 1; }
.check input:checked + label { color: var(--muted); text-decoration: line-through; }

/* Inventario */
.stock { display: grid; gap: 8px; width: 100%; }
.stock__top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stock__ctrl { display: flex; align-items: center; gap: 8px; }
.stock__qty { min-width: 3ch; text-align: center; font-weight: 800; font-size: 1.1rem; }

/* Interruptor (compartir) */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.switch-row:first-of-type { border-top: 0; }
.switch { position: relative; width: 52px; height: 32px; border-radius: 999px; border: 0; background: #9fb0ba; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* Tabla del reporte: se desplaza dentro de su caja, nunca rompe la página */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; min-width: 480px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }

/* Notificación "push" simulada */
.push { display: flex; gap: 12px; align-items: flex-start; background: #0c1f2e; color: #fff; border-radius: 16px; padding: 12px 14px; }
.push img { border-radius: 8px; background: #fff; }
.push small { opacity: .75; }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; }
.footer-note { font-size: .8rem; color: var(--muted); text-align: center; padding: 8px 0; }
.footer-note button { background: none; border: 0; color: var(--green); text-decoration: underline; padding: 8px; font-size: inherit; }

/* Diálogo */
.dlg { width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border: 0; border-radius: 18px; padding: 0; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); color: var(--ink); }
.dlg::backdrop { background: rgba(8, 24, 38, .6); }
.dlg__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 16px 8px; }
.dlg__body { padding: 8px 16px 16px; overflow-y: auto; }
.menu-list { display: grid; gap: 8px; }
.menu-list a { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--navy); font-weight: 700; }

/* Aviso breve */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s, transform .2s, visibility 0s .2s; z-index: 60; max-width: calc(100vw - 32px); text-align: center; }
.toast.is-on { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }

/* Respeta a quien pidió menos movimiento en su sistema */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- 5. TABLET (≥ 600px) ------------------------------------------------- */
@media (min-width: 600px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .status-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .role { width: auto; order: 0; }
  .toast { bottom: 24px; }
}

/* ---- 6. ESCRITORIO (≥ 900px): barra lateral ------------------------------ */
@media (min-width: 900px) {
  .app {
    grid-template-columns: 248px minmax(0, 1fr);
    grid-template-areas: "top top" "nav main";
  }
  .topbar { padding: 10px 24px; }
  .nav { grid-area: nav; position: sticky; top: var(--top-h); align-self: start; height: calc(100vh - var(--top-h)); border-top: 0; border-right: 1px solid var(--line); padding: 16px 12px; }
  .nav__list { flex-direction: column; gap: 4px; }
  .nav__link { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 48px; padding: 0 14px; border-radius: 12px; font-size: .98rem; text-align: left; }
  .nav__link:hover { background: #eef4f1; }
  .nav__link[aria-current="page"] { background: var(--green-soft); }
  .nav__item--secondary { display: block; }
  .nav__item--more { display: none; }
  .main { padding: 24px 32px 48px; }
  h1 { font-size: 1.75rem; }
  .cols-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .toast { left: calc(50% + 124px); }
}

/* ---- 7. IMPRESIÓN: solo el reporte sanitario ----------------------------- */
@media print {
  .topbar, .nav, .toast, .no-print, .skip { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .card { box-shadow: none; border-color: #999; break-inside: avoid; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
