/* ═══════════════════════════════════════════════════════════════════
   DIFOR AUTOMOTORES — Sistema de Financiación
   Hoja de estilos principal · Versión 2.0
   ═══════════════════════════════════════════════════════════════════ */

/* ── Reset ─────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ── Variables ─────────────────────────────────────────────────── */
:root {
    /* Paleta principal */
    --primary: #1d4ed8;
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;

    /* Semánticos */
    --success: #059669;
    --success-bg: #d1fae5;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --info: #0284c7;
    --info-bg: #e0f2fe;

    /* Escala de grises */
    --dark: #0f172a;
    --gray-900: #111827;
    --gray-700: #374151;
    --gray-500: #6b7280;
    --gray-400: #9ca3af;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --gray-50: #f9fafb;
    --white: #ffffff;

    /* Alias semánticos */
    --gray: var(--gray-500);
    --border: var(--gray-200);
    --light-gray: var(--gray-100);

    /* Espaciado base */
    --radius-sm: 0.375rem;
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.25rem;

    /* Tipografía */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Sombras */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.18);

    /* Navbar */
    --navbar-h: 64px;
}

/* ── Base ───────────────────────────────────────────────────────── */
html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background-color: #f0f4f8;
    color: var(--gray-900);
    line-height: 1.6;
    font-size: 0.9375rem;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ════════════════════════════════════════════════════════════════
   NAVBAR
   ════════════════════════════════════════════════════════════════ */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    height: var(--navbar-h);
    padding: 0 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 500;
    box-shadow: 0 1px 0 var(--gray-200), var(--shadow-sm);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.125rem;
    font-weight: 800;
    color: var(--primary-dark);
    letter-spacing: -0.02em;
    text-decoration: none;
    flex-shrink: 0;
}

.nav-brand::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 28px;
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary-dark) 100%);
    border-radius: 4px;
    flex-shrink: 0;
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    justify-content: center;
    padding: 0 1.5rem;
}

.nav-link {
    position: relative;
    color: var(--gray-700);
    text-decoration: none;
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.nav-link:hover {
    background: var(--gray-100);
    color: var(--dark);
    text-decoration: none;
}

.nav-link.active {
    background: var(--primary-50);
    color: var(--primary);
    font-weight: 600;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 2px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

/* Badge de notificaciones */
.notif-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: var(--white);
    border-radius: 999px;
    font-size: 0.62rem;
    font-weight: 800;
    min-width: 17px;
    height: 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
    pointer-events: none;
    border: 2px solid var(--white);
    animation: pulse-notif 2.5s ease-in-out infinite;
}

@keyframes pulse-notif {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.18);
    }
}

.nav-link-alerta {
    color: var(--danger) !important;
    font-weight: 600;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ── Botón de usuario ── */
.nav-user-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 0.35rem 0.75rem 0.35rem 0.4rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    transition: all 0.15s ease;
}

.nav-user-btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--dark);
}

/* Avatar */
.nav-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    color: var(--white);
    font-weight: 700;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.nav-avatar-lg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    color: var(--white);
    font-weight: 800;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.nav-nombre {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.875rem;
}

.nav-chevron {
    font-size: 0.7rem;
    color: var(--gray-400);
    transition: transform 0.15s;
}

/* ── Dropdown ── */
.nav-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    min-width: 240px;
    z-index: 1000;
    overflow: hidden;
    animation: fadeInDown 0.15s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.nav-dropdown-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 0.9rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.nav-dropdown-divider {
    height: 1px;
    background: var(--gray-200);
}

.nav-dropdown-section {
    padding: 0.6rem 1rem 0.2rem;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.nav-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    color: var(--gray-700);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
    font-family: var(--font);
}

.nav-dropdown-item:hover {
    background: var(--gray-100);
    color: var(--dark);
    text-decoration: none;
}

.nav-dropdown-logout {
    color: var(--danger);
    font-weight: 600;
}

.nav-dropdown-logout:hover {
    background: var(--danger-bg);
    color: #b91c1c;
}

/* Quick-links de usuario en navbar */
.nav-link-usuarios,
.nav-link-config {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius);
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--gray-700);
    text-decoration: none;
    border: 1px solid var(--gray-200);
    transition: all 0.15s;
    white-space: nowrap;
}

