/* =====================================================
   AlgoVisualizer V2 - Feuilles de Styles Globales
===================================================== */

:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --bg-main: #f8fafc;
  --bg-header: #0f172a;
  --bg-sidebar: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --text-color: #334155;
  --text-heading: #0f172a;
  --border-color: #cbd5e1;
  --card-bg: #ffffff;
  --code-bg: #0f172a;
  --code-text: #f8fafc;
  --table-header-bg: #f1f5f9;
  --success: #16a34a;
  --warning: #eab308;
}

/* Thème Sombre */
[data-theme="dark"] {
  --bg-main: #0f172a;
  --bg-header: #020617;
  --bg-sidebar: #020617;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --text-color: #f8fafc;
  --text-heading: #38bdf8;
  --border-color: #334155;
  --card-bg: #1e293b;
  --code-bg: #020617;
  --code-text: #38bdf8;
  --table-header-bg: #334155;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s, color 0.3s;
}

/* -----------------------------------------------------
  1. En-tête (Header)
----------------------------------------------------- */
.main-header {
  background: var(--bg-header);
  color: #fff;
  padding: 1rem 2rem;
  border-bottom: 3px solid var(--primary);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-container h1 {
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.subtitle {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-top: 4px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-theme {
  background: transparent;
  color: #fff;
  border: 1px solid #334155;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-theme:hover {
  background-color: var(--primary);
  border-color: var(--primary);
}

.btn-mobile-menu {
  display: none;
  background: transparent;
  color: #fff;
  border: 1px solid #334155;
  font-size: 1.4rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

/* -----------------------------------------------------
  2. Disposition Principale (App Layout)
----------------------------------------------------- */
.app-layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 130px);
}

/* -----------------------------------------------------
  3. Menu Latéral (Sidebar)
----------------------------------------------------- */
.sidebar {
  width: 280px;
  background-color: var(--bg-sidebar);
  color: #fff;
  flex-shrink: 0;
  padding: 1.5rem 0;
  border-right: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

#sidebar-menu ul, 
.nav-list, 
.submenu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  margin-bottom: 2px;
}

.nav-link, 
.submenu-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.nav-link:hover, 
.submenu-toggle:hover {
  background-color: var(--sidebar-hover);
  color: #f8fafc;
}

.nav-link.active {
  background-color: var(--primary);
  color: #ffffff !important;
  font-weight: 600;
}

.chevron {
  margin-left: auto;
  font-size: 0.7rem;
  transition: transform 0.3s ease;
}

.has-submenu.open .chevron {
  transform: rotate(180deg);
}

/* Sous-menu */
.submenu {
  display: none;
  background-color: rgba(0, 0, 0, 0.2);
}

.has-submenu.open .submenu {
  display: block;
}

.submenu .nav-link {
  padding-left: 48px;
  font-size: 0.88rem;
}

/* -----------------------------------------------------
  4. Zone de Contenu Principal (Main Content)
----------------------------------------------------- */
.main-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

/* Panneaux / Cartes */
.panel {
  background-color: var(--card-bg);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.panel h1, .panel h2, .panel h3 {
  color: var(--text-heading);
  margin-bottom: 0.75rem;
}

/* Grilles de disposition */
.workspace-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
}

.code-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* -----------------------------------------------------
  5. Boutons, Formulaires & Contrôles
----------------------------------------------------- */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-secondary {
  background-color: #e2e8f0;
  color: #334155;
}

.btn:hover {
  opacity: 0.9;
}

/* -----------------------------------------------------
  6. Code & Tableaux
----------------------------------------------------- */
pre {
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
}

.tableau {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.tableau th, .tableau td {
  border: 1px solid var(--border-color);
  padding: 10px;
  text-align: center;
}

.tableau th {
  background-color: var(--table-header-bg);
  color: var(--text-heading);
}

/* -----------------------------------------------------
  7. Pied de Page (Footer)
----------------------------------------------------- */
.main-footer {
  background-color: var(--bg-header);
  color: #64748b;
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
}

/* -----------------------------------------------------
  8. Zone de Recherche (Search Box)
----------------------------------------------------- */
.search-box {
  position: relative;
  width: 280px;
}

.search-box input {
  width: 100%;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid #334155;
  background-color: var(--card-bg);
  color: var(--text-color);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
}

.search-results-dropdown {
  position: absolute;
  top: 110%;
  left: 0;
  right: 0;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

.search-results-dropdown div {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-color);
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.2s;
}

.search-results-dropdown div:last-child {
  border-bottom: none;
}

.search-results-dropdown div:hover {
  background-color: var(--primary);
  color: #ffffff;
}

/* -----------------------------------------------------
  9. Section Contact
----------------------------------------------------- */
.contact-section {
  background-color: var(--card-bg);
  border-top: 1px solid var(--border-color);
  padding: 2rem;
  transition: background-color 0.3s;
}

.contact-container {
  max-width: 800px;
  margin: 0 auto;
}

.contact-section h2 {
  color: var(--text-heading);
  margin-bottom: 0.5rem;
  font-size: 1.4rem;
}

.contact-desc {
  color: var(--sidebar-text);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.contact-form .form-group {
  margin-bottom: 1.2rem;
}

.contact-form label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-color);
}

.contact-form input, 
.contact-form textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-main);
  color: var(--text-color);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.contact-form input:focus, 
.contact-form textarea:focus {
  border-color: var(--primary);
}

.contact-form button[type="submit"] {
  margin-top: 0.5rem;
}

/* -----------------------------------------------------
  10. Responsive Design (Smartphones et Tablettes)
----------------------------------------------------- */
@media (max-width: 992px) {
  /* Passer le conteneur principal en disposition verticale */
  .workspace-grid,
  .main-content {
     display: flex !important;
     flex-direction: column !important;
  }

  /* Définir l'ordre d'affichage explicite des panneaux */
  
  /* 1. Zone du Visualiseur / Simulation en 1er */
  .simulation-zone,
  #simulation-container,
  .panel:has(#visualizer),
  .panel:has(.array-container) {
     order: 1 !important;
     width: 100% !important;
  }

  /* 2. Zone Variables / Statistiques directement en 2ème */
  .variables-zone,
  #variables-container,
  .stats-zone,
  .panel:has(#variables),
  .panel:has(h3:contains("Variables")),
  .panel:has(h3:contains("Statistiques")) {
     order: 2 !important;
     width: 100% !important;
  }

  /* 3. Bloc Exemple d'exécution / Trace repoussé en 3ème position */
  .exemple-zone,
  .trace-zone,
  #exemple-container,
  .panel:has(h3:contains("Exemple")) {
     order: 3 !important;
     width: 100% !important;
  }

  /* 4. Tout autre panneau s'affiche après */
  .workspace-grid > .panel,
  .main-content > .panel {
     order: 4;
  }

  .code-grid {
     display: flex !important;
     flex-direction: column !important;
  }
}

@media (max-width: 768px) {
  .main-header {
     flex-wrap: wrap;
     gap: 10px;
     padding: 0.8rem 1rem;
  }

  .logo-container h1 {
     font-size: 1.2rem;
  }

  .search-box {
     order: 3;
     width: 100%;
  }

  .btn-mobile-menu {
     display: block;
  }

  .app-layout {
     flex-direction: column;
  }

  .sidebar {
     width: 100%;
     display: none;
     border-right: none;
     border-bottom: 1px solid var(--border-color);
  }

  .sidebar.mobile-open {
     display: block;
  }

  .main-content {
     padding: 1rem;
  }
}