* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #001a4e; 
    --primary-color-dark: #000f2a; 
    --text-color: #333;
    --text-color-light: #666;
    --border-color: #e0e0e0;
    --background-light: #f9fbfd;
    --background-white: #ffffff;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --- INTEGRACIÓN SIDEBAR Y LAYOUT --- */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background-color: var(--background-light);
}

.sidebar {
    width: 250px;
    background-color: #001233;
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid #000a1f;
}

.sidebar-header {
    padding: 30px 20px 20px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    color: #ffffff;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
    padding-top: 20px;
}

.sidebar-nav li {
    padding: 15px 25px;
    font-size: 15px;
    font-weight: 500;
    color: #aeb9cc;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    position: relative;
}

.sidebar-nav li:hover {
    background-color: rgba(255, 255, 255, 0.03);
    color: #ffffff;
}

.sidebar-nav li.active {
    background-color: #172b4d;
    color: #ffffff;
    font-weight: 600;
}

.sidebar-nav li.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 4px;
    background-color: #007bff;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-logout {
    width: 100%;
    padding: 12px;
    background-color: transparent;
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-logout:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.main-content-wrapper {
    flex-grow: 1;
    height: 100vh;
    overflow-y: auto;
}

.view-section {
    display: none;
}

.view-section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}


/* --- CSS DE CARTAS Y COTIZACIONES (Original) --- */
#intranet-app {
    font-family: var(--font-family);
    margin: 0;
    background-color: var(--background-light);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}
#intranet-app .container {
    width: 90%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px 0;
}

#intranet-app .header {
    background-color: var(--background-white);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    padding: 15px 0;
    position: static; 
}
#intranet-app .header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5%;
}
#intranet-app .logo {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}
#intranet-app .page-title {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-color-light);
}

.generador-container, .cotizador-container {
    display: grid;
    grid-template-columns: 45% 1fr;
    gap: 30px;
    margin-top: 30px;
}

#formulario-columna {
    background-color: var(--background-white);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
    overflow: hidden;
    height: fit-content;
}
.generador-form, .cotizacion-form {
    padding: 30px 40px;
}

.form-section {
    margin-bottom: 35px;
}
.form-section h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
    margin-top: 0;
    margin-bottom: 25px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.form-group {
    display: flex;
    flex-direction: column;
}
.form-group.span-2 {
    grid-column: 1 / -1;
}
.form-group label {
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.9em;
    color: var(--text-color-light);
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: calc(100% - 30px);
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: var(--font-family);
    background-color: #fcfcfc;
    transition: all 0.2s ease;
    box-sizing: border-box;
    width: 100%;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: var(--background-white);
    box-shadow: 0 0 0 3px rgba(0,26,78,0.1);
}
.form-group textarea {
    resize: vertical;
    min-height: 200px;
}

.form-group input[readonly], .locked-input {
    background-color: #f1f5f9 !important;
    color: #64748b;
    border-color: #cbd5e1 !important;
    cursor: not-allowed;
    box-shadow: none !important;
}

.add-item-group {
    display: flex;
    gap: 10px;
}
.add-item-group input {
    flex-grow: 1;
    width: auto;
}
.btn-add-item {
    background-color: var(--primary-color);
    color: white;
    border: none;
    font-size: 2rem;
    font-weight: 300;
    line-height: 42px;
    border-radius: 8px;
    height: 46px; 
    width: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    text-align: center;
    flex-shrink: 0;
}
.btn-add-item:hover {
    background-color: var(--primary-color-dark);
}

.item-list {
    list-style: none;
    padding: 0;
    margin: 15px 0 0 0;
    max-height: 150px;
    overflow-y: auto;
}
.item-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: var(--background-light);
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
}
.item-list .item-desc {
    font-size: 0.9em;
    font-weight: 500;
    flex-grow: 1;
    padding-right: 10px;
}
.item-list .btn-delete-item {
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 0.9em;
    font-weight: bold;
    cursor: pointer;
    line-height: 22px;
    text-align: center;
    flex-shrink: 0;
}
.item-list .btn-delete-item:hover {
    background-color: #c0392b;
}

#pdf-columna {
    position: sticky;
    top: 30px;
    height: 90vh;
}
.pdf-preview-section {
    background-color: var(--background-white);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
}
.pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}
.pdf-header h2 {
    color: var(--primary-color);
    margin: 0;
    font-size: 1.5rem;
}

