/* ============================================
   Styles CSS pour l'application de gestion des dépenses
   Interface RTL en arabe, optimisée mobile-first
   ============================================ */

/* Import des polices arabes */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@300;400;500;600;700&display=swap');

/* Variables CSS */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --light-bg: #ecf0f1;
    --dark-text: #2c3e50;
    --light-text: #7f8c8d;
    --white: #ffffff;
    --border-color: #bdc3c7;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

/* Reset et styles de base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    direction: rtl;
    font-size: 16px;
}

body {
    font-family: 'Noto Sans Arabic', sans-serif;
    line-height: 1.6;
    color: var(--dark-text);
    background-color: var(--light-bg);
    direction: rtl;
    text-align: right;
}


/* === ANALYSES PAGE STYLES === */

/* Navigation */
.main-nav {
    background: var(--card-background);
    padding: 1rem 0;
    margin-bottom: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--primary-color);
}

.nav-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.nav-links a {
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-links a:hover,
.nav-links a.active {
    background: var(--primary-color);
    color: white;
}

/* Sections principales */
.filters-section,
.stats-section,
.charts-section,
.table-section {
    margin-bottom: 2rem;
}

/* === FILTRES === */
.filters-card {
    background: var(--card-background);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.filters-card h3 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-weight: 600;
    color: var(--text-color);
}

.filter-group select,
.filter-group input {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-background);
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Boutons de périodes prédéfinies */
.preset-periods {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.period-btn {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-background);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.period-btn:hover {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.period-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

#clearFilters {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
}

#clearFilters:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.filter-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* === STATISTIQUES === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--card-background);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-icon {
    font-size: 2.5rem;
    color: var(--primary-color);
    opacity: 0.8;
}

.stat-info h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-color);
    font-size: 0.9rem;
    opacity: 0.8;
}

.stat-value {
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* === GRAPHIQUES === */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
}

.chart-card {
    background: var(--card-background);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.chart-header h3 {
    margin: 0;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-controls {
    display: flex;
    gap: 0.5rem;
}

.chart-toggle {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-background);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
}

.chart-toggle:hover,
.chart-toggle.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.chart-container {
    position: relative;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-container canvas {
    max-height: 100%;
}

.chart-empty {
    text-align: center;
    color: var(--text-secondary);
}

.chart-empty i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.chart-empty p {
    font-size: 1.1rem;
    margin: 0;
}

/* === TABLEAU === */
.table-card {
    background: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.table-header h3 {
    margin: 0;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.table-controls select {
    padding: 0.5rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-background);
    color: var(--text-color);
}

.table-container {
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
}

#expensesTable {
    width: 100%;
    border-collapse: collapse;
}

#expensesTable th {
    background: var(--primary-color);
    color: white;
    padding: 1rem;
    text-align: right;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

#expensesTable td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

#expensesTable tbody tr:hover {
    background: var(--hover-color);
}

.table-empty,
.table-loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.table-empty i,
.table-loading i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.table-pagination {
    padding: 1rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

/* Badges pour catégories */
.category-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}

.amount-cell {
    font-weight: bold;
    color: var(--primary-color);
}

.payment-method {
    background: var(--secondary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
}

/* === RESPONSIVE DESIGN === */
@media (max-width: 768px) {
    .main-nav {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-links {
        width: 100%;
        justify-content: center;
    }
    
    .filters-grid {
        grid-template-columns: 1fr;
    }
    
    .preset-periods {
        justify-content: center;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .chart-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .chart-controls {
        justify-content: center;
    }
    
    .filter-actions {
        justify-content: center;
    }
    
    .table-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .chart-container {
        height: 250px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }
    
    .filters-card,
    .stat-card,
    .chart-card {
        padding: 1rem;
    }
    
    .stat-card {
        flex-direction: column;
        text-align: center;
    }
    
    .stat-icon {
        font-size: 2rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .chart-container {
        height: 200px;
    }
    
    #expensesTable th,
    #expensesTable td {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
}

/* Variables CSS pour les couleurs des graphiques */
:root {
    --chart-color-1: #3498db;
    --chart-color-2: #e74c3c;
    --chart-color-3: #2ecc71;
    --chart-color-4: #f39c12;
    --chart-color-5: #9b59b6;
    --chart-color-6: #1abc9c;
    --chart-color-7: #34495e;
    --chart-color-8: #e67e22;
}

/* Animation de chargement */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.fa-spin {
    animation: spin 1s infinite linear;
}

/* Amélioration de l'accessibilité */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* Container principal */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 15px;
}

@media (min-width: 768px) {
    .container {
        max-width: 750px;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1200px;
    }
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    padding: 1rem 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo i {
    font-size: 2rem;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Navigation mobile */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--border-color);
    padding: 10px 0;
    z-index: 1000;
}

.nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--light-text);
    font-size: 0.8rem;
    padding: 5px;
    transition: var(--transition);
}

.nav-item.active,
.nav-item:hover {
    color: var(--secondary-color);
}

.nav-item i {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

@media (max-width: 767px) {
    .mobile-nav {
        display: block;
    }
    
    body {
        padding-bottom: 70px;
    }
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    overflow: hidden;
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.card-header {
    padding: 1rem;
    background: var(--light-bg);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-body {
    padding: 1rem;
}

.card-footer {
    padding: 0.5rem 1rem;
    background: var(--light-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    text-align: center;
    white-space: nowrap;
}

.btn-primary {
    background: var(--secondary-color);
    color: var(--white);
}

.btn-primary:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success-color);
    color: var(--white);
}

.btn-success:hover {
    background: #219a52;
}

.btn-warning {
    background: var(--warning-color);
    color: var(--white);
}

.btn-warning:hover {
    background: #d68910;
}

.btn-danger {
    background: var(--danger-color);
    color: var(--white);
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-secondary {
    background: var(--light-text);
    color: var(--white);
}

.btn-secondary:hover {
    background: #6c7b7d;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 24px;
    font-size: 1.1rem;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--dark-text);
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
    direction: rtl;
    text-align: right;
}

.form-control:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.form-control.is-invalid {
    border-color: var(--danger-color);
}

.form-control.is-valid {
    border-color: var(--success-color);
}

.invalid-feedback {
    color: var(--danger-color);
    font-size: 0.8rem;
    margin-top: 5px;
}

.valid-feedback {
    color: var(--success-color);
    font-size: 0.8rem;
    margin-top: 5px;
}

select.form-control {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: left 8px center;
    background-repeat: no-repeat;
    background-size: 16px 12px;
    padding-left: 40px;
}

/* Search and Filters */
.search-filters {
    background: var(--white);
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.filters-row {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .filters-row {
        grid-template-columns: 2fr 1fr 1fr 1fr auto;
        align-items: end;
    }
}

.search-input {
    position: relative;
}

.search-input input {
    padding-left: 40px;
}

.search-input i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--light-text);
}

/* Expense Items */
.expense-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.expense-item:last-child {
    border-bottom: none;
}

.expense-item:hover {
    background: #f8f9fa;
}

.expense-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 1rem;
    font-size: 1.2rem;
    color: var(--white);
}

.expense-details {
    flex: 1;
}

.expense-description {
    font-weight: 600;
    margin-bottom: 4px;
}

.expense-meta {
    font-size: 0.8rem;
    color: var(--light-text);
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.expense-amount {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--danger-color);
    text-align: left;
    direction: ltr;
}

.expense-actions {
    display: flex;
    gap: 5px;
    margin-right: 10px;
}

/* Category Badge */
.category-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--white);
}

