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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #1e293b;
    --gray-800: #0f172a;
    --bg-body: var(--gray-50);
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-sidebar: var(--gray-800);
    --text-body: var(--gray-700);
    --text-heading: var(--gray-800);
    --text-muted: var(--gray-500);
    --text-sidebar: var(--gray-300);
    --border-color: var(--gray-200);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --sidebar-width: 250px;
    --overlay-bg: rgba(0,0,0,0.5);
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #60a5fa;
    --primary-light: #1e3a5f;
    --success: #22c55e;
    --success-light: #1a3a2a;
    --warning: #fbbf24;
    --warning-light: #3a2e1a;
    --danger: #ef4444;
    --danger-light: #3a1a1a;
    --gray-50: #0f172a;
    --gray-100: #1e293b;
    --gray-200: #334155;
    --gray-300: #475569;
    --gray-400: #64748b;
    --gray-500: #94a3b8;
    --gray-600: #cbd5e1;
    --gray-700: #e2e8f0;
    --gray-800: #f1f5f9;
    --bg-body: #0b1120;
    --bg-card: #1a2332;
    --bg-input: #1a2332;
    --bg-sidebar: #0f172a;
    --text-body: #cbd5e1;
    --text-heading: #f1f5f9;
    --text-muted: #64748b;
    --text-sidebar: #94a3b8;
    --border-color: #1e293b;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.4);
    --overlay-bg: rgba(0,0,0,0.7);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-body);
    background: var(--bg-body);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.screen { display: none; }
.screen.active { display: block; }

/* Auth screens */
.auth-container {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2d1b4e 100%);
}
.auth-card {
    background: var(--bg-card); border-radius: var(--radius-lg); padding: 40px;
    width: 100%; max-width: 480px; box-shadow: var(--shadow-lg);
}
.auth-header { text-align: center; margin-bottom: 30px; }
.auth-header h1 { font-size: 1.5rem; color: var(--text-heading); margin: 10px 0 5px; }
.auth-header p { color: var(--text-muted); }
.auth-footer { text-align: center; margin-top: 20px; color: var(--text-muted); font-size: 0.9rem; }

.logo {
    width: 64px; height: 64px; background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 16px; display: inline-flex; align-items: center; justify-content: center;
    color: white; font-size: 1.8rem; font-weight: 800;
}

/* Layout principal */
#main-screen.screen.active { display: flex; height: 100vh; }

/* Sidebar */
#sidebar {
    width: var(--sidebar-width); background: var(--bg-sidebar); color: white;
    display: flex; flex-direction: column; flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 100;
}
.sidebar-header {
    display: flex; align-items: center; gap: 10px; padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.logo-small {
    width: 36px; height: 36px; background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
    color: white; font-size: 1rem; font-weight: 800; flex-shrink: 0;
}
.sidebar-title { font-size: 1.1rem; font-weight: 600; }

.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-item { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 20px;
    color: var(--text-sidebar); transition: all 0.2s; cursor: pointer; text-decoration: none; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: white; text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,0.1); color: white; border-right: 3px solid var(--primary); }
.nav-icon { font-size: 0.8rem; width: 20px; text-align: center; }

.nav-badge {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: var(--danger); color: white; font-size: 0.65rem; font-weight: 700;
    min-width: 18px; height: 18px; border-radius: 9px; display: none;
    align-items: center; justify-content: center; padding: 0 5px; line-height: 1;
}
.nav-badge.show { display: flex; }

.sidebar-footer {
    padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-footer-top {
    display: flex; align-items: center; gap: 8px;
}
.sidebar-footer .user-info { display: flex; align-items: center; gap: 10px; flex: 1; overflow: hidden; }
.sidebar-logout {
    margin-top: 10px; width: 100%; text-align: center;
}
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.75rem; color: var(--gray-400); }

/* Theme toggle & hamburger */
.theme-btn, .hamburger-btn {
    background: rgba(255,255,255,0.1); border: none; color: white;
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.1rem; flex-shrink: 0; transition: background 0.2s;
}
.theme-btn:hover, .hamburger-btn:hover { background: rgba(255,255,255,0.2); }

.hamburger-btn { display: none; }

/* Sidebar overlay mobile */
.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: var(--overlay-bg);
    z-index: 99;
}
.sidebar-overlay.open { display: block; }

/* Main content area */
#main-content { flex: 1; overflow-y: auto; padding: 30px; }
.page { display: none; }
.page.active { display: block; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; }
.page-header h2 { font-size: 1.5rem; color: var(--text-heading); }
.page-header p { color: var(--text-muted); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card {
    background: var(--bg-card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 15px;
}
.stat-icon {
    width: 48px; height: 48px; border-radius: var(--radius); display: flex;
    align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0;
}
.stat-members { background: var(--primary-light); color: var(--primary); }
.stat-contrib { background: var(--success-light); color: var(--success); }
.stat-expense { background: var(--danger-light); color: var(--danger); }
.stat-balance { background: var(--warning-light); color: var(--warning); }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--text-heading); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* Content grid */
.content-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .content-grid { grid-template-columns: 1fr; } }

