:root {
    --blue: #3b82f6;
    --blue-dark: #2563eb;
    --red: #ef4444;
    --red-dark: #dc2626;
    --green: #22c55e;
    --green-dark: #16a34a;
    --orange: #f97316;
    --orange-dark: #ea580c;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    min-height: 100vh;
}

.hidden { display: none !important; }

/* LOGIN */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 50%, #1e3a5f 100%);
}

.login-card {
    background: white;
    padding: 48px 40px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    width: 400px;
    max-width: 90vw;
}

.login-icon { font-size: 48px; margin-bottom: 16px; }

.login-card h1 {
    font-size: 22px;
    color: var(--gray-800);
    margin-bottom: 8px;
}

.login-card > p { color: var(--gray-500); margin-bottom: 24px; font-size: 14px; }

.login-card input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color .2s;
}

.login-card input:focus { border-color: var(--blue); }

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}

.login-card button:hover { background: var(--blue-dark); }

.login-error { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 20px; }

.setup-pass {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-200);
}

.setup-pass p { color: var(--gray-600); font-size: 14px; margin-bottom: 12px; }

/* HEADER */
.header {
    background: white;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 { font-size: 18px; color: var(--gray-800); }

.header-right { display: flex; gap: 4px; }

.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--gray-500);
    transition: all .2s;
    display: flex;
    align-items: center;
}

.btn-icon:hover { background: var(--gray-100); color: var(--gray-800); }
.btn-icon.active { background: var(--blue); color: white; }
.btn-logout:hover { background: #fef2f2; color: var(--red); }

/* MES SELECTOR */
.mes-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
}

.btn-mes-nav {
    background: var(--gray-100);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-600);
    transition: all .2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-mes-nav:hover { background: var(--gray-200); }

.mes-display { display: flex; gap: 8px; }

.mes-display select {
    padding: 8px 12px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-800);
    background: white;
    cursor: pointer;
    outline: none;
}

.mes-display select:focus { border-color: var(--blue); }

/* SECTIONS */
.section { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* CARDS */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border-left: 4px solid;
}

.card-blue { border-color: var(--blue); }
.card-red { border-color: var(--red); }
.card-green { border-color: var(--green); }
.card-orange { border-color: var(--orange); }

.card-label { font-size: 13px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.card-value { font-size: 28px; font-weight: 700; color: var(--gray-800); }

.card-red .card-value { color: var(--red); }
.card-green .card-value { color: var(--green); }

/* RESUMEN MOTIVOS */
.resumen-motivos {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.resumen-motivos h3 { font-size: 16px; margin-bottom: 16px; color: var(--gray-700); }

.motivos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.motivo-card {
    padding: 16px;
    border-radius: 8px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    text-align: center;
}

.motivo-card .motivo-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-600);
    margin-bottom: 8px;
    padding: 2px 10px;
    border-radius: 12px;
    display: inline-block;
}

.motivo-card .motivo-count { font-size: 24px; font-weight: 700; color: var(--gray-800); }
.motivo-card .motivo-importe { font-size: 13px; color: var(--red); margin-top: 4px; }
.motivo-card .motivo-liquida { font-size: 13px; color: var(--green); }

