:root {
  --primary-color: #36c;
  --primary-dark: #2a4b8d;
  --text-color: #202122;
  --text-light: #54595d;
  --bg-color: #f8f9fa;
  --border-color: #a2a9b1;
  --border-light: #eaecf0;
  --white: #ffffff;
  --error-color: #dc2626;
  --success-color: #34d399;
  --user-color: #60a5fa;
  
  /* Space units */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  
  /* Font sizes */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-2xl: 28px;
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

html {
  height: 100%;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Améliorer le scrolling sur iOS */
  -webkit-overflow-scrolling: touch;
}

body {
  height: 100%;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text-color);
  background: var(--bg-color);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Wikipedia-like layout --- */
.mw {
  max-width: none;
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-md) var(--space-lg);
  min-height: 100vh;
  background: var(--bg-color);
}

/* --- Appearance toggles --- */
/* Text size */
.mw.text-small { font-size: 15px; }
.mw.text-large { font-size: 18px; }

/* Content width: Standard (default) vs Wide */
.mw-content { max-width: 980px; margin: 0 auto; }
.wide-layout .mw-content { max-width: none; }

/* Theme overrides using CSS variables scoped to .mw */
.mw.theme-light {
  --primary-color: #36c;
  --primary-dark: #2a4b8d;
  --text-color: #202122;
  --text-light: #54595d;
  --bg-color: #f8f9fa;
  --border-color: #a2a9b1;
  --border-light: #eaecf0;
  --white: #ffffff;
}
.mw.theme-dark {
  --primary-color: #8ab4ff; /* light blue for links */
  --primary-dark: #5e8eff; /* hover/focus */
  --text-color: #e5e7eb;
  --text-light: #9aa4af;
  --bg-color: #0b0f14;
  --border-color: #253042;
  --border-light: #14202e;
  --white: #0f1720;
}

.mw-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--space-sm);
  gap: var(--space-md);
  flex-wrap: wrap;
}

.mw-brand {
  display: grid;
  grid-template-columns: auto;
  gap: var(--space-xs);
}

.mw-logo {
  font-weight: 400;
  font-size: var(--text-xl);
  text-decoration: none;
  color: var(--text-color);
  transition: opacity 0.2s ease;
  font-family: Georgia, "Times New Roman", Times, serif;
  font-variant: small-caps;
  letter-spacing: 0.2px;
  line-height: 1.15;
}

/* Dark mode: make header brand link light blue, like other links */
.mw.theme-dark .mw-logo { color: var(--primary-color); }
.mw.theme-dark .mw-logo:hover,
.mw.theme-dark .mw-logo:focus { color: var(--primary-dark); }

.mw-logo-icon {
  width: 18px;
  height: 18px;
  vertical-align: text-bottom;
  margin-right: var(--space-xs);
}

/* Dark mode: tint the raster logo icon to light blue to match links */
.mw.theme-dark .mw-logo-icon {
  filter: invert(80%) sepia(12%) saturate(3000%) hue-rotate(195deg) brightness(105%) contrast(100%);
}
/* Light mode: ensure no tint is applied */
.mw.theme-light .mw-logo-icon { filter: none; }

.mw-logo:hover,
.mw-logo:focus {
  opacity: 0.8;
}

.mw-slogan {
  font-size: var(--text-sm);
  color: var(--text-light);
  font-style: italic;
  font-family: Georgia, "Times New Roman", Times, serif;
}

.mw-search {
  display: flex;
  gap: 0;
  flex: 0 0 420px; /* slightly longer */
  align-items: center;
  margin-left: var(--space-md);
}

.mw-search-input {
  border: 1px solid var(--border-color);
  padding: var(--space-sm) var(--space-md);
  border-radius: 2px 0 0 2px;
  flex: 1;
  max-width: 100%;
  font-size: var(--text-base);
  transition: border-color 0.2s ease;
  border-right: none; /* attach to button */
}

.mw-search-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(51, 102, 204, 0.1);
}

