/* Thème clair par défaut, sombre selon les préférences du système. */
:root {
  --fond: #ffffff;
  --fond-secondaire: #f3f4f6;
  --texte: #1a1a1a;
  --texte-discret: #555b66;
  --bordure: #c9ced6;
  --accent: #0b5cad;
  --accent-texte: #ffffff;
  --erreur: #b00020;
  --erreur-fond: #fdecee;
  --succes: #1b6e3a;
  --code-fond: #eef0f3;
  --message-utilisateur: #e3effb;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #16181d;
    --fond-secondaire: #1f232b;
    --texte: #eceff4;
    --texte-discret: #aab1bd;
    --bordure: #3b414d;
    --accent: #6cb2f5;
    --accent-texte: #0b1220;
    --erreur: #ff8a98;
    --erreur-fond: #3a1e24;
    --succes: #7fd49a;
    --code-fond: #262b35;
    --message-utilisateur: #1d3350;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

h1 { margin: 0; font-size: 1.2rem; }

button {
  font: inherit;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-texte);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button.danger { background: var(--erreur); border-color: var(--erreur); color: var(--fond); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, textarea {
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--bordure);
  border-radius: 6px;
  background: var(--fond);
  color: var(--texte);
  width: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.error-text { color: var(--erreur); }

/* Connexion */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  width: 100%; max-width: 26rem;
  display: flex; flex-direction: column; gap: 0.6rem;
  padding: 1.5rem;
  border: 1px solid var(--bordure);
  border-radius: 10px;
  background: var(--fond-secondaire);
}

a { color: var(--accent); }
.login-help { margin: 0; font-size: 0.9rem; color: var(--texte-discret); }

/* Installation de l'extension */
.install-card { max-width: 40rem; }
.install-card h2 { margin: 0.6rem 0 0; font-size: 1rem; }
.install-card p { margin: 0; }
.install-card ol { margin: 0; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 0.4rem; }
.install-card code { background: var(--code-fond); padding: 0 0.3rem; border-radius: 4px; overflow-wrap: anywhere; }
.download-link {
  align-self: flex-start;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-texte);
  text-decoration: none;
}

/* Application */
.app-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.app-header {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--bordure);
}
.project-domain { flex: 1; color: var(--texte-discret); overflow-wrap: anywhere; }

.conversation { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; }

.message { max-width: 50rem; padding: 0.6rem 0.9rem; border-radius: 10px; border: 1px solid var(--bordure); }
.message.user { align-self: flex-end; background: var(--message-utilisateur); }
.message.assistant { align-self: flex-start; background: var(--fond); }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message pre {
  margin: 0.5rem 0; padding: 0.6rem;
  background: var(--code-fond); border-radius: 6px;
  overflow-x: auto;
}

.tool-line { align-self: flex-start; font-size: 0.85rem; color: var(--texte-discret); overflow-wrap: anywhere; }
.tool-line.done { color: var(--succes); }
.tool-line.failed { color: var(--erreur); }

.permission-card {
  align-self: flex-start; max-width: 50rem;
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--accent); border-radius: 10px;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.permission-card .actions { display: flex; gap: 0.5rem; }

.error-message {
  align-self: stretch; padding: 0.6rem 0.9rem;
  border: 1px solid var(--erreur); border-radius: 10px;
  background: var(--erreur-fond); color: var(--erreur);
}
.done-line { align-self: flex-start; font-size: 0.8rem; color: var(--texte-discret); }

.composer { display: flex; gap: 0.5rem; padding: 0.8rem 1rem; border-top: 1px solid var(--bordure); }
.composer textarea { flex: 1; resize: vertical; max-height: 12rem; }

/* Petits écrans */
@media (max-width: 700px) {
  .app-header { flex-wrap: wrap; }
  .composer { flex-wrap: wrap; }
}
