/* ==========================================================================
   NikoGPT web — themes, layout and components.
   Theme variables live under html[data-theme="…"]; font size under
   html[data-fs="s|m|l|xl"].
   ========================================================================== */

:root {
  --fs: 16px;
  --fs-sm: calc(var(--fs) - 2px);
  --fs-xs: calc(var(--fs) - 3px);
  --radius: 14px;
  --thread-width: 780px;
}

/* ---------- themes: simple ---------- */

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --side: #f9f9f9;
  --side-hover: #ececec;
  --side-active: #e3e3e3;
  --text: #0d0d0d;
  --muted: #8e8e8e;
  --border: #e5e5e5;
  --bubble: #f4f4f4;
  --accent: #0d0d0d;
  --accent-text: #ffffff;
  --code-bg: #f6f6f6;
  --danger: #d64545;
  --link: #1a6ed8;
  --shadow: 0 4px 16px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #212121;
    --side: #171717;
    --side-hover: #272727;
    --side-active: #2f2f2f;
    --text: #ececec;
    --muted: #9b9b9b;
    --border: #333333;
    --bubble: #2f2f2f;
    --accent: #ececec;
    --accent-text: #171717;
    --code-bg: #171717;
    --danger: #ff7b7b;
    --link: #7ab8ff;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212121;
  --side: #171717;
  --side-hover: #272727;
  --side-active: #2f2f2f;
  --text: #ececec;
  --muted: #9b9b9b;
  --border: #333333;
  --bubble: #2f2f2f;
  --accent: #ececec;
  --accent-text: #171717;
  --code-bg: #171717;
  --danger: #ff7b7b;
  --link: #7ab8ff;
}

:root[data-theme="black"] {
  color-scheme: dark;
  --bg: #000000;
  --side: #050505;
  --side-hover: #141414;
  --side-active: #1d1d1d;
  --text: #f2f2f2;
  --muted: #8a8a8a;
  --border: #232323;
  --bubble: #1a1a1a;
  --accent: #ffffff;
  --accent-text: #000000;
  --code-bg: #0d0d0d;
  --danger: #ff6b6b;
  --link: #6db3ff;
}

:root[data-theme="gray"] {
  color-scheme: dark;
  --bg: #2e3033;
  --side: #26282b;
  --side-hover: #35383c;
  --side-active: #3d4145;
  --text: #e6e7e9;
  --muted: #9fa4a9;
  --border: #42464a;
  --bubble: #383b3f;
  --accent: #d0d3d6;
  --accent-text: #232527;
  --code-bg: #26282b;
  --danger: #ef7b7b;
  --link: #8fb8e8;
}

/* ---------- themes: WM / terminal favourites ---------- */

:root[data-theme="adwaita"] {
  color-scheme: light;
  --bg: #ffffff;
  --side: #ebebeb;
  --side-hover: #e0e0e0;
  --side-active: #d6d6d6;
  --text: #2e3436;
  --muted: #77767b;
  --border: #d6d6d6;
  --bubble: #f0efed;
  --accent: #3584e4;
  --accent-text: #ffffff;
  --code-bg: #f6f5f4;
  --danger: #e01b24;
  --link: #1c71d8;
}

:root[data-theme="adwaita-dark"] {
  color-scheme: dark;
  --bg: #242424;
  --side: #303030;
  --side-hover: #3a3a3a;
  --side-active: #444444;
  --text: #ffffff;
  --muted: #b5b5b5;
  --border: #444444;
  --bubble: #303030;
  --accent: #78aeed;
  --accent-text: #1a1a1a;
  --code-bg: #1e1e1e;
  --danger: #ff7b72;
  --link: #78aeed;
}

:root[data-theme="kanagawa"] {
  color-scheme: dark;
  --bg: #1f1f28;
  --side: #16161d;
  --side-hover: #2a2a37;
  --side-active: #363646;
  --text: #dcd7ba;
  --muted: #938aa9;
  --border: #2a2a37;
  --bubble: #2a2a37;
  --accent: #7e9cd8;
  --accent-text: #1f1f28;
  --code-bg: #16161d;
  --danger: #e82424;
  --link: #7fb4ca;
}

:root[data-theme="kanagawa-lotus"] {
  color-scheme: light;
  --bg: #f2ecbc;
  --side: #e7dba0;
  --side-hover: #ded08c;
  --side-active: #d5c57d;
  --text: #545464;
  --muted: #8a8980;
  --border: #d5cea3;
  --bubble: #e4d794;
  --accent: #4d699b;
  --accent-text: #f2ecbc;
  --code-bg: #e7dba0;
  --danger: #c84053;
  --link: #4d699b;
}

