/* ===========================
   TATA COMPTA - GLOBAL STYLES
   =========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a3a5c;
  --primary-light: #2563a8;
  --primary-dark: #0f2540;
  --accent: #e8a020;
  --accent-light: #f5c36e;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0284c7;
  --bg: #f0f4f8;
  --bg-card: #ffffff;
  --bg-sidebar: #0f2540;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #2563a8;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --sidebar-width: 260px;
  --font: 'Inter', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: width 0.3s ease;
  z-index: 100;
}

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

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 28px; }
.logo-title { display: block; font-size: 16px; font-weight: 700; color: #fff; letter-spacing: 0.5px; }
.logo-sub { display: block; font-size: 10px; color: var(--accent-light); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-toggle {
  background: none; border: none; color: rgba(255,255,255,0.5);
  font-size: 18px; cursor: pointer; padding: 4px;
}

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.05);
  margin: 12px 12px 0;
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--primary-dark);
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.user-name { display: block; font-size: 13px; font-weight: 600; color: #fff; }
.user-role { display: block; font-size: 11px; color: rgba(255,255,255,0.5); }

.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-section-label {
  font-size: 10px; letter-spacing: 1.5px; color: rgba(255,255,255,0.3);
  padding: 16px 20px 6px; text-transform: uppercase; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; cursor: pointer; color: rgba(255,255,255,0.65);
  transition: all 0.2s; text-decoration: none; border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,0.1); color: #fff;
  border-left-color: var(--accent);
}
.nav-icon { font-size: 15px; width: 20px; text-align: center; }
.nav-label { font-size: 13px; font-weight: 500; }

.sidebar-footer {
  padding: 12px 20px;
  font-size: 11px; color: rgba(255,255,255,0.25);
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  background: var(--bg);
}

#page-container { min-height: 100vh; }

/* ===== PAGE HEADER ===== */
.page-header {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 20px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--primary); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.page-actions { display: flex; gap: 10px; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--primary); }
.card-body { padding: 20px; }

