/* Нашми AI — chat app (nashmi.vip/chat) */
@import url("/assets/fonts.css");

:root {
  --serif: "PT Serif", Georgia, serif;
  --sans: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --bg: #F6F3EC; --bg-2: #EFEADF; --paper: #FFFDF8; --side: #FBF8F2;
  --ink: #10172A; --ink-2: #3A4256; --muted: #667085; --faint: #98A0B3;
  --line: #E3DDD0; --line-2: #D6CEBE;
  --cobalt: #1F3F94; --cobalt-2: #2E5BDA; --cobalt-soft: #E8EEFB;
  --gold: #B8862B; --gold-2: #D4A93C; --gold-soft: #F6EDD6;
  --crimson: #B3232D; --crimson-soft: #FBE9EA; --green: #1F7A4D;
  --user: #1F3F94; --on-user: #FFFFFF;
  --code-bg: #0E1630; --code-ink: #E3E8F5;
  --shadow-1: 0 1px 2px rgba(16, 23, 42, .06);
  --shadow-2: 0 2px 6px rgba(16, 23, 42, .05), 0 18px 40px -18px rgba(16, 23, 42, .25);
  --shadow-3: 0 4px 12px rgba(16, 23, 42, .08), 0 40px 80px -30px rgba(11, 22, 51, .45);
  --ease: cubic-bezier(.22, 1, .36, 1);
  --side-w: 288px;
}
:root[data-theme="dark"] {
  --bg: #0A1022; --bg-2: #0E1630; --paper: #111A36; --side: #0C1329;
  --ink: #EEF1F8; --ink-2: #C4CBDB; --muted: #8E98B0; --faint: #66708A;
  --line: #22305A; --line-2: #2E3E6E;
  --cobalt: #7FA2FF; --cobalt-2: #9DB6FF; --cobalt-soft: rgba(127, 162, 255, .12);
  --gold: #E2BD5A; --gold-2: #E9C86F; --gold-soft: rgba(226, 189, 90, .12);
  --crimson: #F07A82; --crimson-soft: rgba(240, 122, 130, .12);
  --user: #2E4FB4; --code-bg: #070C1C;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, .35), 0 20px 44px -18px rgba(0, 0, 0, .7);
  --shadow-3: 0 4px 14px rgba(0, 0, 0, .45), 0 44px 90px -30px rgba(0, 0, 0, .85);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.6; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--cobalt-2); }
:focus-visible { outline: 2.5px solid var(--gold-2); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
svg { display: block; }

.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100dvh; }

