/* --- Wireframe UI Style Definition --- */
:root {
  /* Palette "Papier" (Clair) */
  --background: #FDFBF5;
  --foreground: #212529;
  --accent-color: #3B82F6;
  --accent-color-hover: #3B82F6; /* Couleur de survol pour le thème clair */
  --accent-color-text-hover: #FDFBF5; /* Couleur du texte pour le survol */
  --valid-color: #198754;
  --invalid-color: #b02a37;

  --border-width: 2px;
  --shadow-offset: 5px;
  --shadow-color: #212529;
  --font-family: monospace, sans-serif;
}

/* Thème "Blueprint" (Sombre) */
.blueprint-theme {
  --background: #1E293B;
  --foreground: #CBD5E1;
  --shadow-color: #CBD5E1;
  --accent-color-hover: #334155; /* Version plus sombre du fond pour le survol */
  --accent-color-text-hover: #CBD5E1; /* Le texte ne change pas de couleur au survol */
}

/* --- Animation pour l'icône des paramètres --- */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-family);
  background-color: var(--background);
  color: var(--foreground);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  gap: 1.5rem;
  transition: background-color 0.3s, color 0.3s;
}

/* --- Core Layout & Panels --- */
.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  flex-shrink: 0;
}

.header-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
}

.header-buttons .button {
    width: auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-buttons .button svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.app-header__title {
  font-size: 1.8rem;
  font-weight: bold;
  text-align: center;
  /* Ajouts pour aligner l'icône et le texte */
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header__icon {
  width: 36px; /* Ou la taille que vous préférez */
  height: 36px;
  margin-right: 0.75rem; /* Espace entre l'icône et le titre */
}

.main-content {
  display: flex;
  flex-grow: 1;
  gap: 1.5rem;
  min-height: 0;
}

.panel {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  overflow-y: auto;
}

.main-panel {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* --- Modification pour le textarea dynamique --- */
#form-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem; /* Espacement réduit pour optimiser l'espace vertical */
  flex-grow: 1; /* Permet au conteneur de grandir */
  min-height: 0;
}

/* --- Wireframe Visual Primitives --- */
.shadow-base {
  border: var(--border-width) solid var(--foreground);
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 0 var(--shadow-color);
  transition: box-shadow 0.1s ease-out, transform 0.1s ease-out, border-color 0.2s, background-color 0.2s;
}

.press-effect {
  position: relative;
  cursor: pointer;
}

/* --- Amélioration de l'interactivité --- */
/* Effet de pression (au clic) reste le même */
.press-effect:active {
  transform: translate(var(--shadow-offset), var(--shadow-offset));
  box-shadow: 0 0 0 0 var(--shadow-color);
}

/* Animation de l'icône des paramètres */
#settings-button:hover svg {
    animation: spin 4s linear infinite;
}


/* --- Component Styling --- */
.button {
  background: none;
  color: var(--foreground);
  padding: 0.75rem 1.5rem;
  font-family: inherit;
  font-size: 1rem;
  text-align: center;
  width: 100%;
  transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out; /* Ajout de la transition pour le fade */
}

/* --- Modification pour le survol unifié des boutons --- */
.button:not(:disabled):not(.button--valid):not(.button--invalid):hover {
    background-color: var(--accent-color-hover);
    color: var(--accent-color-text-hover);
}

.button:disabled:not(.button--valid):not(.button--invalid) {
  opacity: 0.6;
  cursor: not-allowed;
  background-color: #888888 !important;
  color: #cccccc !important;
  border-color: #888888 !important;
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 0 #555555 !important;
  transform: none !important;
}

.button--valid {
  background: var(--valid-color) !important;
  border-color: var(--valid-color) !important;
  color: var(--background) !important;
}

.button--invalid {
  background: var(--invalid-color) !important;
  border-color: var(--invalid-color) !important;
  color: var(--background) !important;
}

.button-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  flex-shrink: 0; /* Empêche les boutons d'être compressés */
}

.instructions {
  text-align: left;
  margin-top: 1rem;
  opacity: 0.8;
  flex-shrink: 0; /* Empêche les instructions d'être compressées */
}

.instructions h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.instructions p {
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 0.25rem;
}

/* --- Modification pour le textarea dynamique --- */
textarea#info {
  width: 100%;
  min-height: 5rem; /* Hauteur de départ (environ 3 lignes) */
  flex-grow: 1; /* Permet au textarea de grandir pour remplir l'espace */
  padding: 1rem;
  background-color: var(--background);
  color: var(--foreground);
  font-family: inherit;
  font-size: 1rem;
  resize: none; /* Le redimensionnement manuel est désactivé au profit de l'ajustement automatique JS */
  overflow-y: auto; /* Affiche une barre de défilement si le contenu dépasse la hauteur max */
}

textarea#info:focus {
  outline: none;
  border-color: var(--accent-color);
}

#mcq-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100%;
}

.mcq-header {
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
  flex-wrap: wrap;
  gap: 1.5rem;
  flex-shrink: 0;
}

.question {
  font-size: 1.5em;
  font-weight: bold;
  margin-bottom: 1rem;
  line-height: 1.4;
  flex-shrink: 0;
}

.answers {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 1rem;
}

#status {
  font-style: italic;
}

.progress-bar-container {
  width: 100%;
  height: 24px;
  padding: 4px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background-color: var(--accent-color);
  transition: width 0.3s ease-in-out;
}

/* --- Settings Modal --- */
.settings-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    background-color: var(--background);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: var(--border-width) solid var(--foreground);
    flex-shrink: 0;
}

.settings-header h2 {
    font-size: 1.2rem;
}

.close-settings-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--foreground);
    cursor: pointer;
    line-height: 1;
}

