:root {
  --bg: #f4f2ee;
  --bg-soft: #efece6;
  --card: #ffffff;
  --ink: #2a2724;
  --muted: #8b857d;
  --faint: #b4afa6;
  --border: #e7e2da;
  --border-strong: #d8d2c8;
  --accent: #c4623f;
  --accent-hover: #ad5232;
  --accent-ink: #ffffff;
  --accent-tint: #f6e7e0;
  --violet: #6d5bd0;
  --violet-tint: #ece9fa;
  --user-bg: #efe9e2;
  --tool-bg: #eef3ee;
  --tool-ink: #3f6b4e;
  --success: #3f8f5f;
  --error: #c0503a;
  --ring: rgba(196, 98, 63, .18);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(40,35,30,.04), 0 8px 30px rgba(40,35,30,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #201f1d; --bg-soft: #262523; --card: #2c2b28; --ink: #ece9e4;
    --muted: #a09a91; --faint: #736e66; --border: #3b3934; --border-strong: #4a4842;
    --accent: #d4744f; --accent-hover: #c2643f; --accent-tint: #3a2b24;
    --violet: #9b8bef; --violet-tint: #2e2a44;
    --user-bg: #38352f; --tool-bg: #29332b; --tool-ink: #8fcaa2;
    --success: #6cc088; --error: #e0755c; --ring: rgba(212,116,79,.25);
    --shadow: 0 1px 2px rgba(0,0,0,.2), 0 10px 34px rgba(0,0,0,.28);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* атрибут hidden должен перекрывать display:flex у .lang-menu/.attachments/.error-msg */
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1100px 600px at 100% -10%, var(--accent-tint), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--violet-tint), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- icons ---------- */
.icon { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex: none; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 26px; height: 26px; }

/* ---------- top bar / language switcher ---------- */
.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: flex-end; padding: 18px 20px; }
.lang { position: relative; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--card) 82%, transparent); color: var(--ink);
  font: inherit; font-size: 14px; backdrop-filter: blur(8px);
}
.lang-btn:hover { border-color: var(--accent); }
.lang-btn .lang-cur { font-weight: 500; }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; z-index: 10;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.lang-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 10px; border: none; background: none; border-radius: 9px; cursor: pointer;
  font: inherit; font-size: 14px; color: var(--ink); text-align: left;
}
.lang-item:hover { background: var(--bg-soft); }
.lang-item.active { color: var(--accent); font-weight: 500; }

/* ---------- centered auth cards ---------- */
.centered { display: flex; min-height: 100%; align-items: center; justify-content: center; padding: 88px 24px 40px; }
.card {
  width: 100%; max-width: 400px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 34px 30px; box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-badge {
  width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-tint); color: var(--accent);
}
.brand-badge.violet { background: var(--violet-tint); color: var(--violet); }
.brand h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: -6px; }

/* icon-prefixed input field */
.field {
  display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg-soft);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field:focus-within { border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 4px var(--ring); }
.field .icon { color: var(--faint); }
.field:focus-within .icon { color: var(--accent); }
.field input {
  flex: 1; border: none; background: none; outline: none; min-width: 0;
  font: inherit; font-size: 15px; color: var(--ink);
}
.field input::placeholder { color: var(--faint); }
.field .toggle { border: none; background: none; cursor: pointer; color: var(--faint); padding: 4px; display: flex; }
.field .toggle:hover { color: var(--ink); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 18px; border: none; border-radius: var(--radius); cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-size: 15px; font-weight: 600;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.99); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border-strong); font-weight: 500; }
.btn.ghost:hover { background: var(--bg-soft); color: var(--ink); }
.btn.icon-only { width: 48px; padding: 0; }

.note { margin: 20px 0 0; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.6; }
.error-msg { display: flex; align-items: center; gap: 8px; color: var(--error); font-size: 14px; margin: 2px 0 0; }
.error-msg .icon { flex: none; }

