:root {
    --primary-color: #4361ee;
    --primary-hover: #3a53d0;
    --secondary-color: #3f37c9;
    --success-color: #2ecc71;
    --danger-color: #e74c3c;
    --bg-color: #f4f7fe;
    --sidebar-bg: #111c44;
    --sidebar-text: #a0aec0;
    --sidebar-active: #ffffff;
    --card-bg: #ffffff;
    --text-main: #2b3674;
    --text-muted: #a3aed1;
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* Mobile Header */
.mobile-header {
    display: none;
    background-color: var(--sidebar-bg);
    color: white;
    padding: 15px 20px;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 101;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.mobile-header h2 {
    color: white;
    margin: 0;
    font-size: 1.2rem;
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

/* Custom properties for sidebar sizing */
:root {
    --sidebar-width-expanded: 260px;
    --sidebar-width-collapsed: 72px;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width-collapsed);
    background-color: var(--sidebar-bg);
    color: white;
    position: fixed;
    height: 100vh;
    padding: 15px 0;
    box-shadow: 4px 0 10px rgba(0,0,0,0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    overflow-x: hidden;
}

/* Hovering the unpinned sidebar expands it overlaying the content */
body:not(.sidebar-pinned) .sidebar:hover {
    width: var(--sidebar-width-expanded);
    box-shadow: 6px 0 25px rgba(0, 0, 0, 0.25);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 12px 15px 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    height: 60px;
    box-sizing: border-box;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 1.4rem;
    display: inline-block;
    min-width: 25px;
    text-align: center;
}

.logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: white;
    margin: 0;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.nav-menu {
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    border-left: 4px solid transparent;
    gap: 16px;
    height: 50px;
    box-sizing: border-box;
}

.menu-icon {
    font-size: 1.2rem;
    display: inline-block;
    min-width: 25px;
    text-align: center;
    flex-shrink: 0;
}

.menu-text {
    opacity: 0;
    visibility: hidden;
    white-space: nowrap;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Show texts and logos when hovered or pinned */
body.sidebar-pinned .logo-text,
body.sidebar-pinned .menu-text,
.sidebar:hover .logo-text,
.sidebar:hover .menu-text {
    opacity: 1;
    visibility: visible;
    transition-delay: 0.05s;
}

.nav-link:hover, .nav-link.active {
    background-color: rgba(255,255,255,0.05);
    color: var(--sidebar-active);
    border-left-color: var(--primary-color);
}

/* Pinned sidebar keeps it wide */
body.sidebar-pinned .sidebar {
    width: var(--sidebar-width-expanded);
}

/* Pin button styling */
.pin-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.4);
    cursor: pointer;
    font-size: 1rem;
    padding: 5px;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
}

/* Pin button is only visible when hovered or pinned */
.sidebar:hover .pin-btn,
body.sidebar-pinned .pin-btn {
    opacity: 1;
    visibility: visible;
}

.pin-btn:hover {
    color: white;
    background-color: rgba(255,255,255,0.1);
}

/* Active pinned lock tilted visual style */
body.sidebar-pinned .pin-btn {
    color: var(--primary-color) !important;
    transform: rotate(-45deg);
}

/* Main Content responsive adjustments */
.main-content {
    margin-left: var(--sidebar-width-collapsed);
    padding: 30px;
    width: calc(100% - var(--sidebar-width-collapsed));
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-pinned .main-content {
    margin-left: var(--sidebar-width-expanded);
    width: calc(100% - var(--sidebar-width-expanded));
}

.view-section {
    display: none;
    animation: fadeIn 0.4s ease-in-out;
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Containers and Cards */
.container {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    margin-bottom: 24px;
}

.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

h1, h2, h3 {
    color: var(--text-main);
    margin-bottom: 10px;
}

hr {
    border: 0;
    height: 1px;
    background: #e9ecef;
    margin: 20px 0;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-primary:disabled {
    background-color: #a0aec0;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #312a9e;
}

.btn-close {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid #e2e8f0;
}
.btn-close:hover {
    background: #f8f9fa;
    color: var(--danger-color);
}

/* Forms */
.input-group {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.form-control {
    padding: 12px 15px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
    flex: 1;
    min-width: 250px;
    max-width: 350px;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

.status-msg {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 5px;
}

/* DataTables Styling Overrides */
.table-container {
    overflow-x: auto;
    width: 100%;
}
table.dataTable {
    border-collapse: collapse !important;
    width: 100% !important;
    margin-top: 15px !important;
}
table.dataTable thead th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #e2e8f0 !important;
    color: var(--text-main);
    font-weight: 600;
    padding: 12px 10px !important;
}
table.dataTable tbody td {
    padding: 12px 10px !important;
    border-bottom: 1px solid #edf2f7;
    color: #4a5568;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current, 
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--primary-color);
    color: white !important;
    border: none;
    border-radius: 6px;
}

/* Detail Table Custom */
.styled-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    white-space: nowrap;
}
.styled-table thead tr {
    background-color: #f8f9fa;
    text-align: left;
}
.styled-table th, .styled-table td {
    padding: 12px 15px;
    border-bottom: 1px solid #e2e8f0;
}
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}
.detail-info p {
    margin-bottom: 8px;
    color: #4a5568;
}
.mt-4 { margin-top: 24px; }


/* --- RESPONSIVE DESIGN (MÓVIL) --- */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    
    .mobile-header {
        display: flex; /* Mostrar header móvil */
    }

    .sidebar {
        transform: translateX(-100%); /* Ocultar sidebar a la izquierda */
        transition: transform 0.3s ease;
        padding-top: 20px;
        top: 60px; /* Debajo del header móvil */
        height: calc(100vh - 60px);
    }

    .sidebar-header {
        display: none; /* Ocultar título en sidebar, ya está en mobile-header */
    }

    .sidebar.open {
        transform: translateX(0); /* Mostrar sidebar */
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 15px;
    }
    
    .header-actions {
        flex-direction: column;
        align-items: flex-start;
    }

    .container {
        padding: 15px;
    }

    .form-control {
        max-width: 100%;
    }

    /* Reducir texto y padding en tablas en móvil */
    .styled-table th, .styled-table td {
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    table.dataTable tbody td, table.dataTable thead th {
        padding: 8px 10px !important;
        font-size: 0.85rem;
    }
}

/* --- LOGIN VIEW --- */
.login-view {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: var(--sidebar-bg); /* Use a nice dark background */
    width: 100%;
}

.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 400px;
}

/* --- MODALS --- */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}
.modal-content {
    background: var(--card-bg);
    width: 90%;
    max-width: 600px;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #e2e8f0;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-header .close-modal { cursor: pointer; font-size: 1.5rem; color: #a0aec0; }
.modal-header .close-modal:hover { color: var(--danger-color); }
.modal-body { padding: 25px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}
.form-row {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}
.form-group {
    margin-bottom: 15px;
    flex: 1;
}
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: #4a5568;
    font-weight: 500;
}
.form-group .form-control { width: 100%; }
.form-control[readonly] { background-color: #f8f9fa; cursor: not-allowed; }

/* Responsive adjustments for Quotations table */
@media (max-width: 768px) {
    #quotationsTable {
        font-size: 0.8rem;
    }
    #quotationsTable th, 
    #quotationsTable td {
        padding: 8px 4px; /* Reduce padding significantly */
    }
    .customer-name-cell {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px; /* Force text to wrap */
        white-space: normal;
        line-height: 1.2;
    }
}

/* --- ESTILOS COMPLEMENTARIOS PARA EL MODAL DE VISTA PREVIA DEL PDF --- */
#modalPdfPreview .modal-content {
    max-width: 890px;
    width: 95%;
    height: 90vh; /* Ocupa el 90% del alto de pantalla para no perderse */
    margin: 3vh auto;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 15px 40px rgba(0,0,0,0.3);
    border: none;
}

#modalPdfPreview .modal-header {
    background: #1a365d;
    color: #fff;
    padding: 15px 20px;
    flex-shrink: 0; /* Mantiene la cabecera fija arriba */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#modalPdfPreview .modal-body {
    background: #718096;
    padding: 15px;
    flex-grow: 1;
    overflow: hidden; /* Evita scrolls dobles; el iframe maneja su propio scroll */
    display: flex;
    justify-content: center;
    align-items: stretch; /* Estira el contenedor del iframe verticalmente */
}

#modalPdfPreview .modal-footer {
    background: #f7fafc;
    padding: 15px 20px;
    flex-shrink: 0; /* Mantiene el pie de página fijo abajo */
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
