:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #16212b;
  --muted: #5d6b78;
  --line: #dde3e9;
  --brand: #0f3b5f;
  --accent: #1f6fb2;
  --user: #0f3b5f;
  --user-text: #ffffff;
  --link-bg: #e8f1fa;
  --warn: #b42318;
  --warn-bg: #fdecea;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1419;
    --surface: #171f27;
    --text: #e6edf3;
    --muted: #93a1ae;
    --line: #26323d;
    --brand: #7cb7ea;
    --accent: #7cb7ea;
    --user: #1f4f7a;
    --user-text: #ffffff;
    --link-bg: #1a2b3b;
    --warn: #ff8a80;
    --warn-bg: #3a1a18;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(120px + env(safe-area-inset-bottom));
}
button { font: inherit; }

.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  flex: none; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--brand); color: var(--bg);
  font-weight: 700; font-size: 20px;
}
.logo.big { width: 52px; height: 52px; font-size: 30px; border-radius: 14px; }
h1 { margin: 0; font-size: 17px; line-height: 1.2; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 6px; flex: none; }
.ghost {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.brand > div { min-width: 0; }
.brand h1, .brand .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.empty { padding: 8vh 0 0; }
.empty h2 { margin: 0 0 4px; font-size: 24px; }
.empty p { margin: 0 0 20px; color: var(--muted); }
.chips { display: grid; gap: 8px; }
.chips button {
  text-align: left; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 12px 14px;
}
.chips button:hover { border-color: var(--accent); }

.msg { margin: 14px 0; }
.msg.user {
  margin-left: auto; max-width: 85%; width: fit-content;
  background: var(--user); color: var(--user-text);
  padding: 10px 14px; border-radius: var(--radius) var(--radius) 4px var(--radius);
  white-space: pre-wrap;
}
.msg.bot {
  background: var(--surface); border: 1px solid var(--line);
  padding: 12px 16px; border-radius: var(--radius) var(--radius) var(--radius) 4px;
  overflow-wrap: anywhere;
}
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body h1, .body h2, .body h3 { font-size: 16px; margin: 16px 0 6px; }
.body blockquote p { margin: 0; }
.body blockquote {
  margin: 10px 0; padding: 8px 12px;
  border-left: 3px solid var(--accent); background: var(--link-bg); border-radius: 0 8px 8px 0;
}
.body table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.body td, .body th { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; }
.body ul, .body ol { padding-left: 22px; }
a.edok {
  color: var(--accent); text-decoration: none;
  background: var(--link-bg); border-radius: 6px; padding: 0 4px;
}
a.edok:hover { text-decoration: underline; }
a.foreign { color: var(--warn); }
.flag {
  display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 6px;
  background: var(--warn-bg); color: var(--warn); font-size: 12px; font-weight: 600;
}

.steps { list-style: none; margin: 0 0 8px; padding: 0; font-size: 13px; color: var(--muted); }
.steps:empty { display: none; }
.steps li::before { content: "↳ "; }
.steps.done { opacity: .75; }
.err { color: var(--warn); margin: 8px 0 0; }

.dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 10px 16px env(safe-area-inset-bottom);
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}
.ask {
  max-width: 760px; margin: 0 auto;
  display: flex; gap: 8px; align-items: flex-end;
}
.ask textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 160px;
  padding: 12px 14px; border-radius: 24px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; box-shadow: 0 4px 16px rgb(0 0 0 / .08);
}
.ask textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.ask button {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand); color: var(--bg); display: grid; place-items: center;
}
.ask button:disabled { opacity: .45; cursor: default; }
.foot { margin: 0; padding: 6px 0 8px; text-align: center; font-size: 12px; color: var(--muted); }

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card {
  width: 100%; max-width: 360px; display: grid; gap: 12px; justify-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 24px;
}
.card h1 { font-size: 22px; }
.card label { display: grid; gap: 4px; width: 100%; font-size: 14px; color: var(--muted); }
.card input {
  width: 100%; padding: 11px 12px; border-radius: 10px; font: inherit;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.card button[type=submit] {
  width: 100%; margin-top: 4px; padding: 12px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--brand); color: var(--bg); font-weight: 600;
}
