/**
 * =================================================================================
 * ARCHIVO: /pdv/css/estilos.css
 * PROYECTO: Sistema POS y Control Operativo - Centro de Diagnóstico Médico
 * DESCRIPCIÓN: Hoja de estilos universal responsiva. Implementa la paleta de colores
 *              corporativa (Arena, Verde #70822e, Azul #2c3e50 y Naranja #f59622)
 *              con optimización táctil para dispositivos móviles y escritorio.
 * =================================================================================
 */

/* ---------------------------------------------------------------------------------
 * 1. VARIABLES GLOBALES DE COLOR Y DISEÑO
 * --------------------------------------------------------------------------------- */
:root {
    --bg-arena: #f7f5f0;           /* Fondo general Arena Clara Tenue */
    --bg-card: #ffffff;            /* Fondo blanco para tarjetas y contenedores */
    
    /* INVERSIÓN CROMÁTICA: VERDE EN BANNERS / NARANJA EN CAJAS DE TEXTO */
    --green-primary: #70822e;      /* Verde Corporativo para Banners y Títulos */
    --green-light: #eef2e6;        /* Verde tenue para resaltados de tabla */
    
    --orange-accent: #f59622;     /* Naranja para Bordes de Cajas de Texto e Inputs */
    --orange-light: #fdf4eb;      /* Naranja Tenue para Foco Activo de Texto */
    
    --blue-primary: #2c3e50;       /* Azul para Botones y Encabezados de Tabla */
    --blue-hover: #1a252f;         /* Azul Oscuro Hover */
    --text-dark: #2c3e50;          /* Color de Texto Principal */
    --border-soft: #d1d8c5;        /* Color de Bordes Suaves */
}

/* ---------------------------------------------------------------------------------
 * 2. RESET Y ESTILOS BASE DEL CUERPO (BODY)
 * --------------------------------------------------------------------------------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-arena);
    color: var(--text-dark);
    min-height: 100vh;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

/* ---------------------------------------------------------------------------------
 * 3. CONTENEDORES Y TARJETAS PRINCIPALES AL 100% ANCHO DE PANTALLA
 * --------------------------------------------------------------------------------- */
div[id^="contenedor-"],
div[id$="-card"],
div.modal-search-card,
div.entity-card,
div.panel-card {
    background-color: var(--bg-card);
    width: 100% !important;       /* Ocupa el 100% del ancho de pantalla disponible */
    max-width: 100% !important;   /* Elimina la restricción de px */
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow-soft);
    border: 1px solid var(--border-soft);
    margin-bottom: 20px;
}

/* ---------------------------------------------------------------------------------
 * 4. JERARQUÍA TIPOGRÁFICA Y ENCABEZADOS CLÍNICOS (H1, H2, H3, H4)
 * --------------------------------------------------------------------------------- */

/**
 * H1 Y H2: TITULO PRINCIPAL DE PANTALLA O MÓDULO.
 * Se unifican para dar soporte transparente a las vistas que arrancan directamente en H2.
 * Estilo: Gris Oscuro Corporativo (#2c3e50), sobrio, Propercase (Capitalize),
 * rematado con la linea guia inferior en Verde Corporativo (#70822e).
 */
h1,
h2,
div#banner-encabezado {
    background-color: transparent !important;
    color: var(--text-dark) !important;                 /* Gris Oscuro Corporativo #2c3e50 */
    font-size: 20px !important;                         /* Escala visual jerarquica de apertura */
    font-weight: 800 !important;                         /* Negrita dominante */
    text-transform: capitalize !important;              /* Propercase */
    letter-spacing: 0.3px;
    margin: 0 0 16px 0 !important;
    padding: 0 0 8px 0 !important;
    border: none !important;
    border-bottom: 2px solid var(--green-primary) !important; /* Linea institucional de acento */
    display: block;
    width: 100%;
    text-align: left !important;
}

/**
 * H3: SECCIONES PRINCIPALES DENTRO DE TARJETAS / CONTENEDORES.
 * Color Verde Corporativo (#70822e), en MAYÚSCULAS para delimitar bloques operativos.
 * Sin lineas divisorias adicionales para mantener la interfaz limpia.
 */