.motivo-BAJA .motivo-label { background: #fef2f2; color: var(--red); }
.motivo-DES .motivo-label { background: #fefce8; color: #a16207; }
.motivo-FALL .motivo-label { background: #f0f9ff; color: #0369a1; }
.motivo-OTRO .motivo-label { background: #faf5ff; color: #7e22ce; }
.motivo-RES .motivo-label { background: #f0fdf4; color: #15803d; }

/* CHART */
.chart-container {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.chart-container h3 { font-size: 16px; margin-bottom: 16px; color: var(--gray-700); }

.chart-bars { display: flex; flex-direction: column; gap: 10px; }

.chart-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chart-bar-label { width: 50px; font-size: 13px; font-weight: 600; color: var(--gray-600); text-align: right; }

.chart-bar-track {
    flex: 1;
    height: 28px;
    background: var(--gray-100);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.chart-bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width .5s ease;
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-size: 12px;
    font-weight: 600;
    color: white;
    min-width: fit-content;
}

.chart-bar-fill.bar-BAJA { background: var(--red); }
.chart-bar-fill.bar-DES { background: #eab308; }
.chart-bar-fill.bar-FALL { background: var(--blue); }
.chart-bar-fill.bar-OTRO { background: #a855f7; }
.chart-bar-fill.bar-RES { background: var(--green); }
.chart-bar-fill.bar-default { background: var(--gray-400); }

.chart-bar-value { width: 30px; font-size: 13px; font-weight: 600; color: var(--gray-700); }

/* DASHBOARD ACTIONS */
.dashboard-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* BUTTONS */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-accent { background: linear-gradient(135deg, var(--blue) 0%, #1e3a5f 100%); color: white; font-size: 15px; padding: 12px 24px; }
.btn-accent:hover { background: linear-gradient(135deg, var(--blue-dark) 0%, #162d4a 100%); }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger { background: #fef2f2; color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* SECTION HEADER */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header h2 { font-size: 20px; color: var(--gray-800); }

/* FILTROS */
.filtros-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filtros-bar input,
.filtros-bar select {
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color .2s;
    background: white;
}

.filtros-bar input { flex: 1; min-width: 200px; }
.filtros-bar input:focus,
.filtros-bar select:focus { border-color: var(--blue); }

/* TABLAS */
.tabla-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.tabla {
    width: 100%;
    border-collapse: collapse;
}

.tabla th {
    background: var(--gray-50);
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.tabla td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 14px;
}

.tabla tr:hover td { background: var(--gray-50); }

.tabla tr:last-child td { border-bottom: none; }

.tabla .nexp { font-weight: 700; color: var(--blue); font-family: monospace; font-size: 15px; }
.tabla .cuota { font-weight: 600; }
.tabla .liquidacion { color: var(--green); font-weight: 600; }

.motivo-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
}

.motivo-badge-BAJA { background: #fef2f2; color: var(--red); }
.motivo-badge-DES { background: #fefce8; color: #a16207; }
.motivo-badge-FALL { background: #f0f9ff; color: #0369a1; }
.motivo-badge-OTRO { background: #faf5ff; color: #7e22ce; }
.motivo-badge-RES { background: #f0fdf4; color: #15803d; }

.terminal-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    background: #fff7ed;
    color: var(--orange);
    margin-left: 4px;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    margin-top: 24px;
}
.bajadas-cards {
    display: grid;
    grid-template-columns: 1fr;
    max-width: 300px;
    gap: 12px;
    margin-bottom: 16px;
}
.bajadas-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}
.bajadas-card-label {
    font-size: 12px;
    color: var(--gray-500);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.bajadas-card-value {
    font-size: 22px;
    font-weight: 700;
}

.check-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--orange);
}

.tabla .acciones { display: flex; gap: 4px; }

.btn-accion {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--gray-400);
    transition: all .2s;
}

.btn-accion:hover { background: var(--gray-100); color: var(--gray-700); }
.btn-accion.delete:hover { background: #fef2f2; color: var(--red); }

.tabla-footer {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--gray-500);
}

.tabla-empty {
    text-align: center;
    padding: 48px 16px !important;
    color: var(--gray-400);
}

/* BBDD */
.bbdd-actions { display: flex; gap: 8px; align-items: center; }
.bbdd-count { font-size: 14px; color: var(--gray-500); margin-right: 8px; }

.drop-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    margin-bottom: 16px;
    transition: all .2s;
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--blue);
    background: #eff6ff;
}

.drop-zone-content svg { color: var(--gray-400); margin-bottom: 12px; }
.drop-zone-content p { font-size: 16px; color: var(--gray-600); margin-bottom: 4px; }
.drop-zone-content span { font-size: 13px; color: var(--gray-400); }

/* MODAL */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn .2s;
}

@keyframes fadeIn { from { opacity: 0; } }

.modal-content {
    background: white;
    border-radius: 16px;
    width: 560px;
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-sm { width: 400px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 { font-size: 17px; }

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.modal-close:hover { background: var(--gray-100); color: var(--gray-700); }

.modal form,
.lista-motivos { padding: 24px; }

.form-row { display: flex; gap: 16px; margin-bottom: 16px; }

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    padding: 10px 12px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color .2s;
}

.form-group input:focus,
.form-group select:focus { border-color: var(--blue); }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 24px 24px;
}

/* AUTOCOMPLETE */
.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    max-height: 180px;
    overflow-y: auto;
    z-index: 10;
    display: none;
    box-shadow: var(--shadow-lg);
}

.autocomplete-results.show { display: block; }

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
}

.autocomplete-item:hover { background: var(--gray-50); }
.autocomplete-item .ac-exp { font-weight: 700; color: var(--blue); font-family: monospace; }
.autocomplete-item .ac-name { color: var(--gray-600); }

/* LISTA MOTIVOS */
.lista-motivos { display: flex; flex-direction: column; gap: 8px; }

.motivo-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--gray-50);
    border-radius: 6px;
}

.motivo-item span { font-weight: 600; font-size: 14px; }

/* TOAST */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--gray-800);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: slideUp .3s;
}

.toast.success { background: var(--green-dark); }
.toast.error { background: var(--red-dark); }

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
}

/* RESPONSIVE */
@media (max-width: 640px) {
    .header { padding: 0 12px; }
    .header h1 { font-size: 15px; }
    .section { padding: 16px; }
    .cards-grid { grid-template-columns: 1fr 1fr; }
    .card { padding: 16px; }
    .card-value { font-size: 22px; }
    .form-row { flex-direction: column; gap: 12px; }
    .section-header { flex-direction: column; align-items: flex-start; }
    .bbdd-actions { flex-wrap: wrap; }
    .filtros-bar { flex-direction: column; }
    .filtros-bar input { min-width: 0; }
    .dashboard-actions { flex-direction: column; }
    .btn { width: 100%; justify-content: center; }
}

/* CIERRE DE MES */
.btn-cerrado {
    background: var(--gray-200);
    color: var(--gray-500);
    cursor: not-allowed;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    border: 2px solid var(--gray-300);
}

.badge-cerrado {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    background: var(--gray-100);
    color: var(--gray-400);
}
