@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg-app: #f1f5f9;
    --bg-topbar: #ffffff;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-brand-bg: #ffffff;
    --primary: #0877e8;
    --primary-hover: #0756a8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --table-header: #f8fafc;
    --table-hover: #f9fafb;
    --input-bg: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

body.dark-theme {
    --bg-app: #090d16;
    --bg-topbar: #111827;
    --bg-card: #111827;
    --bg-sidebar: #070a12;
    --sidebar-hover: #1b2436;
    --sidebar-brand-bg: #111827;
    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #1f2937;
    --table-header: #1a2234;
    --table-hover: #141c2b;
    --input-bg: #1a2234;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; font-family: 'Inter', sans-serif; margin: 0; padding: 0; }
body { display: flex; height: 100vh; background: var(--bg-app); color: var(--text-main); font-size: 13px; overflow-x: hidden; transition: background-color 0.2s ease, color 0.2s ease; }

h1, h2, h3, h4 { color: var(--text-main); font-weight: 600; margin-bottom: 12px; }
.btn { padding: 8px 14px; border: none; border-radius: 4px; cursor: pointer; font-weight: 500; transition: 0.2s ease; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; user-select: none; text-decoration: none;}
.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #ffffff; }
.btn-danger  { background: var(--danger); color: #ffffff; }
.btn-warning { background: var(--warning); color: #ffffff; }
.btn-sm { padding: 5px 9px; font-size: 12px; border-radius: 3px; }

.badge { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; color: #ffffff; display: inline-block; letter-spacing: 0.3px; }
.badge-success { background: var(--success); }
.badge-warning { background: var(--warning); color: #ffffff; }
.badge-danger  { background: var(--danger); }
.badge-neutral { background: var(--border); color: var(--text-main); }
.badge-credited { background: #6366f1; color: #ffffff; }
.badge-total-credited { background: #475569; color: #ffffff; }
.badge-void { background: #94a3b8; color: #ffffff; text-decoration: line-through; }

.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 15px;}
.actions-group { display: flex; gap: 4px; align-items: center; }

/* SIDEBAR */
.sidebar { width: 250px; background: var(--bg-sidebar); color: #ffffff; display: flex; flex-direction: column; height: 100vh; z-index: 1000; flex-shrink: 0; transition: transform 0.3s ease; }
.sidebar-brand { padding: 20px 15px; border-bottom: 1px solid var(--sidebar-hover); text-align: center; background: var(--sidebar-brand-bg); }
.sidebar-brand img { max-width: 90%; height: auto; }
.nav-links { list-style: none; padding: 10px 0; flex-grow: 1; overflow-y: auto;}
.nav-links li a { display: flex; align-items: center; gap: 12px; padding: 12px 18px; color: #cbd5e1; text-decoration: none; font-weight: 500; transition: background-color 0.2s ease, border 0.2s ease; font-size: 14px; }
.nav-links li a:hover, .nav-links li a.active { background: var(--sidebar-hover); color: #ffffff; border-left: 3px solid var(--primary); }
.menu-icon { width: 22px; height: 22px; flex-shrink: 0; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15)); }

/* MAIN CONTENT & TOP BAR */
.main-content { flex: 1; overflow-y: auto; height: 100vh; display: flex; flex-direction: column; }
.top-bar { position: sticky; top: 0; height: 60px; background: var(--bg-topbar); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 25px; z-index: 900; box-shadow: var(--shadow); flex-shrink: 0; }
.top-bar-left { display: flex; align-items: center; gap: 15px; }
.top-bar-right { display: flex; align-items: center; gap: 15px; }

.mobile-brand { display: none; align-items: center; }
.mobile-brand img { height: 24px; width: auto; }

.datetime-display { font-size: 13px; font-weight: 500; color: var(--text-main); display: flex; align-items: center; gap: 10px; }
.datetime-display .date-part { color: var(--text-muted); font-weight: 500; }
.datetime-display .sep-part  { color: var(--border); }
.datetime-display .time-part { color: var(--text-main); font-weight: 700; }

.theme-toggle-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--bg-app); border: 1px solid var(--border); color: var(--text-main); padding: 6px 14px; border-radius: 30px; cursor: pointer; font-size: 12.5px; font-weight: 500; transition: border-color 0.25s ease, background-color 0.25s ease; }
.theme-toggle-btn:hover { border-color: var(--primary); }
.hamburger { display: none; }

.page-container { padding: 25px; flex: 1; }
.page { display: none; animation: fadeIn 0.2s ease; }
.page.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* CARTES & KPI */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 20px; }
.card { background: var(--bg-card); padding: 18px; border-radius: 6px; border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 15px; }
.card h4 { color: var(--text-muted); font-size: 11px; text-transform: uppercase; margin-bottom: 5px; font-weight: 600;}
.card .value { font-size: 20px; font-weight: 700; color: var(--text-main); }
.sub-form-card { background: var(--bg-app) !important; border: 1px solid var(--border); }

.dashboard-charts { display: grid; grid-template-columns: 2fr 1fr; gap: 15px; margin-bottom: 20px; }
.chart-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.chart-container { position: relative; height: 250px; width: 100%; }

/* TABLEAUX */
.table-container { background: var(--bg-card); border-radius: 6px; border: 1px solid var(--border); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; min-width: 600px; }
th { background: var(--table-header); padding: 10px 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 13px; color: var(--text-main); }
tr:hover { background: var(--table-hover); }

.text-right  { text-align: right; }
.text-center { text-align: center; }

/* PAGINATION SERVEUR */
.pagination-container { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 12px 15px; background: var(--bg-card); border: 1px solid var(--border); border-top: none; border-radius: 0 0 6px 6px; font-size: 12px; }
.pagination-info { color: var(--text-muted); font-weight: 500; }
.pagination-controls { display: flex; align-items: center; gap: 5px; }
.page-btn { min-width: 32px; height: 32px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-main); border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 500; transition: all 0.15s ease; }
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #ffffff; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-size-selector { padding: 4px 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-main); border-radius: 4px; outline: none; cursor: pointer; }

/* FORMULAIRES */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; color: var(--text-main); font-size: 12px; }
.form-control { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; outline: none; font-size: 13px; background: var(--input-bg); color: var(--text-main); transition: border-color 0.2s ease; }
.form-control:focus { border-color: var(--primary); }
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.help-text   { font-size: 11px; color: var(--text-muted); font-weight: normal; }

/* DROPDOWN MENU */
.doc-dropdown-wrapper { position: relative; display: inline-block; }
.doc-dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 6px); background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15); min-width: 210px; z-index: 1050; overflow: hidden; animation: fadeIn 0.15s ease-out; }
.doc-dropdown-menu.show { display: block; }
.doc-dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 15px; background: transparent; border: none; color: var(--text-main); font-size: 13px; font-weight: 500; text-align: left; cursor: pointer; transition: background-color 0.15s ease, color 0.15s ease; }
.doc-dropdown-item:hover { background: var(--table-hover); color: var(--primary); }
.doc-dropdown-item .doc-item-icon { font-size: 15px; }