.mw-search-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 2px 2px 0;
  color: var(--text-color);
  margin-left: 0; /* ensure no gap */
  font-size: var(--text-base);
  transition: all 0.2s ease;
}

.mw-search-btn:hover {
  background: var(--bg-color);
  border-color: var(--border-color);
  color: var(--text-color);
}

.mw-layout {
  display: grid;
  grid-template-columns: minmax(200px, 240px) 1fr;
  gap: var(--space-md);
  min-height: calc(100vh - 80px);
}

/* Collapsed sidebar state toggled from header button */
.sidebar-collapsed .mw-sidebar { display: none; }
.sidebar-collapsed .mw-layout { grid-template-columns: 1fr; }

@media (max-width: 768px) {
  .mw {
    padding: 0;
  }

  .mw-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .mw-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--white);
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-xs);
    gap: var(--space-xs);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  .mw-brand {
    text-align: center;
  }

  .mw-search {
    margin: 0;
    padding: 0 var(--space-xs);
    flex: 1 1 auto;
    position: relative;
  }

  .mw-search-input {
    width: 100%;
    height: 44px;
    padding-right: 44px;
    font-size: 16px;
  }

  .mw-search-btn {
    position: absolute;
    right: var(--space-xs);
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  .mw-auth {
    margin: 0;
    padding: var(--space-xs);
    justify-content: center;
    gap: var(--space-sm);
  }

  .mw-auth-btn {
    flex: 1;
    max-width: 160px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-base);
    padding: 0 var(--space-md);
  }

  .mw-sidebar {
    position: static;
    padding: var(--space-xs);
    margin: 0;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-light);
  }

  .mw-sidebar ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    padding: var(--space-xs);
  }

  .mw-sidebar li {
    margin: 0;
  }

  .mw-sidebar a {
    padding: var(--space-xs) var(--space-sm);
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: var(--text-base);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: 44px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  }

  .mw-sidebar a:active {
    background: var(--bg-color);
    transform: translateY(1px);
    box-shadow: none;
  }

  .mw-content {
    padding: var(--space-sm);
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg-color);
  }

  .chat-messages {
    padding: var(--space-xs);
  }

  .message {
    max-width: 100%;
  }

  .message-content {
    font-size: 14px;
    padding: var(--space-xs) var(--space-sm);
  }

  .chat-input-container {
    padding: var(--space-xs);
  }

  #chatInput {
    font-size: 14px;
    padding: 8px;
  }

  .mw-modal-dialog {
    margin: 4vh 16px;
    max-width: none;
  }
}

.mw-sidebar {
  font-size: var(--text-sm);
  position: sticky;
  top: var(--space-md);
  height: fit-content;
  padding-right: var(--space-sm);
}

.mw-sidebar h3 {
  font-size: var(--text-sm);
  margin: var(--space-sm) 0 var(--space-xs);
  color: var(--text-color);
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-xs);
}

/* Place the toggle icon inline with the title */
.mw-sidebar h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
}

/* Minimal icon-button for sidebar toggle */
.mw-sidebar-toggle {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
.mw-sidebar-toggle:hover,
.mw-sidebar-toggle:focus {
  background: transparent;
  color: inherit;
  outline: none;
}

/* Keep title visible; hide only the links when collapsed */
.mw-sidebar.collapsed #sidebar-links { display: none; }

.mw-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mw-sidebar li {
  margin: var(--space-xs) 0;
}

/* Appearance controls in sidebar */
.mw-appearance {
  display: grid;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}
.mw-appearance fieldset {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: var(--space-xs) var(--space-sm) var(--space-sm);
}
.mw-appearance legend {
  font-weight: 600;
  color: var(--text-light);
  padding: 0 var(--space-xs);
}
.mw-appearance label {
  display: block;
  margin-top: 6px;
  cursor: pointer;
}
.mw-appearance input[type="radio"] {
  margin-right: 6px;
}

/* Collapse behavior for the 'Apparence' section: keep title, hide form */
#appearance-section.collapsed .mw-appearance { display: none; }

.mw-sidebar a,
.mw-linklike {
  color: var(--primary-color);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  display: block;
  transition: color 0.2s ease;
}

.mw-sidebar a:visited,
.mw-linklike:visited {
  color: var(--primary-color);
}

.mw-sidebar a:hover,
.mw-sidebar a:focus,
.mw-linklike:hover,
.mw-linklike:focus {
  color: var(--primary-dark);
  text-decoration: underline;
}

.mw-content {
  background: var(--white);
  border: 1px solid var(--border-color);
  padding: var(--space-md);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
  width: 100%;
}

/* Styles pour le contenu des articles */
.mw-article {
  max-width: 100%;
  overflow-x: hidden;
  word-wrap: break-word;
}

.mw-article img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: var(--space-sm) auto;
}