h3 {
    background-color: transparent !important;
    color: var(--green-primary) !important;             /* Verde Corporativo #70822e */
    font-size: 15px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;               /* Mayusculas para secciones */
    letter-spacing: 0.5px;
    margin: 15px 0 10px 0 !important;
    padding: 0 !important;
    border: none !important;
    display: block;
    width: 100%;
    text-align: left !important;
}

/**
 * H4: SUB-SECCIONES Y SUBCONTENEDORES MENORES.
 * Verde Corporativo (#70822e), en Propercase para agrupaciones menores.
 */
h4 {
    background-color: transparent !important;
    color: var(--green-primary) !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    text-transform: capitalize !important;              /* Propercase */
    letter-spacing: 0.2px;
    margin: 10px 0 6px 0 !important;
    padding: 0 !important;
    border: none !important;
    display: block;
    width: 100%;
    text-align: left !important;
}

/**
 * Lineas divisorias universales de soporte
 */
hr {
    border: 0;
    height: 1px;
    background-color: var(--border-soft);
    margin: 20px 0;
}

/**
 * Lineas divisorias universales auxiliares (opcionales)
 */
hr {
    border: 0;
    height: 1px;
    background-color: var(--border-soft);
    margin: 20px 0;
}

/**
 * Compatibilidad con etiquetas historicas tipo label.label-orange
 */
label.label-orange {
    background-color: transparent !important;
    color: var(--orange-accent) !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    border-bottom: 1px dashed var(--orange-accent) !important;
    padding-bottom: 4px;
    margin-bottom: 10px;
}

/**
 * Divisores universales de seccion
 */
hr {
    border: 0;
    height: 1px;
    background-color: var(--border-soft);
    margin: 20px 0;
}

/* ---------------------------------------------------------------------------------
 * 5. CAMPOS DE ENTRADA Y FORMULARIOS EN NARANJA (#f59622)
 * --------------------------------------------------------------------------------- */
label {
    display: block;
    font-size: 14px;
    font-weight: bold;
    color: var(--text-dark);
    margin-bottom: 6px;
    text-transform: uppercase;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
    width: 100%;
    height: 46px; /* Altura táctil móvil */
    padding: 10px 14px;
    font-size: 16px; /* Evita zoom en celulares */
    font-weight: 600;
    color: var(--text-dark);
    background-color: #ffffff;
    border: 2px solid var(--orange-accent); /* Borde Naranja #f59622 */
    border-radius: 6px;
    outline: none;
    transition: all 0.2s ease-in-out;
    margin-bottom: 15px;
}

/* Foco activo en Naranja Tenue (#fdf4eb) */
input:focus,
select:focus,
textarea:focus {
    background-color: var(--orange-light); /* Fondo Naranja Tenue */
    border-color: var(--orange-accent);    /* Borde Naranja #f59622 */
    box-shadow: 0 0 6px rgba(245, 150, 34, 0.4);
}

/* =================================================================================
 * 6. BOTONES DE COMANDO PRINCIPALES, ENLACES Y ALINEACIÓN DERECHA INFERIOR
 * ================================================================================= */

/* Apariencia de Botón Azul para todos los botones y enlaces de acción del sistema */
button,
a.btn-command,
a.btn-action,
#panel-comandos a,
.bottom-actions a,
.bottom-bar a,
#contenedor-buscador div:last-child a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--blue-primary); /* Azul Corporativo #2c3e50 */
    color: #ffffff !important;
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    text-decoration: none;
    padding: 12px 20px;
    min-height: 46px; /* Altura táctil móvil */
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    margin: 4px;
    text-align: center;
}

/* Efectos de paso de mouse (Hover) y clic (Active) */
button:hover,
a.btn-command:hover,
a.btn-action:hover,
#panel-comandos a:hover,
.bottom-actions a:hover,
.bottom-bar a:hover, /* CORREGIDO: Se agregó el hover faltante */
#contenedor-buscador div:last-child a:hover {
    background-color: var(--blue-hover);
    transform: translateY(-1px);
}

button:active,
a.btn-command:active,
a.btn-action:active {
    transform: translateY(1px);
}

