:root {
    --primary: #1E3A8A;       
    --secondary: #0284C7;     
    --success: #10B981;       
    --warning: #F59E0B;       
    --danger: #EF4444;        
    --dark: #0F172A;          
    --glass-bg: rgba(255, 255, 255, 0.45);
    --glass-border: rgba(255, 255, 255, 0.6);
    --glass-shadow: 0 8px 32px 0 rgba(15, 23, 42, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; }

body {
    background: linear-gradient(135deg, #E0E7FF 0%, #E0F2FE 50%, #F1F5F9 100%);
    color: var(--dark);
    min-height: 100vh; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}

.glass-panel {
    background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border); border-radius: 16px; box-shadow: var(--glass-shadow);
}

/* ================= LOGIN ================= */
#login-view { width: 90%; max-width: 440px; padding: 40px; text-align: center; animation: fadeIn 0.5s ease-out; }
.login-header h2 { font-size: 1.8rem; color: var(--primary); font-weight: 700; letter-spacing: -0.5px; }
.login-header p { color: #475569; font-size: 0.95rem; margin-bottom: 30px; }

.form-group { margin-bottom: 20px; text-align: left; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--primary); margin-bottom: 6px; text-transform: uppercase; }
.input-wrapper { position: relative; }
.input-wrapper i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #64748B; }

input, select, textarea {
    width: 100%; padding: 12px 12px 12px 40px; border-radius: 10px; border: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.6); font-size: 1rem; color: var(--dark); outline: none; transition: all 0.3s ease;
}
select { padding-left: 12px; cursor: pointer; } 
.input-wrapper select { padding-left: 40px; }
textarea { padding-left: 12px; }
input:focus, select:focus, textarea:focus { border-color: var(--secondary); background: rgba(255, 255, 255, 0.9); box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15); }