.mw-article table {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  display: block;
  margin: var(--space-sm) 0;
  border-collapse: collapse;
}

.mw-article pre {
  max-width: 100%;
  overflow-x: auto;
  padding: var(--space-sm);
  background: var(--bg-color);
  border: 1px solid var(--border-light);
  border-radius: 4px;
}

/* Content links honor theme colors (light blue in dark mode) */
.mw-content a {
  color: var(--primary-color);
  text-decoration: none;
}
.mw-content a:hover,
.mw-content a:focus {
  color: var(--primary-dark);
  text-decoration: underline;
}
.mw-content a:visited {
  color: var(--primary-color);
}

.mw-controls {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  background: var(--bg-color);
  border: 1px solid var(--border-light);
  padding: var(--space-sm);
  margin-bottom: var(--space-sm);
  border-radius: 4px;
}

.mw-control-item {
  display: grid;
  gap: var(--space-xs);
  font-size: var(--text-sm);
}

.mw-control-item label {
  color: var(--text-light);
}

select {
  border: 1px solid var(--border-color);
  background: var(--white);
  border-radius: 4px;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-sm);
  transition: border-color 0.2s ease;
}

select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(51, 102, 204, 0.1);
}

button {
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Baseline rectangular buttons everywhere (including inside cards/modals) */
button,
.mw-auth-btn,
.mw-primary,
.mw-tab,
#send,
.mw-search-btn {
  border-radius: 2px !important;
}

.mw-article-header { border-bottom: 1px solid #eaecf0; margin-bottom: 12px; }
.mw-title { font-size: 28px; font-weight: 600; margin: 4px 0; }
.mw-subtitle { color: #54595d; margin: 0 0 12px; }

.chat {
  overflow-y: auto;
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.message {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: var(--space-sm);
  align-items: start;
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  color: var(--white);
  transition: transform 0.2s ease;
}

.avatar:hover {
  transform: scale(1.05);
}

.avatar.user {
  background: var(--user-color);
}

.avatar.bot {
  background: var(--success-color);
}

.bubble {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: var(--space-sm) var(--space-md);
  line-height: 1.6;
  white-space: pre-wrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  max-width: 100%;
  overflow-x: auto;
}

.bubble .meta {
  font-size: var(--text-xs);
  color: var(--text-light);
  margin-bottom: var(--space-xs);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background: var(--bg-color);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin-top: var(--space-md);
}

textarea {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  outline: none;
  resize: none;
  font-size: var(--text-base);
  padding: var(--space-sm);
  background: var(--white);
  max-height: 40vh;
  transition: border-color 0.2s ease;
  line-height: 1.5;
}

textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(51, 102, 204, 0.1);
}

#send {
  background: var(--primary-color);
  color: var(--white);
  border: 1px solid var(--primary-color);
  border-radius: 2px;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-base);
  transition: all 0.2s ease;
}

#send:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
}

#send:active {
  transform: translateY(0);
}

.system {
  text-align: center;
  color: var(--text-light);
  font-size: var(--text-sm);
  padding: var(--space-sm) 0;
}

.error {
  color: var(--error-color);
  padding: var(--space-sm);
  border: 1px solid var(--error-color);
  border-radius: 6px;
  background-color: rgba(220, 38, 38, 0.1);
  margin: var(--space-sm) 0;
}

