/* =========================================================
   🎨 VARIABLES & RESET
   ========================================================= */
:root {
    --primary: #2C3E50;    /* Azul oscuro elegante */
    --accent: #3498DB;     /* Azul brillante para acciones */
    --success: #27AE60;    /* Verde éxito */
    --danger: #C0392B;     /* Rojo error/cancelar */
    --warning: #F39C12;    /* Naranja alerta */
    --bg-body: #ECF0F1;    /* Gris muy claro fondo */
    --bg-card: #FFFFFF;    /* Blanco tarjetas */
    --text-main: #2C3E50;  /* Texto principal */
    --text-light: #7F8C8D; /* Texto secundario */
    --border: #BDC3C7;     /* Bordes suaves */
    
    --shadow: 0 2px 5px rgba(0,0,0,0.05);
    --radius: 6px;
    --transition: all 0.2s ease;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    font-size: 14px; /* Tamaño base compacto para datos */
}

h1, h2, h3, h4 {
    margin: 0 0 10px 0;
    font-weight: 600;
}

/* =========================================================
   🔐 VISTA LOGIN (Centrado y Limpio)
   ========================================================= */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, #34495e 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
}

.login-card h2 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.login-card input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: var(--transition);
}

.login-card input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.login-card button {
    width: 100%;
    padding: 12px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.login-card button:hover {
    background-color: #2980B9;
    transform: translateY(-1px);
}

/* =========================================================
   🧭 HEADER & DASHBOARD LAYOUT
   ========================================================= */
header {
    background-color: var(--bg-card);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    /*position: relative; */
    padding-bottom: 10px; /* Quitamos padding bottom para que la barra pegue al borde */
}

/* BARRA DE CARGA */
.header-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px; /* Alto fijo solicitado */
    background-color: #F1C40F; /* Un amarillo/dorado que destaca sobre el azul */
    width: 0%;
    transition: width 0.3s ease-in-out;
    z-index: 101;
}

/* Ajuste para la tarjeta de descargas */
.download-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    border: 1px solid #E5E7E9;
    border-radius: 6px;
    background-color: #FBFCFC;
    text-decoration: none;
    color: var(--text-main);
    margin-bottom: 10px;
    transition: all 0.2s;
}

.download-item:hover {
    background-color: #EBF5FB;
    border-color: var(--accent);
    transform: translateX(5px);
}

header h1 {
    font-size: 1.2rem;
    color: var(--primary);
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info {
    text-align: right;
    line-height: 1.2;
}

#user-name { font-weight: 700; }

/* Icon Buttons (Header) */
.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    background-color: #F0F3F4;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--primary);
}

main {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* =========================================================
   📦 CARDS & ESTRUCTURA
   ========================================================= */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #E5E7E9;
}

.detalle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Sub-cards (para Datasets) */
.sub-card {
    background-color: #F8F9F9;
    border: 1px solid #E5E8E8;
    border-radius: var(--radius);
    padding: 10px 15px;
    margin-top: 15px;
}

/* Headers colapsables */
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding-bottom: 5px;
    user-select: none;
}

.card-header-actions {
    border-bottom: 1px solid #ECF0F1;
    margin-bottom: 15px;
    padding-bottom: 10px;
}

.collapsible-header h3, .collapsible-header h4 {
    margin: 0;
    color: var(--primary);
}

.collapsible-icon {
    width: 18px;
    height: 18px;
    fill: var(--text-light);
    transition: transform 0.3s ease;
}

.collapsible-content {
    /* El JS maneja display: block/none */
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   📝 FORMULARIOS & GRIDS
   ========================================================= */
/* Grilla responsiva para formularios (Identificación y Visitas) */
.info-grid {
    display: grid;
    grid-template-columns: 120px 1fr; /* Label fijo, input flexible */
    gap: 10px 15px;
    align-items: center;
    margin-bottom: 15px;
}

/* Labels */
.info-grid label {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.9rem;
}

/* Inputs generales */
input[type="text"], 
input[type="email"], 
input[type="password"], 
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    background-color: #fff;
    transition: var(--transition);
}

/* Inputs Read-only (parecen texto) */
input[readonly] {
    background-color: transparent;
    border-color: transparent;
    padding-left: 0;
    font-weight: 500;
    color: #555;
    cursor: default;
}

/* Inputs Editables Focus */
input:not([readonly]):focus, 
select:focus, 
textarea:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

/* Fila flexible para fecha/hora */
.flex-row {
    display: flex;
    gap: 10px;
}

/* Textarea para observaciones */
textarea {
    resize: vertical;
    min-height: 60px;
}

/* Botones de acción (Guardar) */
.action-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #F0F3F4;
}

.btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn:hover {
    background-color: #2980B9;
    transform: translateY(-1px);
}

.btn:disabled {
    background-color: #BDC3C7;
    cursor: not-allowed;
    transform: none;
}

/* Separador visual */
hr {
    border: 0;
    height: 1px;
    background: #E5E7E9;
    margin: 20px 0;
}

/* =========================================================
   📊 TABLAS (Listado y Datasets)
   ========================================================= */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid #E5E7E9;
    border-radius: var(--radius);
    background: white;
    max-height: 600px; /* Scroll vertical si es muy larga */
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px; /* Asegura ancho mínimo en móviles */
}

thead th {
    background-color: var(--primary);
    color: white;
    padding: 10px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9rem;
    position: sticky; /* Header fijo */
    top: 0;
    z-index: 5;
}

tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid #ECF0F1;
    color: var(--text-main);
    vertical-align: middle;
}

/* Filas interactivas (Listado principal) */
#table-establecimientos tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}

#table-establecimientos tbody tr:hover {
    background-color: #EBF5FB;
}

/* Inputs dentro de tablas (Datasets) */
.dirty-input {
    border: 1px solid #ddd;
    background: #fff;
    padding: 4px;
    font-size: 0.85rem;
    border-radius: 3px;
}

/* Checkboxes */
input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--success);
}

/* =========================================================
   🍞 TOAST & MODALS
   ========================================================= */
#toast {
    visibility: hidden;
    min-width: 250px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 4px;
    padding: 12px;
    position: fixed;
    z-index: 2000;
    left: 50%;
    top: 30px;
    transform: translateX(-50%);
    font-size: 0.95rem;
    opacity: 0;
    transition: opacity 0.3s, top 0.3s;
}

#toast.show {
    visibility: visible;
    opacity: 1;
    top: 50px;
}

#toast.success { background-color: var(--success); }
#toast.error { background-color: var(--danger); }
#toast.info { background-color: var(--primary); }

/* Modal Backdrop */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    animation: fadeIn 0.2s;
}

.modal-dialog {
    background: white;
    padding: 25px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    max-width: 350px;
}

.modal-dialog h3 { margin-top: 0; color: var(--danger); }

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.btn-secondary { background-color: #95A5A6; }
.btn-secondary:hover { background-color: #7F8C8D; }

.btn-danger { background-color: var(--danger); }
.btn-danger:hover { background-color: #A93226; }

/* =========================================================
   📱 RESPONSIVE
   ========================================================= */
@media (max-width: 768px) {
    .info-grid {
        grid-template-columns: 1fr; /* Una sola columna en móviles */
        gap: 5px;
    }
    
    .info-grid label {
        margin-top: 10px;
        color: var(--accent); /* Destacar labels en móvil */
    }
    
    .flex-row {
        gap: 5px;
    }

    main { padding: 10px; }
    
    .login-card { padding: 1.5rem; }
}