/* Collab — дизайн-система «away from anime»: тёмная тема, один акцент, стекло, Manrope. */

:root {
  --bg: #ffffff; --surface: #f2f3f5; --surface-2: #e8e9ec;
  --text: #16171a; --text-2: #5f636b; --muted: #8d9199;
  --accent: #12b76a; --accent-rgb: 18 183 106; --on-accent: #06231a;
  --accent-fill: var(--accent);
  --accent-soft: rgb(var(--accent-rgb) / .12);
  --divider: rgba(0,0,0,.08);
  --grid-line: rgba(0,0,0,.035);
  --danger: #e5484d;
  --spring: cubic-bezier(.34,1.56,.64,1);
}
:root[data-theme="dark"] {
  --bg: #121316; --surface: #1e2024; --surface-2: #2a2d32;
  --text: #eceef1; --text-2: #a9adb5; --muted: #7d828b;
  --accent: #34d98a; --accent-rgb: 52 217 138; --on-accent: #06231a;
  --accent-soft: rgb(var(--accent-rgb) / .16);
  --divider: rgba(255,255,255,.08);
  --grid-line: rgba(255,255,255,.025);
  --danger: #ff7b7f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  background-color: var(--bg);
  background-image:
    radial-gradient(135% 60% at 50% -20%, rgb(var(--accent-rgb) / .22), transparent 60%),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 100% 100%, 56px 56px, 56px 56px;
  color: var(--text);
  font: 500 14px/1.45 Manrope, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* «Созвездие» — только под экраном входа */
.stars { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
body.in-session .stars { display: none; }

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border: 0; border-radius: 12px;
  background: var(--surface); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--divider);
  font: 700 14px Manrope, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  transition: background .16s ease, transform .18s var(--spring);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.96); transition-duration: .08s; }

.btn.primary {
  width: 100%; height: 46px; margin-top: 6px; font-size: 15px;
  background: var(--accent-fill); color: var(--on-accent); box-shadow: none;
}
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.btn.primary .icon { stroke-width: 2.2; }

.btn.soft {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 38%, transparent);
  color: var(--accent);
}
.btn.soft:hover { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }

/* ---------- вход ---------- */

.login {
  position: relative;
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px 16px;
}

.card {
  width: 100%; max-width: 440px;
  padding: 26px 24px 22px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(1.3); backdrop-filter: blur(12px) saturate(1.3);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.07), 0 18px 46px rgba(0,0,0,.5);
  animation: rise .4s ease both;
}

@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.98); filter: blur(4px); } }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
}
.brand-icon .icon { width: 22px; height: 22px; stroke-width: 2.2; }
h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.02em; }

.lead { margin: 10px 0 20px; color: var(--text-2); font-weight: 600; }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  flex: 1; height: 38px; padding: 0 15px; border: 0; border-radius: 11px;
  background: var(--surface-2); color: var(--text-2);
  font: 700 14px Manrope, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, transform .18s var(--spring);
}
.tab:active { transform: scale(.96); transition-duration: .08s; }
.tab.on {
  background: var(--accent-soft); color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 38%, transparent);
}

.field { display: block; margin-bottom: 14px; }
.caption {
  display: block; margin-bottom: 7px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}

input, textarea {
  display: block; width: 100%;
  padding: 11px 13px; border: 0; border-radius: 12px;
  background: var(--bg); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--divider);
  font: 600 16px Manrope, -apple-system, "Segoe UI", sans-serif; /* 16px — иначе iOS увеличивает страницу */
  transition: box-shadow .16s ease;
}
textarea { font: 500 13.5px/1.5 "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace; resize: vertical; }
input:focus, textarea:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--accent); }

.error { margin: 14px 0 0; color: var(--danger); font-weight: 600; }
.hint { margin: 16px 0 0; color: var(--muted); font-size: 12.5px; }

/* ---------- сессия ---------- */

.workspace {
  height: 100dvh;
  display: flex; flex-direction: column;
  padding: 12px; padding-top: max(12px, env(safe-area-inset-top));
  gap: 12px;
  animation: rise .4s ease both;
}

.top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--divider);
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.file-chip { min-width: 0; }
.file-chip .icon { width: 16px; height: 16px; color: var(--accent); }
.file-chip span { overflow: hidden; text-overflow: ellipsis; }

.users { display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.user {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px 0 4px; border-radius: 999px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--divider);
  font-size: 13px; font-weight: 700; white-space: nowrap;
  animation: rise .28s ease both;
}
.avatar {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 800; text-transform: uppercase;
}

.main { flex: 1; min-height: 0; display: flex; gap: 12px; }

.editor {
  flex: 1; min-width: 0; min-height: 0;
  border-radius: 18px; overflow: hidden;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.07), 0 18px 46px rgba(0,0,0,.35);
}
.editor .cm-editor { height: 100%; }

/* ---------- ИИ-помощник ---------- */

.chat {
  width: 400px; flex: none;
  display: flex; flex-direction: column; min-height: 0;
  border-radius: 18px; overflow: hidden;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.07), 0 18px 46px rgba(0,0,0,.35);
}
.workspace.chat-hidden .chat { display: none; }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px 10px 16px;
  box-shadow: inset 0 -1px 0 var(--divider);
}
.chat-title { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 800; }
.chat-title .icon { color: var(--accent); }
.chat-head .caption { margin: 0; flex: 1; }