.btn-download {
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: var(--primary-color);
    color: var(--background-white);
}
.btn-download:hover {
    background-color: var(--primary-color-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,26,78,0.3);
}

.pdf-viewer {
    width: 100%;
    flex-grow: 1;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 15px;
}

.search-group {
    display: flex;
    flex-wrap: wrap; 
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 20px; 
}
.search-group label {
    width: 100%; 
    margin: 0;
    font-weight: 500;
    font-size: 0.9em;
    color: var(--text-color-light);
}
.search-group input {
    flex-grow: 1; 
    width: auto;
    margin: 0;
}
.btn-buscar {
    background-color: var(--text-color-light);
    color: white;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    height: 46px; 
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0 20px;
    flex-shrink: 0;
}
.btn-buscar:hover {
    background-color: var(--text-color);
}

.form-grid-add-item {
    display: grid;
    grid-template-columns: 1fr 60px 80px 110px 50px; 
    gap: 10px;
    align-items: flex-end;
    grid-template-rows: auto auto; 
}
.form-grid-add-item .form-group { margin: 0; }
.form-grid-add-item .desc { grid-column: 1 / -1; grid-row: 1; }
.form-grid-add-item .cant { grid-row: 2; grid-column: 2 / 3; }
.form-grid-add-item .um { grid-row: 2; grid-column: 3 / 4; }
.form-grid-add-item .precio { grid-row: 2; grid-column: 4 / 5; }
.btn-add {
    grid-row: 2;
    grid-column: 5 / 6;
    background-color: var(--primary-color);
    color: white;
    border: none;
    font-size: 2rem;
    font-weight: 300;
    line-height: 42px;
    border-radius: 8px;
    height: 46px; 
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    text-align: center;
}
.btn-add:hover {
    background-color: var(--primary-color-dark);
    transform: translateY(-2px);
}

#itemsAgregadosList { list-style: none; padding: 0; margin: 0; max-height: 250px; overflow-y: auto; margin-top: 20px; }
#itemsAgregadosList li { display: flex; justify-content: space-between; align-items: center; padding: 12px; background-color: var(--background-light); border-radius: 8px; margin-bottom: 8px; border: 1px solid var(--border-color); }
#itemsAgregadosList li.empty-list { padding: 15px; text-align: center; color: var(--text-color-light); border-style: dashed; }
#itemsAgregadosList .item-desc { font-size: 0.9em; font-weight: 500; flex-grow: 1; padding-right: 10px; }
#itemsAgregadosList .item-price { font-size: 0.9em; font-weight: 600; color: var(--text-color); margin-left: 15px; white-space: nowrap; }
#itemsAgregadosList .btn-delete-item { background-color: #e74c3c; color: white; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 0.9em; font-weight: bold; cursor: pointer; line-height: 22px; text-align: center; margin-left: 15px; transition: background-color 0.2s; flex-shrink: 0; }
#itemsAgregadosList .btn-delete-item:hover { background-color: #c0392b; }

@media (max-width: 1024px) {
    .generador-container, .cotizador-container {
        grid-template-columns: 1fr; 
        gap: 40px;
    }
    #pdf-columna {
        position: relative; 
        top: 0;
        height: 80vh; 
    }
    .form-grid {
        grid-template-columns: 1fr; 
    }
    .generador-form, .cotizacion-form {
        padding: 20px;
    }
    .form-grid-add-item {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: 15px;
    }
    .form-grid-add-item .desc { grid-column: 1; grid-row: 1; }
    .form-grid-add-item .cant { grid-column: 1; grid-row: 2; }
    .form-grid-add-item .um { grid-column: 1; grid-row: 3; }
    .form-grid-add-item .precio { grid-column: 1; grid-row: 4; }
    .btn-add { grid-column: 1; grid-row: 5; }
    
    .search-group {
        flex-direction: column; 
        align-items: stretch; 
    }
    .search-group input {
        width: calc(100% - 30px);
    }
    .btn-buscar {
        width: 100%;
    }
}

/* --- LOGIN OVERLAY --- */
.app-layout {
    display: none; 
}
.app-layout.authenticated {
    display: flex; 
}