.nav-link-usuarios:hover,
.nav-link-config:hover {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--primary);
    text-decoration: none;
}

.nav-link-usuarios.active,
.nav-link-config.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

/* ════════════════════════════════════════════════════════════════
   LAYOUT
   ════════════════════════════════════════════════════════════════ */
.container {
    max-width: 1440px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* ── Page header ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--gray-200);
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--dark);
    letter-spacing: -0.03em;
}

/* ════════════════════════════════════════════════════════════════
   LOGIN
   ════════════════════════════════════════════════════════════════ */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1d4ed8 100%);
    position: relative;
    overflow: hidden;
}

/* Ornamento de fondo */
.login-container::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    top: -200px;
    right: -150px;
    pointer-events: none;
}

.login-container::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.04);
    bottom: -100px;
    left: -100px;
    pointer-events: none;
}

.login-box {
    background: var(--white);
    padding: 2.75rem 2.5rem 2.25rem;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
}

.login-logo {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: var(--radius-xl);
    margin-bottom: 1rem;
    box-shadow: 0 8px 20px rgba(29, 78, 216, 0.35);
}

.login-logo-mark span {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--white);
    letter-spacing: -0.05em;
}

.login-box h1 {
    color: var(--dark);
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
    text-align: center;
}

.login-box h2 {
    font-size: 0.95rem;
    font-weight: 400;
    color: var(--gray-500);
    margin-bottom: 2rem;
    text-align: center;
}

.login-footer {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--gray-400);
    font-size: 0.82rem;
}

/* ════════════════════════════════════════════════════════════════
   CARDS
   ════════════════════════════════════════════════════════════════ */
.card {
    background: var(--white);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    transition: box-shadow 0.2s;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

/* KPI Card */
.kpi-card {
    background: var(--white);
    border-radius: var(--radius-xl);
    padding: 1.4rem 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.kpi-card.kpi-blue::after {
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
}

.kpi-card.kpi-green::after {
    background: linear-gradient(90deg, var(--success), #34d399);
}

.kpi-card.kpi-yellow::after {
    background: linear-gradient(90deg, var(--warning), #fbbf24);
}

.kpi-card.kpi-red::after {
    background: linear-gradient(90deg, var(--danger), #f87171);
}

.kpi-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
    margin-bottom: 0.6rem;
}

.stat-number {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.1;
    margin: 0.4rem 0;
}

.card h2,
.card h3 {
    margin-bottom: 1rem;
    color: var(--dark);
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* Variantes de borde lateral (legacy, mantenidas) */
.card-info {
    border-left: 3px solid var(--info);
}

.card-success {
    border-left: 3px solid var(--success);
}

.card-warning {
    border-left: 3px solid var(--warning);
}

.card-danger {
    border-left: 3px solid var(--danger);
}

/* ── Grid 2 cols ── */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.25rem;
}

/* ════════════════════════════════════════════════════════════════
   FORMULARIOS
   ════════════════════════════════════════════════════════════════ */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.65rem 0.875rem;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-family: var(--font);
    color: var(--dark);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--gray-400);
}

.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 4 3.5-4' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 1.1rem;
    padding-right: 2.25rem;
    cursor: pointer;
}

.form-group small {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-section {
    background: var(--gray-50);
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    margin: 1.5rem 0;
}

.form-section h3 {
    margin-bottom: 1rem;
    color: var(--dark);
    font-size: 1rem;
    font-weight: 700;
}

/* ════════════════════════════════════════════════════════════════
   BOTONES
   ════════════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.25rem;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--white);
    color: var(--gray-700);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1;
}

.btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
    color: var(--dark);
    transform: translateY(-1px);
    text-decoration: none;
}

.btn:active {
    transform: translateY(0);
}

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

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

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

.btn-success:hover {
    background: #047857;
    border-color: #047857;
    color: var(--white);
}

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

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: var(--white);
}

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

.btn-warning:hover {
    background: #b45309;
    border-color: #b45309;
    color: var(--white);
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
}

.btn-xs {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
}

/* ════════════════════════════════════════════════════════════════
   TABLAS
   ════════════════════════════════════════════════════════════════ */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

th {
    background: var(--gray-50);
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
    padding: 0.8rem 1rem;
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
    text-align: left;
}

td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    color: var(--gray-700);
    vertical-align: middle;
}

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

tbody tr {
    transition: background 0.1s;
}

tbody tr:hover {
    background: var(--primary-50);
}

/* ════════════════════════════════════════════════════════════════
   MODAL
   ════════════════════════════════════════════════════════════════ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
    padding: 1rem;
}

.modal-content {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--radius-2xl);
    max-width: 620px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.97) translateY(-12px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.close {
    float: right;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--gray-400);
    transition: color 0.15s;
    margin: -0.25rem -0.25rem 0 0;
}

.close:hover {
    color: var(--dark);
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--gray-200);
}

/* ── Modal de gestión ── */
.modal-gestion {
    max-width: 900px;
    width: 95vw;
    padding: 0;
    border-radius: var(--radius-xl);
    overflow: hidden;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
}

.modal-gestion-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: var(--white);
    flex-shrink: 0;
}

