/* ===================================
   Dashboard CSS - Version Professionnelle & Responsive
   =================================== */

/* === 1. Variables & Reset === */
:root {
    /* Couleurs Principales */
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    
    /* Couleurs Sémantiques */
    --success-color: #10b981;
    --success-bg: #d1fae5;
    --warning-color: #f59e0b;
    --warning-bg: #fef3c7;
    --danger-color: #ef4444;
    --danger-bg: #fee2e2;
    --info-color: #3b82f6;
    --info-bg: #dbeafe;
    
    /* Neutres */
    --dark-color: #1e293b;
    --light-color: #f8fafc;
    --white: #ffffff;
    --border-color: #e2e8f0;
    --text-muted: #64748b;
    
    /* Ombres */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Layout */
    --sidebar-width: 280px;
    --header-height: 64px;
    --border-radius: 0.5rem;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset de base */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--dark-color);
    background-color: var(--light-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Accessibilité : Focus visible */
a:focus-visible, button:focus-visible, input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* === 2. Layout Administration === */
.admin-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
    flex-wrap: wrap;
}

/* Sidebar */
.admin-sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: var(--white);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.admin-sidebar.hidden {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.sidebar-title {
    color: var(--white);
    font-size: clamp(1rem, 2vw, 1.25rem);
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    letter-spacing: -0.025em;
}

.sidebar-title i {
    font-size: 1.5rem;
    color: #60a5fa;
}

.sidebar-nav {
    padding: 1.5rem 1rem;
    flex: 1;
    overflow-y: auto;
}

.sidebar-nav .nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-nav .nav-link {
    color: rgba(255, 255, 255, 0.7);
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    font-weight: 500;
    font-size: clamp(0.875rem, 1.5vw, 0.95rem);
    min-height: 44px;
}

.sidebar-nav .nav-link:hover {
    color: var(--white);
    background-color: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.sidebar-nav .nav-link:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: -2px;
}

.sidebar-nav .nav-link.active {
    color: var(--white);
    background: linear-gradient(135deg, var(--primary-color) 0%, #4338ca 100%);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.9);
    flex-shrink: 0;
}

.user-info {
    text-align: center;
}

.user-info .text-muted {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}

.user-name {
    color: var(--white);
    font-weight: 600;
    font-size: 0.9rem;
    word-break: break-word;
}

/* Main Content */
.admin-main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
    width: auto;
    overflow-x: hidden;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    background: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    padding: 0.5rem 0.75rem;
    min-height: 44px;
    min-width: 44px;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Sidebar Backdrop (Mobile) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* === 3. Dashboard Components === */

/* Content Wrapper */
.content-wrapper {
    background: linear-gradient(135deg, #f1f5f9 0%, #f8fafc 100%);
    min-height: 100vh;
    padding: clamp(1rem, 3vw, 2rem);
}

/* Header */
.dashboard-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: grid;
    gap: 1rem;
    align-items: start;
}

.dashboard-title {
    color: var(--dark-color);
    font-size: clamp(1.5rem, 4vw, 1.75rem);
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.dashboard-title i {
    color: var(--primary-color);
    font-size: 1.5em;
}

.dashboard-subtitle {
    color: var(--text-muted);
    font-size: clamp(0.875rem, 1.5vw, 1rem);
    margin: 0.25rem 0 0 0;
}

.dashboard-meta {
    color: var(--text-muted);
    font-size: 0.875rem;
    background: var(--white);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    border: 1px solid var(--border-color);
    white-space: nowrap;
    width: fit-content;
}

/* Section Headers */
.section-header {
    display: flex;
    align-items: center;
    margin: 2.5rem 0 1.5rem 0;
    gap: 0.75rem;
}

.section-header i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark-color);
    margin: 0;
}

.section-subtitle {
    color: var(--dark-color);
    font-size: 1.25rem;
    font-weight: 600;
    margin: 2rem 0 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    align-items: center;
}

.section-subtitle i {
    color: var(--primary-color);
    margin-right: 0.5rem;
}

/* === 4. Cards (General & Specific) === */

/* Generic Card Style */
.dashboard-card, .payment-card, .stat-card, .receipt-card {
    background: var(--white);
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.dashboard-card:hover, .payment-card:hover, .stat-card:hover, .receipt-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

/* Dashboard Card Specifics */
.dashboard-card-header {
    background: var(--light-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: 1rem 1rem 0 0;
}

.dashboard-card-title {
    color: var(--dark-color);
    font-weight: 600;
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
}

.dashboard-card-title i {
    color: var(--primary-color);
    margin-right: 0.5rem;
}

.dashboard-card .card-body {
    padding: 1.5rem;
    flex: 1;
}

/* Stat Cards */
.stat-card {
    border: none;
    overflow: hidden;
    position: relative;
}

.stat-card .card-body {
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--white);
    position: relative;
    z-index: 1;
}

/* Stat Card Variants */
.stat-primary .card-body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.stat-success .card-body { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }
.stat-warning .card-body { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); }
.stat-info .card-body { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); }
.stat-danger .card-body { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }

.stat-card .stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.95rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Payment Cards */
.payment-card {
    border: none;
    overflow: hidden;
}

.payment-card .card-header {
    color: white;
    font-weight: 600;
    padding: 1rem 1.5rem;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.payment-card .card-body {
    padding: 2rem 1.5rem;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.payment-amount {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--dark-color);
}

.payment-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0;
}

/* Payment Variants */
.payment-primary .card-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.payment-success .card-header { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }
.payment-warning .card-header { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); }
.payment-info .card-header { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); }
.payment-danger .card-header { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }

/* Receipt Cards */
.receipt-card {
    cursor: pointer;
    border: 1px solid var(--border-color);
}

.receipt-card .card-body {
    padding: 1.25rem;
}

.receipt-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.receipt-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark-color);
    margin-bottom: 0.25rem;
}

.receipt-card-number {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
    background: var(--light-color);
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
}

.receipt-card-amount {
    font-weight: 700;
    color: var(--success-color);
    font-size: 1.25rem;
    margin: 1rem 0;
}

.receipt-card-info {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.receipt-card-info i {
    color: var(--primary-color);
    margin-right: 0.5rem;
    width: 16px;
}

.receipt-card-actions {
    margin-top: auto;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Receipt States */
.receipt-paid { border-left: 4px solid var(--success-color); }
.receipt-pending { border-left: 4px solid var(--warning-color); }
.receipt-rejected { border-left: 4px solid var(--danger-color); }

.receipt-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 600;
    background-color: var(--success-bg);
    color: var(--success-color);
}

/* Buttons */
.btn-xs {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 0.25rem;
    border: 1px solid var(--border-color);
    background: var(--white);
    color: var(--dark-color);
    cursor: pointer;
    transition: var(--transition);
    min-height: 32px; /* Touch target size */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-xs:hover {
    background: var(--light-color);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* === 5. Tables === */
.dashboard-table {
    width: 100%;
    border-radius: var(--border-radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--white);
    border-collapse: separate;
    border-spacing: 0;
}

/* Container for horizontal scroll on mobile */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.5rem;
}

.dashboard-table thead th {
    background: var(--light-color);
    border-bottom: 2px solid var(--border-color);
    color: var(--dark-color);
    font-weight: 600;
    padding: 1rem;
    text-align: left;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dashboard-table tbody td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    font-size: 0.95rem;
}

.dashboard-table tbody tr:last-child td {
    border-bottom: none;
}

.dashboard-table tbody tr:hover {
    background-color: rgba(79, 70, 229, 0.02);
}

/* === 6. Modal Receipt === */
#recuModal .modal-dialog {
    max-width: 700px;
    margin: 1.75rem auto;
}

#recuModal .modal-content {
    border: none;
    border-radius: 1rem;
    box-shadow: var(--shadow-xl);
}

#recuModal .modal-body {
    padding: 2rem;
    background: #f8fafc;
    border-radius: 1rem;
}

#recuContent {
    background: var(--white);
    padding: 2.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

/* === 7. Animations === */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.receipt-card, .dashboard-card, .stat-card {
    animation: fadeIn 0.4s ease-out forwards;
}

/* === 8. Print Styles === */
@media print {
    .btn, .navbar, .footer, .modal, .sidebar-toggle, .admin-sidebar, .sidebar-backdrop {
        display: none !important;
    }
    
    .admin-main-content {
        margin-left: 0 !important;
        width: 100%;
    }
    
    .receipt-container, #recuContent {
        box-shadow: none;
        border: 1px solid #000;
        page-break-inside: avoid;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .content-wrapper {
        padding: 0;
        background: white;
    }
}

/* === 9. Responsive Media Queries === */

/* Tablet & Mobile (max-width: 992px) */
@media (max-width: 992px) {
    .content-wrapper {
        padding: 1.5rem;
    }
    
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    /* Sidebar Logic */
    .admin-sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    
    .admin-sidebar.show {
        transform: translateX(0);
    }
    
    .admin-main-content {
        margin-left: 0;
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    /* Hide text in sidebar icons only mode if needed, but keeping full menu on slide-in is better */
    
    /* Layout Adjustments */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .receipt-card-header {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .receipt-card-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .receipt-card-actions .btn-xs {
        width: 100%;
        justify-content: center;
    }
    
    /* Modal */
    #recuModal .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    #recuContent {
        padding: 1.5rem;
        font-size: 0.9rem;
    }
    
    /* Stats */
    .stat-card .stat-value {
        font-size: 2rem;
    }
    
    /* Tables */
    .dashboard-table thead th,
    .dashboard-table tbody td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }
}