/* Loading states */
.loading {
  opacity: 0.7;
  pointer-events: none;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(51, 102, 204, 0.3);
  border-radius: 50%;
  border-top-color: var(--primary-color);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .message,
  .avatar,
  .loading-spinner {
    animation: none;
  }
  
  button,
  a,
  .mw-search-input,
  textarea {
    transition: none;
  }
}

/* Focus styles */
:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Styles tactiles pour mobile */
@media (hover: none) and (pointer: coarse) {
  /* Augmenter la taille des zones tactiles */
  .mw-auth-btn,
  .mw-search-btn,
  .mw-sidebar a,
  .mw-primary,
  #send,
  .msg-btn,
  .chat-send-btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  /* Améliorer la lisibilité du texte */
  .message-content,
  .chat-input {
    font-size: 16px;
  }

  /* Eviter le zoom sur les inputs iOS */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  textarea {
    font-size: 16px;
  }

  /* Réduire les animations pour de meilleures performances */
  .message,
  .avatar,
  button,
  a {
    transition: none;
  }
}

/* Gestion des écrans de très petite taille */
@media (max-width: 320px) {
  .mw-auth {
    flex-direction: column;
    gap: 8px;
  }

  .mw-search {
    flex-basis: auto;
  }

  .chat-input-wrapper {
    gap: 4px;
  }
}

/* Support des écrans avec encoche */
@supports(padding: max(0px)) {
  .mw {
    padding-left: max(var(--space-md), env(safe-area-inset-left));
    padding-right: max(var(--space-md), env(safe-area-inset-right));
    padding-bottom: max(var(--space-lg), env(safe-area-inset-bottom));
  }

  @media (max-width: 768px) {
    .mw {
      padding-left: max(var(--space-xs), env(safe-area-inset-left));
      padding-right: max(var(--space-xs), env(safe-area-inset-right));
      padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
    }
  }
}