/* Rejilla de comandos de Mostrador */
#panel-comandos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    width: 100%;
    margin-top: 15px;
}

/* CORREGIDO: Se eliminó el bloque duplicado que se contradecía */
#panel-comandos a {
    min-height: 70px;
    font-size: 16px;
}

/* Contenedores inferiores de botones ALINEADOS ESTRICTAMENTE AL BORDE DERECHO */
.bottom-actions,
.bottom-bar,
#contenedor-buscador > div:last-child,
form > div:last-child,
div[id^="contenedor-"] > form > div:last-child,
div[id^="contenedor-"] > div:last-child {
    display: flex;
    justify-content: flex-end; /* Alineación a la derecha universal */
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
    width: 100%;
}

/* Optimización táctil para celulares y pantallas pequeñas (< 768px) */
@media (max-width: 768px) {
    /* Mismos contenedores pero con comportamiento móvil */
    .bottom-actions,
    .bottom-bar,
    #contenedor-buscador > div:last-child,
    form > div:last-child,
    div[id^="contenedor-"] > form > div:last-child,
    div[id^="contenedor-"] > div:last-child {
        justify-content: center;
        flex-direction: column-reverse; /* El botón de confirmación queda arriba del de regresar */
    }
    
    .bottom-actions button,
    .bottom-actions a,
    .bottom-bar a,
    #contenedor-buscador div:last-child a {
        width: 100%; /* Botones de ancho completo en celular */
    }
}

/* =================================================================================
 * 7. ESTILO ÚNICO Y UNIVERSAL PARA TODAS LAS TABLAS DEL SISTEMA (TABLE 100% ANCHO)
 * ================================================================================= */

div.table-container,
div table,
table {
    width: 100% !important;       /* Ocupa el 100% del ancho disponible */
    max-width: 100% !important;   /* Elimina cualquier restricción de ancho */
    border-collapse: collapse;
    margin-bottom: 15px;
    background-color: #ffffff;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-soft);
}

th {
    background-color: var(--blue-primary); /* Azul Corporativo #2c3e50 */
    color: #ffffff;
    padding: 12px 10px;
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
    border: 1px solid var(--blue-hover);
}

td {
    padding: 10px 12px;
    font-size: 15px; /* Tamaño de letra estandarizado en 15px */
    font-weight: 600;
    color: var(--text-dark);
    border-bottom: 1px solid #eef2e6;
}

/* Renglones alternados con fondo tenue */
tr:nth-child(even) {
    background-color: #fbfdf9;
}

/* Efecto de resalte en verde claro al pasar el mouse o toque táctil */
tr:hover td {
    background-color: var(--green-light);
}

/* ---------------------------------------------------------------------------------
 * 8. BOTONES COMPACTOS DENTRO DE CELDAS DE TABLA (EVITA ESTIRAR LAS FILAS)
 * --------------------------------------------------------------------------------- */
td button,
td a.btn-command {
    min-height: 32px !important;
    height: 32px !important;
    min-width: 36px !important; /* Ancho mínimo uniforme para botones de celda */
    padding: 0 10px !important;
    font-size: 14px !important;
    font-weight: bold;
    margin: 0 !important;
    line-height: 32px;
    text-align: center !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

/* ---------------------------------------------------------------------------------
 * 9. MENSAJES DE ALERTA Y NOTIFICACIONES
 * --------------------------------------------------------------------------------- */
div#mensaje-exito,
div.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    padding: 12px 18px;
    border-radius: 6px;
    font-weight: bold;
    margin-bottom: 15px;
    width: 100%;
}

div#mensaje-error,
div.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    padding: 12px 18px;
    border-radius: 6px;
    font-weight: bold;
    margin-bottom: 15px;
    width: 100%;
}

div#alerta-paciente-fijo {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
    padding: 12px 18px;
    border-radius: 6px;
    font-weight: bold;
    margin-bottom: 15px;
    width: 100%;
}