/* MODAL AVOIR */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.75); z-index: 10000; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(4px); overflow-y: auto; }
.modal-dialog { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; width: 100%; max-width: 850px; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; max-height: 90vh; animation: fadeIn 0.2s ease-out; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 15px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.credit-info-box { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; background: var(--bg-app); padding: 12px 16px; border-radius: 6px; border: 1px solid var(--border); margin-bottom: 15px; text-align: center; }
.credit-info-box .item label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px; }
.credit-info-box .item .val { font-size: 15px; font-weight: 700; color: var(--text-main); }

/* LOGIN & ÉCRAN DE VERROUILLAGE */
.login-wrapper { display: flex; justify-content: center; align-items: center; width: 100%; height: 100vh; background: var(--bg-sidebar); }
.login-box { background: var(--bg-card); padding: 40px; border-radius: 8px; width: 360px; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); border: 1px solid var(--border); }
#lock-screen-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.95); z-index: 99999; align-items: center; justify-content: center; backdrop-filter: blur(8px); }
.lock-box { background: var(--bg-card); border: 1px solid var(--border); padding: 35px 30px; border-radius: 8px; width: 320px; text-align: center; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4); }
.lock-icon-wrapper { font-size: 38px; margin-bottom: 12px; }

/* BOTTOM NAVIGATION BAR (Mobile) */
.bottom-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; height: 64px; background: var(--bg-topbar); border-top: 1px solid var(--border); z-index: 1000; box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.06); padding: 0 5px; justify-content: space-around; align-items: center; }
.bottom-nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text-muted); text-decoration: none; font-size: 10.5px; font-weight: 500; transition: all 0.15s ease; padding: 6px 0; border-radius: 6px; }
.bottom-nav-item.active { color: var(--primary); font-weight: 700; }
.bottom-nav-item .nav-icon { width: 20px; height: 20px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15)); }

/* LAYOUT 2 : MOBILE & PETITS ÉCRANS (<= 768px) */
@media (max-width: 768px) {
    .sidebar { display: none !important; }
    .bottom-nav { display: flex !important; }
    .main-content { margin-left: 0 !important; width: 100% !important; padding-bottom: 85px !important; }
    .top-bar { padding: 0 15px; height: 54px; }
    .mobile-brand { display: flex; }
    .datetime-display .date-part { display: none; }
    .datetime-display .sep-part  { display: none; }
    .theme-toggle-btn { padding: 5px 10px; font-size: 11px; }
    .theme-toggle-btn #theme-text { display: none; }
    .page-container { padding: 15px 12px; }

    /* Transformation Tableaux ➔ Cartes */
    .table-container { background: transparent !important; border: none !important; box-shadow: none !important; overflow: visible !important; }
    .table-container table, .table-container thead, .table-container tbody, .table-container tr, .table-container td { display: block !important; width: 100% !important; min-width: 0 !important; }
    .table-container thead { display: none !important; }
    .table-container tbody tr { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
    .table-container tbody td { display: flex !important; justify-content: space-between !important; align-items: center !important; padding: 6px 0 !important; border-bottom: 1px dashed var(--border) !important; text-align: right !important; font-size: 12.5px !important; }
    .table-container tbody td[data-label]::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); font-size: 11.5px; text-align: left; margin-right: 10px; }
    .table-container tbody td:last-child { border-bottom: none !important; padding-top: 10px !important; justify-content: flex-end !important; }

    .actions-group { width: 100%; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
    .actions-group .btn { padding: 6px 10px; font-size: 11.5px; }

    .form-grid, .form-grid-3, .dashboard-charts, .credit-info-box { grid-template-columns: 1fr !important; }
    .modal-dialog { width: 96% !important; max-height: 92vh !important; margin: 10px auto; }
    .modal-body { padding: 15px; }
    .pagination-container { border-top: 1px solid var(--border); border-radius: 6px; flex-direction: column; align-items: center; text-align: center; gap: 8px; }
}

@media print {
    .sidebar, .top-bar, .bottom-nav, .no-print, #lock-screen-overlay, .modal-overlay { display: none !important; }
}