/* =====================================================
   AlgorithmeFacile V2 - Feuilles de Styles Globales (Optimisé)
===================================================== */

: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: #e2e8f0;
  --card-bg: #ffffff;
  --code-bg: #0b0f19;
  --code-text: #38bdf8;
  --table-header-bg: #f8fafc;
  --table-stripe-bg: #f8fafc;
  --success: #16a34a;
  --warning: #eab308;
}

/* Thème Sombre */
[data-theme="dark"] {
  --bg-main: #090d16;
  --bg-header: #020617;
  --bg-sidebar: #020617;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --text-color: #cbd5e1;
  --text-heading: #f8fafc;
  --border-color: #1e293b;
  --card-bg: #0f172a;
  --code-bg: #020617;
  --code-text: #38bdf8;
  --table-header-bg: #1e293b;
  --table-stripe-bg: #131c2e;
}

* {
  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 ease, color 0.3s ease;
}

/* -----------------------------------------------------
  1. En-tête (Header) & Menus Déroulants
----------------------------------------------------- */
.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;
  gap: 15px;
  flex-wrap: wrap;
}

.logo-container h1 {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.82rem;
  color: #94a3b8;
  margin-top: 2px;
}

/* Navigation Déroulante du Header */
.header-nav {
  display: flex;
  align-items: center;
}

.header-nav-list {
  display: flex;
  list-style: none;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.header-nav-item {
  position: relative;
}

.header-nav-link {
  color: #f8fafc;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s, color 0.2s;
}

.header-nav-link:hover {
  background-color: var(--sidebar-hover);
  color: var(--primary);
}

.header-nav-link .arrow {
  font-size: 0.75rem;
}

/* Sous-menu Dropdown Header */
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
  list-style: none;
  padding: 6px 0;
  min-width: 220px;
  display: none;
  z-index: 1000;
}

.dropdown-menu li a {
  display: block;
  padding: 9px 16px;
  color: var(--text-color);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
}

.dropdown-menu li a:hover {
  background-color: var(--primary);
  color: #ffffff;
}

.header-nav-item:hover .dropdown-menu {
  display: block;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-theme {
  background: transparent;
  color: #fff;
  border: 1px solid #334155;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  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.3rem;
  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: 11px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.92rem;
  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.65rem;
  transition: transform 0.3s ease;
}

.has-submenu.open .chevron {
  transform: rotate(180deg);
}

/* Sous-menu */
.submenu {
  display: none;
  background-color: rgba(0, 0, 0, 0.15);
}

.has-submenu.open .submenu {
  display: block;
}

.submenu .nav-link {
  padding-left: 48px;
  font-size: 0.86rem;
}

/* -----------------------------------------------------
  4. Zone de Contenu Principal (Main Content)
----------------------------------------------------- */
.main-content {
  flex: 1;
  padding: 2.5rem;
  overflow-y: auto;
  max-width: 1200px;
}

/* Panneaux / Cartes modernes */
.panel {
  background-color: var(--card-bg);
  border-radius: 12px;
  padding: 2rem 2.5rem;
  margin-bottom: 1.75rem;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px -2px rgba(0, 0, 0, 0.02);
}

.panel h1 {
  color: var(--text-heading);
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.panel h2 {
  color: var(--text-heading);
  font-size: 1.3rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border-color);
}

.panel h3 {
  color: var(--text-heading);
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.6rem;
}

.panel p {
  line-height: 1.7;
  margin-bottom: 1rem;
  color: var(--text-color);
}

.panel ul, .panel ol {
  padding-left: 1.5rem;
  margin-top: 0.5rem;
  margin-bottom: 1.25rem;
}

.panel li {
  line-height: 1.6;
  margin-bottom: 0.5rem;
  color: var(--text-color);
}

.panel hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 1.5rem 0;
}

