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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  line-height: 1.5;
}

:root {
  --bg: #ffffff;
  --fg: #353740;
  --primary: #10a37f;
  --primary-hover: #0d8c6f;
  --surface: #f7f7f8;
  --border: #e5e5e6;
  --message-user-bg: #10a37f;
  --message-assistant-bg: #f7f7f8;
  --sidebar-bg: #f7f7f8;
}

[data-theme="dark"] {
  --bg: #343541;
  --fg: #ececf1;
  --primary: #10a37f;
  --primary-hover: #0d8c6f;
  --surface: #40414f;
  --border: #565869;
  --message-user-bg: #10a37f;
  --message-assistant-bg: #40414f;
  --sidebar-bg: #202123;
}

.container {
  display: flex;
  min-height: 100vh;
}

aside {
  width: 260px;
  background: var(--sidebar-bg);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-right: 1px solid var(--border);
  transition: transform 0.3s ease;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.brand img {
  width: 32px;
  height: 32px;
  border-radius: 4px;
}

.brand span {
  font-size: 1rem;
  font-weight: 500;
  color: var(--fg);
}

nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--fg);
  text-decoration: none;
  padding: 0.75rem;
  border-radius: 6px;
  transition: background 0.2s;
  font-size: 0.875rem;
}

nav a:hover {
  background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] nav a:hover {
  background: rgba(255, 255, 255, 0.1);
}

.toggle-btn {
  display: none;
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: none;
  border: none;
  color: var(--fg);
  font-size: 24px;
  z-index: 999;
  padding: 8px;
  border-radius: 8px;
  transition: background-color 0.3s ease;
}

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

.toggle-btn:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  color: var(--fg);
  font-size: 0.875rem;
  width: 100%;
  text-align: left;
  transition: background 0.2s;
}

.theme-toggle:hover {
  background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

main {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
}

#chatbox {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  padding-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
  max-height: calc(100vh - 200px);
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

.message {
  padding: 1.5rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fadeIn 0.3s ease-in forwards;
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.message:last-child {
  border-bottom: none;
}

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

.assistant {
  background: var(--message-assistant-bg);
  color: var(--fg);
}

.message-content {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  gap: 1.5rem;
}

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.875rem;
  margin-top: 0.125rem;
}

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

.assistant .message-avatar {
  background: #5436da;
}

[data-theme="dark"] .assistant .message-avatar {
  background: #19c37d;
}

.message-text {
  flex: 1;
  padding-top: 0.25rem;
}

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

#inputArea {
  padding: 1rem 0 1.5rem 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: sticky;
  bottom: 0;
  z-index: 100;
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

textarea {
  width: 100%;
  min-height: 52px;
  max-height: 200px;
  resize: none;
  background: var(--bg);
  color: var(--fg);
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] textarea {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(16, 163, 127, 0.1);
}

select {
  font-size: 0.875rem;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s;
}

select:focus {
  outline: none;
  border-color: var(--primary);
}

button {
  font-size: 1rem;
  border-radius: 8px;
  padding: 0.6rem 1rem;
}

button {
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s ease;
  border-radius: 6px;
}

button:hover {
  background: var(--primary-hover);
}

button:active {
  transform: scale(0.98);
}

#modelSelect {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
}

#loading {
  color: var(--fg);
  font-style: italic;
  opacity: 0.7;
}

#chatbox:empty::before {
  content: "Comment puis-je vous aider aujourd'hui ?";
  display: block;
  text-align: center;
  color: var(--fg);
  opacity: 0.5;
  padding: 3rem 1rem;
  font-size: 1.1rem;
}

@media (max-width: 768px) {
  aside {
    transform: translateX(-100%);
    z-index: 998;
    width: 100%;
    max-width: 280px;
  }
  aside.open {
    transform: translateX(0);
  }
  main {
    margin-left: 0;
    width: 100%;
  }
  .toggle-btn {
    display: block;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 999;
  }
  #chatbox {
    max-width: 100%;
    padding: 0;
  }
  .message-content {
    padding: 0 1rem;
  }
  #inputArea {
    padding: 1rem;
    max-width: 100%;
  }
  #chatbox {
    max-height: calc(100vh - 200px);
    padding-bottom: 1rem;
  }
  textarea {
    min-height: 52px;
    font-size: 1rem;
    padding-right: 3rem;
  }
  #sendButton {
    right: 0.75rem;
    bottom: 0.75rem;
  }
  .brand span {
    font-size: 1rem;
  }
  footer {
    padding: 0.8rem;
    font-size: 0.7rem;
  }
  .footer-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  .footer-links a {
    margin: 0;
  }
}

@media (max-width: 480px) {
  .message {
    padding: 1rem 0.5rem;
  }
  .message-content {
    padding: 0 0.5rem;
    gap: 0.75rem;
  }
  .message-avatar {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
  }
  .brand img {
    width: 28px;
    height: 28px;
  }
  .brand span {
    font-size: 0.95rem;
  }
  nav a {
    padding: 0.6rem 0.75rem;
    font-size: 0.875rem;
  }
  .theme-toggle {
    font-size: 0.8rem;
    padding: 0.5rem 0.75rem;
  }
  #inputArea {
    padding: 0.75rem;
  }
}

footer {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--fg);
  opacity: 0.7;
}

.bandeau-footer {
  display: none;
}

.footer-links {
  font-size: 0.75rem;
}

.footer-links a {
  color: var(--fg);
  text-decoration: none;
  margin: 0 0.5rem;
  opacity: 0.8;
}

.footer-links a:hover {
  opacity: 1;
  text-decoration: underline;
}

#chatbox:focus {
  outline: 2px solid #3b82f6;
}

.tool-btn {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.tool-btn:hover {
  background: var(--border);
  transform: translateY(-1px);
}

.tool-btn:active {
  transform: translateY(0);
}

.template-btn {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all 0.2s ease;
}

.template-btn:hover {
  background: var(--border);
  transform: translateY(-1px);
}

.template-btn:active {
  transform: translateY(0);
}

.dev-toolbar {
  border-bottom: 1px solid var(--border);
}

.toolbar-section {
  margin-bottom: 0.5rem;
}

.toolbar-section:last-child {
  margin-bottom: 0;
}

.analysis-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin: 0.5rem 0;
}

.analysis-score {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.score-excellent {
  color: #10b981;
}
.score-good {
  color: #f59e0b;
}
.score-poor {
  color: #ef4444;
}

.analysis-issues {
  margin-top: 0.5rem;
}

.issue-item {
  padding: 0.25rem 0;
  border-left: 3px solid var(--border);
  padding-left: 0.5rem;
  margin: 0.25rem 0;
}

.issue-error {
  border-left-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.issue-warning {
  border-left-color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

.issue-suggestion {
  border-left-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
}

@media (prefers-color-scheme: light) {
  .tool-btn,
  .template-btn {
    background: rgba(59, 130, 246, 0.1);
    color: #1e293b;
    border-color: rgba(59, 130, 246, 0.2);
  }

  .tool-btn:hover,
  .template-btn:hover {
    background: rgba(59, 130, 246, 0.2);
  }
}