.modal-close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: var(--white);
    font-size: 1rem;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.modal-gestion-body {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.modal-gestion-form {
    padding: 1.5rem;
    overflow-y: auto;
    border-right: 1px solid var(--gray-200);
}

.modal-gestion-historial {
    padding: 1.25rem;
    background: var(--gray-50);
    overflow-y: auto;
    max-height: 75vh;
}

/* ════════════════════════════════════════════════════════════════
   ALERTAS Y MENSAJES
   ════════════════════════════════════════════════════════════════ */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.alert-success {
    background: var(--success-bg);
    color: #065f46;
    border-color: #6ee7b7;
}

.alert-danger {
    background: var(--danger-bg);
    color: #991b1b;
    border-color: #fca5a5;
}

.alert-warning {
    background: var(--warning-bg);
    color: #78350f;
    border-color: #fde68a;
}

.alert-info {
    background: var(--info-bg);
    color: #0c4a6e;
    border-color: #7dd3fc;
}

.error-message {
    color: var(--danger);
    background: var(--danger-bg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid #fca5a5;
    margin: 1rem 0;
    font-size: 0.875rem;
    font-weight: 500;
}

/* ════════════════════════════════════════════════════════════════
   BADGES
   ════════════════════════════════════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.73rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.badge-ok,
.badge-success {
    background: #dcfce7;
    color: #15803d;
}

.badge-warning {
    background: #fef9c3;
    color: #a16207;
}

.badge-danger {
    background: #ffedd5;
    color: #c2410c;
}

.badge-critical {
    background: var(--danger-bg);
    color: #991b1b;
    animation: pulse-badge 1.8s ease-in-out infinite;
}

.badge-primary {
    background: var(--primary-100);
    color: var(--primary-dark);
}

.badge-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
}

@keyframes pulse-badge {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* ── Badges de acción recomendada ── */
.accion-badge {
    display: inline-block;
    padding: 0.18rem 0.55rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
    background: var(--gray-100);
    color: var(--gray-700);
}

.accion-RECORDATORIO {
    background: #fef9c3;
    color: #854d0e;
}

.accion-CONTACTAR {
    background: #ffedd5;
    color: #9a3412;
}

.accion-GESTIONCOBRO {
    background: var(--danger-bg);
    color: #991b1b;
}

.accion-EMBARGO {
    background: #fce7f3;
    color: #9d174d;
    font-weight: 800;
}

.accion-ALDIA {
    background: #dcfce7;
    color: #166534;
}

/* ════════════════════════════════════════════════════════════════
   FILTROS
   ════════════════════════════════════════════════════════════════ */
.filters {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem 0 0.5rem;
    flex-wrap: wrap;
}

.filters label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    border: 1.5px solid var(--gray-200);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-600, var(--gray-700));
    transition: all 0.15s;
    background: var(--white);
}

.filters label:has(input:checked) {
    background: var(--primary-50);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 700;
}

.filters input[type="radio"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
}

/* ════════════════════════════════════════════════════════════════
   BARRA DE BÚSQUEDA
   ════════════════════════════════════════════════════════════════ */
.search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.55rem 0.875rem;
    background: var(--white);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-lg);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-bar:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}

.search-bar input {
    border: none;
    outline: none;
    flex: 1;
    font-size: 0.9375rem;
    font-family: var(--font);
    background: transparent;
    color: var(--dark);
}

.search-bar input::placeholder {
    color: var(--gray-400);
}