/* 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: 9px 18px;
  border-radius: 8px;
  border: none;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.2);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--table-header-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

/* -----------------------------------------------------
  6. Code, Algorithmes & Tableaux Modernes
----------------------------------------------------- */
pre, code {
  font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
}

pre {
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.5;
  border: 1px solid var(--border-color);
  margin: 1rem 0;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

/* Amélioration visuelle inline code */
p code, li code, td code {
  background-color: var(--table-header-bg);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  font-size: 0.85em;
}

/* Tableaux professionnels redessinés */
table, .tableau {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.25rem 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  font-size: 0.92rem;
}

table th, table td, .tableau th, .tableau td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

table th:last-child, table td:last-child, 
.tableau th:last-child, .tableau td:last-child {
  border-right: none;
}

table tr:last-child td, .tableau tr:last-child td {
  border-bottom: none;
}

table th, .tableau th {
  background-color: var(--table-header-bg);
  color: var(--text-heading);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
}

table tr:nth-child(even) td, .tableau tr:nth-child(even) td {
  background-color: var(--table-stripe-bg);
}

/* -----------------------------------------------------
  7. Pied de Page (Footer)
----------------------------------------------------- */
.main-footer {
  background-color: var(--bg-header);
  color: #64748b;
  text-align: center;
  padding: 1.25rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
}

/* -----------------------------------------------------
  8. Zone de Recherche (Search Box)
----------------------------------------------------- */
.search-box {
  position: relative;
  width: 260px;
}

.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: all 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.search-results-dropdown {
  position: absolute;
  top: 115%;
  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 25px -5px rgba(0, 0, 0, 0.2);
}

.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.15s;
}

.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: 2.5rem;
  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.25rem;
}

.contact-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-color);
}

.contact-form input, 
.contact-form textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-main);
  color: var(--text-color);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s;
}

.contact-form input:focus, 
.contact-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

/* -----------------------------------------------------
  10. Responsive Design
----------------------------------------------------- */
@media (max-width: 992px) {
  .header-nav {
    order: 4;
    width: 100%;
    margin-top: 10px;
  }

  .header-nav-list {
    flex-direction: column;
    gap: 5px;
    width: 100%;
  }

  .dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    padding-left: 20px;
    background: transparent;
  }

  .workspace-grid,
  .main-content {
     display: flex !important;
     flex-direction: column !important;
  }
}

@media (max-width: 768px) {
  .main-header {
     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: 1.25rem;
  }
}

/* -----------------------------------------------------
  11. Pages d'Aide Pédagogique & Cartes
----------------------------------------------------- */
.aide-container, .cc-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 20px;
}

.aide-card, .cc-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 22px 26px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.aide-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px -3px rgba(0, 0, 0, 0.05);
}

.aide-card.blue { border-left: 5px solid #0284c7; }
.aide-card.green { border-left: 5px solid #16a34a; }
.aide-card.orange { border-left: 5px solid #eab308; }
.aide-card.purple { border-left: 5px solid #9333ea; }
.cc-card { border-left: 5px solid var(--primary); }

.aide-card-title, .cc-card h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.aide-list, .cc-card ul {
  list-style-type: disc;
  padding-left: 20px;
  margin: 0;
}

.aide-list > li, .cc-card li {
  margin-bottom: 10px;
  line-height: 1.6;
  color: var(--text-color);
}

.badge-remarque {
  display: inline-block;
  background-color: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 8px;
}

[data-theme="dark"] .badge-remarque {
  background-color: #422006;
  color: #fef08a;
  border-color: #713f12;
}

/* Boîte de formule de calcul de moyenne */
.code-box {
  background-color: var(--table-header-bg);
  border: 2px dashed var(--primary);
  color: var(--primary);
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 16px 20px;
  border-radius: 8px;
  text-align: center;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  letter-spacing: 0.5px;
}

[data-theme="dark"] .code-box {
  background-color: #020617;
  color: #38bdf8;
  border-color: #38bdf8;
}