/* ========================================
   RESPONSIVE DESIGN - MOBILE FIRST
   ======================================== */

/* Extra Small Devices (max-width: 575px) */
@media (max-width: 575px) {
    :root {
        --sidebar-width: 0px;
    }

    .admin-layout {
        flex-direction: column;
    }

    .admin-main-content {
        margin-left: 0;
        width: 100%;
    }

    .admin-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 70vw;
        max-width: 280px;
        transform: translateX(-100%);
    }

    .admin-sidebar.show {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
        top: 1rem;
        left: 1rem;
    }

    .sidebar-backdrop {
        display: none;
    }

    .sidebar-backdrop.show {
        display: block;
    }

    .content-wrapper {
        padding: 1rem 0.75rem;
    }

    .dashboard-header {
        grid-template-columns: 1fr;
        margin-bottom: 1rem;
    }

    .dashboard-title {
        font-size: 1.5rem;
    }

    .dashboard-meta {
        width: 100%;
        white-space: normal;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-header i {
        font-size: 1.25rem;
    }

    .stat-card .stat-value {
        font-size: 1.75rem;
    }

    .stat-card .stat-label {
        font-size: 0.8rem;
    }

    .payment-amount {
        font-size: 1.5rem;
    }

    .payment-label {
        font-size: 0.75rem;
    }

    .sidebar-nav .nav-link {
        padding: 0.75rem 1rem;
        min-height: 44px;
        font-size: 0.875rem;
    }

    .dashboard-card {
        margin-bottom: 1rem;
    }

    .dashboard-table {
        font-size: 0.8rem;
    }

    .dashboard-table thead th {
        padding: 0.75rem 0.5rem;
        font-size: 0.75rem;
    }

    .dashboard-table tbody td {
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    .btn {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
        width: 100%;
        font-size: 0.875rem;
    }

    .quick-actions-grid {
        grid-template-columns: 1fr;
    }
}

/* Small Devices (576px - 767px) */
@media (min-width: 576px) and (max-width: 767px) {
    :root {
        --sidebar-width: 0px;
    }

    .admin-main-content {
        margin-left: 0;
        width: 100%;
    }

    .admin-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        transform: translateX(-100%);
        z-index: 1000;
    }

    .admin-sidebar.show {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .content-wrapper {
        padding: 1.5rem 1rem;
    }

    .dashboard-header {
        grid-template-columns: 1fr;
    }

    .dashboard-card-header {
        padding: 0.75rem 1rem;
    }

    .stat-card .stat-value {
        font-size: 2rem;
    }

    .quick-actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Tablet (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    :root {
        --sidebar-width: 240px;
    }

    .admin-main-content {
        margin-left: var(--sidebar-width);
    }

    .sidebar-nav {
        padding: 1rem 0.875rem;
    }

    .sidebar-nav .nav-link {
        padding: 0.675rem 0.875rem;
        font-size: 0.9rem;
    }

    .content-wrapper {
        padding: 1.5rem;
    }

    .sidebar-title {
        font-size: 1.1rem;
    }

    .quick-actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-table thead th {
        padding: 0.875rem;
    }

    .dashboard-table tbody td {
        padding: 0.875rem;
    }
}

/* Desktop (1024px and up) */
@media (min-width: 1024px) {
    :root {
        --sidebar-width: 280px;
    }

    .admin-main-content {
        margin-left: var(--sidebar-width);
    }

    .sidebar-toggle {
        display: none !important;
    }

    .sidebar-backdrop {
        display: none !important;
    }

    .content-wrapper {
        padding: 2rem;
    }

    .quick-actions-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    .dashboard-header {
        grid-template-columns: 1fr auto;
        align-items: center;
    }

    .dashboard-title {
        font-size: 1.75rem;
    }
}

/* Large Desktop (1440px and up) */
@media (min-width: 1440px) {
    .content-wrapper {
        padding: 2.5rem;
        max-width: 1920px;
        margin: 0 auto;
    }

    .quick-actions-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .stat-card .stat-value {
        font-size: 3rem;
    }
}

/* Touch Devices */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 48px;
    }

    .sidebar-nav .nav-link {
        min-height: 48px;
    }

    .form-control, .form-select {
        min-height: 48px;
    }

    .dashboard-table tbody tr:hover {
        background-color: transparent;
    }
}

/* Print */
@media print {
    .admin-sidebar,
    .sidebar-toggle,
    .sidebar-backdrop,
    .dashboard-header,
    .btn,
    .no-print {
        display: none !important;
    }

    .admin-main-content {
        margin-left: 0;
    }

    .content-wrapper {
        padding: 0;
        background: white;
    }

    .dashboard-card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: more) {
    .dashboard-card {
        border: 2px solid var(--primary-color);
    }

    .btn {
        border: 2px solid currentColor;
    }
}