/* Styles responsives améliorés */
@media screen and (max-width: 768px) {
  /* Layout global */
  .mw {
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
  }

  /* Amélioration de l'affichage des articles sur mobile */
  .mw-article {
    font-size: 16px;
    line-height: 1.6;
    padding: 0 var(--space-xs);
  }

  .mw-article h1 {
    font-size: var(--text-xl);
    line-height: 1.3;
    margin: var(--space-md) 0 var(--space-sm);
  }

  .mw-article h2 {
    font-size: var(--text-lg);
    margin: var(--space-md) 0 var(--space-sm);
  }

  .mw-article h3,
  .mw-article h4 {
    font-size: var(--text-base);
    margin: var(--space-sm) 0;
  }

  .mw-article p {
    margin: var(--space-sm) 0;
  }

  /* Amélioration des tableaux sur mobile */
  .mw-article table {
    font-size: var(--text-sm);
  }

  .mw-article td,
  .mw-article th {
    padding: var(--space-xs);
    min-width: 120px;
  }

  /* Gestion des images */
  .mw-article figure {
    margin: var(--space-md) -var(--space-xs);
    max-width: calc(100% + 2 * var(--space-xs));
  }

  .mw-article figure img {
    width: 100%;
    border-radius: 4px;
  }

  .mw-article figcaption {
    font-size: var(--text-sm);
    color: var(--text-light);
    padding: var(--space-xs);
    text-align: center;
  }

  /* Header */
  .mw-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--white);
    padding: var(--space-xs);
    border-bottom: 1px solid var(--border-color);
    flex-direction: column;
    gap: var(--space-xs);
  }

  /* Logo et marque */
  .mw-brand {
    text-align: center;
    padding: var(--space-xs) 0;
  }

  .mw-logo {
    font-size: 1.5rem;
    display: inline-flex;
    align-items: center;
  }

  .mw-slogan {
    font-size: 0.8rem;
  }

  /* Barre de recherche */
  .mw-search {
    width: 100%;
    margin: 0;
    padding: 0 var(--space-xs);
  }

  .mw-search-input {
    height: 40px;
  }

  .mw-search-btn {
    height: 40px;
  }

  /* Boutons d'authentification */
  .mw-auth {
    display: flex;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-xs);
    margin: 0;
  }

  .mw-auth-btn {
    flex: 1;
    max-width: 160px;
    height: 40px;
    justify-content: center;
  }

  /* Layout principal */
  .mw-layout {
    flex: 1;
    grid-template-columns: 1fr;
    gap: 0;
    overflow-x: hidden;
  }

  /* Sidebar */
  .mw-sidebar {
    position: static;
    padding: var(--space-xs);
    background: var(--white);
    border-bottom: 1px solid var(--border-light);
  }

  .mw-sidebar section {
    margin-bottom: var(--space-sm);
  }

  .mw-sidebar h3 {
    margin: 0;
    padding: var(--space-xs) 0;
  }

  .mw-sidebar ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
  }

  .mw-sidebar li {
    margin: 0;
  }

  .mw-sidebar a {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-color);
    border-radius: 4px;
    white-space: nowrap;
  }

  /* Contenu principal */
  .mw-content {
    flex: 1;
    padding: var(--space-sm);
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg-color);
  }

  /* Chat */
  .chat {
    height: calc(100vh - 180px);
    display: flex;
    flex-direction: column;
  }

  .chat-messages {
    flex: 1;
    padding: var(--space-xs);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .message {
    max-width: 90%;
    margin-bottom: var(--space-xs);
  }

  .message-content {
    font-size: 0.9rem;
    padding: var(--space-sm);
    word-break: break-word;
  }

  .chat-input-container {
    position: sticky;
    bottom: 0;
    background: var(--white);
    padding: var(--space-xs);
    border-top: 1px solid var(--border-light);
  }

  #chatInput {
    height: 40px;
    padding: var(--space-xs);
    font-size: 16px;
  }

  /* Modal */
  .mw-modal-dialog {
    margin: 0;
    max-width: none;
    height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  .mw-modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Formulaires */
  input[type="email"],
  input[type="password"],
  input[type="text"],
  textarea {
    height: 40px;
    font-size: 16px;
    padding: var(--space-xs) var(--space-sm);
  }

  /* Boutons */
  button,
  .mw-primary {
    height: 40px;
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Tables responsive */
  .mw-article table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Images responsive */
  .mw-article img,
  .mw-article figure {
    max-width: 100%;
    height: auto;
  }

  /* Correction des flottants */
  .mw-article .infobox,
  .mw-article .tright,
  .mw-article .tleft {
    float: none;
    width: 100%;
    margin: 1em 0;
  }
}

/* Très petits écrans */
@media screen and (max-width: 320px) {
  .mw-header {
    padding: var(--space-xs) 0;
  }

  .mw-brand {
    padding: var(--space-xs) var(--space-sm);
  }

  .mw-logo {
    font-size: var(--text-lg);
  }

  .mw-slogan {
    display: none;
  }

  .mw-auth {
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-xs);
  }

  .mw-auth-btn {
    max-width: none;
    width: 100%;
  }

  .mw-search {
    padding: 0 var(--space-xs);
  }

  .mw-search-input,
  .mw-search-btn {
    height: 40px;
  }

  .mw-sidebar ul {
    padding: var(--space-xs) 0;
  }

  .mw-sidebar a {
    padding: var(--space-xs);
    font-size: var(--text-sm);
  }

  /* Empiler les contrôles verticalement */
  .mw-controls {
    flex-direction: column;
    gap: var(--space-xs);
  }

  .mw-control-item {
    width: 100%;
  }
}

/* Support pour les appareils avec encoche */
@supports(padding: max(0px)) {
  .mw {
    padding-left: max(var(--space-xs), env(safe-area-inset-left));
    padding-right: max(var(--space-xs), env(safe-area-inset-right));
    padding-bottom: max(var(--space-xs), env(safe-area-inset-bottom));
  }

  .mw-header {
    padding-top: max(var(--space-xs), env(safe-area-inset-top));
  }

  .mw-content {
    padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
  }
}