.login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background-color: var(--primary-color);
    background-image: linear-gradient(135deg, var(--primary-color) 0%, #002c83 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}
.login-overlay.hidden {
    display: none;
}

.login-box {
    background: var(--background-white);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

/* --- CARGADOR DE LOGIN --- */
.login-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}
.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: var(--primary-color);
    animation: spin 1s ease infinite;
    margin-bottom: 15px;
}
@keyframes spin { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
}

.login-logo {
    font-size: 28px;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.login-title {
    font-size: 1.2rem;
    color: var(--text-color-light);
    margin-bottom: 30px;
    font-weight: 500;
}

.login-form .form-group {
    text-align: left;
    margin-bottom: 20px;
}

.btn-login {
    width: 100%;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
}
.btn-login:hover {
    background-color: var(--primary-color-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,26,78,0.2);
}

.error-message {
    color: #e74c3c;
    font-size: 0.9em;
    margin-bottom: 15px;
    min-height: 20px;
}

.forgot-pass-link-container {
    margin-top: 15px;
    text-align: center;
}
.forgot-pass-link-container a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s;
}
.forgot-pass-link-container a:hover {
    text-decoration: underline;
    color: var(--primary-color-dark);
}
.forgot-pass-instructions {
    font-size: 0.9rem;
    color: var(--text-color-light);
    margin-bottom: 20px;
}

/* --- ELEMENTOS DE SIDEBAR (PERFIL RESUMIDO) --- */
.sidebar-user-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.sidebar-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 10px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}
.sidebar-name {
    font-size: 0.95rem;
    font-weight: 600;
}
.sidebar-role {
    font-size: 0.8rem;
    color: #aeb9cc;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

/* --- BOTONES GLOBALES --- */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-primary:hover {
    background-color: var(--primary-color-dark);
}
.btn-secondary {
    background-color: #f1f1f1;
    color: var(--text-color);
    border: 1px solid #ccc;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-secondary:hover {
    background-color: #e2e2e2;
}
.btn-danger {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-danger:hover { background-color: #c0392b; }
.btn-warning {
    background-color: #f39c12;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-warning:hover { background-color: #d68910; }
.btn-edit {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-edit:hover { background-color: #2980b9; }

/* --- PERFIL VIEW --- */
.dashboard-welcome {
    background: var(--background-white);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    text-align: center;
    margin-top: 30px;
}

.profile-container {
    max-width: 800px;
    margin: 30px auto;
}

.profile-card {
    background: var(--background-white);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    display: flex;
    overflow: hidden;
}

.profile-avatar-section {
    background-color: #f8fafc;
    width: 35%;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border-color);
}

.avatar-wrapper {
    position: relative;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #e2e8f0;
}

.avatar-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 4px solid var(--primary-color);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.btn-upload-avatar {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background-color: var(--primary-color);
    color: white;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
    transition: all 0.2s;
    border: 3px solid white;
}
.btn-upload-avatar:hover { 
    transform: scale(1.1); 
    background-color: var(--primary-color-dark);
}

.upload-status {
    font-size: 0.85rem;
    color: #27ae60;
    text-align: center;
    margin-top: 10px;
}

.profile-form-section {
    width: 65%;
    padding: 40px;
}

.profile-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 30px 0;
}

/* --- ADMIN VIEW --- */
.admin-container {
    background: var(--background-white);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    padding: 30px;
    margin-top: 30px;
}
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 15px;
}
.admin-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-color);
}

.table-responsive {
    overflow-x: auto;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
}
.admin-table th, .admin-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.admin-table th {
    background-color: #f8fafc;
    color: var(--text-color-light);
    font-weight: 600;
}
.admin-table tbody tr:hover {
    background-color: #fcfcfc;
}
.td-actions {
    display: flex;
    gap: 8px;
}
.badge-role {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    color: white;
}
.badge-admin { background-color: #9b59b6; }
.badge-user { background-color: #3498db; }

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: var(--background-white);
    padding: 30px;
    border-radius: 12px;
    width: 100%;
    max-width: 450px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content {
    transform: translateY(0);
}
.modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--primary-color);
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 25px;
}

@media (max-width: 768px) {
    .profile-card { flex-direction: column; }
    .profile-avatar-section, .profile-form-section { width: 100%; }
    .profile-form-section { padding: 20px; }
}