/* =========================================================
   TarifarioLab — sistema de diseño
   Paleta clínica: teal profundo + tinta azul-carbón + acentos
   de tubos de muestra reales (morado, celeste, amarillo, rojo, verde)
   ========================================================= */

:root {
  --bg: #F5F8F7;
  --surface: #FFFFFF;
  --surface-soft: #EEF3F1;
  --ink: #10222A;
  --ink-soft: #4C6169;
  --ink-faint: #7C8C92;

  --brand: #0B6E5D;
  --brand-dark: #084F43;
  --brand-tint: #E3F1EC;

  --accent: #2E6E8E;
  --accent-tint: #E5EFF3;

  --warn: #A85423;
  --warn-tint: #F7EAE0;

  --success: #1C8C5B;
  --success-tint: #E5F4EC;

  --danger: #B3261E;

  --border: #DCE4E2;
  --border-strong: #C3D0CC;

  --focus: #2E6E8E;

  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(16, 34, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 34, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(16, 34, 42, 0.14);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; }

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  z-index: 1000;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ================= Header ================= */
.site-header {
  background: linear-gradient(180deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: 18px clamp(16px, 4vw, 40px);
}
.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: #fff;
  padding: 3px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.35);
  object-fit: contain;
  flex-shrink: 0;
}
.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.brand-name em { font-style: italic; color: #CDEAE0; }
.brand-tag {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: rgba(255,255,255,0.78);
}
.data-status {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.22);
  padding: 6px 12px;
  border-radius: 999px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #E8C24A;
  flex-shrink: 0;
}
.data-status.ok .status-dot { background: #5FE0A6; }
.data-status.error .status-dot { background: #F08A6C; }

/* ================= Banner ================= */
.banner-area {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px);
}
.banner {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid transparent;
}
.banner-warn { background: var(--warn-tint); color: var(--warn); border-color: #E9CBAE; }
.banner-error { background: #FBE9E7; color: var(--danger); border-color: #F0C4C0; }
.banner-info { background: var(--accent-tint); color: var(--accent); border-color: #C7DDE7; }
.banner strong { font-weight: 600; }
.banner-close {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  font-size: 15px; color: inherit; opacity: 0.7;
  padding: 0 2px;
}
.banner-close:hover { opacity: 1; }

/* ================= Buscador hero ================= */
.search-hero {
  padding: 30px clamp(16px, 4vw, 40px) 18px;
  max-width: 1180px;
  margin: 0 auto;
}
.search-hero-inner { max-width: 720px; }
.search-label {
  display: block;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 19px;
  color: var(--brand-dark);
  margin-bottom: 10px;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 4px 6px 4px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-tint);
}
.search-icon { color: var(--ink-faint); flex-shrink: 0; }
#searchInput {
  flex: 1;
  border: none;
  outline: none;
  padding: 13px 4px;
  font-size: 16px;
  background: transparent;
  color: var(--ink);
}
#searchInput::placeholder { color: var(--ink-faint); }
.clear-search {
  color: var(--ink-faint);
}
.search-hint {
  margin: 8px 2px 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ================= Barra de control ================= */
.control-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px clamp(16px, 4vw, 40px);
}
.control-bar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.btn {
  font-weight: 600;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-outline {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--ink);
}
.btn-outline:hover { border-color: var(--brand); color: var(--brand-dark); }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--ink-soft); }
.btn-ghost:hover { border-color: var(--ink-soft); color: var(--ink); }

.filter-count {
  background: var(--brand);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}
.sort-control select {
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface);
}

.results-count {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  margin-left: auto;
}

.print-btn { flex-shrink: 0; }

.print-all-hint {
  max-width: 1180px;
  margin: 8px auto 0;
  font-size: 12.5px;
  color: var(--ink-faint);
}
.print-all-hint button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.share-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.share-label {
  font-size: 12px;
  color: var(--ink-faint);
  margin-right: 2px;
  display: none;
}
.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand-dark); }