.search-bar .search-icon {
    color: var(--gray-400);
    font-size: 1rem;
}

/* ════════════════════════════════════════════════════════════════
   TABLAS DE MOROSIDAD
   ════════════════════════════════════════════════════════════════ */
tr.nivel-ok {
    background: #f0fdf4;
}

tr.nivel-advertencia {
    background: #fefce8;
}

tr.nivel-mora {
    background: #fff7ed;
}

tr.nivel-critico {
    background: #fff1f2;
}

tr.nivel-advertencia td:first-child {
    border-left: 3px solid #eab308;
}

tr.nivel-mora td:first-child {
    border-left: 3px solid #f97316;
}

tr.nivel-critico td:first-child {
    border-left: 3px solid #dc2626;
}

tr.nivel-ok td:first-child {
    border-left: 3px solid #22c55e;
}

.morosidad-table th,
.morosidad-table td {
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.85rem;
}

.morosidad-table tbody tr:hover {
    filter: brightness(0.97);
}

/* ════════════════════════════════════════════════════════════════
   BOTONES DE GESTIÓN (tabla morosidad)
   ════════════════════════════════════════════════════════════════ */
.btn-gestion {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.25rem 0.55rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
    transition: filter 0.15s, transform 0.1s;
    font-family: var(--font);
}

.btn-gestion:hover {
    filter: brightness(0.92);
    transform: translateY(-1px);
    text-decoration: none;
}

.btn-gestion:active {
    transform: translateY(0);
}

.btn-gestion-embargo {
    background: #fce7f3;
    color: #9d174d;
    border-color: #fbcfe8;
}

.btn-gestion-llamada {
    background: var(--primary-50);
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.btn-gestion-cobro {
    background: #fff7ed;
    color: #c2410c;
    border-color: #fed7aa;
}

.btn-gestion-wp {
    background: #f0fdf4;
    color: #15803d;
    border-color: #bbf7d0;
}

.btn-gestion-nota {
    background: #f5f3ff;
    color: #7c3aed;
    border-color: #ddd6fe;
}

.btn-gestion-ver {
    background: var(--gray-100);
    color: var(--gray-700);
    border-color: var(--gray-200);
}

/* ════════════════════════════════════════════════════════════════
   HISTORIAL DE GESTIONES
   ════════════════════════════════════════════════════════════════ */
.historial-item {
    padding: 0.7rem 0.8rem;
    border-radius: var(--radius);
    background: var(--white);
    border: 1px solid var(--gray-200);
    margin-bottom: 0.6rem;
    font-size: 0.82rem;
}

.historial-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}

.historial-item-tipo {
    font-weight: 700;
    color: var(--dark);
}

.historial-item-fecha {
    color: var(--gray-400);
    font-size: 0.76rem;
}

.historial-item-resultado {
    color: var(--gray-700);
    margin-bottom: 0.2rem;
}

.historial-item-nota {
    color: var(--gray-500);
    font-style: italic;
}

.historial-item-proxima {
    color: var(--primary);
    font-size: 0.8rem;
    margin-top: 0.3rem;
}

.historial-tipo-badge {
    display: inline-block;
    padding: 0.12rem 0.45rem;
    border-radius: 4px;
    font-size: 0.71rem;
    font-weight: 700;
}

.htb-Llamada {
    background: #eff6ff;
    color: #1d4ed8;
}

.htb-WhatsApp {
    background: #f0fdf4;
    color: #15803d;
}

.htb-Visita {
    background: #fef9c3;
    color: #854d0e;
}

.htb-Email {
    background: #f5f3ff;
    color: #7c3aed;
}

.htb-Carta {
    background: var(--gray-100);
    color: var(--gray-700);
}

.htb-GestiAncobro {
    background: #fff7ed;
    color: #c2410c;
}

.htb-EMBARGO {
    background: #fce7f3;
    color: #9d174d;
}

.htb-Otro {
    background: var(--gray-100);
    color: var(--gray-500);
}

/* ════════════════════════════════════════════════════════════════
   TRAMOS DE CUOTAS
   ════════════════════════════════════════════════════════════════ */
.tramo-item {
    background: var(--white);
    padding: 1rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    margin-bottom: 0.85rem;
    position: relative;
    transition: border-color 0.15s;
}

.tramo-item:hover {
    border-color: var(--primary-light);
}