/* ---------------------------------------------------------------------------------
 * 10. AJUSTES DE OPTIMIZACIÓN RESPONSIVA PARA MÓVILES (< 768px)
 * --------------------------------------------------------------------------------- */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    div[id^="contenedor-"],
    div[id$="-card"] {
        padding: 12px;
    }

    h2, h3, label.label-orange {
        font-size: 14px;
        padding: 10px;
    }

    button, a.btn-command {
        width: 100%;
        margin: 4px 0;
    }

    /* Tabla ultra-compacta para móvil */
    td, th {
        padding: 8px 4px;
        font-size: 12px;
    }
}

/* ---------------------------------------------------------------------------------
 * 11. DESGLOSE DE TOTALES JUSTIFICADO A LA DERECHA COMO FACTURA
 * --------------------------------------------------------------------------------- */
div#desglose-totales {
    text-align: right !important; /* Justificación a la derecha */
    font-size: 16px;
    color: var(--text-dark);
    margin: 20px 0;
    padding: 15px;
    background-color: var(--bg-arena);
    border-radius: 6px;
    border: 1px solid var(--border-soft);
    line-height: 1.8;
}

div#desglose-totales h4 {
    font-size: 22px;
    color: var(--orange-accent);
    margin-top: 10px;
    text-align: right !important;
}

/* ---------------------------------------------------------------------------------
 * 12. ALINEAR CONTROLES HORIZONTALMENTE (form-row)
 * --------------------------------------------------------------------------------- */
.form-row,
div.filter-grid {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
    margin-bottom: 15px;
}

/* Cancela márgenes inferiores internos dentro de la fila horizontal */
.form-row > div {
    margin-bottom: 0;
}

/* Adaptabilidad para pantallas de celular (< 768px) */
@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ---------------------------------------------------------------------------------
 * 13. MODALES, VENTANAS FLOTANTES Y CAPAS DE BLOQUEO (.modal-overlay)
 * --------------------------------------------------------------------------------- */

/**
 * Capa oscura de bloqueo de fondo (Backdrop).
 * Cubre el 100% de la ventana gráfica (Viewport) e impide interacción con el fondo.
 */
.modal-overlay,
div[id$="-modal"],
div[id^="modal-"] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: rgba(44, 62, 80, 0.75) !important; /* Azul corporativo traslúcido */
    z-index: 9999 !important;                             /* Por encima de th fijos y banners */
    display: flex !important;                             /* Centrado con Flexbox */
    align-items: center !important;                       /* Centrado vertical */
    justify-content: center !important;                   /* Centrado horizontal */
    padding: 15px !important;
    backdrop-filter: blur(2px);                          /* Efecto de desenfoque moderno */
}

/**
 * Contenedor interno o tarjeta del Modal.
 * Hereda el estilo de tarjeta pero limita dimensiones para evitar fugas de pantalla.
 */
.modal-content,
.modal-overlay .modal-search-card,
.modal-overlay .panel-card,
.modal-overlay div[class*="-card"] {
    background-color: var(--bg-card) !important;
    width: 100% !important;
    max-width: 750px !important;                         /* Ancho máximo ergonómico en escritorio */
    max-height: 90vh !important;                         /* Evita salirse del alto de pantalla */
    overflow-y: auto !important;                          /* Scroll interno exclusivo si desborda */
    border-radius: 8px !important;
    border: 2px solid var(--border-soft) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35) !important;
    margin-bottom: 0 !important;                          /* Anula margen inferior de tarjetas estándar */
    animation: modal-aparecer 0.2s ease-out;              /* Entrada suave */
}

/**
 * Clase utilitaria para ocultar el modal mediante JS
 */
.modal-overlay.hidden,
.modal-overlay[style*="display: none"] {
    display: none !important;
}

/**
 * Animación sutil de entrada (KISS, sin sobrecargar la GPU de una tablet vieja)
 */
@keyframes modal-aparecer {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/**
 * Adaptación móvil para modales (< 768px)
 */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 8px !important;
        align-items: flex-end !important;                /* Se ancla abajo estilo Bottom Sheet táctil */
    }

    .modal-content,
    .modal-overlay .modal-search-card,
    .modal-overlay .panel-card {
        max-width: 100% !important;
        max-height: 95vh !important;
        border-radius: 12px 12px 0 0 !important;        /* Esquinas superiores redondeadas */
    }
}