/* ===== MODALES ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.show {
  opacity: 1;
}

.modal-overlay.hide {
  opacity: 0;
}

.modal-dialog {
  background: white;
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9) translateY(-20px);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal-dialog {
  transform: scale(1) translateY(0);
}

.modal-overlay.hide .modal-dialog {
  transform: scale(0.9) translateY(-20px);
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-title {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--gray-900);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ===== FLASH MESSAGES AMÉLIORÉS ===== */
.flash-message {
  position: relative;
  transition: all 0.3s ease;
}

.flash-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.flash-close:hover {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.1);
}

/* ===== FORMULAIRES AVANCÉS ===== */
.form-control.error {
  border-color: var(--danger-color);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.field-error {
  color: var(--danger-color);
  font-size: var(--font-size-sm);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.field-error::before {
  content: "⚠";
  font-size: 0.875rem;
}

.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-col {
  flex: 1;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* ===== TABLEAUX AVANCÉS ===== */
.table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 2rem;
}

.table th.sortable:hover {
  background-color: var(--gray-100);
}

.table th.sort-asc::after,
.table th.sort-desc::after {
  content: "";
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.table th.sort-asc::after {
  border-bottom: 6px solid var(--gray-600);
}

.table th.sort-desc::after {
  border-top: 6px solid var(--gray-600);
}

.table-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.table-actions .btn {
  padding: 0.25rem 0.5rem;
  font-size: var(--font-size-sm);
}

.table-actions form {
  display: inline;
  margin: 0;
}

/* ===== BADGES ET STATUTS ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.badge-primary {
  background-color: rgba(37, 99, 235, 0.1);
  color: var(--primary-color);
}

.badge-success {
  background-color: rgba(5, 150, 105, 0.1);
  color: var(--success-color);
}

.badge-warning {
  background-color: rgba(217, 119, 6, 0.1);
  color: var(--warning-color);
}

.badge-danger {
  background-color: rgba(220, 38, 38, 0.1);
  color: var(--danger-color);
}

.badge-secondary {
  background-color: rgba(100, 116, 139, 0.1);
  color: var(--secondary-color);
}

/* ===== LOADING STATES ===== */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid transparent;
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ===== TOOLTIPS ===== */
.tooltip {
  position: relative;
  cursor: help;
}

.tooltip::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--gray-900);
  color: white;
  padding: 0.5rem;
  border-radius: var(--border-radius);
  font-size: var(--font-size-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--gray-900);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.tooltip:hover::before,
.tooltip:hover::after {
  opacity: 1;
}

/* ===== ACCORDÉONS ===== */
.accordion {
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.accordion-item {
  border-bottom: 1px solid var(--gray-200);
}

.accordion-item:last-child {
  border-bottom: none;
}

.accordion-header {
  background: white;
  padding: 1rem 1.5rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.2s ease;
}

.accordion-header:hover {
  background-color: var(--gray-50);
}

.accordion-content {
  padding: 0 1.5rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.accordion-item.active .accordion-content {
  padding: 1.5rem;
  max-height: 500px;
}

.accordion-icon {
  transition: transform 0.3s ease;
}

.accordion-item.active .accordion-icon {
  transform: rotate(180deg);
}

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  margin: 2rem 0;
}

.pagination a,
.pagination span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius);
  text-decoration: none;
  color: var(--gray-700);
  transition: all 0.2s ease;
}

.pagination a:hover {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.pagination .current {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* ===== BREADCRUMBS ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0.75rem 0;
  color: var(--gray-500);
  font-size: var(--font-size-sm);
}

.breadcrumb a {
  color: var(--primary-color);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb-divider {
  color: var(--gray-400);
}

/* ===== STATUTS DE PERMISSIONS ===== */
.permission-owner {
  color: var(--success-color);
  font-weight: 600;
}

.permission-write {
  color: var(--warning-color);
  font-weight: 500;
}

.permission-read {
  color: var(--primary-color);
}

.permission-none {
  color: var(--gray-400);
}

/* ===== RESPONSIVE AMÉLIORÉ ===== */
@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .form-actions {
    flex-direction: column;
  }
  
  .table-actions {
    flex-direction: column;
    gap: 0.25rem;
  }
  
  .modal-dialog {
    width: 95%;
    margin: 1rem;
  }
  
  .modal-footer {
    flex-direction: column;
  }
  
  .permissions-matrix {
    font-size: var(--font-size-sm);
  }
}

/* ===== DARK MODE (optionnel) ===== */
.theme-dark,
.theme-dark :root,
.theme-dark body {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --success-color: #059669;
  --warning-color: #d97706;
  --danger-color: #dc2626;
  --dark-color: #f8fafc;

  /* TRUE DARK palette */
  --light-color: #0f172a;
  --gray-50: #0f172a;
  --gray-100: #1e293b;
  --gray-200: #334155;
  --gray-300: #475569;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #94a3b8;
  --gray-700: #cbd5e1;
  --gray-800: #f1f5f9;
  --gray-900: #ffffff;
}

.theme-dark body {
  background-color: var(--gray-50) !important;
  color: var(--gray-800) !important;
}

/* Exemple de surcharge "dark" pour d'autres composants */
.theme-dark .card,
.theme-dark .table-container,
.theme-dark .modal-dialog {
  background-color: var(--gray-100) !important;
  border: 1px solid var(--gray-300) !important;
  color: var(--gray-900) !important;
}

.theme-dark .form-control {
  background-color: var(--gray-100) !important;
  border-color: var(--gray-300) !important;
  color: var(--gray-900) !important;
}

.theme-dark .card-header,
.theme-dark .card-footer {
  background: var(--gray-50) !important;
  color: var(--gray-800) !important;
}

.theme-dark .navbar,
.theme-dark .login-container {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%) !important;
}

.theme-dark .nav-link {
  color: var(--gray-200) !important;
}

.theme-dark .nav-link:hover {
  background-color: rgba(255,255,255,0.08) !important;
  color: white !important;
}

.theme-dark .flash-message.success {
  background-color: #063720 !important;
  color: #34d399 !important;
  border-left-color: var(--success-color) !important;
}
.theme-dark .flash-message.danger {
  background-color: #4b1e1e !important;
  color: #f87171 !important;
  border-left-color: var(--danger-color) !important;
}
.theme-dark .flash-message.warning {
  background-color: #4b3b1e !important;
  color: #fbbf24 !important;
  border-left-color: var(--warning-color) !important;
}
.theme-dark .flash-message.info {
  background-color: #1e293b !important;
  color: #60a5fa !important;
  border-left-color: var(--primary-color) !important;
}

.theme-dark .nav-link,
.theme-dark .navbar-nav .nav-link,
.theme-dark a,
.theme-dark .nav-link:visited {
  color: #e0e7ff !important;  /* bleu très pâle, très lisible */
  text-shadow: 0 1px 2px rgba(10,16,24,0.24);
}

.theme-dark .nav-link.active,
.theme-dark .nav-link:hover {
  color: #fbbf24 !important; /* jaune clair pour hover/actif */
  background-color: rgba(255, 255, 255, 0.06) !important;
}

.theme-dark .navbar-brand {
  color: #f1f5fa !important;
  text-shadow: 0 1px 2px rgba(10,16,24,0.26);
}

.theme-dark .nav-divider {
  color: #334155 !important;  /* gris bleuté doux pour séparateur */
}

.theme-dark a:visited {
  color: #c7d2fe !important;
}

.theme-dark .text-muted,
.theme-dark .text-small {
  color: #a5b4fc !important;  /* un bleu/violet pâle lisible sur fond foncé */
}


/* ===== MODAL ANIMATION ENHANCED ===== */
.modal-dialog {
  transition: box-shadow 0.25s, transform 0.22s cubic-bezier(.55,1.25,.64,.95);
}
.modal-overlay.show .modal-dialog {
  animation: fadeInDown 0.4s cubic-bezier(.51,1.13,.71,.93);
}

/* ===== ACCORDION ENHANCED ===== */
.accordion-header:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}
.accordion-item.active .accordion-header {
  background: linear-gradient(94deg, #e0e7ff 0%, #f1f5ff 100%);
}

/* ===== FOCUS FORMS ===== */
.form-control:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* ===== PAGINATION ===== */
.pagination a:focus {
  outline: 2px solid var(--primary-color);
}

/* ===== TOOLTIP FOR ICON BUTTONS ===== */
[aria-label][role="button"] {
  position: relative;
}
[aria-label][role="button"]:hover::after, [aria-label][role="button"]:focus::after {
  content: attr(aria-label);
  position: absolute;
  left: 50%; bottom: 120%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: white;
  border-radius: var(--border-radius);
  padding: 0.5em 0.9em;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  pointer-events: none;
  z-index: 1100;
  opacity: 1;
}

/* -------- Vaulty Dashboard Cards -------- */
.card {
  border: 1.5px solid var(--gray-200);
  box-shadow: 0 3px 16px 0 rgba(36,42,52,0.10);
  transition: box-shadow 0.22s, border-color 0.19s, background 0.19s;
  background: var(--gray-100);
  position: relative;
}
.theme-dark .card {
  border: 1.5px solid var(--gray-700);
  background: linear-gradient(130deg, #21273b 60%, #1b2232 100%);
  box-shadow: 0 4px 32px 0 rgba(6,8,30,0.27);
}

.card-header {
  background: linear-gradient(91deg, var(--primary-color) 7%, transparent 90%);
  color: var(--gray-900);
  padding: 1.2rem 1.5rem;
  border-bottom: 1.5px solid var(--gray-200);
  display: flex;
  align-items: center;
  font-size: 1.12em;
  font-weight: 600;
}
.theme-dark .card-header {
  background: linear-gradient(91deg, #293266 7%, transparent 90%);
  color: #e0e7ff;
  border-bottom: 1.5px solid #232a41;
  box-shadow: 0 1px 0 0 #202846;
}

.card-body {
  padding: 1.5rem 1.3rem 1.2rem 1.3rem;
  color: var(--gray-800);
  background: transparent;
}
.theme-dark .card-body {
  color: #bcd2fc;
}

.card .badge,
.card .btn {
  margin-bottom: 0.2rem;
}

.card .btn-outline {
  background: transparent;
  border: 1.5px dashed var(--primary-color);
  color: var(--primary-color);
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: all 0.17s;
}
.card .btn-outline:hover {
  background: var(--primary-color);
  color: #fff;
  border-style: solid;
}

.theme-dark .btn-outline {
  border-color: #6366f1;
  color: #a5b4fc;
}
.theme-dark .btn-outline:hover {
  background: #4347aa;
  color: #fff;
  border-color: #818cf8;
}

/* Quick-actions vaulty dashboard */
.quick-actions a {
  background: var(--gray-50);
  font-size: 1.04em;
  border-left: 3.5px solid var(--primary-color);
  border-radius: 0.6em;
  margin-bottom: 0.7em;
  box-shadow: 0 1.5px 10px 0 rgba(60,62,80,0.08);
  padding: 0.7em 1em;
  color: var(--gray-700);
  transition: all 0.18s;
}
.quick-actions a:hover {
  background: linear-gradient(92deg, #dbeafe 0%, #f1f5ff 100%);
  color: var(--primary-color);
  border-color: var(--primary-hover);
}
.theme-dark .quick-actions a {
  background: #1b2232;
  color: #bcd2fc;
  border-color: #6366f1;
  box-shadow: 0 2px 10px 0 rgba(32,32,46,0.19);
}
.theme-dark .quick-actions a:hover {
  background: linear-gradient(90deg, #232b42 60%, #232b3c 100%);
  color: #fff;
  border-color: #a5b4fc;
}

/* Titres d’encart */
.card-header h3, .card-header h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.theme-dark .text-muted,
.theme-dark small,
.theme-dark .text-small {
  color: #90a3cc !important;
}
.theme-dark .dashboard-grid strong {
  color: #f9fafc !important;
}
.theme-dark .dashboard-grid .badge {
  filter: brightness(1.12) saturate(1.3);
}

.dashboard-grid {
  gap: 2.2rem;
}
@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1.2rem;
  }
}