:root[data-theme="tokyo-night"] {
  color-scheme: dark;
  --bg: #1a1b26;
  --side: #16161e;
  --side-hover: #24283b;
  --side-active: #2f3549;
  --text: #c0caf5;
  --muted: #565f89;
  --border: #292e42;
  --bubble: #24283b;
  --accent: #7aa2f7;
  --accent-text: #1a1b26;
  --code-bg: #16161e;
  --danger: #f7768e;
  --link: #7dcfff;
}

:root[data-theme="nord"] {
  color-scheme: dark;
  --bg: #2e3440;
  --side: #292e39;
  --side-hover: #3b4252;
  --side-active: #434c5e;
  --text: #eceff4;
  --muted: #8f9bb0;
  --border: #3b4252;
  --bubble: #3b4252;
  --accent: #88c0d0;
  --accent-text: #2e3440;
  --code-bg: #292e39;
  --danger: #bf616a;
  --link: #88c0d0;
}

:root[data-theme="gruvbox"] {
  color-scheme: dark;
  --bg: #282828;
  --side: #1d2021;
  --side-hover: #3c3836;
  --side-active: #504945;
  --text: #ebdbb2;
  --muted: #928374;
  --border: #3c3836;
  --bubble: #3c3836;
  --accent: #fabd2f;
  --accent-text: #282828;
  --code-bg: #1d2021;
  --danger: #fb4934;
  --link: #83a598;
}

:root[data-theme="catppuccin-mocha"] {
  color-scheme: dark;
  --bg: #1e1e2e;
  --side: #181825;
  --side-hover: #313244;
  --side-active: #45475a;
  --text: #cdd6f4;
  --muted: #7f849c;
  --border: #313244;
  --bubble: #313244;
  --accent: #cba6f7;
  --accent-text: #1e1e2e;
  --code-bg: #181825;
  --danger: #f38ba8;
  --link: #89b4fa;
}

:root[data-theme="catppuccin-latte"] {
  color-scheme: light;
  --bg: #eff1f5;
  --side: #e6e9ef;
  --side-hover: #dce0e8;
  --side-active: #ccd0da;
  --text: #4c4f69;
  --muted: #8c8fa1;
  --border: #ccd0da;
  --bubble: #e6e9ef;
  --accent: #8839ef;
  --accent-text: #eff1f5;
  --code-bg: #e6e9ef;
  --danger: #d20f39;
  --link: #1e66f5;
}

:root[data-theme="dracula"] {
  color-scheme: dark;
  --bg: #282a36;
  --side: #21222c;
  --side-hover: #343746;
  --side-active: #44475a;
  --text: #f8f8f2;
  --muted: #6272a4;
  --border: #44475a;
  --bubble: #44475a;
  --accent: #bd93f9;
  --accent-text: #282a36;
  --code-bg: #21222c;
  --danger: #ff5555;
  --link: #8be9fd;
}

/* ---------- font size ---------- */
:root[data-fs="s"] { --fs: 14px; }
:root[data-fs="m"] { --fs: 16px; }
:root[data-fs="l"] { --fs: 18px; }
:root[data-fs="xl"] { --fs: 20px; }

/* ---------- base ---------- */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--link); }
.hidden { display: none !important; }
.sprite { display: none; }
.ico { width: 18px; height: 18px; flex: none; display: block; }
svg { fill: none; }
.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;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- auth ---------- */

#auth {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 28px; font-weight: 650; letter-spacing: -.3px; margin-bottom: 28px;
}
.auth-card .brand .ico { width: 26px; height: 26px; }
.tabs {
  display: flex; gap: 4px; background: var(--side);
  border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 20px;
}
.tabs button {
  flex: 1; border: 0; background: none; color: var(--muted);
  border-radius: 9px; padding: 9px; font-weight: 550;
}
.tabs button.active {
  background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.field { margin-bottom: 12px; }
.field label { display: block; font-size: var(--fs-sm); color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 13px;
}
.field input:focus { outline: none; border-color: var(--muted); }
.btn {
  width: 100%; border: 0; border-radius: 10px; padding: 11px 14px;
  font-weight: 600; background: var(--accent); color: var(--accent-text); margin-top: 4px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--side); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.link { background: none; color: var(--muted); font-weight: 500; margin-top: 10px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  margin-top: 14px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); text-decoration: none;
}
.google-btn:hover { background: var(--side-hover); }
.google-btn .ico { width: 17px; height: 17px; }
.btn.small { width: auto; padding: 7px 13px; font-size: var(--fs-sm); font-weight: 550; }
.account-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.account-row .hint { margin: 0; flex: 1; min-width: 0; }
.danger-text { color: var(--danger); }
#delete-account { margin-top: 8px; }
.auth-note { text-align: center; color: var(--muted); font-size: var(--fs-sm); margin: 14px 0 0; }
.auth-error {
  color: var(--danger); font-size: var(--fs-sm); text-align: center;
  margin: 12px 0 0; min-height: 18px; white-space: pre-wrap;
}
.code-input { letter-spacing: 6px; text-align: center; font-size: 20px !important; }