/* ===== STAT CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  flex-shrink: 0;
}
.stat-icon.blue { background: #dbeafe; }
.stat-icon.green { background: #dcfce7; }
.stat-icon.orange { background: #fef3c7; }
.stat-icon.red { background: #fee2e2; }
.stat-icon.purple { background: #ede9fe; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-trend { font-size: 11px; margin-top: 4px; font-weight: 500; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: none; transition: all 0.2s; text-decoration: none; line-height: 1;
}
.btn-primary { background: var(--primary-light); color: #fff; }
.btn-primary:hover { background: var(--primary); }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: var(--accent-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline {
  background: transparent; color: var(--primary-light);
  border: 1px solid var(--primary-light);
}
.btn-outline:hover { background: #eff6ff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-label .required { color: var(--danger); }
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text); background: #fff;
  transition: border-color 0.2s;
  font-family: var(--font);
}
.form-control:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(37,99,168,0.1); }
.form-control::placeholder { color: var(--text-light); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }

.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ===== TABLES ===== */
.table-container { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table thead tr { background: #f8fafc; }
.data-table th {
  padding: 11px 14px; text-align: left; font-weight: 600;
  color: var(--text-muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.5px; border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef3c7; color: #d97706; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-muted { background: #f1f5f9; color: #64748b; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 20px; cursor: pointer; font-size: 13px; font-weight: 500;
  color: var(--text-muted); border: none; background: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all 0.2s;
}
.tab-btn:hover { color: var(--primary-light); }
.tab-btn.active { color: var(--primary-light); border-bottom-color: var(--primary-light); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== SEARCH BAR ===== */
.search-bar {
  position: relative; display: flex; align-items: center;
}
.search-bar input {
  padding: 9px 12px 9px 36px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); font-size: 13px; width: 280px;
  background: #fff;
}
.search-bar input:focus { outline: none; border-color: var(--border-focus); }
.search-bar .search-icon {
  position: absolute; left: 10px; color: var(--text-muted); font-size: 15px;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 20px; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: #fff; border-radius: var(--radius);
  max-width: 640px; width: 100%; max-height: 90vh; overflow-y: auto;
  transform: translateY(-20px); transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1100px; }
.modal-header {
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 17px; font-weight: 700; color: var(--primary); }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--border); cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
}
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ===== ALERT ===== */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 16px; display: flex; gap: 10px;
}
.alert-info { background: #dbeafe; border-left: 4px solid #1d4ed8; color: #1e40af; }
.alert-success { background: #dcfce7; border-left: 4px solid #16a34a; color: #15803d; }
.alert-warning { background: #fef3c7; border-left: 4px solid #d97706; color: #92400e; }
.alert-danger { background: #fee2e2; border-left: 4px solid #dc2626; color: #991b1b; }

/* ===== PAGINATION ===== */
.pagination {
  display: flex; align-items: center; gap: 6px;
  padding: 16px 20px; border-top: 1px solid var(--border);
}
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 13px; color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.page-btn:hover { background: #f1f5f9; }
.page-btn.active { background: var(--primary-light); color: #fff; border-color: var(--primary-light); }
.page-info { font-size: 13px; color: var(--text-muted); margin-left: auto; }

/* ===== DASHBOARD ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}
.activities-list { display: flex; flex-direction: column; gap: 0; }
.activity-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
  width: 10px; height: 10px; border-radius: 50%;
  margin-top: 4px; flex-shrink: 0;
}
.activity-dot.blue { background: var(--primary-light); }
.activity-dot.green { background: var(--success); }
.activity-dot.orange { background: var(--accent); }
.activity-dot.red { background: var(--danger); }
.activity-text { font-size: 13px; color: var(--text); flex: 1; }
.activity-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ===== PLAN COMPTABLE ===== */
.compte-class {
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden;
}
.compte-class-header {
  background: var(--primary); color: #fff;
  padding: 12px 16px; display: flex; align-items: center;
  justify-content: space-between; cursor: pointer; font-weight: 600;
}
.compte-class-header:hover { background: var(--primary-light); }
.compte-class-body { display: none; }
.compte-class-body.open { display: block; }
.compte-row {
  display: flex; align-items: center; padding: 9px 16px;
  border-bottom: 1px solid var(--border); gap: 12px;
}
.compte-row:last-child { border-bottom: none; }
.compte-row:hover { background: #f8fafc; }
.compte-code {
  font-weight: 600; font-family: monospace; font-size: 13px;
  color: var(--primary-light); min-width: 80px;
}
.compte-intitule { flex: 1; font-size: 13px; }
.compte-type {
  font-size: 11px; padding: 2px 8px; border-radius: 4px;
  background: #f1f5f9; color: var(--text-muted);
}
.compte-level-1 { padding-left: 16px; }
.compte-level-2 { padding-left: 32px; background: #fafbfc; }
.compte-level-3 { padding-left: 48px; background: #f8f9fa; }

/* ===== PARAMETRAGE ===== */
.param-section {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); margin-bottom: 20px; overflow: hidden;
}
.param-section-header {
  padding: 14px 20px; background: #f8fafc; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.param-section-title { font-size: 14px; font-weight: 600; color: var(--primary); flex: 1; }
.param-section-body { padding: 20px; }

/* ===== SAISIE ===== */
.saisie-header {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 16px;
  display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
}
.ecriture-table-wrapper {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); overflow: hidden;
}
.ecriture-row td { padding: 8px 10px; }
.ecriture-row td input, .ecriture-row td select {
  width: 100%; border: 1px solid var(--border); border-radius: 4px;
  padding: 6px 8px; font-size: 13px; font-family: var(--font);
}
.ecriture-row td input:focus, .ecriture-row td select:focus {
  outline: none; border-color: var(--border-focus);
}
.totals-bar {
  display: flex; justify-content: flex-end; gap: 24px;
  padding: 12px 16px; background: #f8fafc; border-top: 2px solid var(--border);
  font-weight: 600; font-size: 14px;
}
.total-debit { color: var(--primary-light); }
.total-credit { color: var(--success); }
.total-balance { color: var(--danger); }
.total-balance.balanced { color: var(--success); }

/* ===== AUTOCOMPLETE ===== */
.autocomplete-wrapper { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  max-height: 200px; overflow-y: auto; z-index: 200;
  display: none;
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  display: flex; gap: 10px; align-items: center;
  border-bottom: 1px solid #f1f5f9;
}
.autocomplete-item:hover, .autocomplete-item.selected { background: #eff6ff; }
.autocomplete-item:last-child { border-bottom: none; }
.ac-code { font-weight: 600; color: var(--primary-light); font-family: monospace; min-width: 60px; }
.ac-label { color: var(--text); }

/* ===== ESPACE CLIENT ===== */
.client-portal { background: linear-gradient(135deg, #0f2540 0%, #1a3a5c 100%); min-height: 100vh; }
.portal-header { padding: 20px 28px; display: flex; align-items: center; justify-content: space-between; }
.portal-logo { color: #fff; font-size: 20px; font-weight: 700; }
.portal-content { padding: 28px; }
.upload-zone {
  border: 2px dashed rgba(255,255,255,0.3); border-radius: var(--radius);
  padding: 40px; text-align: center; cursor: pointer;
  color: rgba(255,255,255,0.7); transition: all 0.2s;
}
.upload-zone:hover { border-color: var(--accent); background: rgba(255,255,255,0.05); }
.upload-zone .upload-icon { font-size: 40px; margin-bottom: 12px; }

/* ===== PAIE ===== */
.bulletin-wrapper {
  background: #fff; padding: 32px; max-width: 800px; margin: 0 auto;
  font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius);
}
.bulletin-title { text-align: center; font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 20px; }
.bulletin-section { margin-bottom: 16px; }
.bulletin-section-title {
  font-weight: 700; padding: 8px 12px;
  background: var(--primary); color: #fff; border-radius: 4px; margin-bottom: 8px;
}
.bulletin-table { width: 100%; border-collapse: collapse; }
.bulletin-table th { background: #f1f5f9; padding: 8px 12px; text-align: left; font-size: 12px; border: 1px solid var(--border); }
.bulletin-table td { padding: 7px 12px; border: 1px solid var(--border); }
.bulletin-table .total-row { background: #fef3c7; font-weight: 700; }
.bulletin-table .net-row { background: #dcfce7; font-weight: 700; font-size: 14px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar .logo-title, .sidebar .logo-sub, .nav-label,
  .nav-section-label, .sidebar-user .user-info, .sidebar-footer { display: none; }
  .sidebar .logo-icon { margin: 0 auto; }
  .main-content { width: calc(100% - 64px); }
  .form-row.cols-2, .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== UTILS ===== */
.p-20 { padding: 20px; }
.p-24 { padding: 24px; }
.p-28 { padding: 28px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.font-mono { font-family: monospace; }
.text-primary { color: var(--primary-light); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.w-full { width: 100%; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; background: #f1f5f9; color: var(--text-muted); }
.number-field { text-align: right; font-family: monospace; font-weight: 500; }
