:root {
  --bg: #111318;
  --surface: #1a1d24;
  --surface-2: #232730;
  --text: #e6e8ee;
  --muted: #9aa1b1;
  --accent: #7aa2f7;
  --accent-text: #0b1020;
  --error: #f7768e;
  --radius: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eceef2;
    --text: #14171d;
    --muted: #5d6472;
    --accent: #2f5fd0;
    --accent-text: #ffffff;
    --error: #c1344e;
  }
}

* { box-sizing: border-box; }

/* Musí přebít i selektory podle id (#chat má display:flex), jinak by se
   skrytá sekce vykreslovala dál. Proto !important, ne vyšší specificita —
   tohle má platit pro cokoli, co dostane atribut hidden. */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Bez tohohle iOS při psaní zvětšuje celou stránku. */
  -webkit-text-size-adjust: 100%;
}

/* ---------- přihlášení ---------- */

#login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.login-box { width: min(360px, 100%); text-align: center; }
.login-box h1 { margin: 0 0 4px; font-size: 28px; }
.muted { color: var(--muted); margin-top: 0; }

#login-form { display: grid; gap: 10px; margin-top: 24px; }

input, textarea, button {
  font: inherit;
  color: inherit;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

input, textarea {
  background: var(--surface);
  border-color: var(--surface-2);
  padding: 13px 15px;
  width: 100%;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 13px 16px;
  font-weight: 600;
  cursor: pointer;
}

button:disabled { opacity: .5; cursor: default; }

.error { color: var(--error); margin-top: 14px; }

/* ---------- chat ---------- */

#chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
}

/* Vlevo přepínač konverzací, vpravo odhlášení — nic víc. */

.switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text);
  padding: 6px 4px;
  font-size: 15px;
  font-weight: 600;
  min-width: 0;
}

#conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 52vw;
}

.chevron { color: var(--muted); font-size: 12px; flex: none; }

/* Stav spojení jako tečka, ať hlavičku nezaplevelí text. */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
  transition: background .2s;
}

.dot.online { background: #6ecf8e; }
.dot.offline { background: var(--error); }

#logout {
  background: var(--surface-2);
  color: var(--text);
  padding: 7px 12px;
  font-size: 14px;
  font-weight: 500;
  flex: none;
}

.drawer {
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
  max-height: 55dvh;
  overflow-y: auto;
}

.drawer-new {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--accent);
  border-radius: 0;
  padding: 14px;
  font-weight: 600;
}

#conversation-list { list-style: none; margin: 0; padding: 0 0 6px; }

#conversation-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border-radius: 0;
  padding: 11px 14px;
  font-weight: 400;
}

#conversation-list button.active { background: var(--surface-2); }
#conversation-list .when { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
#conversation-list .empty { color: var(--muted); padding: 0 14px 12px; font-size: 14px; }

.banner {
  padding: 10px 14px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 85%;
  padding: 11px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.msg.bot { align-self: flex-start; background: var(--surface); }
.msg.err { align-self: flex-start; background: var(--surface); color: var(--error); }

.msg.tool {
  align-self: flex-start;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}

.msg .commit { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }

/* Blikající kurzor, dokud odpověď proudí. */
.msg.streaming::after {
  content: "▋";
  color: var(--muted);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

#composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
}

#input {
  flex: 1;
  resize: none;
  max-height: 140px;
  background: var(--bg);
}

#composer button {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  flex: none;
}

#abort { background: var(--error); color: #fff; }

/* ---------- vykreslený markdown ---------- */

.msg.md { white-space: normal; }
.msg.md > :first-child { margin-top: 0; }
.msg.md > :last-child { margin-bottom: 0; }
.msg.md p { margin: 0 0 8px; }
.msg.md h1, .msg.md h2, .msg.md h3 { margin: 12px 0 6px; font-size: 1.05em; line-height: 1.3; }
.msg.md ul, .msg.md ol { margin: 0 0 8px; padding-left: 20px; }
.msg.md li { margin: 2px 0; }
.msg.md strong { font-weight: 650; }

.msg.md code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: .9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.msg.md pre {
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 0 0 8px;
}

.msg.md pre code { background: none; padding: 0; }

.msg.md blockquote {
  margin: 0 0 8px;
  padding-left: 10px;
  border-left: 3px solid var(--surface-2);
  color: var(--muted);
}

.msg.md a { color: var(--accent); }