/* ---------- app layout ---------- */

#app { height: 100dvh; display: flex; }
#backdrop {
  position: fixed; inset: 0; z-index: 19; background: rgba(0, 0, 0, .45);
}
#sidebar {
  width: 272px; flex: none; background: var(--side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width .18s ease, transform .18s ease;
  z-index: 20; overflow: hidden;
}
.desktop-only { display: inline-flex; }
@media (min-width: 861px) {
  body.sidebar-hidden #sidebar { width: 62px; border-right: 1px solid var(--border); }
  body.sidebar-hidden .brand-text,
  body.sidebar-hidden #search-toggle,
  body.sidebar-hidden #collapse-sidebar,
  body.sidebar-hidden .side-search,
  body.sidebar-hidden #chat-list,
  body.sidebar-hidden .side-foot .who,
  body.sidebar-hidden #logout { display: none; }
  body.sidebar-hidden .side-head {
    flex-direction: column; align-items: center; gap: 6px; padding: 10px 0 2px;
  }
  /* The logo and "new chat" are the same 42x42 square with the same hitbox. */
  body.sidebar-hidden .side-head .brand,
  body.sidebar-hidden .new-chat-row {
    width: 42px; height: 42px; flex: none; margin: 0; padding: 0;
    justify-content: center; border-radius: 12px;
  }
  body.sidebar-hidden .side-head .brand .ico,
  body.sidebar-hidden .new-chat-row .ico { width: 19px; height: 19px; }
  body.sidebar-hidden .side-new { padding: 2px 0 6px; display: flex; justify-content: center; }
  body.sidebar-hidden .new-chat-row span { display: none; }
  /* The account avatar sits at the very bottom of the rail. */
  body.sidebar-hidden .side-foot {
    margin-top: auto; justify-content: center;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    border-top: 0;
  }
  body.sidebar-hidden .user-btn {
    flex: none; width: 42px; height: 42px; padding: 0;
    justify-content: center; border-radius: 12px;
  }
  body.sidebar-hidden .user-btn .ico { display: none; }
  body.sidebar-hidden .avatar-sm { width: 34px; height: 34px; }
}
@media (max-width: 860px) {
  .desktop-only { display: none !important; }
}
.side-head {
  display: flex; align-items: center; gap: 2px;
  padding: calc(10px + env(safe-area-inset-top)) 8px 4px 12px;
}
.side-head .brand {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  font-weight: 650; font-size: var(--fs); flex: 1; letter-spacing: -.2px;
  border: 0; background: none; color: var(--text); text-align: left;
  border-radius: 10px; padding: 6px 8px; margin-left: -4px;
}
.side-head .brand:hover { background: var(--side-hover); }
.side-head .brand .ico { width: 19px; height: 19px; }
.side-head .icon-btn { width: 34px; height: 34px; }
.brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-new { padding: 4px 10px 6px; }
.new-chat-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: none; color: var(--text); text-align: left;
  border-radius: 10px; padding: 10px 10px; font-size: var(--fs-sm); font-weight: 550;
}
.new-chat-row:hover { background: var(--side-hover); }
.new-chat-row .ico { width: 17px; height: 17px; flex: none; }
.icon-btn {
  width: 38px; height: 38px; flex: none; display: inline-flex;
  align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px;
}
.icon-btn:hover { background: var(--side-hover); }
.icon-btn.ghost { border: 0; background: none; color: var(--muted); width: 36px; height: 36px; }
.icon-btn.ghost:hover { color: var(--text); background: var(--side-hover); }
.side-search { padding: 2px 12px 8px; }
#search-toggle.active { background: var(--side-active); }
.side-search input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 11px; font-size: var(--fs-sm); outline: none;
}
.side-search input:focus { border-color: var(--muted); }
#chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; overscroll-behavior: contain; }
.search-hit {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  color: var(--text); border-radius: 9px; padding: 8px 10px; margin-bottom: 2px;
}
.search-hit:hover { background: var(--side-hover); }
.search-hit .hit-chat {
  font-size: var(--fs-xs); color: var(--muted); margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-hit .hit-snippet {
  font-size: var(--fs-sm); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.search-hit mark {
  background: var(--accent); color: var(--accent-text);
  border-radius: 3px; padding: 0 2px;
}
.stream-dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--accent); animation: blink 1.2s infinite ease-in-out;
}
/* loading skeleton shown while a freshly opened chat is fetched */
.skeleton {
  max-width: var(--thread-width); margin: 0 auto;
  display: flex; flex-direction: column; gap: 14px; padding-top: 10px;
}
.sk-line {
  height: 14px; border-radius: 7px;
  background: linear-gradient(90deg, var(--side) 25%, var(--side-hover) 50%, var(--side) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.sk-line.w60 { width: 60%; }
.sk-line.w85 { width: 85%; }
.sk-line.w45 { width: 45%; }
.sk-line.w75 { width: 75%; }
@keyframes flashmsg {
  0% { background: var(--side-active); }
  100% { background: transparent; }
}
.msg.flash .content, .msg.flash .bubble { animation: flashmsg 1.5s ease-out both; border-radius: 10px; }
.act.cost { margin-left: auto; cursor: default; color: var(--muted); }
.act.cost:hover { background: none; }
.group-label {
  font-size: var(--fs-xs); color: var(--muted); font-weight: 600;
  padding: 12px 10px 4px; letter-spacing: .02em;
}
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 10px;
  border-radius: 10px; cursor: pointer; margin-bottom: 2px; min-height: 40px;
}
.chat-item:hover { background: var(--side-hover); }
.chat-item.active { background: var(--side-active); }
.chat-item .title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: var(--fs-sm);
}
.chat-item .del {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: none; color: var(--muted); padding: 6px; border-radius: 8px;
  visibility: hidden;
}
.chat-item .del .ico { width: 16px; height: 16px; }
.chat-item:hover .del, .chat-item:focus-within .del { visibility: visible; }
.chat-item .del:hover { color: var(--danger); background: var(--side-active); }
.side-empty { color: var(--muted); font-size: var(--fs-sm); text-align: center; padding: 24px 12px; }
.side-foot {
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px;
}
.user-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  border: 0; background: none; border-radius: 10px; padding: 6px 8px; text-align: left;
}
.user-btn:hover { background: var(--side-hover); }
.user-btn .ico { width: 16px; height: 16px; color: var(--muted); }
.avatar-sm {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: var(--fs-sm); text-transform: uppercase;
}
.side-foot .who { flex: 1; min-width: 0; }
.side-foot .who .name {
  display: block; font-size: var(--fs-sm); font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-foot .who .mail {
  display: block; font-size: var(--fs-xs); color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- main column ---------- */

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.chat-title {
  flex: 1; min-width: 0; font-weight: 600; font-size: var(--fs-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.model-picker { position: relative; }
.model-btn {
  display: inline-flex; align-items: center; gap: 7px; max-width: 52vw;
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 9px;
  background: var(--bg); color: var(--text); font-size: var(--fs-sm);
}
.model-btn:hover { background: var(--side-hover); }
.model-btn .ico { width: 15px; height: 15px; color: var(--muted); }
.model-btn .model-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34vw;
}
.model-btn .eye { color: var(--accent); }
.model-btn .chevron { width: 13px; height: 13px; }
.model-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
  min-width: 250px; max-width: min(380px, 86vw); max-height: 330px; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
  padding: 5px; display: flex; flex-direction: column; gap: 2px;
}
.model-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: none; color: var(--text); text-align: left;
  border-radius: 8px; padding: 9px 10px; font-size: var(--fs-sm);
}
.model-item:hover { background: var(--side-hover); }
.model-item .name {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-item .ico { width: 14px; height: 14px; flex: none; }
.model-item .eye { color: var(--accent); }
.model-item .check { color: var(--accent); opacity: 0; }
.model-item.selected .check { opacity: 1; }
.only-mobile { display: none; }

#messages {
  flex: 1; overflow-y: auto; padding: 26px 16px 10px;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
.thread {
  max-width: var(--thread-width); margin: 0 auto;
  display: flex; flex-direction: column; gap: 26px;
}

/* ---------- welcome / empty ---------- */

.empty {
  min-height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; text-align: center;
  padding: 24px 8px;
}
.empty .logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 32px; font-weight: 650; letter-spacing: -.4px; color: var(--text);
}
.empty .logo .ico { width: 30px; height: 30px; }
.empty .hello { color: var(--muted); font-size: var(--fs); margin: 0 0 18px; }
.suggestions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px; max-width: 720px; width: 100%;
}
.sugg {
  text-align: left; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--side); padding: 13px 15px; color: var(--text);
  font-size: var(--fs-sm); line-height: 1.45;
}
.sugg:hover { background: var(--side-hover); }
.sugg b { display: block; font-weight: 600; margin-bottom: 3px; }
.sugg span { color: var(--muted); }

