:root {
  --accent: #c8102e;            /* Swiss red */
  --accent-soft: #c8102e18;
  --background: #faf9f7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-dim: #6b6b6b;
  --border: #e3e0db;
  --user-bubble: #f0ede8;
  --max-width: 760px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #191817;
    --surface: #232120;
    --text: #ece9e4;
    --text-dim: #9b968f;
    --border: #3a3733;
    --user-bubble: #2c2a27;
    --accent-soft: #c8102e30;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--background);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

/* ---------- header ---------- */

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

#top-bar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
}

#auth-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

#user-name {
  color: var(--text-dim);
  font-size: 14px;
}

.pill-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.pill-button:hover { border-color: var(--text-dim); }

/* An explicit display on .pill-button overrides the `hidden` attribute's
   display:none, so re-assert it or the hidden button would still show. */
.pill-button[hidden] { display: none; }

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
}

/* ---------- messages ---------- */

#chat-container {
  flex: 1;
  overflow-y: auto;
}

#messages {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#welcome {
  text-align: center;
  margin-top: 8vh;
}

#welcome h1 { font-size: 26px; margin-bottom: 8px; }
#welcome p { color: var(--text-dim); max-width: 520px; margin: 0 auto 24px; }

/* Two columns so the four example questions keep a fixed 2x2 order:
   French top-left, English top-right, German bottom-left, Italian bottom-right. */
#suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 560px) {
  #suggestions { grid-template-columns: 1fr; }
}

.suggestion {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: center;
}

.suggestion:hover { background: var(--accent-soft); border-color: var(--accent); }

.message { display: flex; }

.message.user { justify-content: flex-end; }

.message.user .bubble {
  background: var(--user-bubble);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 16px;
  max-width: 85%;
  white-space: pre-wrap;
}

.message.assistant { justify-content: flex-start; }

.message.assistant .bubble {
  max-width: 100%;
  width: 100%;
}

/* activity shown while the assistant is working */
.activity {
  color: var(--text-dim);
  font-size: 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.activity .spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  flex: none;
  align-self: center;
  border: 2px solid var(--text-dim);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

details.working-log {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

details.working-log summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}

/* hide the browser's default disclosure triangle */
details.working-log summary::-webkit-details-marker { display: none; }
details.working-log summary::marker { content: ''; }

/* custom chevron that rotates when the log is opened/closed */
details.working-log summary .chevron {
  display: inline-block;
  width: 6px;
  height: 6px;
  flex: none;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
}

details.working-log[open] summary .chevron {
  transform: rotate(45deg);
}

details.working-log li { margin: 3px 0; overflow-wrap: anywhere; }

/* rendered markdown answer */
.answer { overflow-wrap: break-word; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer pre {
  background: var(--user-bubble);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 14px;
}
.answer code { font-size: 0.92em; }
.answer table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.answer th, .answer td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  font-size: 14px;
}
.answer blockquote {
  margin: 0.6em 0;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}
.answer a { color: var(--accent); }

.error-text { color: #c0392b; }

.meta-line {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- input ---------- */

#input-area {
  background: var(--background);
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
}

#chat-form {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 8px 8px 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

#chat-form:focus-within { border-color: var(--accent); }

#question-input {
  flex: 1;
  border: none;
  background: none;
  resize: none;
  font: inherit;
  color: var(--text);
  outline: none;
  max-height: 160px;
  padding: 4px 0;
}

#send-button {
  flex: none;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#send-button:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: default;
}

#footer-note {
  max-width: var(--max-width);
  margin: 8px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  justify-content: center;
  gap: 14px;
}
