:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --panel: #f7f7f8;
  --border: #e3e3e6;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --accent: #2f5fe0;
  --accent-text: #ffffff;
  --user-bubble: #eef2fd;
  --tool-bg: #f0f4ea;
  --tool-border: #d5e0c5;
  --error: #b3261e;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --panel: #1e2024;
    --border: #303339;
    --text: #e8e8ea;
    --muted: #9a9aa2;
    --accent: #5c86ff;
    --user-bubble: #23293a;
    --tool-bg: #1f261c;
    --tool-border: #36452d;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }

/* FONTOS: a .gate / #app sajat display szabalya erosebb a bongeszo
   alapertelmezett [hidden] { display: none } szabalyanal, ezert enelkul a
   hidden attributum hatastalan - a belepteto es a chat egyszerre latszana. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- belépő ---------- */
.gate {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h1 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.error { color: var(--error); font-size: 14px; margin: 0; }

input[type=password], textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  resize: none;
}

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

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-text);
}

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

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 13px;
}

button.ghost:hover { color: var(--text); }

/* ---------- app ---------- */
#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--tool-border);
  background: var(--tool-bg);
  color: var(--muted);
}

.badge.warn { border-color: #e0c07a; background: #fdf6e5; color: #7a5b12; }
@media (prefers-color-scheme: dark) {
  .badge.warn { border-color: #6b5620; background: #2a2413; color: #e6c96f; }
}

main#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg { max-width: 820px; width: 100%; margin: 0 auto; }
.msg.user .bubble {
  background: var(--user-bubble);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-left: auto;
  width: fit-content;
  max-width: 85%;
  white-space: pre-wrap;
}

.msg.assistant .bubble > *:first-child { margin-top: 0; }
.msg.assistant .bubble > *:last-child { margin-bottom: 0; }

.tool {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  font-size: 13px;
  background: var(--tool-bg);
  border: 1px solid var(--tool-border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--muted);
}

.tool code {
  display: block;
  margin-top: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  color: var(--text);
}

.tool.failed { border-color: var(--error); }

.msg.error .bubble {
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: 8px;
  padding: 10px 14px;
}

/* ---------- markdown ---------- */
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: 1.2em 0 .4em; }
.bubble p { margin: .6em 0; }
.bubble ul, .bubble ol { margin: .6em 0; padding-left: 1.4em; }
.bubble li { margin: .2em 0; }
.bubble code {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .9em;
}
.bubble pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}
.bubble pre code { background: none; border: 0; padding: 0; }

.table-wrap { overflow-x: auto; margin: .8em 0; }
.bubble table { border-collapse: collapse; font-size: 14px; }
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}
.bubble th { background: var(--panel); font-weight: 600; }

/* ---------- üres állapot ---------- */
.empty { max-width: 820px; margin: 8vh auto 0; text-align: center; }
.empty h2 { font-weight: 600; font-size: 20px; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.suggestions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 8px 14px;
  text-align: left;
}
.suggestions button:hover { border-color: var(--accent); }

/* ---------- beviteli sáv ---------- */
#composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 20px 20px;
}

#input { max-height: 200px; overflow-y: auto; }

.cursor::after {
  content: "▍";
  animation: blink 1s steps(2) infinite;
  color: var(--muted);
}

@keyframes blink { 50% { opacity: 0; } }