/* ---------- messages ---------- */

.msg { display: flex; flex-direction: column; min-width: 0; }
.msg.user { align-items: flex-end; }
.msg .bubble {
  max-width: min(82%, 640px); background: var(--bubble);
  border-radius: 18px; padding: 11px 16px; white-space: pre-wrap;
  overflow-wrap: anywhere; font-size: var(--fs);
}
.msg.bot { align-items: stretch; }
.msg .content { overflow-wrap: anywhere; max-width: 100%; }
.msg .content p { margin: 0 0 12px; }
.msg .content > *:last-child { margin-bottom: 0; }
.msg .media { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.msg .media img {
  max-width: min(420px, 100%); border-radius: 12px;
  border: 1px solid var(--border); display: block;
}
.msg .media a.file {
  color: inherit; text-decoration: none; border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: var(--fs-sm);
  background: var(--side);
}
.notes {
  color: var(--muted); font-size: var(--fs-sm); margin-top: 8px;
  white-space: pre-wrap;
}
/* progress timeline: web-specific, replaces messenger status lines */
.activity { margin-bottom: 10px; display: flex; flex-direction: column; gap: 2px; }
.step {
  display: flex; align-items: center; gap: 9px;
  color: var(--muted); font-size: var(--fs-sm); min-height: 22px;
}
.step .ico { width: 16px; height: 16px; flex: none; opacity: .75; }
.step.active { color: var(--text); }
.step.active .ico { opacity: 1; color: var(--accent); }
.step.active .step-text {
  background: linear-gradient(90deg, var(--muted) 0%, var(--text) 45%, var(--muted) 90%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  animation: shimmer 1.5s linear infinite;
}
.step .spinner {
  width: 12px; height: 12px; margin-left: 2px; flex: none;
  border: 2px solid var(--border); border-top-color: var(--muted);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.step.done .ico { opacity: .45; }
.step .check { width: 13px; height: 13px; margin-left: 2px; opacity: .65; }
.trail { margin: 0 0 12px; color: var(--muted); font-size: var(--fs-xs); }
.trail > summary {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  list-style: none; padding: 3px 0; border-radius: 7px;
}
.trail > summary::-webkit-details-marker { display: none; }
.trail > summary:hover { color: var(--text); }
.trail > summary .ico { width: 14px; height: 14px; }
.trail ol {
  margin: 6px 0 0; padding: 0 0 0 2px; list-style: none;
  display: flex; flex-direction: column; gap: 4px;
}
.trail li { display: flex; align-items: center; gap: 8px; }
.trail li .ico { width: 14px; height: 14px; opacity: .6; }
/* stream caret removed: the blur-in of fresh letters is the live indicator */

.actions {
  display: flex; gap: 2px; margin-top: 8px; opacity: 0;
  transition: opacity .12s ease;
}
.msg:hover .actions, .msg:focus-within .actions, .msg.actions-open .actions { opacity: 1; }
.act {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; background: none; color: var(--muted);
  border-radius: 8px; padding: 5px 8px; font-size: var(--fs-xs);
}
.act:hover { background: var(--side-hover); color: var(--text); }
.act .ico { width: 14px; height: 14px; }
.act.danger:hover { color: var(--danger); }

.edit-box { display: flex; flex-direction: column; gap: 8px; width: min(100%, 720px); }
.edit-box textarea {
  width: 100%; resize: vertical; min-height: 72px; max-height: 40dvh;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); padding: 10px 12px; outline: none;
}
.edit-box textarea:focus { border-color: var(--muted); }
.edit-actions { display: flex; gap: 8px; justify-content: flex-end; }
.edit-actions .btn { width: auto; margin: 0; padding: 8px 14px; }

#scroll-down {
  position: absolute; right: 20px; bottom: 128px; z-index: 5;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  box-shadow: var(--shadow); display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- markdown ---------- */

.msg .content h1, .msg .content h2, .msg .content h3, .msg .content h4 {
  margin: 20px 0 10px; line-height: 1.3; font-weight: 650;
}
.msg .content h1 { font-size: calc(var(--fs) + 8px); }
.msg .content h2 { font-size: calc(var(--fs) + 5px); }
.msg .content h3 { font-size: calc(var(--fs) + 2px); }
.msg .content h4 { font-size: var(--fs); }
.msg .content > :first-child { margin-top: 0; }
.msg .content ul, .msg .content ol { margin: 0 0 12px; padding-left: 24px; }
.msg .content li { margin: 3px 0; }
.msg .content li > p { margin: 0; }
.msg .content blockquote {
  margin: 0 0 12px; padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border); color: var(--muted);
}
.msg .content hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.msg .content .table-wrap { overflow-x: auto; margin: 0 0 12px; }
.msg .content table { border-collapse: collapse; }
.msg .content th, .msg .content td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left;
}
.msg .content th { background: var(--side); font-weight: 600; }
.msg .content img { max-width: 100%; border-radius: 10px; }
.msg .content code {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: calc(var(--fs) - 3px);
  line-height: 1.5;
}
/* A code block is one card, not "smeared" inline code: the resets below must
   outrank the inline-code rule above. */