.tramo-item .btn-danger {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.2rem 0.4rem;
    font-size: 1.1rem;
    line-height: 1;
}

.total-financiado {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    margin-top: 1rem;
    letter-spacing: -0.01em;
}

/* Tramos en modal de edición */
.tramo-edit-row,
.tramo-det-row {
    display: grid;
    grid-template-columns: 1fr 80px 110px 135px auto;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.6rem;
    padding: 0.7rem 0.8rem;
    background: var(--gray-50);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}

.tramo-edit-row:hover,
.tramo-det-row:hover {
    border-color: #93c5fd;
}

/* ════════════════════════════════════════════════════════════════
   ITEM RECIENTE (DASHBOARD)
   ════════════════════════════════════════════════════════════════ */
.reciente-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.875rem;
    gap: 0.5rem;
}

.reciente-item:last-child {
    border-bottom: none;
}

.reciente-item a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.reciente-item a:hover {
    text-decoration: underline;
}

/* ════════════════════════════════════════════════════════════════
   UTILIDADES
   ════════════════════════════════════════════════════════════════ */
.loading {
    text-align: center;
    color: var(--gray-400);
    padding: 2.5rem 2rem;
    font-size: 0.9rem;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--gray-500);
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.78rem;
}

.font-bold {
    font-weight: 700;
}

.font-medium {
    font-weight: 500;
}

.mb-0 {
    margin-bottom: 0;
}

.mb-1 {
    margin-bottom: 1rem;
}

.mb-2 {
    margin-bottom: 2rem;
}

.mt-1 {
    margin-top: 1rem;
}

.mt-2 {
    margin-top: 2rem;
}

/* ════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ════════════════════════════════════════════════════════════════ */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
    max-width: 380px;
    width: calc(100vw - 3rem);
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-lg);
    background: var(--white);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid transparent;
    pointer-events: auto;
    animation: toastIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
    font-size: 0.9rem;
    line-height: 1.45;
    min-width: 260px;
}

.toast.toast-hide {
    animation: toastOut 0.25s ease forwards;
}

.toast-success {
    border-left-color: var(--success);
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-warning {
    border-left-color: var(--warning);
}

.toast-info {
    border-left-color: var(--primary);
}

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}

.toast-body {
    flex: 1;
}

.toast-title {
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.1rem;
    font-size: 0.88rem;
}

.toast-msg {
    color: var(--gray-700);
    font-size: 0.84rem;
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-400);
    font-size: 1rem;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    margin-top: -0.1rem;
    transition: color 0.15s;
}

.toast-close:hover {
    color: var(--gray-700);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: scale(1);
        max-height: 100px;
        margin-bottom: 0;
    }

    to {
        opacity: 0;
        transform: scale(0.95);
        max-height: 0;
        margin-bottom: -0.6rem;
    }
}

/* ════════════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .navbar {
        padding: 0 1.25rem;
    }

    .nav-menu {
        gap: 0.15rem;
    }

    .nav-link {
        padding: 0.4rem 0.6rem;
        font-size: 0.82rem;
    }
}

@media (max-width: 768px) {
    :root {
        --navbar-h: auto;
    }

    .navbar {
        flex-wrap: wrap;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        height: auto;
    }

    .nav-menu {
        flex-wrap: wrap;
        justify-content: flex-start;
        order: 3;
        width: 100%;
        padding: 0;
    }

    .nav-link::after {
        display: none;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .cards-grid {
        grid-template-columns: 1fr 1fr;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .container {
        padding: 0 1rem;
        margin: 1rem auto;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .modal-gestion-body {
        grid-template-columns: 1fr;
    }

    .modal-gestion-historial {
        border-top: 1px solid var(--gray-200);
        max-height: 200px;
    }

    .tramo-edit-row,
    .tramo-det-row {
        grid-template-columns: 1fr 1fr;
    }

    .tramo-edit-row>div:first-child,
    .tramo-det-row>div:first-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 480px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }

    .login-box {
        padding: 2rem 1.5rem;
    }
}

/* ── Tabs de período (caja diaria) ─────────────────────────────── */
.caja-tab {
    background: var(--surface, #f9fafb);
    color: var(--gray, #6b7280);
    border: 1px solid var(--border, #e5e7eb);
}

.caja-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}