/* --- Global --- */
:root {
  --primary: #0b1a33;
  --accent: #2563eb;
  --bg: #f1f5f9;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --card-border: 1px solid rgba(255, 255, 255, 0.2);
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  background: var(--bg);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  padding: 10px;
  color: #0f172a;
}

/* --- Login Overlay --- */
#loginOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #0b1a33 0%, #1a3a6b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.6s ease;
}
#loginOverlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.login-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 24px;
  padding: 40px 48px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  animation: fadeUp 0.6s ease;
}
.login-card .logo {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  margin-bottom: 8px;
}
.login-card .logo span {
  color: var(--accent);
}
.login-card .subtitle {
  text-align: center;
  color: #6b7280;
  margin-bottom: 24px;
}
.login-card .form-control {
  border-radius: 12px;
  padding: 12px 16px;
  border: 2px solid #e5e7eb;
  font-size: 0.95rem;
}
.login-card .form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.login-card .btn-login {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border: none;
  transition: all 0.2s;
}
.login-card .btn-login:hover {
  background: #1d4ed8;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(37, 99, 235, 0.3);
}
.login-error {
  color: #dc2626;
  font-size: 0.85rem;
  margin-top: 8px;
  display: none;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Dashboard --- */
.container-fluid {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 6px;
}
.header {
  background: linear-gradient(135deg, #0b1a33 0%, #1a3a6b 100%);
  border-radius: var(--radius);
  padding: 12px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  border-bottom: 4px solid var(--accent);
}
.header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}
.header h1 i {
  color: var(--accent);
}
.header .badge-version {
  background: var(--accent);
  color: #fff;
  font-size: 0.5rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
  margin-left: 4px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.header-actions .btn {
  border-radius: 10px;
  padding: 5px 12px;
  font-weight: 500;
  font-size: 0.75rem;
}
.header-actions .btn-outline-light {
  border-color: rgba(255,255,255,0.4);
  color: #fff;
}
.header-actions .btn-outline-light:hover {
  background: rgba(255,255,255,0.1);
}
.header-actions .btn-primary-light {
  background: var(--accent);
  color: #fff;
  border: none;
}
.header-actions .btn-primary-light:hover {
  background: #1d4ed8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.4);
}
.header-actions .btn-danger-light {
  background: #dc2626;
  color: #fff;
  border: none;
}
.header-actions .btn-danger-light:hover {
  background: #b91c1c;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(220,38,38,0.4);
}

.period-bar {
  background: #fff;
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  border: var(--card-border);
}
.period-bar .label {
  font-size: 0.65rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.period-bar input[type="number"] {
  width: 70px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.8rem;
  background: #fff;
  color: #0f172a;
}
.period-bar input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.period-bar .btn-apply,
.period-bar .btn-today {
  font-size: 0.65rem;
  padding: 4px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.period-bar .btn-apply:hover {
  background: #1d4ed8;
  transform: translateY(-2px);
}
.period-bar .btn-today {
  background: #fff;
  color: #374151;
  border: 2px solid #e5e7eb;
}
.period-bar .btn-today:hover {
  background: #f3f4f6;
}
.period-bar .btn-today.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.period-display {
  font-size: 0.65rem;
  color: #6b7280;
  margin-left: auto;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--accent);
  transition: all 0.25s;
  cursor: default;
}
.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.08);
}
.kpi-card .label {
  font-size: 0.55rem;
  text-transform: uppercase;
  color: #6b7280;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.kpi-card .value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.kpi-card .sub {
  font-size: 0.55rem;
  color: #6b7280;
  margin-top: 2px;
}
.kpi-card.border-blue { border-color: #2563eb; }
.kpi-card.border-green { border-color: #16a34a; }
.kpi-card.border-purple { border-color: #7c3aed; }
.kpi-card.border-orange { border-color: #f59e0b; }
.kpi-card.border-red { border-color: #dc2626; }
.kpi-card.border-teal { border-color: #0d9488; }
.kpi-card.border-pink { border-color: #db2777; }
.kpi-card.border-indigo { border-color: #4f46e5; }
.kpi-card.border-amber { border-color: #d97706; }
.kpi-card.border-rose { border-color: #e11d48; }
.kpi-card.border-cyan { border-color: #0891b2; }
.kpi-card.border-gray { border-color: #6b7280; }
.kpi-card.border-sky { border-color: #0ea5e9; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  margin-top: 6px;
}
.section-title h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}
.section-title .badge-count {
  background: var(--accent);
  color: #fff;
  font-size: 0.55rem;
  padding: 3px 10px;
  border-radius: 20px;
}
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: var(--card-border);
  transition: all 0.2s;
}
.card:hover {
  box-shadow: 0 12px 40px rgba(0,0,0,0.06);
}
.card h5 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card h5 i {
  color: var(--accent);
}
.chart-wrap {
  height: 140px;
  position: relative;
}
.chart-wrap.tall {
  height: 160px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid #f1f3f5;
  font-size: 0.75rem;
}
.stat-row:last-child { border-bottom: none; }
.stat-row .label { color: #6b7280; }
.stat-row .value { font-weight: 500; color: #0f172a; }

.top-list {
  max-height: 150px;
  overflow-y: auto;
}
.top-item {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid #f1f3f5;
  font-size: 0.75rem;
}
.top-item:last-child { border-bottom: none; }
.top-item .name { font-weight: 500; color: #0f172a; }
.top-item .count { font-weight: 600; color: var(--accent); }
.loading-placeholder {
  text-align: center;
  color: #9ca3af;
  padding: 10px 0;
  font-size: 0.75rem;
}
.refresh-time {
  font-size: 0.55rem;
  color: #9ca3af;
  text-align: right;
  margin-top: 4px;
}

/* Search sections */
.search-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: var(--card-border);
}
.search-section .search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.search-section .search-row input[type="text"] {
  flex: 1;
  min-width: 160px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.search-section .search-row input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.search-section .search-row select {
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.75rem;
  background: #fff;
  color: #0f172a;
}
.search-section .search-row select:focus {
  border-color: var(--accent);
  outline: none;
}
.search-section .search-row .btn {
  padding: 5px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.75rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-outline {
  background: transparent;
  border: 2px solid #e5e7eb;
  color: #374151;
}
.btn-outline:hover { background: #f9fafb; }
.btn-sm {
  padding: 3px 10px;
  font-size: 0.65rem;
}
.btn-accent {
  background: var(--accent);
  color: #fff;
}
.btn-accent:hover {
  background: #1d4ed8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e5e7eb;
}
.results-header .count {
  font-size: 0.75rem;
  color: #6b7280;
}
.results-header .count strong { color: var(--primary); }

.table-wrap {
  max-height: 280px;
  overflow-y: auto;
  margin-top: 6px;
}
.table-wrap::-webkit-scrollbar { width: 5px; }
.table-wrap::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
}
.table-wrap th {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 5px 8px;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
  white-space: nowrap;
}
.table-wrap td {
  padding: 4px 8px;
  border-bottom: 1px solid #f1f3f5;
  vertical-align: middle;
}
.table-wrap tr:hover td { background: #f8fafc; }

.badge-status {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.55rem;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-status.bg-success-light { background: #dcfce7; color: #166534; }
.badge-status.bg-warning-light { background: #fef3c7; color: #92400e; }
.badge-status.bg-danger-light { background: #fde8e8; color: #991b1b; }
.badge-status.bg-info-light { background: #dbeafe; color: #1e40af; }
.badge-status.bg-purple-light { background: #ede9fe; color: #5b21b6; }
.badge-status.bg-secondary-light { background: #f1f5f9; color: #475569; }
.badge-status.bg-amber-light { background: #fef3c7; color: #92400e; }
.badge-status.bg-rose-light { background: #ffe4e6; color: #9f1239; }
.badge-status.bg-cyan-light { background: #cffafe; color: #0e7490; }
.badge-status.bg-gray-light { background: #f3f4f6; color: #4b5563; }

.badge-module {
  font-size: 0.5rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  background: #e5e7eb;
  color: #374151;
}
.badge-module.bg-commande { background: #dbeafe; color: #1e40af; }
.badge-module.bg-facture { background: #dcfce7; color: #166534; }
.badge-module.bg-voyage { background: #ede9fe; color: #5b21b6; }
.badge-module.bg-caisse { background: #fef3c7; color: #92400e; }
.badge-module.bg-guerite { background: #fce7f3; color: #9d174d; }

.dossier-hidden { opacity: 0.5; background: #f9fafb; }
.dossier-hidden td { color: #9ca3af; }
.dossier-hidden .badge-status { opacity: 0.5; }

.toggle-dossiers {
  font-size: 0.65rem;
  padding: 3px 12px;
  border-radius: 20px;
  border: 2px solid #e5e7eb;
  background: #fff;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-dossiers:hover { background: #f3f4f6; }
.toggle-dossiers.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.text-truncate-2 {
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: middle;
}
.badge-vehicule-status {
  font-size: 0.55rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}
.badge-vehicule-status.disponible { background: #dcfce7; color: #166534; }
.badge-vehicule-status.indisponible { background: #fef3c7; color: #92400e; }
.badge-employe-status {
  font-size: 0.55rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}
.badge-employe-status.disponible { background: #dcfce7; color: #166534; }
.badge-employe-status.mission { background: #fef3c7; color: #92400e; }
.badge-employe-status.inactif { background: #f3f4f6; color: #6b7280; }

/* Financial comparison */
.financial-comparison {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  border: 2px solid var(--accent);
}
.financial-comparison h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.financial-comparison h4 i { color: var(--accent); font-size: 1.2rem; }
.financial-comparison .fc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.financial-comparison .fc-item {
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  border-left: 4px solid var(--accent);
}
.financial-comparison .fc-item .fc-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  color: #6b7280;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.financial-comparison .fc-item .fc-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 2px;
}
.financial-comparison .fc-item .fc-sub {
  font-size: 0.55rem;
  color: #6b7280;
  margin-top: 2px;
}
.financial-comparison .fc-item.border-green { border-color: #16a34a; }
.financial-comparison .fc-item.border-red { border-color: #dc2626; }
.financial-comparison .fc-item.border-blue { border-color: #2563eb; }
.financial-comparison .fc-item.border-purple { border-color: #7c3aed; }
.financial-comparison .fc-item.border-amber { border-color: #d97706; }
.financial-comparison .fc-item.border-sky { border-color: #0ea5e9; }
.financial-comparison .fc-item.border-teal { border-color: #0d9488; }
.financial-comparison .fc-item.border-rose { border-color: #e11d48; }

/* Responsive */
@media (max-width:768px) {
  body { padding: 6px; }
  .container-fluid { padding: 0 4px; }
  .header { padding: 10px 14px; }
  .header h1 { font-size: 1.1rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-card .value { font-size: 1.1rem; }
  .period-bar { flex-direction: column; align-items: stretch; gap: 6px; }
  .search-section .search-row { flex-direction: column; align-items: stretch; }
  .search-section .search-row input[type="text"] { width: 100%; }
  .section-title h3 { font-size: 0.8rem; }
  .financial-comparison .fc-grid { grid-template-columns: 1fr 1fr; }
  .financial-comparison .fc-item .fc-value { font-size: 1rem; }
  .chart-wrap { height: 120px; }
  .chart-wrap.tall { height: 140px; }
  .card { padding: 10px 12px; }
  .table-wrap { max-height: 200px; }
  .header-actions .btn { font-size: 0.65rem; padding: 4px 10px; }
}
@media (max-width:480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .financial-comparison .fc-grid { grid-template-columns: 1fr; }
  .header-actions .btn { font-size: 0.6rem; padding: 3px 8px; }
}
@media print {
  .search-section, .period-bar { display: none; }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.kpi-card, .card, .financial-comparison {
  animation: fadeUp 0.4s ease forwards;
}
.card { transition: transform 0.2s, box-shadow 0.2s; }
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 40px rgba(0,0,0,0.08); }
.top-list .top-sub { font-size: 0.55rem; color: #6b7280; margin-top: 4px; text-align: center; }
.text-forecast { color: #f59e0b; }
.text-real { color: #16a34a; }
#loginOverlay.hidden { display: none; }
.login-card .form-label { font-weight: 500; color: #374151; }

/* Role-based visibility */
.role-pdg { display: block; }
.role-finance { display: block; }
.role-ops { display: block; }
.hidden-role { display: none !important; }