/* ── Sidebar ── */
.side { display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); min-height: 0; position: relative; }
.side::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: linear-gradient(90deg, #FFFFFF 0 33%, #0039A6 33% 66%, #D52B1E 66%); opacity: .9; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand img { border-radius: 10px; box-shadow: var(--shadow-1); }
.brand b { font-family: var(--serif); font-size: 19px; }
.ibtn { width: 38px; height: 38px; border-radius: 11px; border: 1px solid transparent; background: transparent; color: var(--ink-2); display: inline-grid; place-items: center; cursor: pointer; transition: background .15s, color .15s; flex: none; }
.ibtn:hover { background: var(--bg-2); color: var(--ink); }
.ibtn svg { width: 20px; height: 20px; }
.side-close, .menu-btn { display: none; }
.new-chat {
  margin: 4px 14px 12px; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 14px; border: 1.5px solid var(--gold-2); background: var(--gold-soft); color: var(--ink); font-weight: 600; cursor: pointer;
  transition: transform .15s var(--ease), box-shadow .15s;
}
.new-chat:hover { box-shadow: var(--shadow-1); transform: translateY(-1px); }
.new-chat svg { width: 18px; height: 18px; color: var(--gold); }
.side-search { margin: 0 14px 8px; display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 40px; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); color: var(--faint); }
.side-search svg { width: 17px; height: 17px; }
.side-search input { border: 0; outline: 0; background: transparent; width: 100%; color: var(--ink); }
.convs { flex: 1; overflow-y: auto; padding: 4px 8px 12px; min-height: 0; }
.conv-group { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); padding: 14px 10px 6px; }
.conv { position: relative; display: flex; align-items: center; gap: 4px; border-radius: 11px; }
.conv a { flex: 1; min-width: 0; padding: 9px 10px; border-radius: 11px; color: var(--ink-2); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.conv:hover a, .conv.active a { background: var(--bg-2); color: var(--ink); }
.conv.active a { font-weight: 600; box-shadow: inset 3px 0 0 var(--gold-2); }
.conv .conv-act { position: absolute; right: 4px; opacity: 0; width: 30px; height: 30px; border-radius: 8px; }
.conv:hover .conv-act, .conv .conv-act:focus-visible { opacity: 1; background: var(--paper); }
.conv-empty { padding: 18px 12px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.conv-empty button { margin-top: 10px; }
.side-bottom { border-top: 1px solid var(--line); padding: 12px 14px 14px; display: grid; gap: 10px; }
.gift-chip { font-size: 12.5px; color: var(--ink-2); background: var(--bg-2); border-radius: 12px; padding: 9px 11px; line-height: 1.45; }
.account { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(160deg, #1F3F94, #2E5BDA); color: #fff; font-weight: 700; font-size: 14px; flex: none; }
.acc-text { min-width: 0; flex: 1; }
.acc-text b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-text span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-main { min-height: 44px; padding: 0 18px; border-radius: 12px; border: 0; background: var(--cobalt); color: #fff; font-weight: 600; cursor: pointer; transition: filter .15s, transform .15s; }
:root[data-theme="dark"] .btn-main { background: #2E5BDA; }
.btn-main:hover { filter: brightness(1.08); }
.btn-main:disabled { opacity: .6; cursor: progress; }
.btn-soft { min-height: 40px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--paper); font-weight: 600; cursor: pointer; }
.btn-soft:hover { background: var(--bg-2); }
.account .btn-main, .account .btn-soft { flex: 1; }
.scrim { position: fixed; inset: 0; background: rgba(8, 12, 28, .45); z-index: 20; }

/* ── Main ── */
.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; height: 60px; padding: 0 18px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); }
.title { font-family: var(--serif); font-size: 18px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.top-actions { display: flex; gap: 4px; }
.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.welcome { max-width: 820px; margin: 0 auto; padding: 8vh 20px 30px; text-align: center; animation: rise .6s var(--ease) both; }
.welcome-mark { margin: 0 auto 18px; border-radius: 22px; box-shadow: var(--shadow-2); }
.welcome h2 { font-family: var(--serif); font-size: clamp(28px, 4vw, 40px); margin: 0; }
.welcome-sub { color: var(--muted); margin: 10px 0 0; font-size: 16.5px; }
.sugs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 34px; text-align: left; }
.sug { display: grid; gap: 4px; text-align: left; padding: 15px 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; transition: transform .2s var(--ease), box-shadow .2s, border-color .2s; animation: rise .5s var(--ease) both; }
.sug:nth-child(2) { animation-delay: .05s; } .sug:nth-child(3) { animation-delay: .1s; } .sug:nth-child(4) { animation-delay: .15s; } .sug:nth-child(5) { animation-delay: .2s; } .sug:nth-child(6) { animation-delay: .25s; }
.sug:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--gold-2); }
.sug b { font-size: 14.5px; }
.sug span { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.messages { max-width: 820px; margin: 0 auto; padding: 24px 20px 40px; display: grid; gap: 22px; }
.msg { display: grid; gap: 8px; animation: rise .35s var(--ease) both; }
.msg.user { justify-items: end; }
.msg.user .bubble { background: var(--user); color: var(--on-user); padding: 11px 16px; border-radius: 20px 20px 6px 20px; max-width: min(78%, 620px); white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow-1); }
.msg.user .att-chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg.bot { grid-template-columns: 34px minmax(0, 1fr); column-gap: 12px; align-items: start; }
.msg.bot .bot-mark { width: 34px; height: 34px; border-radius: 10px; box-shadow: var(--shadow-1); }
.msg.bot .body { min-width: 0; }
.msg-tools { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .2s; }
.msg.bot:hover .msg-tools, .msg-tools:focus-within { opacity: 1; }
.msg-tools .ibtn { width: 32px; height: 32px; color: var(--muted); }
.msg-tools .ibtn svg { width: 17px; height: 17px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); max-width: 260px; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 0; width: 18px; height: 18px; display: grid; place-items: center; }
.chip img { width: 22px; height: 22px; border-radius: 5px; object-fit: cover; }

/* Markdown answer */
.md { color: var(--ink); overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); margin: 18px 0 8px; line-height: 1.3; }
.md h1 { font-size: 23px; } .md h2 { font-size: 20.5px; } .md h3 { font-size: 18px; } .md h4 { font-size: 16.5px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--gold); }
.md strong { font-weight: 700; }
.md a { text-decoration: underline; text-underline-offset: 3px; }
.md blockquote { margin: 0 0 12px; padding: 8px 14px; border-left: 3px solid var(--gold-2); background: var(--gold-soft); border-radius: 0 10px 10px 0; color: var(--ink-2); }
.md hr { border: 0; height: 1px; background: var(--line); margin: 18px 0; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--bg-2); padding: 1px 6px; border-radius: 6px; }
.md .codeblock { margin: 0 0 14px; border-radius: 14px; overflow: hidden; background: var(--code-bg); border: 1px solid rgba(255, 255, 255, .06); }
.md .codehead { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; background: rgba(255, 255, 255, .05); color: #9FB0D8; font-size: 12.5px; }
.md .codehead button { border: 0; background: transparent; color: #C8D4F4; cursor: pointer; font-size: 12.5px; padding: 4px 8px; border-radius: 7px; }
.md .codehead button:hover { background: rgba(255, 255, 255, .08); }
.md pre { margin: 0; padding: 14px; overflow-x: auto; color: var(--code-ink); font-family: var(--mono); font-size: 13.5px; line-height: 1.6; }
.md pre code { background: transparent; padding: 0; font-size: inherit; color: inherit; }
.md .tbl-wrap { overflow-x: auto; margin: 0 0 12px; }
.md table { border-collapse: collapse; font-size: 14.5px; min-width: 50%; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--bg-2); }
.gen-img { margin: 4px 0 8px; max-width: 520px; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-2); border: 1px solid var(--line); background: var(--bg-2); }
.gen-img img { width: 100%; height: auto; display: block; }
.gen-img figcaption { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.gen-img a { font-weight: 600; text-decoration: none; }
.status { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14.5px; padding: 6px 0; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold-2); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: none; } }
.caret::after { content: "▍"; color: var(--gold-2); animation: caret 1s steps(1) infinite; margin-left: 1px; }
@keyframes caret { 50% { opacity: 0; } }
.err-note { color: var(--crimson); background: var(--crimson-soft); padding: 9px 13px; border-radius: 12px; font-size: 14.5px; }