.msg .content pre {
  margin: 0 0 12px; padding: 12px 14px; overflow-x: auto;
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 12px;
}
.msg .content pre code,
.msg .content .code-block pre code {
  background: none; border: 0; border-radius: 0; padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: calc(var(--fs) - 3px);
  line-height: 1.55;
}
/* syntax highlighting: token colours come from per-theme variables */
:root {
  --hl-key: #a626a4; --hl-str: #50a14f; --hl-num: #986801;
  --hl-fn: #4078f2; --hl-var: #e45649; --hl-type: #c18401;
}
:root[data-theme="dark"], :root[data-theme="black"], :root[data-theme="gray"],
:root[data-theme="adwaita-dark"], :root[data-theme="kanagawa"],
:root[data-theme="tokyo-night"], :root[data-theme="nord"], :root[data-theme="gruvbox"],
:root[data-theme="catppuccin-mocha"], :root[data-theme="dracula"] {
  --hl-key: #c678dd; --hl-str: #98c379; --hl-num: #d19a66;
  --hl-fn: #61afef; --hl-var: #e06c75; --hl-type: #e5c07b;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --hl-key: #c678dd; --hl-str: #98c379; --hl-num: #d19a66;
    --hl-fn: #61afef; --hl-var: #e06c75; --hl-type: #e5c07b;
  }
}
.msg .content .katex { font-size: 1.05em; }
.msg .content .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.msg .content .hljs { background: transparent; color: var(--text); }
.msg .content .hljs-comment, .msg .content .hljs-quote { color: var(--muted); font-style: italic; }
.msg .content .hljs-keyword, .msg .content .hljs-selector-tag, .msg .content .hljs-literal,
.msg .content .hljs-section, .msg .content .hljs-doctag, .msg .content .hljs-name { color: var(--hl-key); }
.msg .content .hljs-string, .msg .content .hljs-regexp, .msg .content .hljs-addition,
.msg .content .hljs-attribute { color: var(--hl-str); }
.msg .content .hljs-number, .msg .content .hljs-symbol, .msg .content .hljs-bullet { color: var(--hl-num); }
.msg .content .hljs-title, .msg .content .hljs-title.class_, .msg .content .hljs-title.function_,
.msg .content .hljs-built_in { color: var(--hl-fn); }
.msg .content .hljs-attr, .msg .content .hljs-variable, .msg .content .hljs-template-variable,
.msg .content .hljs-params { color: var(--hl-var); }
.msg .content .hljs-type, .msg .content .hljs-class .hljs-title { color: var(--hl-type); }
.msg .content .hljs-meta, .msg .content .hljs-tag { color: var(--muted); }
.msg .content .hljs-deletion { color: var(--danger); }