.icon-btn {
  display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .14s ease, transform .18s var(--spring);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn .icon { width: 16px; height: 16px; }

.chat-log {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin;
}

.chat-empty { margin: auto 0; color: var(--text-2); text-align: center; padding: 8px; }
.chat-empty p { margin: 0 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip-btn {
  height: 30px; padding: 0 13px; border: 0; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font: 700 12.5px Manrope, -apple-system, "Segoe UI", sans-serif; cursor: pointer;
  transition: background .14s ease, transform .18s var(--spring);
}
.chip-btn:hover { background: var(--accent-soft); color: var(--accent); }
.chip-btn:active { transform: scale(.95); }

.msg { animation: rise .28s ease both; }
.msg-meta { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.msg-meta .avatar { width: 22px; height: 22px; font-size: 11px; }
.msg-meta .ai-mark {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
}
.msg-meta .ai-mark .icon { width: 13px; height: 13px; }

.msg.human .bubble {
  padding: 9px 12px; border-radius: 14px;
  background: var(--surface-2); white-space: pre-wrap; word-break: break-word;
  font-weight: 600;
}

.msg.ai .body { color: var(--text); font-weight: 500; line-height: 1.55; word-break: break-word; }
.msg.ai .body p { margin: 0 0 8px; }
.msg.ai .body p:last-child { margin-bottom: 0; }
.msg.ai .body ul, .msg.ai .body ol { margin: 0 0 8px; padding-left: 20px; }
.msg.ai .body li { margin: 3px 0; }
.msg.ai .body .md-h { font-weight: 800; }
.msg.ai .body code {
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 12.5px;
  padding: 1px 5px; border-radius: 6px; background: rgba(255,255,255,.07);
}
.msg.ai.typing .body::after {
  content: ""; display: inline-block; width: 7px; height: 15px; margin-left: 2px; vertical-align: -2px;
  border-radius: 2px; background: var(--accent); animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.msg.ai.failed .body { color: var(--danger); font-weight: 600; }

.code-block {
  margin: 8px 0; border-radius: 12px; overflow: hidden;
  background: var(--bg); box-shadow: inset 0 0 0 1px var(--divider);
}
.code-bar { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; box-shadow: inset 0 -1px 0 var(--divider); }
.code-lang { flex: 1; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.code-bar button {
  height: 26px; padding: 0 10px; border: 0; border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font: 700 12px Manrope, -apple-system, "Segoe UI", sans-serif; cursor: pointer;
  transition: background .14s ease, transform .18s var(--spring);
}
.code-bar button[data-act="insert"] { background: var(--accent-soft); color: var(--accent); }
.code-bar button:hover { filter: brightness(1.15); }
.code-bar button:active { transform: scale(.94); }
.code-block pre { margin: 0; padding: 10px 12px; overflow-x: auto; }
.msg.ai .body .code-block pre code, .code-block pre code {
  padding: 0; background: none; font-size: 12.5px; line-height: 1.55; white-space: pre;
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

.chat-notice { align-self: center; padding: 6px 12px; border-radius: 999px; background: rgba(250,204,21,.12);
  box-shadow: inset 0 0 0 1px rgba(250,204,21,.3); color: #facc15; font-size: 12.5px; font-weight: 700; text-align: center; }

.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 6px; }
.chat-form textarea {
  flex: 1; min-height: 42px; max-height: 160px; resize: none;
  padding: 10px 12px; border-radius: 12px;
  font: 600 14px/1.45 Manrope, -apple-system, "Segoe UI", sans-serif;
}
.send {
  display: grid; place-items: center; width: 42px; height: 42px; flex: none; border: 0; border-radius: 12px;
  background: var(--accent-fill); color: var(--on-accent); cursor: pointer;
  transition: background .14s ease, transform .18s var(--spring), opacity .14s ease;
}
.send:hover { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .45; cursor: default; }
.send .icon { stroke-width: 2.4; }
.chat-scope { padding: 0 14px 12px; font-size: 12px; font-weight: 600; color: var(--muted); }

.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--accent-fill); color: var(--on-accent); font-size: 11px; font-weight: 800; line-height: 18px;
}
#chat-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 38%, transparent); }

@media (max-width: 900px) {
  /* Телефон и узкое окно: чат — «лист» снизу на плотном стекле */
  .chat {
    position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 10;
    width: auto; height: min(78dvh, 640px);
    background: color-mix(in srgb, var(--surface) 93%, transparent);
    -webkit-backdrop-filter: blur(22px) saturate(1.4); backdrop-filter: blur(22px) saturate(1.4);
    border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
    box-shadow: 0 18px 46px rgba(0,0,0,.5);
    transform: translateY(calc(100% + 16px)); transition: transform .32s var(--spring);
  }
  .workspace.chat-open .chat { transform: none; }
  .workspace.chat-hidden .chat { display: flex; }
}

/* ---------- тост ---------- */

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  padding: 11px 16px; border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(1.4); backdrop-filter: blur(22px) saturate(1.4);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  box-shadow: 0 16px 44px rgba(0,0,0,.45);
  font-weight: 600; white-space: nowrap;
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity .16s ease, transform .2s var(--spring);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- телефон ---------- */

@media (max-width: 600px) {
  .workspace { padding: 8px; gap: 8px; }
  .btn .label { display: none; }
  .btn { width: 38px; padding: 0; }
  .user { padding: 0 4px; }
  .user .name { display: none; }
  .editor { border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Помощник выключен на сервере */
.workspace.no-helper .chat, .workspace.no-helper #chat-toggle { display: none !important; }