.btn-action {
    width: 100%; padding: 14px; border-radius: 10px; border: none;
    background: linear-gradient(135deg, var(--primary) 0%, #1D4ED8 100%);
    color: white; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.3s ease;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-action:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(30, 58, 138, 0.35); }
.btn-action:disabled { background: #94A3B8; cursor: not-allowed; transform: none; box-shadow: none; }

/* ================= APP LAYOUT ================= */
#app-view { width: 100vw; height: 100vh; max-width: 100%; overflow: hidden; display: none; }
#app-view.show-app { display: grid; grid-template-columns: 280px 1fr; }

.sidebar { padding: 30px 20px; display: flex; flex-direction: column; border-right: 1px solid var(--glass-border); height: 100%; overflow-y: auto;}
.brand { display: flex; align-items: center; justify-content: center; gap: 12px; padding-bottom: 25px; border-bottom: 1px solid rgba(0, 0, 0, 0.08); margin-bottom: 25px; }

.user-profile-card { background: rgba(255, 255, 255, 0.4); padding: 15px; border-radius: 12px; margin-bottom: 25px; border: 1px solid rgba(255, 255, 255, 0.5); }
.user-profile-card h4 { font-size: 0.95rem; color: var(--dark); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-profile-card p { font-size: 0.8rem; color: #475569; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-profile-card .tag-role { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 0.75rem; font-weight: 700; background: var(--primary); color: white; margin-top: 8px; }

.menu-items { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.menu-link { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px; color: #475569; font-weight: 600; text-decoration: none; transition: all 0.2s ease; cursor: pointer; }
.menu-link:hover, .menu-link.active { background: rgba(255, 255, 255, 0.7); color: var(--primary); }
.logout-link { color: var(--danger); border-top: 1px solid rgba(0, 0, 0, 0.08); padding-top: 15px; margin-top: 15px;}

.main-content { padding: 35px; overflow-y: auto; height: 100%; display: flex; flex-direction: column; gap: 20px; }
.top-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px;}
.top-bar h1 { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.top-bar .date-pill { padding: 8px 16px; border-radius: 20px; background: rgba(255, 255, 255, 0.6); font-size: 0.9rem; font-weight: 600; color: var(--primary); border: 1px solid var(--glass-border); }

.filter-container { display: none; align-items: center; gap: 10px; background: rgba(255,255,255,0.4); padding: 10px 15px; border-radius: 10px; border: 1px solid var(--glass-border); margin-bottom: 10px;}
.filter-container label { font-weight: 700; color: var(--primary); font-size: 0.9rem; margin: 0; }
.filter-container select { padding: 8px 12px; width: auto; border-radius: 8px; font-weight: 600; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.stat-card { padding: 20px; display: flex; align-items: center; gap: 15px; }
.stat-card .icon-box { width: 50px; height: 50px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; color: white; flex-shrink: 0;}
.stat-card h5 { font-size: 0.85rem; color: #475569; text-transform: uppercase; }
.stat-card p { font-size: 1.7rem; font-weight: 700; color: var(--dark); }

.workspace-view { display: none; }
.workspace-view.active { display: block; animation: fadeInUp 0.4s ease-out; }

/* ================= TABLA ================= */
.table-wrapper {
    max-height: 65vh; /* Ajuste para que la tabla tenga scroll interno */
    overflow-y: auto;
    display: block;
    width: 100%;
}
.table-container { width: 100%; overflow-x: auto; border-radius: 12px; border: 1px solid var(--glass-border); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; text-align: left; background: rgba(255, 255, 255, 0.2); min-width: 800px; }
th { background: rgba(30, 58, 138, 0.05); padding: 14px 16px; font-size: 0.85rem; font-weight: 700; color: var(--primary); text-transform: uppercase; border-bottom: 2px solid var(--glass-border); white-space: nowrap; position: sticky; top: 0; z-index: 10;}
td { padding: 14px 16px; font-size: 0.9rem; border-bottom: 1px solid rgba(0, 0, 0, 0.05); color: #334155; }
tr:hover td { background: rgba(255, 255, 255, 0.4); }

.badge { padding: 5px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; display: inline-block; white-space: nowrap;}
.status-nuevo { background: rgba(30, 58, 138, 0.15); color: var(--primary); }
.status-envcomp { background: rgba(2, 132, 199, 0.15); color: var(--secondary); }
.status-atcomp { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.status-devuelto { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.status-cerradofisc { background: #D1FAE5; color: #065F46; }
.status-final { background: #F3F4F6; color: #374151; }

.dropzone-container { border: 2px dashed var(--secondary); border-radius: 12px; padding: 20px; text-align: center; background: rgba(255, 255, 255, 0.3); cursor: pointer; transition: all 0.3s ease; margin-bottom: 10px; }
.dropzone-container:hover { background: rgba(255, 255, 255, 0.6); border-color: var(--primary); }
.dropzone-container i { font-size: 2rem; color: var(--secondary); margin-bottom: 5px; }
.file-selected-text { font-size: 0.85rem; color: var(--success); font-weight: 600; margin-top: 5px; display: none; word-break: break-all;}

.btn-sm { padding: 6px 12px; border-radius: 6px; border: none; font-weight: 600; cursor: pointer; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 4px; text-decoration: none; white-space: nowrap;}
.btn-sm-primary { background: var(--primary); color: white; }
.btn-sm-success { background: var(--success); color: white; }
.btn-sm-warning { background: var(--warning); color: #000; }
.btn-sm-danger { background: var(--danger); color: white; }

/* ================= MODALES ================= */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(8px); z-index: 2000; align-items: center; justify-content: center; padding: 15px;}
.modal-content { width: 100%; max-width: 750px; padding: 30px; animation: zoomIn 0.3s ease-out; max-height: 95vh; overflow-y: auto;}
.modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(0,0,0,0.08); padding-bottom: 15px; margin-bottom: 20px; }
.modal-header h3 { color: var(--primary); font-weight: 700; font-size: 1.3rem;}
.close-modal { font-size: 1.5rem; cursor: pointer; color: #64748B; padding: 5px;}

.info-card-section { background: rgba(255, 255, 255, 0.5); padding: 15px; border-radius: 12px; border: 1px solid var(--glass-border); margin-bottom: 20px; }
.info-card-section h4 { color: var(--primary); font-size: 1rem; margin-bottom: 15px; border-bottom: 1px solid rgba(0,0,0,0.1); padding-bottom: 5px; text-transform: uppercase;}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; font-size: 0.9rem; }
.detail-grid > div { padding: 5px; word-break: break-word;}
.detail-grid .full-width { grid-column: span 2; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

.history-box { background: rgba(255,255,255,0.7); padding: 15px; border-radius: 8px; border-left: 4px solid var(--primary); margin-bottom: 15px; font-size: 0.9rem; }
.history-box h5 { color: var(--dark); font-size: 0.95rem; margin-bottom: 5px;}
.action-zone { margin-top: 20px; padding-top: 20px; border-top: 2px dashed rgba(0,0,0,0.1); }

/* ================= RESPONSIVO ================= */
@media (max-width: 768px) {
    body { overflow-y: auto; display: block; padding: 0; }
    #login-view { margin: 5vh auto; padding: 30px 20px; }
    #app-view.show-app { display: flex; flex-direction: column; height: auto; overflow: visible; }
    .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--glass-border); padding: 20px 15px; }
    .user-profile-card { text-align: center; }
    .menu-items { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 5px;}
    .menu-link { padding: 8px 10px; font-size: 0.85rem; flex: 1 1 45%; justify-content: center; text-align: center; white-space: nowrap;}
    
    .main-content { padding: 15px 10px; height: auto; overflow: visible; gap: 15px; }
    .detail-grid, .modal-grid { grid-template-columns: 1fr !important; }
    .detail-grid .full-width { grid-column: span 1; }
    .stats-grid { grid-template-columns: 1fr; }
    .table-container { border: none; background: transparent; overflow-x: visible; }
    .table-wrapper { max-height: none; overflow-y: visible; }
    
    table, thead, tbody, th, td, tr { display: block; min-width: auto; }
    thead { display: none; } 
    tr { margin-bottom: 20px; background: rgba(255, 255, 255, 0.55); border: 1px solid var(--glass-border); border-radius: 14px; padding: 16px; box-shadow: var(--glass-shadow); }
    td { border-bottom: 1px solid rgba(0, 0, 0, 0.08); padding: 10px 4px; display: flex; flex-direction: column; text-align: left; }
    td:last-child { border-bottom: none; padding-top: 15px; }
    td::before { content: attr(data-label); font-size: 0.75rem; font-weight: 800; color: var(--primary); text-transform: uppercase; margin-bottom: 4px; opacity: 0.9; }

    /* Corrección de recuadro de notificaciones en móvil */
    #alerts-dropdown {
        position: fixed !important;
        top: 80px !important; 
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 90vw !important; 
        right: auto !important;
        max-width: none !important;
    }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
@keyframes zoomIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