.code-block {
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; margin: 0 0 12px; background: var(--code-bg);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: var(--fs-xs);
}
.code-lang { text-transform: lowercase; }
.code-copy {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; background: none; color: var(--muted);
  border-radius: 6px; padding: 3px 7px; font-size: var(--fs-xs);
}
.code-copy:hover { background: var(--side-hover); color: var(--text); }
.code-copy .ico { width: 13px; height: 13px; }
.msg .content .code-block pre {
  margin: 0; padding: 12px 14px; overflow-x: auto;
  background: none; border: 0; border-radius: 0;
}
.msg .content .task-list { list-style: none; padding-left: 4px; }
.msg .content .task-list input { margin-right: 7px; }

/* ---------- composer ---------- */

.composer-wrap {
  padding: 8px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.attach-row {
  max-width: var(--thread-width); margin: 0 auto 8px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--side); padding: 4px 6px 4px 4px; font-size: var(--fs-xs);
  max-width: 240px;
}
.chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 7px; }
.chip .chip-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip .chip-x {
  border: 0; background: none; color: var(--muted);
  padding: 4px; border-radius: 6px; display: inline-flex;
}
.chip .chip-x:hover { color: var(--danger); background: var(--side-hover); }
.chip .chip-x .ico { width: 13px; height: 13px; }
.composer {
  max-width: var(--thread-width); margin: 0 auto;
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 26px; padding: 7px 8px 7px 8px;
  box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; border: 0; background: none; resize: none; outline: none;
  max-height: 180px; padding: 9px 0; font-size: var(--fs);
}
.composer #attach {
  width: 38px; height: 38px;
}
.composer .menu-wrap { margin-bottom: 3px; }
.composer #send.spinning .ico { animation: spin .8s linear infinite; }
.composer #send:disabled { opacity: .4; }
.btn.active { box-shadow: 0 0 0 1px var(--accent) inset; }
.composer #send {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 3px;
  transition: background .15s ease, transform .12s ease;
}
.composer #send:active { transform: scale(.94); }
.composer #send .ico { width: 18px; height: 18px; }
.composer #send.sending { background: var(--danger); color: #ffffff; }
.composer #send.sending .ico { width: 16px; height: 16px; }
.composer #send:disabled { opacity: .35; cursor: default; }
.composer-note {
  max-width: var(--thread-width); margin: 7px auto 0; text-align: center;
  color: var(--muted); font-size: var(--fs-xs);
}

