/* =============================================
   TADAL-CRM - Design System (PHP Pure)
   ============================================= */
:root {
  --primary: #1a56db;
  --primary-dark: #1544b5;
  --primary-light: #e8effc;
  --secondary: #6366f1;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --info-light: #cffafe;
  --gray-50: #f9fafb; --gray-100: #f3f4f6; --gray-200: #e5e7eb;
  --gray-300: #d1d5db; --gray-400: #9ca3af; --gray-500: #6b7280;
  --gray-600: #4b5563; --gray-700: #374151; --gray-800: #1f2937; --gray-900: #111827;
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px -1px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --transition: all 0.2s ease;
}
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family:'Inter',-apple-system,BlinkMacSystemFont,sans-serif; background:var(--gray-50); color:var(--gray-800); line-height:1.6; -webkit-font-smoothing:antialiased; }
a { color: var(--primary); text-decoration: none; }

/* Layout */
.app-layout { display:flex; min-height:100vh; }
.sidebar { width:var(--sidebar-width); background:linear-gradient(180deg,var(--gray-900) 0%,var(--gray-800) 100%); color:white; position:fixed; top:0; left:0; bottom:0; z-index:50; display:flex; flex-direction:column; overflow-y:auto; }
.sidebar-logo { padding:20px 24px; border-bottom:1px solid rgba(255,255,255,0.08); display:flex; align-items:center; gap:12px; }
.sidebar-logo .logo-icon { width:40px; height:40px; background:var(--primary); border-radius:var(--radius); display:flex; align-items:center; justify-content:center; font-weight:800; font-size:18px; }
.sidebar-logo h1 { font-size:20px; font-weight:700; letter-spacing:-0.5px; }
.sidebar-logo span { font-size:11px; color:var(--gray-400); display:block; margin-top:2px; }
.sidebar-nav { flex:1; padding:16px 12px; }
.sidebar-section { margin-bottom:24px; }
.sidebar-section-title { font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:0.05em; color:var(--gray-400); padding:0 12px; margin-bottom:8px; }
.sidebar-link { display:flex; align-items:center; gap:12px; padding:10px 12px; color:var(--gray-300); text-decoration:none; border-radius:var(--radius); font-size:14px; font-weight:500; transition:var(--transition); margin-bottom:2px; }
.sidebar-link:hover { background:rgba(255,255,255,0.08); color:white; }
.sidebar-link.active { background:var(--primary); color:white; }
.sidebar-link svg { width:20px; height:20px; flex-shrink:0; }
.sidebar-user { padding:16px; border-top:1px solid rgba(255,255,255,0.08); display:flex; align-items:center; gap:12px; }
.sidebar-user-avatar { width:36px; height:36px; border-radius:50%; background:var(--primary); display:flex; align-items:center; justify-content:center; font-weight:600; font-size:14px; }
.sidebar-user-info .name { font-size:13px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sidebar-user-info .role { font-size:11px; color:var(--gray-400); }
.main-content { flex:1; margin-left:var(--sidebar-width); min-height:100vh; }

/* Header */
.header { height:var(--header-height); background:white; border-bottom:1px solid var(--gray-200); display:flex; align-items:center; justify-content:space-between; padding:0 32px; position:sticky; top:0; z-index:40; }
.header-right { display:flex; align-items:center; gap:8px; }
.mobile-menu-btn { display:none; }

/* Page */
.page-content { padding:32px; }
.page-header { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:32px; gap:16px; flex-wrap:wrap; }
.page-header h1 { font-size:28px; font-weight:800; color:var(--gray-900); letter-spacing:-0.5px; }
.page-header p { font-size:14px; color:var(--gray-500); margin-top:4px; }
.page-actions { display:flex; gap:8px; flex-shrink:0; }

/* Alert / Flash */
.alert { padding:14px 20px; border-radius:var(--radius); margin-bottom:20px; display:flex; align-items:center; justify-content:space-between; font-size:14px; font-weight:500; animation:slideDown 0.3s ease; }
@keyframes slideDown { from { opacity:0; transform:translateY(-10px); } to { opacity:1; transform:translateY(0); } }
.alert-success { background:var(--success-light); color:#065f46; border:1px solid #a7f3d0; }
.alert-error { background:var(--danger-light); color:#991b1b; border:1px solid #fca5a5; }
.alert-warning { background:var(--warning-light); color:#92400e; border:1px solid #fcd34d; }
.alert-info { background:var(--info-light); color:#155e75; border:1px solid #67e8f9; }
.alert-close { background:none; border:none; font-size:20px; cursor:pointer; color:inherit; opacity:0.7; padding:0 4px; }

/* Cards */
.card { background:white; border-radius:var(--radius-lg); border:1px solid var(--gray-200); box-shadow:var(--shadow-sm); margin-bottom:24px; }
.card-header { padding:20px 24px; border-bottom:1px solid var(--gray-100); display:flex; align-items:center; justify-content:space-between; }
.card-header h2 { font-size:16px; font-weight:600; color:var(--gray-900); }
.card-body { padding:24px; }

/* Stat Cards */
.stats-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); gap:20px; margin-bottom:32px; }
.stat-card { background:white; border-radius:var(--radius-lg); border:1px solid var(--gray-200); padding:24px; display:flex; align-items:flex-start; gap:16px; transition:var(--transition); text-decoration:none; color:inherit; }
.stat-card:hover { box-shadow:var(--shadow-md); transform:translateY(-2px); }
.stat-icon { width:48px; height:48px; border-radius:var(--radius); display:flex; align-items:center; justify-content:center; font-size:22px; flex-shrink:0; }
.stat-icon.blue { background:var(--primary-light); color:var(--primary); }
.stat-icon.green { background:var(--success-light); color:var(--success); }
.stat-icon.yellow { background:var(--warning-light); color:var(--warning); }
.stat-icon.red { background:var(--danger-light); color:var(--danger); }
.stat-icon.cyan { background:var(--info-light); color:var(--info); }
.stat-icon.purple { background:#ede9fe; color:#7c3aed; }
.stat-info h3 { font-size:28px; font-weight:800; color:var(--gray-900); line-height:1; }
.stat-info p { font-size:13px; color:var(--gray-500); margin-top:4px; }

/* Buttons */
.btn { display:inline-flex; align-items:center; gap:8px; padding:10px 20px; border:none; border-radius:var(--radius); font-size:14px; font-weight:600; cursor:pointer; transition:var(--transition); text-decoration:none; white-space:nowrap; font-family:inherit; }
.btn:disabled { opacity:0.6; cursor:not-allowed; }
.btn-primary { background:var(--primary); color:white; }
.btn-primary:hover:not(:disabled) { background:var(--primary-dark); }
.btn-secondary { background:var(--gray-100); color:var(--gray-700); border:1px solid var(--gray-200); }
.btn-secondary:hover:not(:disabled) { background:var(--gray-200); }
.btn-success { background:var(--success); color:white; }
.btn-success:hover:not(:disabled) { background:#047857; }
.btn-danger { background:var(--danger); color:white; }
.btn-danger:hover:not(:disabled) { background:#b91c1c; }
.btn-warning { background:var(--warning); color:white; }
.btn-sm { padding:6px 12px; font-size:12px; }
.btn-lg { padding:12px 28px; font-size:16px; }
.btn-icon { width:36px; height:36px; padding:0; display:flex; align-items:center; justify-content:center; border-radius:var(--radius); }
.action-btns { display:flex; gap:4px; }

/* Forms */
.form-group { margin-bottom:20px; }
.form-label { display:block; font-size:13px; font-weight:600; color:var(--gray-700); margin-bottom:6px; }
.form-input, .form-select, .form-textarea { width:100%; padding:10px 14px; border:1px solid var(--gray-300); border-radius:var(--radius); font-size:14px; font-family:inherit; color:var(--gray-800); background:white; transition:var(--transition); }
.form-input:focus, .form-select:focus, .form-textarea:focus { outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(26,86,219,0.15); }
.form-textarea { min-height:100px; resize:vertical; }
.form-row { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.form-row-3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:16px; }

/* Tables */
.table-container { overflow-x:auto; }
table { width:100%; border-collapse:collapse; }
table th { background:var(--gray-50); padding:12px 16px; text-align:left; font-size:12px; font-weight:600; color:var(--gray-500); text-transform:uppercase; letter-spacing:0.05em; border-bottom:1px solid var(--gray-200); white-space:nowrap; }
table td { padding:14px 16px; border-bottom:1px solid var(--gray-100); font-size:14px; color:var(--gray-700); }
table tr:hover { background:var(--gray-50); }
table tr:last-child td { border-bottom:none; }
td.truncate { max-width:250px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* Badges */
.badge { display:inline-flex; align-items:center; padding:3px 10px; border-radius:20px; font-size:12px; font-weight:600; white-space:nowrap; }
.badge-nouveau { background:#dbeafe; color:#1d4ed8; }
.badge-en_cours { background:#fef3c7; color:#92400e; }
.badge-en_attente { background:#fed7aa; color:#9a3412; }
.badge-resolu { background:#d1fae5; color:#065f46; }
.badge-ferme { background:var(--gray-200); color:var(--gray-600); }
.badge-rejete { background:#fee2e2; color:#991b1b; }
.badge-basse { background:#d1fae5; color:#065f46; }
.badge-moyenne { background:#dbeafe; color:#1d4ed8; }
.badge-haute { background:#fef3c7; color:#92400e; }
.badge-urgente { background:#fee2e2; color:#991b1b; }
.badge-admin { background:#ede9fe; color:#5b21b6; }
.badge-superviseur { background:#dbeafe; color:#1d4ed8; }
.badge-agent { background:var(--gray-200); color:var(--gray-600); }
.badge-client { background:#dbeafe; color:#1d4ed8; }
.badge-fournisseur { background:#fce7f3; color:#9d174d; }
.badge-article { background:#fef3c7; color:#92400e; }
.badge-interne { background:#ede9fe; color:#5b21b6; }
.badge-autre { background:var(--gray-200); color:var(--gray-600); }
.badge-actif { background:#d1fae5; color:#065f46; }
.badge-inactif { background:#fee2e2; color:#991b1b; }

/* Modal */
.modal-overlay { position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); backdrop-filter:blur(4px); display:none; align-items:center; justify-content:center; z-index:100; padding:20px; }
.modal-overlay.active { display:flex; }
.modal { background:white; border-radius:var(--radius-lg); box-shadow:var(--shadow-lg); width:100%; max-width:640px; max-height:90vh; overflow-y:auto; animation:modalIn 0.2s ease; }
@keyframes modalIn { from { opacity:0; transform:scale(0.95); } to { opacity:1; transform:scale(1); } }
.modal-lg { max-width:900px; }
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:20px 24px; border-bottom:1px solid var(--gray-200); }
.modal-header h2 { font-size:18px; font-weight:700; color:var(--gray-900); }
.modal-close { width:32px; height:32px; border:none; background:var(--gray-100); border-radius:var(--radius); cursor:pointer; display:flex; align-items:center; justify-content:center; font-size:18px; color:var(--gray-500); transition:var(--transition); }
.modal-close:hover { background:var(--gray-200); color:var(--gray-800); }
.modal-body { padding:24px; }
.modal-footer { padding:16px 24px; border-top:1px solid var(--gray-200); display:flex; justify-content:flex-end; gap:12px; }

/* Search & Filters */
.toolbar { display:flex; align-items:center; gap:12px; margin-bottom:24px; flex-wrap:wrap; }
.search-box { flex:1; min-width:250px; position:relative; }
.search-box input { width:100%; padding:10px 14px 10px 40px; border:1px solid var(--gray-300); border-radius:var(--radius); font-size:14px; font-family:inherit; transition:var(--transition); }
.search-box input:focus { outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(26,86,219,0.15); }
.search-box svg { position:absolute; left:12px; top:50%; transform:translateY(-50%); color:var(--gray-400); }
.filter-select { padding:10px 14px; border:1px solid var(--gray-300); border-radius:var(--radius); font-size:14px; font-family:inherit; color:var(--gray-600); background:white; cursor:pointer; min-width:150px; }

/* Login */
.login-page { min-height:100vh; display:flex; align-items:center; justify-content:center; background:linear-gradient(135deg,#1a1a2e 0%,#16213e 50%,#0f3460 100%); padding:20px; }
.login-card { background:white; border-radius:var(--radius-lg); box-shadow:var(--shadow-lg); width:100%; max-width:440px; padding:48px; }
.login-logo { text-align:center; margin-bottom:40px; }
.login-logo .logo-icon { width:64px; height:64px; background:var(--primary); border-radius:16px; display:inline-flex; align-items:center; justify-content:center; color:white; font-size:28px; font-weight:800; margin-bottom:16px; }
.login-logo h1 { font-size:28px; font-weight:800; color:var(--gray-900); letter-spacing:-1px; }
.login-logo p { color:var(--gray-500); font-size:14px; margin-top:4px; }
.login-form .btn { width:100%; justify-content:center; padding:12px; font-size:15px; }
.login-error { background:var(--danger-light); color:var(--danger); padding:12px 16px; border-radius:var(--radius); font-size:13px; margin-bottom:20px; border:1px solid #fca5a5; }

/* Detail page */
.detail-grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-bottom:24px; }
.detail-item { padding:16px; background:var(--gray-50); border-radius:var(--radius); }
.detail-item label { font-size:12px; font-weight:600; color:var(--gray-500); text-transform:uppercase; letter-spacing:0.05em; display:block; }
.detail-item p { margin-top:4px; font-size:14px; color:var(--gray-800); font-weight:500; }
.detail-item.success { background:var(--success-light); }
.detail-item.full { grid-column:1/-1; }

/* Timeline */
.timeline { position:relative; padding-left:32px; }
.timeline::before { content:''; position:absolute; left:12px; top:0; bottom:0; width:2px; background:var(--gray-200); }
.timeline-item { position:relative; margin-bottom:24px; padding:16px 20px; background:white; border:1px solid var(--gray-200); border-radius:var(--radius); }
.timeline-item::before { content:''; position:absolute; left:-26px; top:20px; width:12px; height:12px; border-radius:50%; background:var(--primary); border:2px solid white; box-shadow:var(--shadow); }
.timeline-item .time { font-size:12px; color:var(--gray-400); }
.timeline-item .action-title { font-weight:600; color:var(--gray-800); margin-top:4px; }
.timeline-item .commentaire { color:var(--gray-600); font-size:14px; margin-top:8px; line-height:1.6; }
.timeline-item .agent { font-size:12px; color:var(--gray-500); margin-top:8px; }
.timeline-header { display:flex; justify-content:space-between; align-items:flex-start; }

/* Tabs */
.tabs { display:flex; border-bottom:2px solid var(--gray-200); margin-bottom:24px; }
.tab { padding:12px 20px; font-size:14px; font-weight:600; color:var(--gray-500); text-decoration:none; border-bottom:2px solid transparent; margin-bottom:-2px; transition:var(--transition); }
.tab:hover { color:var(--gray-700); }
.tab.active { color:var(--primary); border-bottom-color:var(--primary); }

/* File items */
.file-list { display:flex; flex-direction:column; gap:8px; margin-top:12px; }
.file-item { display:flex; align-items:center; gap:12px; padding:10px 14px; background:var(--gray-50); border-radius:var(--radius); border:1px solid var(--gray-200); text-decoration:none; color:inherit; transition:var(--transition); }
.file-item:hover { background:var(--gray-100); }
.file-icon { width:36px; height:36px; border-radius:var(--radius); display:flex; align-items:center; justify-content:center; background:var(--primary-light); color:var(--primary); flex-shrink:0; }
.file-info { flex:1; min-width:0; }
.file-name { font-size:13px; font-weight:600; color:var(--gray-800); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.file-size { font-size:11px; color:var(--gray-400); }

/* File upload */
.file-upload-zone { border:2px dashed var(--gray-300); border-radius:var(--radius); padding:32px; text-align:center; cursor:pointer; transition:var(--transition); background:var(--gray-50); }
.file-upload-zone:hover { border-color:var(--primary); background:var(--primary-light); }

/* Empty state */
.empty-state { text-align:center; padding:60px 20px; color:var(--gray-400); }
.empty-state h3 { font-size:18px; font-weight:600; color:var(--gray-600); margin-top:12px; margin-bottom:8px; }

/* Pagination */
.pagination { display:flex; align-items:center; justify-content:center; gap:4px; padding:20px; }
.pagination a, .pagination span { padding:8px 14px; border:1px solid var(--gray-300); border-radius:var(--radius); background:white; text-decoration:none; font-size:13px; font-weight:500; color:var(--gray-600); transition:var(--transition); }
.pagination a:hover { background:var(--gray-100); }
.pagination .active { background:var(--primary); color:white; border-color:var(--primary); }
.pagination .disabled { opacity:0.5; pointer-events:none; }

/* Charts placeholder */
.chart-placeholder { height:200px; background:var(--gray-50); border-radius:var(--radius); display:flex; align-items:center; justify-content:center; color:var(--gray-400); }

/* Progress bars for stats */
.progress-bar { height:8px; background:var(--gray-200); border-radius:4px; overflow:hidden; margin-top:8px; }
.progress-bar .fill { height:100%; border-radius:4px; transition: width 0.5s ease; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform:translateX(-100%); transition:transform 0.3s ease; }
  .sidebar.open { transform:translateX(0); }
  .main-content { margin-left:0; }
  .page-content { padding:20px; }
  .mobile-menu-btn { display:flex !important; }
  .form-row, .form-row-3, .detail-grid { grid-template-columns:1fr; }
  .stats-grid { grid-template-columns:1fr 1fr; }
  .page-header { flex-direction:column; }
}

/* Scrollbar */
::-webkit-scrollbar { width:6px; height:6px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:var(--gray-300); border-radius:3px; }
::-webkit-scrollbar-thumb:hover { background:var(--gray-400); }
