/* ================= CONFIGURACIÓN GENERAL ================= */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: 'Segoe UI', Roboto, Arial, sans-serif; background: #f4f6f8; color: #333; }
.hidden { display: none !important; }

/* ================= NAVBAR ================= */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #003366;
  padding: 10px 20px;
  color: white;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  flex-wrap: wrap;
  gap: 10px;
}
.nav-left { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.nav-center { display: flex; align-items: center; justify-content: center; flex: 1; }
.nav-right { display: flex; align-items: center; gap: 15px; flex: 0 0 auto; }

.user-name {
  font-size: 13px; background: #002244; padding: 5px 12px; border-radius: 20px; color: white; white-space: nowrap;
}
.btn-inicio { background: red; color: white; border: none; padding: 6px 16px; border-radius: 4px; cursor: pointer; font-weight: bold; }
.btn-cerrar-caja-nav {
  background-color: #1E8449; color: white; border: none; padding: 5px 12px; font-size: 14px; font-weight: bold; border-radius: 4px; cursor: pointer;
}
.nav-logo { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; cursor: pointer; }
#salir { background: red; border: none; color: #fff; padding: 5px 12px; font-size: 18px; font-weight: bold; border-radius: 4px; cursor: pointer; }

.dropdown { position: relative; display: inline-block; }
.dropbtn { background-color: #1E8449; color: white; padding: 6px 12px; font-size: 14px; border: none; border-radius: 4px; cursor: pointer; }
.dropdown-content {
  display: none; position: absolute; background-color: white; min-width: 180px;
  right: 0; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; border-radius: 4px;
}
.dropdown-content button {
  color: #003366; padding: 10px 16px; display: block; width: 100%; text-align: left; border: none; background: none; cursor: pointer;
}
.dropdown-content button:hover { background-color: #f1f1f1; }
.dropdown:hover .dropdown-content { display: block; }

/* ================= LOGIN ================= */
#loginView {
  display: flex; justify-content: center; align-items: center; height: 100vh;
  background: linear-gradient(135deg, #003366 0%, #00509d 100%);
}
.login-container {
  background: white; padding: 40px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  width: 100%; max-width: 350px; text-align: center;
}
.login-container h2 { font-size: 20px; margin: 0; color: #003366; }
.subtitle { color: #1E8449 !important; margin-bottom: 20px !important; }
#loginView img { width: 120px; margin-bottom: 20px; }
#loginView input { width: 100%; padding: 12px; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px; }
#loginView button { width: 100%; padding: 12px; background: #00509d; color: white; border: none; border-radius: 4px; cursor: pointer; }

/* ================= MENÚ PRINCIPAL ================= */
.welcome-text { text-align: center; margin: 30px 0; }
.welcome-text h2 { color: #003366; font-size: 28px; }
.card-container {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 25px; padding: 20px; max-width: 1100px; margin: 0 auto;
}
.card {
  background: white; padding: 30px 20px; border-radius: 12px; text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08); cursor: pointer; transition: all 0.3s ease;
  border-bottom: 4px solid #003366;
}
.card:hover { transform: translateY(-8px); background: #f0f7ff; }
.card-icon { font-size: 45px; margin-bottom: 15px; }
.card h3 { margin: 10px 0; color: #003366; }
.card p { font-size: 14px; color: #666; }

/* ================= TABLAS ================= */
.vista { padding: 30px; max-width: 1300px; margin: 0 auto; }

/* Eliminados display: block y overflow-x: auto de la tabla para evitar espacios en blanco */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  margin-top: 15px;
  border-radius: 8px;
}

/* En escritorio se mantiene como tabla normal */
@media (min-width: 768px) {
  table {
    display: table;
  }
}

th, td { border: 1px solid #eee; padding: 12px; text-align: left; }
th { background: #003366; color: white; font-weight: 500; }
tr:nth-child(even) { background: #f9f9f9; }
.td-acciones1 button, .td-acciones2 button, .td-acciones3 button, .td-acciones4 button {
  padding: 6px 12px; border: none; border-radius: 4px; color: white; cursor: pointer; font-size: 13px;
}
.td-acciones1 button { background: #3498db; }
.td-acciones2 button { background: #1E8449; }
.td-acciones3 button { background: #E67E22; }
.td-acciones4 button { background: #e74c3c; }

/* ================= FORMULARIOS ================= */
input, select, button { font-size: 1rem; }
input, select { padding: 8px 12px; border: 1px solid #ccc; border-radius: 4px; width: 100%; }
.search-bar { width: 100%; max-width: 400px; margin-bottom: 15px; display: block; }
.form-horizontal {
  display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap;
  background: #fff; padding: 15px; border-radius: 8px;
}
.btn-add { background: #1E8449; color: white; border: none; padding: 8px 20px; cursor: pointer; border-radius: 4px; }

/* Nueva orden */
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.2rem; background: white; padding: 1.5rem; border-radius: 12px; margin-bottom: 1.5rem;
}
.field-group { display: flex; flex-direction: column; gap: 0.3rem; }
.field-group label { font-size: 0.85rem; font-weight: 600; color: #003366; letter-spacing: 0.3px; }
.sat-group .sat-input-group { display: flex; gap: 8px; }
.sat-group .sat-input-group input { flex: 1; }
.sat-group .sat-input-group button { background: #3498db; color: white; border: none; padding: 0 12px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.checklist-examenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 15px 0; }
.examen-item { background: white; padding: 10px; border: 1px solid #ddd; border-radius: 4px; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.descuento-row { display: flex; flex-wrap: wrap; align-items: center; gap: 15px; margin: 20px 0 10px; }
.descuento-input { display: flex; align-items: center; gap: 10px; background: white; padding: 8px 15px; border-radius: 8px; }
.descuento-input input { width: 140px; margin: 0; }
.btn-generar { background: #1E8449; color: white; border: none; padding: 10px 24px; border-radius: 6px; font-weight: bold; cursor: pointer; }
.totales { background: #eef2f5; padding: 15px; border-radius: 8px; margin-top: 10px; }

/* ================= MODALES ================= */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex;
  align-items: center; justify-content: center; z-index: 1000; padding: 1rem;
}
.modal-hoja { background: white; width: 100%; max-width: 800px; max-height: 85vh; overflow-y: auto; padding: 1.5rem; border-radius: 12px; }
.modal-header, .modal-footer { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; flex-wrap: wrap; gap: 10px; }
.btn-save, .btn-print, .btn-email { color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.btn-save { background: #1E8449; }
.btn-print { background: #3498db; }
.btn-email { background: #e74c3c; }

/* ================= REPORTES ================= */
.tabs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; border-bottom: 2px solid #ccc; }
.tab-btn { background: none; border: none; padding: 10px 20px; font-size: 16px; cursor: pointer; font-weight: bold; color: #555; }
.tab-btn.active { color: #003366; border-bottom: 3px solid #003366; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.reporte-controles { background: white; padding: 20px; border-radius: 8px; margin-bottom: 20px; display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
canvas { max-height: 400px; width: 100% !important; height: auto !important; }

/* ================= DOCUMENTOS IMPRESOS (formato común) ================= */
.documento-impresion {
  padding: 20px;
  background: white;
  font-family: 'Courier New', Courier, monospace;
  color: black;
  max-width: 800px;
  margin: 0 auto;
}

/* Encabezado con logo a la derecha y nombre del laboratorio centrado */
.header-doc {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #003366;
  padding-bottom: 10px;
  margin-bottom: 20px;
}

.lab-info {
  flex: 1;
  text-align: center;
}
.lab-info h1 { margin: 0; font-size: 24px; color: #003366; letter-spacing: 1px; }
.lab-info h2 { margin: 5px 0 0; font-size: 14px; font-weight: normal; color: #1E8449; }

.logo-doc {
  width: 70px;
  height: auto;
  border-radius: 8px;
  margin-left: 15px;
}

.fecha-hora {
  display: flex;
  justify-content: center;
  gap: 25px;
  font-size: 13px;
  margin-bottom: 15px;
  color: #444;
  border-bottom: 1px dashed #999;
  padding-bottom: 10px;
}

.datos-paciente {
  font-size: 14px;
  margin-bottom: 15px;
  line-height: 1.6;
}
.datos-paciente p { margin: 3px 0; }

.titulo-informe {
  text-align: center;
  font-size: 16px;
  margin: 20px 0 15px;
  text-decoration: underline;
}

.lista-resultados { margin-top: 10px; }

/* Línea punteada con valor final a la derecha */
.fila-resultado {
  display: flex;
  align-items: baseline;
  margin-bottom: 12px;
  font-size: 15px;
}

.nombre-examen {
  font-weight: bold;
  white-space: nowrap;
  background: white;
  padding-right: 8px;
  z-index: 1;
}

.valor-resultado {
  white-space: nowrap;
  background: white;
  padding-left: 8px;
  text-align: right;
  z-index: 1;
  order: 2;               /* Aparece después de los puntos */
}

.fila-resultado::after {
  content: "................................................................................";
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  margin: 0 4px;
  color: #999;
  order: 1;               /* Se sitúa entre el nombre y el valor */
}

/* ================= IMPRESIÓN ================= */
@media print {
  /* Forzar impresión de colores de fondo */
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Ocultar elementos de la interfaz */
  .navbar, .no-print, .search-bar, .controles-tabla,
  .modal-header, .modal-footer, .welcome-text, .card-container,
  .dropdown, .tabs, .reporte-botones, button {
    display: none !important;
  }

  /* Modal se convierte en la página completa, sin centrado que restrinja el ancho */
  .modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    align-items: flex-start;   /* contenido pegado arriba */
    justify-content: flex-start; /* no centrar, expandir a todo el ancho */
    padding: 0;
    z-index: 9999;
  }

  /* La hoja del modal ocupa todo el ancho disponible */
  .modal-hoja {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 1.5cm 1cm 1cm 1cm;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }

  /* Contenedor del documento también a ancho completo */
  .documento-impresion {
    width: 100%;
    max-width: 100%;
    padding: 0;
  }

  /* Tablas dentro del documento deben ocupar el 100% */
  .documento-impresion table {
    width: 100%;
    display: table;            /* Asegura que se comporte como tabla normal */
  }

  /* Quita márgenes de la página */
  @page {
    margin: 0;
  }
}



/* ================= RESPONSIVE MÓVIL ================= */
@media (max-width: 768px) {
  .navbar { flex-direction: column; align-items: stretch; text-align: center; }
  .nav-left, .nav-center, .nav-right { justify-content: center; flex-wrap: wrap; width: 100%; }
  .nav-left { order: 1; }
  .nav-center { order: 2; margin: 5px 0; }
  .nav-right { order: 3; justify-content: center; gap: 8px; }
  .btn-inicio { width: 100%; }
  .form-grid { grid-template-columns: 1fr; gap: 1rem; padding: 1rem; }
  .sat-group .sat-input-group { flex-direction: column; }
  .sat-group .sat-input-group button { width: 100%; padding: 8px; }
  .descuento-row { flex-direction: column; align-items: stretch; }
  .btn-generar { width: 100%; }
  .card-container { grid-template-columns: 1fr; padding: 10px; }
  .reporte-controles { flex-direction: column; align-items: stretch; }

  /* Contenedor de vista permite scroll horizontal si la tabla es más ancha */
  .vista {
    overflow-x: auto;
  }

  /* Las tablas mantienen su ancho completo en móvil */
  table {
    display: table;
    width: 100%;
    font-size: 12px;
  }

  th, td { padding: 8px 4px; font-size: 12px; }
}

/* ================= ANIMACIONES ================= */
.vista { animation: fadeIn 0.5s ease-in; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }