:root {
  --bg: #ffffff; --panel: #f7f7f8; --text: #1f2328; --muted: #6b7280; --border: #e5e7eb;
  --user: #f0f0f2; --accent: #2b87cc; --accent-text: #fff; --link: #0d8a22; --flag-blue: #6AB2E7; --flag-green: #12AD2B; --flag-red: #D7141A; --hover: #ececf0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121; --panel: #171717; --text: #ececec; --muted: #9a9a9a; --border: #333;
    --user: #2f2f2f; --accent: #6AB2E7; --accent-text: #04202b; --link: #4cd964; --hover: #2a2a2a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* sidebar */
#sidebar {
  width: 260px; flex: none; background: var(--panel); display: flex; flex-direction: column;
  padding: 12px; gap: 8px; transition: margin-left .2s;
}
body.collapsed #sidebar { margin-left: -260px; }
.new-chat {
  text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.new-chat:hover, .chat-item:hover { background: var(--hover); }
.history-label { color: var(--muted); font-size: 12px; padding: 8px 12px 0; }
#history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-radius: 10px; cursor: pointer; font-size: 14px;
}
.chat-item.active { background: var(--hover); }
.chat-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item button { all: unset; cursor: pointer; color: var(--muted); opacity: 0; padding: 0 4px; }
.chat-item:hover button { opacity: 1; }
.side-footer { color: var(--muted); font-size: 12px; padding: 8px; }

/* main */
main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
header .title { font-weight: 600; }
#menu { all: unset; cursor: pointer; padding: 4px 8px; border-radius: 8px; font-size: 18px; }
#menu:hover { background: var(--hover); }

#scroll { flex: 1; overflow-y: auto; }
#empty { text-align: center; padding: 14vh 16px 0; }
#empty.hidden { display: none; }
.logo { width: 72px; height: 72px; }
#empty h1 { margin: 8px 0 0; font-size: 28px; font-weight: 600; }
.sub { color: var(--muted); margin: 4px 0 24px; }
/* a fixed grid: when a chip is translated its box stays where it is, nothing reflows or reorders */
#suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; grid-auto-rows: 56px; max-width: 560px; margin: 0 auto; padding: 0 16px; }
#suggestions button {
  padding: 6px 14px; line-height: 1.3; border: 1px solid var(--border); border-radius: 14px; background: transparent;
  color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
#suggestions button:hover { background: var(--hover); }

#messages { max-width: 768px; margin: 0 auto; padding: 8px 16px 24px; }
.msg { display: flex; gap: 12px; margin: 20px 0; }
.msg .avatar { width: 30px; height: 30px; flex: none; }
.msg .avatar img { width: 30px; height: 30px; display: block; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.msg.user { justify-content: flex-end; }
.msg.user .avatar { display: none; }
.msg.user .col { max-width: 80%; }   /* the limit goes on the column: a % on the bubble itself is measured against a column that shrinks to the text */
.msg.user .body { background: var(--user); padding: 8px 16px; border-radius: 20px; width: fit-content; max-width: 100%; }
.msg.bot .col { flex: 1; }
.typing span {
  display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%;
  background: var(--muted); animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* composer */
#composer { padding: 0 16px 8px; width: 100%; max-width: 800px; margin: 0 auto; }
.box {
  display: flex; align-items: flex-end; gap: 8px; background: var(--user);
  border-radius: 26px; padding: 8px 8px 8px 20px;
}
#input {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; max-height: 200px; padding: 6px 0;
}
#send {
  width: 36px; height: 36px; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-size: 18px; font-weight: 700;
}
#send:disabled { opacity: .3; cursor: default; }
.disclaimer { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 0; }

@media (max-width: 720px) {
  #sidebar { position: fixed; z-index: 2; inset: 0 auto 0 0; }
  #backdrop { position: fixed; inset: 0; z-index: 1; background: rgba(0, 0, 0, .45); display: none; }
  body:not(.collapsed) #backdrop { display: block; }
  #suggestions { grid-template-columns: 1fr; max-width: 360px; }
}

/* answer actions, ads, static pages */
.msg .col { min-width: 0; }
.share {
  all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  margin-top: 8px; padding: 4px 0; font-size: 13px; line-height: 1; color: var(--muted);
}
.share svg { width: 14px; height: 14px; flex: none; }
.share:hover, .share:focus-visible { color: var(--text); }
.share:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.side-footer .links { margin-top: 6px; }
.side-footer a, .page a { color: var(--link); text-decoration: none; }
.side-footer a:hover, .page a:hover { text-decoration: underline; }

.page { max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; }
.page nav { display: flex; gap: 16px; align-items: center; margin-bottom: 24px; font-size: 15px; }
.page nav .brand { font-weight: 700; color: var(--text); margin-right: auto; }
.page h1 { font-size: 30px; margin: 0 0 8px; }
.page h2 { margin-top: 32px; font-size: 20px; }
.page ul { padding-left: 20px; }
.page li { margin: 6px 0; }
.page .meta { color: var(--muted); font-size: 14px; }
body.static { display: block; overflow-y: auto; }

#lang {
  margin-left: auto; background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 8px; font: inherit; font-size: 14px; cursor: pointer; max-width: 50%;
}
#lang option { color: #111; }

.fade { transition: opacity .3s; }
.fade.out { opacity: 0; }


/* brand */
header { border-bottom: 3px solid transparent; border-image: linear-gradient(90deg, var(--flag-blue) 50%, var(--flag-green) 50%) 1; }
.brand-logo { display: block; }
header .title { font-weight: 700; letter-spacing: -0.01em; }
.page nav .brand { display: inline-flex; align-items: center; gap: 8px; }
.page nav .brand img { display: block; }
.new-chat:hover { border-color: var(--flag-green); }
#send:not(:disabled):hover { background: var(--flag-green); color: #fff; }

/* the name in the flag's colours: Dji (blue) bou (green) ti (red) */
/* text shades: the flag's own colours are too dark (red, green) or too pale (blue) to read as small text on one of the two themes */
:root { --brand-blue: #2f86c9; --brand-green: #0e9a26; --brand-red: #d7141a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --brand-blue: #6ab2e7; --brand-green: #3ddc5c; --brand-red: #ff5d62; } }
.brand-name .c1 { color: var(--brand-blue); }
.brand-name .c2 { color: var(--brand-green); }
.brand-name .c3 { color: var(--brand-red); }
.page nav .brand .brand-name { font-weight: 700; }

/* tip jar */
.tip { display: block; margin: 4px 4px 0; padding: 9px 12px; border-radius: 10px; border: 1px dashed var(--border); color: var(--text); font-size: 13px; text-decoration: none; line-height: 1.3; }
.tip[hidden] { display: none; }
.tip:hover { border-color: var(--flag-green); background: var(--hover); }

/* credit */
.side-footer .made-by { margin-top: 8px; }
.side-footer .made-by a { font-weight: 600; }
.page-footer { max-width: 720px; margin: 0 auto; padding: 0 16px 40px; color: var(--muted); font-size: 14px; }
.page-footer a { color: var(--link); text-decoration: none; font-weight: 600; }

/* the credit sits under the message box, right below the disclaimer */
.composer-credit { text-align: center; color: var(--muted); font-size: 12px; padding: 0 0 10px; }
.composer-credit a { color: var(--link); text-decoration: none; font-weight: 600; }
.composer-credit a:hover { text-decoration: underline; }