/* Cards */
.card {
    background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-header { padding: 15px 20px; border-bottom: 1px solid var(--border-color); }
.card-header h3 { font-size: 1rem; color: var(--text-heading); }
.card-body { padding: 20px; }

/* Forms */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-size: 0.9rem; transition: border-color 0.2s;
    background: var(--bg-input); color: var(--text-body);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-select { max-width: 200px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border: none; border-radius: var(--radius); font-size: 0.9rem;
    font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: white; }
.btn-outline:hover { background: rgba(255,255,255,0.1); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Table */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border-color); }
.table th {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); font-weight: 600;
}
.table td { font-size: 0.9rem; }
.table tbody tr:hover { background: var(--gray-100); }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Table filter */
.table-filter {
    display: flex; gap: 10px; margin-bottom: 15px; align-items: center; flex-wrap: wrap;
}
.search-input {
    flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-size: 0.9rem; background: var(--bg-input); color: var(--text-body);
}
.search-input:focus { outline: none; border-color: var(--primary); }

/* Status badges */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 20px;
    font-size: 0.78rem; font-weight: 500;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); display: flex; align-items: center;
    justify-content: center; z-index: 1000; padding: 20px;
}
.modal {
    background: var(--bg-card); border-radius: var(--radius-lg); width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 25px; border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { font-size: 1.1rem; color: var(--text-heading); }
.modal-close {
    background: none; border: none; font-size: 1.5rem; cursor: pointer;
    color: var(--text-muted); padding: 0; line-height: 1;
}
.modal-close:hover { color: var(--text-body); }
.modal-body { padding: 25px; }
.modal-footer {
    padding: 15px 25px; border-top: 1px solid var(--border-color);
    display: flex; gap: 10px; justify-content: flex-end;
}

/* Toast */
#toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 2000;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 14px 20px; border-radius: var(--radius); color: white; font-size: 0.9rem;
    font-weight: 500; box-shadow: var(--shadow-md); animation: slideIn 0.3s ease;
    min-width: 280px; max-width: 400px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Text utilities */
.text-muted { color: var(--text-muted); font-size: 0.9rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-10 { margin-top: 10px; }
.mb-10 { margin-bottom: 10px; }

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* Report filters */
.report-filters .form-row { align-items: flex-end; }
.report-filters .form-row .form-group { margin-bottom: 0; }
#report-content .stats-grid { margin-bottom: 20px; }

/* Print styles */
@media print {
    body * { visibility: hidden; }
    #report-content, #report-content * { visibility: visible; }
    #report-content { position: absolute; left: 0; top: 0; width: 100%; }
    .sidebar-nav, .sidebar-footer, .page-actions, .report-filters, #sidebar { display: none !important; }
    #main-content { padding: 0 !important; margin: 0 !important; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .btn, .no-print { display: none !important; }
    .table th { background: #f5f5f5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge { border: 1px solid #999; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge-success { background: #dcfce7 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge-warning { background: #fef3c7 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge-danger { background: #fee2e2 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    @page { margin: 15mm; size: A4 portrait; }
    #report-content .card { margin-bottom: 10mm; }
}

/* Responsive - tablette */
@media (max-width: 768px) {
    #sidebar { position: fixed; top: 0; left: 0; height: 100vh; transform: translateX(-100%); width: 260px; }
    #sidebar.open { transform: translateX(0); }
    .hamburger-btn { display: inline-flex; }
    #main-content { padding: 15px; }
    .page-actions { gap: 6px; }
    .page-actions .btn { font-size: 0.8rem; padding: 8px 12px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .table-filter { flex-direction: column; }
    .search-input { width: 100%; }
    .form-select { max-width: 100%; }
    .stat-value { font-size: 1.1rem; }
    .stat-icon { width: 40px; height: 40px; }
    .content-grid { gap: 12px; }
}

/* Responsive - mobile */
@media (max-width: 480px) {
    #main-content { padding: 10px; }
    .stats-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-header h2 { font-size: 1.2rem; }
    .page-actions { width: 100%; }
    .page-actions .btn { flex: 1; justify-content: center; font-size: 0.75rem; padding: 8px 6px; }
    .form-row { grid-template-columns: 1fr; }
    .stat-card { padding: 14px; }
    .card-body { padding: 14px; }
    .table th, .table td { padding: 8px 10px; font-size: 0.8rem; }
}