.active-chips {
  max-width: 1180px;
  margin: 10px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-tint);
  color: var(--brand-dark);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 8px 5px 12px;
  border-radius: 999px;
}
.chip button {
  background: none; border: none; cursor: pointer;
  color: var(--brand-dark);
  opacity: 0.65;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  border-radius: 50%;
}
.chip button:hover { opacity: 1; background: rgba(11,110,93,0.15); }

/* ================= Layout ================= */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px clamp(16px, 4vw, 40px) 10px;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  align-items: start;
}

/* ---- Filtros ---- */
.filters-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.filters-panel-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.filters-panel-header h2 { font-size: 17px; }

.filters-body { padding: 18px; display: flex; flex-direction: column; gap: 18px; }

.filter-group label.filter-group-title {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.filter-group select {
  width: 100%;
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--surface);
}
.price-range-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}
.price-range-inputs input {
  width: 100%;
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 9px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.price-range-inputs span { color: var(--ink-faint); font-size: 12px; }

.filters-footer {
  display: none;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.filters-footer .btn { flex: 1; justify-content: center; }

.filters-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,34,42,0.45);
  z-index: 45;
}

/* ---- Resultados ---- */
.results-area { min-height: 300px; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: auto;
  box-shadow: var(--shadow-sm);
}
.results-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.results-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-soft);
  text-align: left;
  padding: 12px 14px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.results-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.results-table tbody tr:hover { background: var(--brand-tint); }
.results-table tbody tr:last-child td { border-bottom: none; }
.cell-name { font-weight: 600; }
.cell-name .synonyms { display: block; font-size: 12px; font-weight: 400; color: var(--ink-faint); margin-top: 2px; }
.cell-price { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }
.cell-price .price-type { display: block; font-family: var(--font-body); font-weight: 400; font-size: 11.5px; color: var(--ink-faint); }
.cell-obs { color: var(--ink-soft); font-size: 13px; max-width: 220px; }

/* Tubo swatch — elemento distintivo: simula el capuchón real del tubo */
.tube-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.tube-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-available { background: var(--success-tint); color: var(--success); }
.badge-unavailable { background: #F4E6E5; color: var(--danger); }
.badge-neutral { background: var(--accent-tint); color: var(--accent); }

/* ---- Tarjetas (móvil) ---- */
.cards-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.result-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.result-card-name { font-weight: 700; font-size: 15.5px; }
.result-card-synonyms { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.result-card-price { font-family: var(--font-mono); font-weight: 700; font-size: 16px; color: var(--brand-dark); white-space: nowrap; text-align: right; }
.result-card-price small { display: block; font-family: var(--font-body); font-weight: 400; font-size: 11px; color: var(--ink-faint); }
.result-card-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.result-card-meta { margin-top: 10px; font-size: 13px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; }
.result-card-meta .meta-label { color: var(--ink-faint); font-weight: 600; margin-right: 4px; }
.result-card-obs { margin-top: 8px; font-size: 12.5px; color: var(--ink-soft); border-top: 1px dashed var(--border); padding-top: 8px; }

/* ---- Estados ---- */
.empty-state, .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 70px 20px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.empty-state svg { color: var(--ink-faint); margin-bottom: 14px; }
.empty-state h2 { font-family: var(--font-display); font-size: 20px; color: var(--ink); margin-bottom: 6px; }
.empty-state p { margin: 0 0 16px; max-width: 320px; }

.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= Carga manual ================= */
.upload-section {
  max-width: 1180px;
  margin: 30px auto 50px;
  padding: 0 clamp(16px, 4vw, 40px);
}
.upload-section[hidden] { display: none; }
.upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  max-width: 520px;
  box-shadow: var(--shadow-sm);
}
.upload-section.prominent .upload-card {
  border: 2px solid var(--brand);
  box-shadow: var(--shadow-md);
  background: var(--brand-tint);
}
.upload-section.prominent .file-drop {
  border-color: var(--brand);
}
.upload-card h2 { font-family: var(--font-display); font-size: 19px; color: var(--brand-dark); margin-bottom: 6px; }
.upload-card p { color: var(--ink-soft); font-size: 13.5px; margin: 0 0 16px; }
.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 26px 16px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: border-color 0.15s, background 0.15s;
}
.file-drop:hover, .file-drop:focus-within { border-color: var(--brand); background: var(--brand-tint); }
.file-drop strong { color: var(--brand-dark); }
.file-drop-hint { font-size: 12px; color: var(--ink-faint); }
.upload-filename { margin: 10px 0 0; font-size: 13px; color: var(--brand-dark); font-weight: 600; }

