/**
 * Architecture Graphique Unifiée - Design Glassmorphism Moderne
 */

:root {
    --bg-blur: blur(12px);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --glass-bg: rgba(255, 255, 255, 0.45);
    --glass-border: rgba(255, 255, 255, 0.25);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #0b4aaf;
    --bs-primary-rgb: #0b4aaf;
    --accent-success: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.08);

    --scrollbar-track: rgba(0, 0, 0, 0.03);
    --scrollbar-thumb: rgba(11, 74, 175, 0.25);
    --scrollbar-thumb-hover: #0b4aaf;
    
    --header-height: 65px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
        --glass-bg: rgba(15, 23, 42, 0.55);
        --glass-border: rgba(255, 255, 255, 0.08);
        --text-primary: #f8fafc;
        --text-secondary: #94a3b8;
        --accent-color: #60a5fa;
        --accent-success: #34d399;
        --accent-danger: #f87171;
        --accent-warning: #fbbf24;
        --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

        --scrollbar-track: rgba(255, 255, 255, 0.02);
        --scrollbar-thumb: rgba(255, 255, 255, 0.15);
        --scrollbar-thumb-hover: #60a5fa;
    }
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    box-sizing: border-box;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
    transition: var(--transition-smooth);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
    background-clip: content-box;
    box-shadow: 0 0 10px var(--scrollbar-thumb-hover);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

.app-main-content {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 1rem !important;
    position: relative;
}

.account-view-container {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
}

.login-viewport-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    padding: 1.5rem;
    overflow-y: auto;
}

/* Header & Navbar */
.navbar-glass {
    flex-shrink: 0;
    height: var(--header-height);
    width: 100%;
    z-index: 1030;
    background: var(--glass-bg);
    backdrop-filter: var(--bg-blur);
    -webkit-backdrop-filter: var(--bg-blur);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
}

.navbar-brand {
    color: whitesmoke;
}

.navbar-brand:focus,
.navbar-brand:hover {
    color: whitesmoke;
    text-shadow: 0 0 15px rgba(185, 185, 185, 0.8);
}

.header-balance-badge {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.35rem 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: var(--bg-blur);
    -webkit-backdrop-filter: var(--bg-blur);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    box-shadow: var(--shadow-glass);
    padding: 1rem 1.25rem;
    transition: var(--transition-smooth);
}

.account-tile {
    background: var(--glass-bg);
    backdrop-filter: var(--bg-blur);
    -webkit-backdrop-filter: var(--bg-blur);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    box-shadow: var(--shadow-glass);
    padding: 0.85rem 1rem;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.account-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.15);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    padding: 0.5rem 0;
    width: 100%;
}

.account-tile .info-icon {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.75;
    transition: var(--transition-smooth);
}

.account-tile .info-icon:hover {
    color: var(--accent-color);
    opacity: 1;
    transform: scale(1.1);
}

.balance-real {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0.25rem 0;
}

.balance-forecast {
    font-size: 1rem;
    color: var(--text-secondary);
}

.form-control-glass {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    border-radius: 8px;
    transition: var(--transition-smooth);
}

.form-control-glass:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
    outline: none;
    color: #a0abb5;
}