/* Print styles */
@media print {
  .mw-sidebar,
  .composer,
  .mw-controls,
  .mw-search {
    display: none;
  }
  
  .mw-content {
    border: none;
    padding: 0;
    box-shadow: none;
  }
  
  .bubble {
    break-inside: avoid;
  }
}

/* --- Auth UI --- */
.mw-auth { display: flex; gap: var(--space-xs); }
.mw-auth { margin-left: auto; }
.mw-auth-btn {
  border: 1px solid var(--border-color);
  background: var(--white);
  color: var(--text-color);
  padding: .35em .6em; /* match .mw-audio-btn size */
  border-radius: 2px;
  font: inherit; /* match .mw-audio-btn */
  line-height: inherit; /* match .mw-audio-btn */
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.mw-auth-btn.primary {
  background: var(--primary-color);
  color: var(--white);
  border-color: var(--primary-color);
}
.mw-auth-btn:hover { filter: brightness(0.97); }
.mw-auth-btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.mw-modal[hidden] { display: none !important; }
.mw-modal { position: fixed; inset: 0; z-index: 1000; }
.mw-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.mw-modal-dialog {
  position: relative;
  margin: 8vh auto;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  overflow: hidden;
}
.mw-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border-light); }
.mw-modal-close { border: none; background: transparent; font-size: 22px; line-height: 1; padding: 2px 6px; color: var(--text-light); }
.mw-modal-close:hover { color: var(--text-color); }
.mw-modal-tabs { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border-light); }
.mw-tab { border: none; background: transparent; padding: 6px 10px; border-radius: 2px; color: var(--text-light); font-weight: 600; }
.mw-tab.active { background: var(--bg-color); color: var(--text-color); }
.mw-modal-body { padding: 14px; display: grid; gap: 12px; }
.mw-modal-body form { display: grid; gap: 10px; }
.mw-modal-body label { display: grid; gap: 6px; font-size: var(--text-sm); color: var(--text-light); }
.mw-modal-body input[type="email"],
.mw-modal-body input[type="password"] {
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: var(--text-base);
}
.mw-primary { background: var(--primary-color); color: var(--white); border: 1px solid var(--primary-color); padding: 8px 12px; border-radius: 2px; font-weight: 600; }
.mw-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.mw-hint { margin: 4px 0 0; font-size: var(--text-xs); color: var(--text-light); }

/* Inline Auth Card */
.auth-card {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: none; /* flatter, more encyclopedic */
}
.auth-title {
  margin: 0 0 10px;
  font-size: 1.4rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 6px;
}
.auth-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.auth-body { display: grid; gap: 12px; }
.auth-body form { display: grid; gap: 10px; max-width: 480px; }
.auth-body label { display: grid; gap: 4px; font-size: var(--text-sm); color: var(--text-light); }
.auth-body input[type="email"],
.auth-body input[type="password"] {
  border: 1px solid var(--border-color);
  padding: 6px 8px;
  border-radius: 4px;
  font-size: var(--text-base);
  background: var(--white);
}

/* Auth switch link styles */
.auth-switch { font-size: var(--text-sm); margin-top: 8px; }
.auth-switch a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 600;
}
.auth-switch a:hover,
.auth-switch a:focus {
  text-decoration: underline;
}
.auth-switch a:active {
  color: var(--primary-dark);
}

/* Subtle primary button for encyclopedic look */
.auth-card .mw-primary {
  padding: 6px 10px;
  font-size: var(--text-sm);
  border-radius: 2px;
  font-weight: 600;
}
.auth-card .mw-primary:active {
  transform: none;
}

/* Default boxed buttons: white (exclude explicit primary buttons) */
.auth-card button:not(.mw-primary),
.mw-content button:not(.mw-primary) {
  background: var(--white);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.auth-card button:not(.mw-primary):hover,
.mw-content button:not(.mw-primary):hover {
  background: var(--bg-color);
  border-color: var(--border-color);
}