.settings-content {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    overflow-y: auto;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.setting-item label {
    font-weight: bold;
}

.theme-buttons {
    display: flex;
    gap: 1rem;
}

.theme-buttons .button {
    flex: 1;
}

.api-key-link-container {
    margin-top: -0.5rem;
    margin-bottom: 0.5rem;
}

.api-key-link {
    font-size: 0.8rem;
    display: inline;
    width: fit-content;
    color: var(--foreground);
    opacity: 0.8;
}

.api-key-note {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-left: 0.5rem;
}

.input-with-button {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.input-with-button input {
    flex-grow: 1;
}

.setting-item input[type="password"],
.setting-item select {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--background);
    color: var(--foreground);
    font-family: inherit;
    font-size: 1rem;
    border: var(--border-width) solid var(--foreground);
}

.setting-item input[type="password"]:focus,
.setting-item select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.setting-item button,
.setting-item a.button {
    width: fit-content;
    align-self: flex-start;
    text-decoration: none;
}

.api-key-message {
    font-size: 0.9rem;
    font-weight: bold;
}

.api-key-message.success {
    color: var(--valid-color);
}

.api-key-message.error {
    color: var(--invalid-color);
}

/* --- History Sidebar --- */
.history-sidebar {
  position: fixed;
  top: 0;
  left: -420px;
  width: 100%;
  max-width: 400px;
  height: 100%;
  background-color: var(--background);
  z-index: 1000;
  transition: left 0.3s ease-in-out;
  display: flex;
  flex-direction: column;
}

.history-sidebar.open {
  left: 0;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: var(--border-width) solid var(--foreground);
  flex-shrink: 0;
}

.history-header h2 { font-size: 1.2rem; }

.close-history-btn {
  background: none; border: none; font-size: 2rem;
  color: var(--foreground); cursor: pointer;
  line-height: 1;
}

.history-list {
  list-style: none;
  padding: 2rem;
  overflow-y: auto;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
}

.history-item-title {
  font-weight: bold;
  cursor: pointer;
  word-break: break-word;
}

.history-item-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.history-item-actions button {
  background: none; border: none; color: var(--foreground);
  font-size: 1.2rem; cursor: pointer; padding: 5px;
  display: flex; justify-content: center; align-items: center;
  transition: transform 0.2s;
}
.history-item-actions button:hover {
    transform: scale(1.15);
}
.history-item-actions button.reset-button { color: var(--valid-color); }
.history-item-actions button.delete-button { color: var(--invalid-color); }

/* --- Utilities & Overrides --- */
.hidden { display: none !important; }

.overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0, 0, 0, 0.6); z-index: 999;
}

#error-message {
  color: var(--invalid-color);
  font-weight: bold;
}

/* --- Footer --- */
.app-footer {
  text-align: center;
  padding: 0.5rem;
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 0;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
  body { 
    padding: 0.75rem; 
    gap: 0.75rem; 
    height: 100%;
  }

  .app-header {
    padding: 0.75rem;
  }

  .app-header__title {
    font-size: 1.5rem;
  }

  .header-buttons {
    gap: 0.75rem;
  }

  .header-buttons .button {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  .main-content { 
    flex-direction: column; 
    height: auto; 
    gap: 0.75rem;
  }

  .panel {
    padding: 1rem;
    gap: 1.5rem;
  }

  #form-container {
    gap: 1.5rem;
  }

  .button-group { 
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
  }

  .button-group .button {
    font-size: 0.7rem;
    padding: 0.6rem;
  }

  textarea#info {
    min-height: 6rem; /* Hauteur de départ réduite pour mobile */
  }

  .question { 
    font-size: 1.1rem; 
  }

  .answers {
    gap: 0.75rem; /* Reduced gap */
  }

  /* New rule for answer buttons on mobile */
  .answers .button {
    font-size: 0.8rem;
    padding: 0.6rem 1rem;
  }

  .mcq-header {
    gap: 1rem;
    font-size: 0.8rem; /* Reduced font size */
  }

  .history-sidebar { 
    max-width: 280px; 
    left: -280px; 
  }
  
  .settings-modal {
    padding: 0.5rem;
  }

  .settings-content {
    padding: 1.5rem;
    gap: 1.5rem;
  }
}

/* --- Print Styles --- */
@media print {
  body {
      background-color: #fff !important;
      color: #000 !important;
      padding: 0 !important;
      margin: 0 !important;
      display: block !important;
      overflow: visible !important;
  }

  .app-header, .main-content, #form-container, #mcq-container,
  .history-sidebar, .overlay, #error-message, #status, #progress-container {
      display: none !important;
  }

  #printable-mcq-content {
      display: block !important;
      width: 100%;
      padding: 20mm;
      box-sizing: border-box;
      font-family: var(--font-family);
      color: #000;
  }

  .printable-question {
      margin-bottom: 25px;
      page-break-inside: avoid;
  }

  .printable-question p {
      font-weight: bold;
      margin-bottom: 10px;
      font-size: 18px;
  }

  .printable-question ul {
      list-style: none;
      padding-left: 0;
  }

  .printable-question li {
      margin-bottom: 8px;
      font-size: 16px;
  }

  .printable-question label {
      display: flex;
      align-items: flex-start;
      gap: 10px;
  }

  #printable-mcq-content input[type="checkbox"] {
      -webkit-appearance: checkbox !important;
      -moz-appearance: checkbox !important;
      appearance: checkbox !important;
      border: 1px solid #000 !important;
      background-color: #fff !important;
      width: 18px !important;
      height: 18px !important;
      border-radius: 0 !important;
      margin-top: 0 !important;
      margin-right: 5px;
  }
}