/* ============================================================
   IPDO - Institut Paramédical de Prothèse Dentaire et d'Optique - ERP Financier
   Styles Professionnels
   ============================================================ */

/* CSS Variables */
:root {
    --primary: #1F4E79;
    --primary-dark: #153A5B;
    --primary-light: #2A6B9C;
    --secondary: #6c757d;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --dark: #1a1a2e;
    --light: #f8f9fa;
    --white: #ffffff;
    --sidebar-width: 260px;
    --navbar-height: 60px;
    --card-shadow: 0 2px 8px rgba(0,0,0,0.08);
    --card-hover-shadow: 0 8px 25px rgba(0,0,0,0.12);
    --transition: all 0.3s ease;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Dark Mode Variables */
[data-bs-theme="dark"] {
    --primary: #2A6B9C;
    --primary-dark: #1F4E79;
    --light: #1e1e2e;
    --dark: #f8f9fa;
    --white: #16161f;
    --card-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

body {
    font-family: var(--font-family);
    background: #f0f2f5;
    color: #333;
    overflow-x: hidden;
}

[data-bs-theme="dark"] body {
    background: #12121a;
    color: #e0e0e0;
}

a { text-decoration: none; }
.card { border-radius: var(--border-radius); transition: var(--transition); }
.card:hover { box-shadow: var(--card-hover-shadow); }
.badge { font-weight: 500; padding: 0.4em 0.7em; border-radius: 6px; }
.btn { border-radius: 8px; font-weight: 500; transition: var(--transition); }
.btn-sm { border-radius: 6px; }
.shadow-sm { box-shadow: var(--card-shadow) !important; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1F4E79 0%, #153A5B 50%, #0f2b42 100%);
    padding: 20px;
}

.login-container { width: 100%; max-width: 450px; }

.login-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

[data-bs-theme="dark"] .login-card { background: #1e1e2e; }

.login-header { padding: 30px 30px 20px; }
.login-logo { color: var(--primary); }
.login-body { padding: 0 30px 30px; }
.login-footer { padding: 15px 30px; background: #f8f9fa; }
[data-bs-theme="dark"] .login-footer { background: #16161f; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#wrapper {
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1F4E79 0%, #153A5B 100%);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-logo { color: #4fc3f7; }
.brand-title { font-weight: 700; font-size: 1.1rem; }
.brand-subtitle { font-size: 0.7rem; opacity: 0.7; }

.sidebar-user {
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-nav {
    list-style: none;
    padding: 10px 0;
    flex-grow: 1;
    margin: 0;
}

.nav-section {
    padding: 10px 20px 5px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.5;
    font-weight: 600;
}

.sidebar-nav .nav-item { margin: 2px 8px; }
.sidebar-nav .nav-link {
    color: rgba(255,255,255,0.7);
    padding: 10px 15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    transition: var(--transition);
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.sidebar-nav .nav-link.active {
    background: rgba(255,255,255,0.15);
    color: white;
    font-weight: 600;
}

.sidebar-nav .nav-link i { width: 20px; text-align: center; font-size: 1rem; }

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

#page-content-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: var(--transition);
}

/* Sidebar Toggle */
#menuToggle {
    color: var(--primary);
    font-size: 1.3rem;
    padding: 0;
    border: none;
    background: none;
}

/* ============================================================
   TOP NAVBAR
   ============================================================ */
.top-navbar {
    background: white;
    height: var(--navbar-height);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    padding: 0 20px;
}

[data-bs-theme="dark"] .top-navbar {
    background: #1e1e2e;
}

.nav-icon {
    color: #6c757d;
    font-size: 1.2rem;
    position: relative;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
}

.nav-icon:hover {
    background: #f0f2f5;
    color: var(--primary);
}

[data-bs-theme="dark"] .nav-icon:hover { background: #2a2a3e; }

.notification-badge { font-size: 0.6rem; min-width: 18px; height: 18px; padding: 0 5px; line-height: 18px; }

.navbar-date { color: #6c757d; font-size: 0.85rem; }

/* Notification Dropdown */
.notification-dropdown { width: 350px; max-height: 450px; overflow-y: auto; padding: 0; }
.notification-list { max-height: 350px; overflow-y: auto; }
.notification-footer { padding: 10px; border-top: 1px solid #eee; }

/* ============================================================
   KPI CARDS
   ============================================================ */
.card-kpi {
    background: white;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

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

a .card-kpi { cursor: pointer; }
a:hover .card-kpi { transform: translateY(-3px); box-shadow: var(--card-hover-shadow); }
a .card-kpi-sm { cursor: pointer; }

.kpi-label { font-size: 0.8rem; color: #6c757d; margin-bottom: 5px; font-weight: 500; }
.kpi-value { font-weight: 700; margin-bottom: 0; }
.kpi-value small { font-size: 0.7rem; font-weight: 400; }

.kpi-icon {
    width: 55px;
    height: 55px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bg-soft-green { background: rgba(40, 167, 69, 0.1); }
.bg-soft-red { background: rgba(220, 53, 69, 0.1); }
.bg-soft-primary { background: rgba(31, 78, 121, 0.1); }
.bg-soft-info { background: rgba(23, 162, 184, 0.1); }
.bg-soft-warning { background: rgba(255, 193, 7, 0.1); }

.card-kpi-sm {
    background: white;
    border-radius: var(--border-radius);
    transition: var(--transition);
    cursor: default;
}

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

[data-bs-theme="dark"] .card-kpi,
[data-bs-theme="dark"] .card-kpi-sm,
[data-bs-theme="dark"] .card {
    background: #1e1e2e;
}

/* ============================================================
   TABLES
   ============================================================ */
.table thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    font-weight: 600;
    border-bottom: 2px solid #e9ecef;
}

.table-hover tbody tr {
    transition: var(--transition);
}

.table-hover tbody tr:hover {
    background: rgba(31, 78, 121, 0.03);
}

.avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}

.avatar-lg {
    width: 80px;
    height: 80px;
    border-radius: 50%;
}

/* ============================================================
   REPORTS
   ============================================================ */
.report-card { transition: var(--transition); }
.report-card:hover { transform: translateY(-5px); box-shadow: var(--card-hover-shadow); }
.report-icon { width: 80px; height: 80px; border-radius: 20px; display: flex; align-items: center; justify-content: center; }

/* ============================================================
   FORMS
   ============================================================ */
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(31, 78, 121, 0.15);
}

.form-label { font-size: 0.85rem; font-weight: 500; color: #495057; }

/* ============================================================
   DATA TABLES
   ============================================================ */
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: white !important;
}

/* ============================================================
   RESPONSIVE - Mobile-First Base
   ============================================================ */

/* Fluid container padding on small screens */
.container-fluid {
    padding-left: 12px;
    padding-right: 12px;
}

/* Typography scales fluidly */
h4 { font-size: clamp(1.1rem, 2.5vw, 1.5rem); }
h5 { font-size: clamp(0.95rem, 2vw, 1.25rem); }
h6 { font-size: clamp(0.85rem, 1.5vw, 1rem); }
.card-body { padding: clamp(0.8rem, 2vw, 1.25rem); }

/* Prevent overflow on all tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Images scale responsively */
img { max-width: 100%; height: auto; }

/* ============================================================
   RESPONSIVE - écrans larges (>=1200px)
   ============================================================ */
@media (min-width: 1200px) {
    .container-fluid { max-width: 1400px; margin: 0 auto; }
}

/* ============================================================
   RESPONSIVE - écrans moyens / tablettes (768px - 1199px)
   ============================================================ */
@media (max-width: 1199.98px) {
    .kpi-value { font-size: 1.4rem; }
    .card-kpi .card-body { padding: 1rem; }
}

@media (max-width: 991.98px) {
    .sidebar {
        margin-left: calc(-1 * var(--sidebar-width));
        box-shadow: none;
        z-index: 1050;
    }
    .sidebar.active {
        margin-left: 0;
        box-shadow: 0 0 30px rgba(0,0,0,0.3);
    }
    #page-content-wrapper {
        margin-left: 0;
    }
    #page-content-wrapper.active {
        margin-left: var(--sidebar-width);
    }
    #sidebarOverlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1049;
    }
    #sidebarOverlay.active { display: block; }

    .card-kpi-sm .card-body { padding: 0.8rem; }
    .card-kpi-sm h5 { font-size: 1rem; }

    /* Stack filter forms on tablets */
    .filter-row .col-md-2,
    .filter-row .col-md-3,
    .filter-row .col-md-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

@media (max-width: 767.98px) {
    :root {
        --sidebar-width: 260px;
        --navbar-height: 50px;
    }

    .sidebar-header { padding: 12px 15px; }
    .sidebar-header .brand-title { font-size: 0.95rem; }
    .sidebar-user { padding: 10px 15px; }
    .sidebar-nav .nav-link { padding: 8px 12px; font-size: 0.85rem; }
    .sidebar-nav .nav-item { margin: 1px 5px; }
    .nav-section { padding: 8px 15px 3px; font-size: 0.65rem; }

    .top-navbar { height: 50px; padding: 0 10px; }
    .navbar-date { display: none !important; }

    .card { border-radius: 10px; }
    .card-body { padding: 0.8rem; }

    .kpi-value { font-size: 1.1rem; }
    .kpi-label { font-size: 0.7rem; }
    .kpi-icon { width: 36px; height: 36px; border-radius: 10px; }
    .kpi-icon i { font-size: 1rem; }
    .card-kpi .card-body { padding: 0.8rem; }

    .card-kpi-sm h5 { font-size: 0.9rem; }
    .card-kpi-sm small { font-size: 0.65rem; }

    .table { font-size: 0.78rem; }
    .table thead th { font-size: 0.65rem; }
    .btn-sm { font-size: 0.72rem; padding: 0.25rem 0.45rem; }

    .notification-dropdown {
        width: calc(100vw - 20px) !important;
        right: -70px !important;
        position: fixed !important;
        top: 55px !important;
    }

    .form-label { font-size: 0.78rem; }
    .form-control, .form-select { font-size: 0.85rem; }

    .login-card { border-radius: 16px; margin: 10px; }
    .login-header { padding: 20px 20px 10px; }
    .login-body { padding: 0 20px 20px; }
    .login-header h3 { font-size: 1.2rem; }

    /* Tables: force horizontal scroll on mobile */
    .table-responsive { margin: 0; }
    .table-responsive .table { min-width: 600px; }

    /* KPI grid: 2 columns on mobile (override Bootstrap) */
    .row.g-3 > .col-xl-3.col-md-6 { flex: 0 0 50%; max-width: 50%; }
    .row.g-3 > .col-xl-2 { flex: 0 0 50%; max-width: 50%; }

    /* Chart containers - adaptive height */
    canvas { max-height: 200px !important; }

    .alert { font-size: 0.82rem; padding: 0.5rem 0.8rem; }

    .modal-dialog { margin: 10px; }

    /* Make filter/search forms stack vertically on mobile */
    .filter-row .row {
        flex-direction: column;
    }
    .filter-row .col-md-2,
    .filter-row .col-md-3,
    .filter-row .col-md-4,
    .filter-row .col-md-5 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Stack action buttons on mobile */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    .btn-group-mobile .btn {
        width: 100%;
    }

    /* Sidebar close button always visible on mobile */
    .sidebar-toggle.d-lg-none {
        display: block !important;
    }
}

@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 8px;
        padding-right: 8px;
    }

    .top-navbar { padding: 0 8px; }

    .table { font-size: 0.72rem; }
    .table tbody td { padding: 0.35rem 0.4rem; }

    /* Smaller badges on very small screens */
    .badge { font-size: 0.65rem; padding: 0.3em 0.5em; }

    /* Full-width filter row items */
    .row > [class*="col-"] {
        padding-left: 6px;
        padding-right: 6px;
    }

    .notification-dropdown {
        right: -50px !important;
    }

    /* Minimal padding for very small screens */
    .card-body { padding: 0.6rem; }
}

/* ============================================================
   RESPONSIVE - très petits téléphones (<480px)
   ============================================================ */
@media (max-width: 480px) {
    .row.g-3 > .col-xl-3.col-md-6 { flex: 0 0 100%; max-width: 100%; }
    .row.g-3 > .col-xl-2 { flex: 0 0 100%; max-width: 100%; }
    .row.g-3 > div[class*="col-"] { flex: 0 0 100%; max-width: 100%; }

    .sidebar { width: 240px; }
    .sidebar-nav .nav-link span { font-size: 0.8rem; }

    .top-navbar .nav-icon { padding: 6px; font-size: 1rem; }
    .top-navbar .d-flex.align-items-center { gap: 4px; }
    .top-navbar .me-3 { margin-right: 0.25rem !important; }
}

/* ============================================================
   RESPONSIVE - DataTables Responsive Overrides
   ============================================================ */

/* Make DataTables work on mobile - prevent overflow */
.dataTables_wrapper {
    overflow-x: auto;
}

.dataTables_wrapper .dataTables_filter input {
    max-width: 180px;
}

/* Stack DataTable controls on mobile */
@media (max-width: 767.98px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: left;
        padding: 4px 0;
    }
    .dataTables_wrapper .dataTables_filter input {
        max-width: 140px;
        display: inline-block;
    }
}

/* ============================================================
   RESPONSIVE - Print / Receipt
   ============================================================ */
@media print {
    .sidebar, .top-navbar, .btn, .sidebar-toggle, .no-print { display: none !important; }
    #page-content-wrapper { margin-left: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd; }
}

/* Make receipt-card responsive on screen (not print) */
@media screen and (max-width: 991.98px) {
    .receipt-card {
        width: 100% !important;
        min-height: auto !important;
        height: auto !important;
    }
    .receipt-inner {
        padding: 20px 15px !important;
    }
}
@media screen and (max-width: 575.98px) {
    .receipt-header img {
        height: 60px !important;
    }
    .receipt-header h4 {
        font-size: 1.1rem !important;
    }
    .receipt-table {
        font-size: 0.78rem !important;
    }
    .receipt-table th,
    .receipt-table td {
        padding: 6px !important;
    }
    .receipt-table .amount-cell {
        font-size: 0.95rem !important;
    }
    .receipt-footer {
        flex-direction: column;
        align-items: center !important;
        gap: 12px;
    }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-primary { color: var(--primary) !important; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

.progress { border-radius: 10px; background: #e9ecef; }
[data-bs-theme="dark"] .progress { background: #2a2a3e; }

.unread { background: rgba(31, 78, 121, 0.05); }
[data-bs-theme="dark"] .unread { background: rgba(42, 107, 156, 0.15); }

/* Charts */
canvas { max-width: 100%; }

/* Photo preview responsiveness */
@media (max-width: 575.98px) {
    [style*="width:120px"][style*="height:120px"],
    [style*="width:150px"][style*="height:150px"] {
        width: 100px !important;
        height: 100px !important;
    }
}

/* ============================================================
   RESPONSIVE - Action Column (no fixed width)
   ============================================================ */
.actions-col {
    width: 1%;
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .actions-col {
        white-space: normal;
    }
    .actions-col .btn {
        margin-bottom: 2px;
    }
}

/* ============================================================
   RESPONSIVE - Filter Row Stacking
   ============================================================ */
@media (max-width: 991.98px) and (min-width: 768px) {
    .filter-row > [class*="col-md-"] {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ============================================================
   RESPONSIVE - Dashboard header
   ============================================================ */
@media (max-width: 575.98px) {
    .d-flex.justify-content-between.align-items-center.mb-3 {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 8px;
    }
    .d-flex.justify-content-between.align-items-center.mb-3 > div {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }
    .d-flex.justify-content-between.align-items-center.mb-3 > div .btn {
        flex: 1 1 auto;
    }

    /* Partial payment alert on mobile */
    #partialPaymentInfo .alert {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 8px;
    }
    #partialPaymentInfo .btn {
        width: 100%;
    }
}