.btn-glass-primary {
    background: var(--accent-color);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-glass-primary:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

/* Boutons d'Action */
.btn-action-add {
    background: rgba(13, 110, 253, 0.18) !important;
    border: 1px solid rgba(13, 110, 253, 0.45) !important;
    color: #60a5fa !important;
    transition: var(--transition-smooth);
}
.btn-action-add:hover:not(:disabled) {
    background: #0d6efd !important;
    border-color: #0d6efd !important;
    color: #ffffff !important;
    box-shadow: 0 0 15px rgba(13, 110, 253, 0.45) !important;
    transform: scale(1.02) translateY(-1px);
}

.btn-action-check {
    background: rgba(168, 85, 247, 0.18) !important;
    border: 1px solid rgba(168, 85, 247, 0.45) !important;
    color: #c084fc !important;
    transition: var(--transition-smooth);
}
.btn-action-check:hover:not(:disabled) {
    background: #8b5cf6 !important;
    border-color: #8b5cf6 !important;
    color: #ffffff !important;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.45) !important;
    transform: scale(1.02) translateY(-1px);
}

.btn-action-reconcile {
    background: rgba(16, 185, 129, 0.18) !important;
    border: 1px solid rgba(16, 185, 129, 0.45) !important;
    color: #34d399 !important;
    transition: var(--transition-smooth);
}
.btn-action-reconcile:hover:not(:disabled) {
    background: #10b981 !important;
    border-color: #10b981 !important;
    color: #ffffff !important;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.45) !important;
    transform: scale(1.02) translateY(-1px);
}

.btn-action-recurring {
    background: rgba(6, 182, 212, 0.15) !important;
    border: 1px solid rgba(6, 182, 212, 0.4) !important;
    color: #22d3ee !important;
    transition: var(--transition-smooth);
}
.btn-action-recurring:hover:not(:disabled) {
    background: #0891b2 !important;
    border-color: #0891b2 !important;
    color: #ffffff !important;
    box-shadow: 0 0 15px rgba(8, 145, 178, 0.45) !important;
    transform: scale(1.02) translateY(-1px);
}

/* Structure des Tableaux Généraux (Historique des Écritures) */
.table-responsive-glass {
    width: 100% !important;
    table-layout: fixed !important;
    border-collapse: collapse;
    font-size: 0.8rem !important;
}

.table-responsive-glass th {
    text-align: left;
    padding: 0.5rem 0.5rem;
    background-color: var(--glass-bg) !important;
    color: var(--text-secondary) !important;
    border-bottom: 2px solid var(--glass-border);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.725rem;
    letter-spacing: 0.04em;
}

.table-responsive-glass td {
    border-bottom: 1px solid var(--glass-border) !important;
    transition: var(--transition-smooth);
    background: transparent !important;
    color: var(--text-primary) !important;
    vertical-align: middle;
    padding: 0.35rem 0.5rem !important;
}

/* Allocation des largeurs pour l'historique */
.table-responsive-glass th.col-statut,
.table-responsive-glass td.col-statut { width: 55px; text-align: center; }

.table-responsive-glass th.col-actions,
.table-responsive-glass td.col-actions { width: 90px; text-align: center; }

.table-responsive-glass th.col-date,
.table-responsive-glass td.col-date { width: 105px; }

.table-responsive-glass th.col-categorie,
.table-responsive-glass td.col-categorie { width: 20%; }

.table-responsive-glass th.col-libelle,
.table-responsive-glass td.col-libelle { 
    width: auto; 
    overflow: hidden; 
}

.table-responsive-glass th.col-montant,
.table-responsive-glass td.col-montant { 
    width: 120px; 
    text-align: right !important; 
    white-space: nowrap !important;
}

/* Allocation optimisée pour les Opérations Planifiées (Échéance suiv.) */
.table-responsive-glass th.col-rec-active,
.table-responsive-glass td.col-rec-active { 
    width: 45px; 
    text-align: center; 
}

.table-responsive-glass th.col-rec-date,
.table-responsive-glass td.col-rec-date { 
    width: 120px; 
    white-space: nowrap;
}

.table-responsive-glass th.col-rec-label,
.table-responsive-glass td.col-rec-label { 
    width: 32%; 
}

.table-responsive-glass th.col-rec-account,
.table-responsive-glass td.col-rec-account { 
    width: 150px; 
}

.table-responsive-glass th.col-rec-category,
.table-responsive-glass td.col-rec-category { 
    width: 36%; 
}

.table-responsive-glass th.col-rec-periodicity,
.table-responsive-glass td.col-rec-periodicity { 
    width: 85px; 
    text-align: center;
    white-space: nowrap;
}

.table-responsive-glass th.col-rec-amount,
.table-responsive-glass td.col-rec-amount { 
    width: 110px; 
    text-align: right !important; 
    white-space: nowrap !important; 
}

.table-responsive-glass th.col-rec-actions,
.table-responsive-glass td.col-rec-actions { 
    width: 65px; 
    text-align: center; 
}

/* Gestion propre des badges sans troncature prématurée */
.table-responsive-glass td.col-rec-account .badge,
.table-responsive-glass td.col-rec-category .badge {
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
}

/* Responsive : réajustement des proportions sur écrans moyens/petits */
@media (max-width: 1200px) {
    .table-responsive-glass th.col-categorie,
    .table-responsive-glass td.col-categorie { width: 24%; }

    .table-responsive-glass th.col-rec-label,
    .table-responsive-glass td.col-rec-label { width: 28%; }

    .table-responsive-glass th.col-rec-category,
    .table-responsive-glass td.col-rec-category { width: 32%; }
}

/* Keyframes et animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

.custom-alert {
    background: rgba(25, 135, 84, 0.15) !important;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(25, 135, 84, 0.3) !important;
    color: #4df19d !important;
}

.alert-danger.custom-alert {
    background: rgba(220, 53, 69, 0.15) !important;
    border: 1px solid rgba(220, 53, 69, 0.3) !important;
    color: #ff6b7a !important;
}

.table-responsive-glass tbody tr:hover td {
    background: rgba(255, 255, 255, 0.02) !important;
}

.cursor-not-allowed {
    cursor: not-allowed !important;
}

.fs-7 {
    font-size: 0.74rem !important;
}

.btn-action-icon {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0.15rem 0.35rem !important;
    margin: 0 0.15rem !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-action-icon i {
    transition: color 0.15s ease-in-out, transform 0.15s ease-in-out;
}

.btn-action-icon:hover i {
    color: #fd7e14 !important;
    transform: scale(1.15);
}

/* Badges Périodicité */
.badge-periodicity {
    font-family: var(--bs-font-monospace);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.25em 0.55em;
    border-radius: 6px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    align-self: center;
}

.badge-hebdomadaire { background-color: rgba(255, 0, 127, 0.18) !important; color: #ff3399 !important; border-color: rgba(255, 0, 127, 0.35) !important; }
.badge-bimensuel { background-color: rgba(0, 242, 254, 0.18) !important; color: #00c6ff !important; border-color: rgba(0, 242, 254, 0.35) !important; }
.badge-mensuel { background-color: rgba(138, 43, 226, 0.2) !important; color: #c084fc !important; border-color: rgba(138, 43, 226, 0.4) !important; }
.badge-trimestriel { background-color: rgba(0, 255, 170, 0.18) !important; color: #00e699 !important; border-color: rgba(0, 255, 170, 0.35) !important; }
.badge-semestriel { background-color: rgba(255, 153, 0, 0.18) !important; color: #ff9900 !important; border-color: rgba(255, 153, 0, 0.35) !important; }
.badge-annuel { background-color: rgba(255, 215, 0, 0.2) !important; color: #e6b800 !important; border-color: rgba(255, 215, 0, 0.45) !important; }

/* Filter Sidebar */
.filter-sidebar {
    width: 280px;
    max-width: 280px;
    flex-shrink: 0;
    opacity: 1;
    overflow: hidden;
    transition: 
        max-width 0.4s cubic-bezier(0.25, 1, 0.5, 1),
        opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1),
        padding 0.4s cubic-bezier(0.25, 1, 0.5, 1),
        margin 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.filter-sidebar.collapsed {
    max-width: 0 !important;
    opacity: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    border: none !important;
    pointer-events: none;
}

/* Style du menu déroulant TomSelect */
.ts-dropdown {
    z-index: 1060 !important;
    width: max-content !important;
    min-width: 100% !important;
    max-width: 350px !important;
    
    background-color: #1a2234 !important;
    color: #ffffff !important;
    border: 1px solid #2a354f !important;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4) !important;
}

.ts-dropdown .option, 
.ts-dropdown .optgroup-header {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    background-color: transparent !important;
}

.ts-dropdown .option.active,
.ts-dropdown .option:hover {
    background-color: #2a354f !important;
    color: #ffffff !important;
}

/* Module de Correction des Inversions */
.table-inversions {
    table-layout: fixed !important;
    width: 100% !important;
}

.table-inversions .col-inv-check { width: 38px !important; }
.table-inversions .col-inv-date { width: 120px !important; }
.table-inversions .col-inv-montant { width: 95px !important; }
.table-inversions .col-inv-actuel { width: 30% !important; }
.table-inversions .col-inv-arrow { width: 35px !important; }
.table-inversions .col-inv-correction { width: auto !important; }

.inversion-line-container {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    width: 100% !important;
    gap: 0.4rem !important;
}

.inversion-field-group {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex: 1 1 0% !important;
    min-width: 0 !important;
    gap: 0.3rem !important;
}

.btn-swap-fields {
    flex-shrink: 0 !important;
    height: 26px !important;
    line-height: 1 !important;
    border-radius: 6px !important;
    background-color: rgba(245, 158, 11, 0.1) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
    color: #fbbf24 !important;
    transition: var(--transition-smooth);
}

.btn-swap-fields:hover {
    background-color: #f59e0b !important;
    border-color: #f59e0b !important;
    color: #0f172a !important;
    transform: scale(1.1);
}

.inversion-label {
    display: inline-block !important;
    margin-bottom: 0 !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
}

.inversion-input {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    height: 28px !important;
    font-size: 0.8rem !important;
    padding: 2px 8px !important;
    transition: border-color 0.3s ease;
}

.input-dark-custom {
    background-color: rgba(15, 23, 42, 0.6) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: #f8fafc !important;
}

.input-dark-custom:focus {
    background-color: rgba(15, 23, 42, 0.9) !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25) !important;
}

.table-compact td, 
.table-compact th {
    padding-top: 0.25rem !important;
    padding-bottom: 0.25rem !important;
}

.inversion-label-text {
    font-size: 0.75rem;
}

@media (max-width: 1200px) {
    .inversion-line-container {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.3rem !important;
    }
    
    .inversion-field-group {
        width: 100% !important;
    }

    .btn-swap-fields {
        align-self: center !important;
        transform: rotate(90deg);
    }

    .btn-swap-fields:hover {
        transform: rotate(90deg) scale(1.1);
    }
}