/* ---------- dialogs / toast ---------- */

dialog.dialog {
  border: 0; padding: 0; background: transparent; color: var(--text);
  width: min(600px, calc(100vw - 24px)); max-width: none;
}
dialog.dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog.confirm { width: min(400px, calc(100vw - 24px)); }
.dialog-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
  max-height: min(84dvh, 760px); display: flex; flex-direction: column; overflow: hidden;
}
.confirm .dialog-box { padding: 20px; gap: 8px; }
.confirm h3 { margin: 0 0 4px; font-size: calc(var(--fs) + 2px); }
.confirm p { margin: 0 0 14px; color: var(--muted); font-size: var(--fs-sm); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
}
.dialog-head h3 { margin: 0; font-size: calc(var(--fs) + 2px); }
.dialog-tabs {
  display: flex; gap: 4px; padding: 0 16px 10px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.dialog-tabs::-webkit-scrollbar { display: none; }
.dialog-tabs button {
  flex: none; white-space: nowrap;
  border: 0; background: none; color: var(--muted);
  padding: 7px 12px; border-radius: 9px; font-weight: 550; font-size: var(--fs-sm);
}
.dialog-tabs button.active { background: var(--side-active); color: var(--text); }
.dialog-body { padding: 16px; overflow-y: auto; overscroll-behavior: contain; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-actions .btn { width: auto; margin: 0; padding: 9px 16px; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.hint { color: var(--muted); font-size: var(--fs-sm); margin: 12px 0 0; }
.invisible { visibility: hidden; }
#usage-box { min-height: 210px; }
.app-card {
  display: flex; align-items: center; gap: 13px;
  border: 1px solid var(--border); border-radius: 13px;
  background: var(--side); padding: 13px 15px;
}
.app-icon {
  width: 46px; height: 46px; flex: none; border-radius: 12px;
  background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
}
.app-icon .ico { width: 24px; height: 24px; }
.app-name { font-weight: 600; }
.app-desc { color: var(--muted); font-size: var(--fs-sm); margin-top: 2px; }
.app-download {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 16px; text-decoration: none;
}
.app-download .ico { width: 17px; height: 17px; }
/* composer actions menu (Прикрепить файл / Сжать контекст) */
.menu-wrap { position: relative; flex: none; }
.chat-menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 30;
  min-width: 220px; padding: 5px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; gap: 2px;
  animation: pop .12s ease-out both; transform-origin: bottom left;
}
.chat-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: none; color: var(--text); text-align: left;
  border-radius: 8px; padding: 10px; font-size: var(--fs-sm);
}
.chat-menu button:hover { background: var(--side-hover); }
.chat-menu .ico { width: 16px; height: 16px; color: var(--muted); }
/* ask_user question card (pauses the turn until answered) */
.question-card {
  display: flex; flex-direction: column; gap: 10px;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; background: var(--bg-soft, transparent);
}
.question-text { font-weight: 550; line-height: 1.45; }
.question-options { display: flex; flex-wrap: wrap; gap: 6px; }
.question-options .btn { white-space: normal; text-align: left; }
.question-custom { display: flex; gap: 6px; }
.question-custom input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  font-size: var(--fs-sm);
}
.question-custom input:focus { outline: none; border-color: var(--accent); }
.question-answered { color: var(--muted); font-size: var(--fs-sm); }
.stat-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm);
}
.stat-row:last-child { border-bottom: 0; }
.stat-value { color: var(--text); font-weight: 550; }
.twofa-qr { margin: 10px 0; background: #fff; padding: 8px; border-radius: 10px; width: fit-content; }
.twofa-secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.twofa-codes {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: var(--fs-sm); line-height: 1.6; margin: 8px 0;
  white-space: pre-wrap; word-break: break-all;
}
.session-row {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; margin-bottom: 6px;
}
.session-info { flex: 1; min-width: 0; }
.session-name { font-size: var(--fs-sm); font-weight: 550; }
.session-info .hint { margin: 2px 0 0; }
.setting-label { font-size: var(--fs-sm); font-weight: 600; margin: 4px 0 10px; }
.setting-label:not(:first-child) { margin-top: 22px; }
.theme-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 8px;
}
.theme-card {
  display: flex; align-items: center; gap: 9px; text-align: left;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 11px; padding: 9px 10px; font-size: var(--fs-xs);
}
.theme-card:hover { border-color: var(--muted); }
.theme-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.theme-swatch {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  border: 1px solid var(--border); position: relative; overflow: hidden;
}
.theme-swatch i {
  position: absolute; right: 4px; bottom: 4px; width: 11px; height: 11px;
  border-radius: 50%; display: block;
}
.segmented {
  display: inline-flex; gap: 4px; background: var(--side);
  border: 1px solid var(--border); border-radius: 11px; padding: 4px; flex-wrap: wrap;
}
.segmented button {
  border: 0; background: none; color: var(--muted);
  border-radius: 8px; padding: 7px 12px; font-size: var(--fs-sm); font-weight: 550;
}
.segmented button.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.usage-row { margin-bottom: 18px; }
.usage-row .usage-line {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: var(--fs-sm); margin-bottom: 6px;
}
.usage-row .usage-line span:last-child { color: var(--muted); }
.bar {
  height: 9px; border-radius: 99px; background: var(--side-active); overflow: hidden;
}
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .3s ease; }
.bar i.warn { background: var(--danger); }
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: var(--fs-sm);
  box-shadow: var(--shadow); max-width: min(90vw, 460px);
}