/* ---------- chat ---------- */
.chat-app { display: flex; flex-direction: column; height: 100dvh; max-width: 920px; margin: 0 auto; background: color-mix(in srgb, var(--card) 40%, transparent); }
.chat-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px);
}
.chat-id { display: flex; align-items: center; gap: 11px; }
.chat-id .brand-badge { width: 40px; height: 40px; border-radius: 12px; margin: 0; }
.chat-id strong { display: block; font-size: 15px; font-weight: 600; }
.chat-id .status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.chat-id .status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.chat-id .status.on::before { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 25%, transparent); }
.header-actions { display: flex; align-items: center; gap: 8px; }

.messages { flex: 1; overflow-y: auto; padding: 22px 18px; display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 86%; display: flex; flex-direction: column; gap: 5px; }
.msg .role { font-size: 12px; color: var(--muted); padding: 0 4px; }
.msg .bubble { padding: 12px 15px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; border: 1px solid transparent; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: var(--user-bg); border-color: var(--border); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; }
.msg.assistant .bubble { background: var(--card); border-color: var(--border); border-bottom-left-radius: 5px; box-shadow: var(--shadow); }
.msg.error .bubble { background: transparent; border-color: var(--error); color: var(--error); }

.tool {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; align-self: flex-start;
  background: var(--tool-bg); color: var(--tool-ink); border-radius: 10px; padding: 7px 11px; font-size: 13px;
  border: 1px solid color-mix(in srgb, var(--tool-ink) 22%, transparent);
}
.tool summary { cursor: pointer; font-weight: 500; list-style: none; display: inline-flex; align-items: center; gap: 8px; }
.tool summary::-webkit-details-marker { display: none; }
.tool pre { font-family: var(--mono); font-size: 12px; overflow-x: auto; margin: 8px 0 0; color: var(--ink); }

.typing { display: inline-flex; gap: 4px; padding: 12px 15px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.composer { display: flex; flex-direction: column; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); }
.composer.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: 12px; }
.composer-row { display: flex; align-items: flex-end; gap: 10px; }
.composer .field { flex: 1; height: auto; align-items: flex-end; padding: 10px 14px; border-radius: 14px; }
.composer textarea {
  flex: 1; resize: none; border: none; background: none; outline: none; min-width: 0;
  font: inherit; font-size: 15px; color: var(--ink); max-height: 200px; line-height: 1.5;
}
.composer .btn.icon-only { height: 48px; border-radius: 14px; }

/* attachment previews */
.attachments { display: flex; flex-wrap: wrap; gap: 10px; }
.attachment { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border-strong); }
.attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment .remove {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%;
  border: none; cursor: pointer; background: rgba(20,18,16,.62); color: #fff;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.attachment .remove .icon { width: 13px; height: 13px; }

/* images inside chat bubbles */
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; }
.msg-images img { max-width: 220px; max-height: 220px; border-radius: 12px; border: 1px solid var(--border); display: block; cursor: pointer; }

/* question with clickable options (Desktop-style) */
.askui { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.askui-q { font-size: 14px; font-weight: 500; color: var(--ink); }
.askui-opts { display: flex; flex-direction: column; gap: 8px; }
.askui-opt {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  padding: 11px 14px; border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--card); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
  transition: border-color .12s, background .12s, transform .05s;
}
.askui-opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-tint); }
.askui-opt:active:not(:disabled) { transform: scale(.995); }
.askui-opt.check { cursor: pointer; }
.askui-opt.check input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.askui-opt.chosen { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); font-weight: 500; }
.askui.answered .askui-opt:not(.chosen) { opacity: .55; }
.askui-submit { align-self: flex-start; height: 40px; padding: 0 16px; font-size: 14px; }
.askui-other {
  align-self: flex-start; border: none; background: none; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 13px; padding: 2px 4px; text-decoration: underline;
}
.askui-other:hover { color: var(--accent); }
.askui.answered .askui-other { display: none; }