/* ── Composer ── */
.composer { padding: 0 20px 14px; max-width: 860px; width: 100%; margin: 0 auto; }
.files { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 6px 8px; }
.box {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px; border-radius: 22px;
  background: var(--paper); border: 1px solid var(--line-2); box-shadow: var(--shadow-2);
  transition: border-color .15s, box-shadow .15s;
}
.box:focus-within { border-color: var(--cobalt-2); box-shadow: 0 0 0 4px var(--cobalt-soft), var(--shadow-2); }
.box textarea { flex: 1; min-width: 0; overflow-y: auto; border: 0; outline: 0; resize: none; background: transparent; min-height: 40px; max-height: 220px; padding: 9px 4px; line-height: 1.5; color: var(--ink); }
.box textarea::placeholder { color: var(--faint); }
.send { width: 42px; height: 42px; border-radius: 14px; border: 0; background: var(--cobalt); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; transition: transform .15s, filter .15s, background .15s; }
:root[data-theme="dark"] .send { background: #2E5BDA; }
.send:hover { filter: brightness(1.1); }
.send:disabled { background: var(--line-2); color: var(--muted); cursor: default; }
.send svg { width: 20px; height: 20px; }
.send .i-stop { display: none; }
.composer.busy .send { background: var(--crimson); }
.composer.busy .send .i-send { display: none; }
.composer.busy .send .i-stop { display: block; }
.hint { text-align: center; color: var(--faint); font-size: 12.5px; margin: 8px 0 0; }
.hint a { color: var(--faint); }
.drop { position: absolute; inset: 10px; border: 2px dashed var(--cobalt-2); border-radius: 22px; background: color-mix(in srgb, var(--cobalt-soft) 80%, transparent); display: grid; place-items: center; font-weight: 600; color: var(--cobalt); z-index: 15; }

/* ── Dialog ── */
.dlg { width: min(430px, calc(100% - 24px)); border: 0; border-radius: 24px; padding: 28px 26px 24px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-3); }
.dlg::backdrop { background: rgba(8, 12, 28, .55); backdrop-filter: blur(3px); }
.dlg[open] { animation: rise .35s var(--ease); }
.dlg-close-form { position: absolute; top: 12px; right: 12px; margin: 0; }
.dlg-mark { margin: 0 auto 12px; border-radius: 15px; }
.dlg h2 { font-family: var(--serif); text-align: center; font-size: 24px; margin: 0; }
.dlg-sub { text-align: center; color: var(--muted); font-size: 14.5px; margin: 8px 0 18px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg-2); margin-bottom: 16px; }
.tabs button { border: 0; background: transparent; border-radius: 10px; padding: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-1); }
.auth-form { display: grid; gap: 12px; }
.f { display: grid; gap: 6px; }
.f span { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.f input { min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--bg); color: var(--ink); }
.f input:focus { outline: none; border-color: var(--cobalt-2); box-shadow: 0 0 0 4px var(--cobalt-soft); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; color: var(--ink-2); }
.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--cobalt); }
.form-err { color: var(--crimson); background: var(--crimson-soft); padding: 9px 12px; border-radius: 10px; font-size: 14px; margin: 0; }
.form-ok { color: var(--green); }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.link { border: 0; background: transparent; color: var(--cobalt-2); cursor: pointer; padding: 2px 0; font-size: 14px; }
.link:hover { text-decoration: underline; }

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; justify-items: center; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow-3); font-size: 14.5px; animation: rise .3s var(--ease); }
.toast.err { background: var(--crimson); color: #fff; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); z-index: 30; transform: translateX(-102%); transition: transform .3s var(--ease); box-shadow: var(--shadow-3); }
  .app.nav-open .side { transform: none; }
  .side-close, .menu-btn { display: inline-grid; }
  .sugs { grid-template-columns: 1fr 1fr; }
  .msg-tools { opacity: 1; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 10px; height: 56px; }
  .welcome { padding-top: 5vh; }
  .sugs { grid-template-columns: 1fr; }
  .sug:nth-child(n+5) { display: none; }
  .messages { padding: 18px 14px 30px; }
  .msg.user .bubble { max-width: 88%; }
  .msg.bot { grid-template-columns: 1fr; }
  .msg.bot .bot-mark { display: none; }
  .composer { padding: 0 10px 10px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