/* ---------- motion ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes pop {
  from { opacity: 0; transform: scale(.97) translateY(-4px); }
  to { opacity: 1; transform: none; }
}
/* soft streaming: each fresh character materialises out of a heavy blur,
   starting slightly after the previous one so the text flows in sequence */
@keyframes streamAppear {
  0% { opacity: 0; filter: blur(14px); }
  55% { opacity: .55; filter: blur(3px); }
  100% { opacity: 1; filter: blur(0); }
}
.stream-ch {
  display: inline;
  animation: streamAppear .48s ease-out both;
  will-change: filter, opacity;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Small, quick transitions instead of abrupt swaps. Live-appended elements
   carry .enter; initial renders stay instant so opening a chat is not janky. */
.icon-btn, .act, .btn, .chat-item, .sugg, .model-item, .model-btn,
.theme-card, .user-btn, .segmented button, .dialog-tabs button, .tabs button {
  transition: background .13s ease, color .13s ease, border-color .13s ease,
    box-shadow .13s ease, transform .13s ease, opacity .13s ease;
}
.icon-btn:active, .act:active, .btn:active, .sugg:active, .model-item:active,
.theme-card:active, .segmented button:active, .tabs button:active {
  transform: scale(.975);
}
.msg.enter { animation: rise .18s ease-out both; }
#messages .thread { animation: fade .13s ease-out both; }
.chat-item.enter { animation: rise .16s ease-out both; }
.empty .logo { animation: rise .22s ease-out both; }
.empty .hello { animation: rise .22s ease-out .05s both; }
.sugg { animation: rise .22s ease-out both; }
.sugg:nth-child(1) { animation-delay: .05s; }
.sugg:nth-child(2) { animation-delay: .09s; }
.sugg:nth-child(3) { animation-delay: .13s; }
.sugg:nth-child(4) { animation-delay: .17s; }
.sugg:nth-child(5) { animation-delay: .21s; }
.sugg:nth-child(6) { animation-delay: .25s; }
.model-menu { animation: pop .12s ease-out both; transform-origin: top right; }
dialog.dialog[open] .dialog-box { animation: pop .16s ease-out both; }
dialog.dialog[open]::backdrop { animation: fade .16s ease-out both; }
#scroll-down {
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
#scroll-down.show { opacity: 1; transform: none; pointer-events: auto; }
#toast {
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- mobile ---------- */

@media (max-width: 860px) {
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, .18); }
  .only-mobile { display: inline-flex; }
  .msg .bubble { max-width: 92%; }
  #messages { padding: 18px 12px 8px; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
  .composer-note { display: none; }
  dialog.dialog, dialog.confirm {
    width: 100vw; max-width: 100vw; margin: 0;
  }
  dialog.dialog .dialog-box {
    border-radius: 0; border-left: 0; border-right: 0;
    min-height: 100dvh; max-height: 100dvh;
  }
  .theme-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
}

@media (hover: none) {
  .actions { opacity: 1; }
  .chat-item .del { visibility: visible; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: .01ms !important; }
  #messages { scroll-behavior: auto; }
}