/* ================= Toast ================= */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  z-index: 80;
}

/* ================= Footer ================= */
.site-footer {
  text-align: center;
  padding: 26px 16px 40px;
  color: var(--ink-faint);
  font-size: 12px;
}

/* =========================================================
   Responsive — mobile-first breakpoints
   ========================================================= */
@media (min-width: 720px) {
  .share-label { display: inline; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }

  .filters-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(340px, 86vw);
    max-height: none;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 50;
    display: flex;
    flex-direction: column;
  }
  .filters-panel.open { transform: translateX(0); }
  .filters-panel-header { display: flex; }
  .filters-body { flex: 1; overflow-y: auto; }
  .filters-footer { display: flex; }

  .table-wrap { display: none !important; }
}

@media (min-width: 901px) {
  .filters-toggle { display: none; }
  .cards-list { display: none !important; }
}

@media (max-width: 520px) {
  .control-bar-inner { gap: 8px; }
  .sort-control label { display: none; }
  .results-count { order: 5; width: 100%; margin-left: 0; }
  .brand-tag { display: none; }
}

/* =========================================================
   Encabezado de impresión — oculto en pantalla, visible al imprimir
   ========================================================= */
.print-header { display: none; }

/* =========================================================
   Impresión / Exportar a PDF
   ========================================================= */
@page {
  size: A4;
  margin: 1.6cm 1.4cm;
}

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11.5pt;
  }

  /* Oculta todo lo interactivo: no aporta al documento impreso */
  .site-header,
  .banner-area,
  .search-hero,
  .control-bar,
  .filters-panel,
  .filters-overlay,
  .upload-section,
  .site-footer,
  .toast,
  .skip-link,
  .loading-state,
  .cards-list {
    display: none !important;
  }

  .print-header {
    display: block !important;
    margin-bottom: 16px;
    border-bottom: 2px solid #000;
    padding-bottom: 10px;
  }
  .print-header-top {
    display: flex;
    align-items: center;
    gap: 14px;
  }
  .print-logo { height: 46px; width: auto; }
  .print-doc-title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 16pt;
    color: #000;
  }
  .print-doc-date {
    margin: 2px 0 0;
    font-size: 9.5pt;
    color: #333;
    text-transform: capitalize;
  }
  .print-header-bottom {
    margin-top: 8px;
    font-size: 9pt;
    color: #333;
  }
  .print-header-bottom p { margin: 2px 0; }
  #printFiltersLine:empty, #printCountLine:empty { display: none; }

  .layout {
    display: block !important;
    padding: 0 !important;
    max-width: none;
  }
  .results-area { min-height: 0; }

  .empty-state {
    border: none;
    padding: 20px 0;
  }

  /* Fuerza la vista de tabla en impresión, sin importar el ancho de pantalla */
  .table-wrap {
    display: block !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: visible !important;
  }
  .results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9.5pt;
  }
  .results-table thead { display: table-header-group; } /* repite encabezado en cada página */
  .results-table thead th {
    position: static;
    background: #EFEFEF !important;
    color: #000 !important;
    border-bottom: 1.5px solid #000;
    padding: 6px 8px;
  }
  .results-table tbody td {
    padding: 6px 8px;
    border-bottom: 0.75px solid #999;
    color: #000 !important;
  }
  .results-table tbody tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .results-table tbody tr:hover { background: none !important; }

  .cell-name .synonyms,
  .cell-price .price-type,
  .cell-obs { color: #444 !important; }

  .tube-dot {
    border-color: #000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .badge {
    background: none !important;
    border: 1px solid #666;
    color: #000 !important;
  }

  .site-footer { display: none !important; }

  a[href]::after { content: none !important; }
}