/* Statistics */
.stats-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
    margin-bottom: 2rem;
}

@media (min-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-card {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 1.5rem;
    color: var(--white);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--light-text);
    font-size: 0.9rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin: 2rem 0;
}

.pagination a,
.pagination span {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--dark-text);
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.pagination a:hover,
.pagination .current {
    background: var(--secondary-color);
    color: var(--white);
    border-color: var(--secondary-color);
}

.pagination .disabled {
    color: var(--light-text);
    cursor: not-allowed;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    overflow-y: auto;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--white);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--light-text);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--danger-color);
}

.modal-body {
    padding: 1rem;
}

.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-success {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.alert-warning {
    background: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

.alert-danger {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.alert-info {
    background: #d1ecf1;
    border-color: #bee5eb;
    color: #0c5460;
}

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--light-text);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: var(--border-color);
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--dark-text);
}

/* Responsive Utilities */
.d-none {
    display: none !important;
}

.d-block {
    display: block !important;
}

.d-flex {
    display: flex !important;
}

.text-center {
    text-align: center !important;
}

.text-left {
    text-align: left !important;
}

.text-right {
    text-align: right !important;
}

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.5rem !important; }
.mb-2 { margin-bottom: 1rem !important; }
.mb-3 { margin-bottom: 1.5rem !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.5rem !important; }
.mt-2 { margin-top: 1rem !important; }
.mt-3 { margin-top: 1.5rem !important; }

@media (max-width: 767px) {
    .d-md-none {
        display: none !important;
    }
    
    .btn-sm-block {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .expense-meta {
        flex-direction: column;
        gap: 5px;
    }
    
    .expense-actions {
        flex-direction: column;
    }
    
    .modal-content {
        margin: 1rem;
        width: calc(100% - 2rem);
    }
    
    .filters-row {
        grid-template-columns: 1fr;
    }
    
    .btn-group {
        justify-content: center;
    }
}