/* ============================================================
   ShardChat v2 — дизайн-система
   Dark-first. Electric purple accent. Mobile-first.
   Простое сверху, мощное под капотом.
   ============================================================ */

:root {
  --bg: #0a0a0a;
  --bg-2: #111111;
  --bg-input: #17171c;
  --bg-hover: #1f1f26;
  --border: #232328;
  --text: #f5f5f7;
  --text-dim: #9a9aa5;
  --accent: #8b5cf6;
  --accent-2: #a78bfa;
  --accent-soft: rgba(139, 92, 246, 0.14);
  --danger: #ef4444;
  --ok: #34d399;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sbw: 240px;
  --sbw-c: 56px;
}

body.light {
  --bg: #fafafa;
  --bg-2: #ffffff;
  --bg-input: #f2f2f7;
  --bg-hover: #e8e8f0;
  --border: #e2e2ea;
  --text: #1b1b21;
  --text-dim: #6b6b7a;
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.1);
  --shadow: 0 8px 28px rgba(20, 20, 40, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  font-family: -apple-system, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; color: inherit; }
a { color: var(--accent-2); }
::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(140, 140, 160, 0.3); border-radius: 3px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

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

/* ---------- Кнопки ---------- */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  min-height: 44px;
  transition: transform 0.12s, filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.12); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 14px;
  min-height: 44px;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-sm { padding: 8px 14px; min-height: 38px; font-size: 13px; border-radius: 10px; }

.icon-btn {
  background: var(--bg-input);
  border: none;
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 22px;
  line-height: 1;
}

/* ============================================================
   ОНБОРДИНГ
   ============================================================ */
#onboarding {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: radial-gradient(ellipse at 50% -20%, rgba(139, 92, 246, 0.25), transparent 60%), var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.onb-card { max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 18px; }
.onb-logo { font-size: 64px; filter: drop-shadow(0 0 24px rgba(139, 92, 246, 0.6)); }
.onb-card h1 { font-size: 32px; letter-spacing: -0.02em; }
.onb-tag { color: var(--text-dim); font-size: 16px; }
.onb-features { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 6px; }
.onb-features span {
  padding: 8px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-dim);
}
.onb-btn { width: 100%; }
.onb-q { font-size: 16px; font-weight: 600; }
.onb-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.onb-opt {
  padding: 16px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  min-height: 52px;
  transition: border-color 0.15s, background 0.15s;
}
.onb-opt:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ============================================================
   КАРКАС: views + bottom nav + sidebar
   ============================================================ */
#app { height: 100dvh; }

.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--sat);
  animation: viewIn 0.22s ease;
}
.view.active { display: flex; }

@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  min-height: calc(56px + var(--sat));
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
#chat-header { flex: 1; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.model-chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  min-height: 38px;
  white-space: nowrap;
}
.model-chip:hover { border-color: var(--accent); }

/* Bottom nav — мобильный */
#bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: flex;
  background: rgba(18, 18, 26, 0.92);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--sab);
}
body.light #bottom-nav { background: rgba(255, 255, 255, 0.92); }

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  font-size: 10px;
  color: var(--text-dim);
  min-height: 52px;
  transition: color 0.15s;
}
.nav-ico { font-size: 20px; line-height: 1; }
.nav-btn.active { color: var(--accent-2); }
.nav-btn.active .nav-ico { filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.6)); }

/* Sidebar — один на всех носителях (desktop: слева; mobile: drawer) */
#sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sbw);
  z-index: 90;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: none;
  flex-direction: column;
  padding: 14px 10px calc(12px + var(--sab));
  transition: width 0.2s ease, transform 0.2s ease;
  overflow: hidden;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.logo { font-weight: 700; font-size: 16px; padding: 4px 6px; display: flex; align-items: center; gap: 8px; }
.sb-new {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 14px; font-weight: 600; color: var(--text);
  min-height: 44px; margin-bottom: 14px;
  transition: background 0.15s;
}
.sb-new:hover { background: var(--bg-hover); }
.sb-section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); padding: 0 8px; margin-bottom: 6px; }
.sb-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; text-align: left;
  padding: 10px 8px; border-radius: 10px; font-size: 14px; color: var(--text-dim);
  min-height: 44px; width: 100%;
  transition: background 0.15s, color 0.15s;
}
.sb-item:hover { background: var(--bg-hover); color: var(--text); }
.sb-ico { font-size: 16px; width: 22px; text-align: center; }
.sidebar-bottom { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 8px; }
#chat-list { flex: 1; overflow-y: auto; }
#collapse-btn {
  background: none; border: none; color: var(--text-dim);
  width: 28px; height: 28px; border-radius: 8px; font-size: 15px; line-height: 1;
}
#collapse-btn:hover { background: var(--bg-hover); color: var(--text); }
#sidebar.collapsed { width: var(--sbw-c); }
#sidebar.collapsed .sb-label { display: none; }
#sidebar.collapsed .logo svg { margin: 0 auto; }
#sidebar.collapsed .sb-new, #sidebar.collapsed .sb-item { justify-content: center; padding: 10px 0; }
#sidebar.collapsed .sb-section { display: none; }

/* Mobile drawer */
@media (max-width: 899px) {
  body.sb-open #sidebar { display: flex; }
  body.sb-open #view-home { transform: translateX(var(--sbw)); }
}
#menu-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 85; }

.page-scroll { flex: 1; overflow-y: auto; padding: 8px 16px calc(90px + var(--sab)); }
#home-scroll { flex: 1; overflow-y: auto; padding: 0 16px calc(16px + var(--sab)); display: flex; flex-direction: column; }

/* ============================================================
   HOME
   ============================================================ */
#welcome { text-align: center; padding: 6vh 0 20px; }
#welcome h1 {
  font-size: clamp(24px, 5vw, 34px);
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, var(--text), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.welcome-sub { color: var(--text-dim); margin-top: 8px; font-size: 14px; }
.welcome-auth { margin-top: 16px; }

.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}
.quick {
  padding: 16px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  text-align: left;
  min-height: 56px;
  transition: border-color 0.15s, transform 0.12s;
}
.quick:hover { border-color: var(--accent); transform: translateY(-1px); }
.quick:active { transform: scale(0.98); }
.hint-note { text-align: center; color: var(--text-dim); font-size: 12px; margin-top: 14px; }

/* ============================================================
   COMPOSER
   ============================================================ */
#composer-zone { padding: 6px 16px calc(12px + var(--sab)); background: var(--bg); }

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 780px;
  margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 10px;
  transition: border-color 0.15s;
}
.input-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.input-row button {
  width: 40px; height: 40px; min-width: 40px;
  border: none; background: none; color: var(--text-dim);
  font-size: 19px; border-radius: 50%;
}
.input-row button:hover { background: var(--bg-hover); color: var(--text); }
#mic-btn.rec, #mic-btn-chat.rec { background: rgba(239, 68, 68, 0.15); color: var(--danger); animation: mic-pulse 1.2s infinite; }
@keyframes mic-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); } 50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); } }

#send-btn, #send-btn-chat {
  background: linear-gradient(135deg, var(--accent), #7c3aed) !important;
  color: #fff !important;
}
#user-input, #user-input-chat {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 16px; font-family: inherit;
  resize: none; line-height: 1.5; max-height: 180px; padding: 8px 0;
}
#user-input::placeholder, #user-input-chat::placeholder { color: var(--text-dim); }

.composer-pills {
  display: flex; gap: 8px; justify-content: center;
  max-width: 780px; margin: 8px auto 0;
}
.pill {
  padding: 8px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  font-size: 12.5px;
  color: var(--text-dim);
  min-height: 36px;
  transition: all 0.15s;
}
.pill:hover { color: var(--text); }
.pill.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }

/* ============================================================
   ЧАТ
   ============================================================ */
#messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 0 6px; }

.msg { display: flex; gap: 10px; padding: 10px 18px; max-width: 820px; margin: 0 auto; width: 100%; animation: msgIn 0.25s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg .avatar {
  width: 30px; height: 30px; min-width: 30px;
  border-radius: 10px; background: var(--bg-input);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--accent-soft); }
.msg.user .bubble { background: var(--accent-soft); border: none; }

.bubble { min-width: 0; max-width: 100%; font-size: 15px; line-height: 1.6; }
.msg.ai .bubble { padding: 2px 0; }
.msg.user .bubble { background: var(--bg-input); border-radius: 16px; padding: 10px 14px; }
.msg-img { max-width: 220px; max-height: 180px; border-radius: 12px; display: block; margin-bottom: 6px; }
.chip { display: inline-block; padding: 4px 10px; background: var(--bg-input); border-radius: 10px; font-size: 12px; margin: 0 4px 4px 0; }
.chip-x { cursor: pointer; opacity: 0.6; margin-left: 4px; }
.chip-x:hover { opacity: 1; color: var(--danger); }

#attachments, #attachments-chat { max-width: 780px; margin: 0 auto 6px; padding: 0 6px; }

.msg-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.msg-act {
  background: none; border: none; color: var(--text-dim);
  font-size: 12px; padding: 6px 8px; border-radius: 8px; min-height: 32px;
}
.msg-act:hover { background: var(--bg-hover); color: var(--text); }

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

pre {
  position: relative;
  background: #101018;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13.5px;
  line-height: 1.5;
}
code { font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace; }
p code, li code { background: var(--bg-input); padding: 2px 6px; border-radius: 6px; font-size: 13px; }
.code-copy { position: absolute; top: 8px; right: 8px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 5px 9px; font-size: 12px; }
h1, h2, h3 { margin: 14px 0 6px; line-height: 1.3; }
h1 { font-size: 20px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
ul, ol { padding-left: 22px; margin: 6px 0; }
blockquote { border-left: 3px solid var(--accent); padding: 2px 12px; color: var(--text-dim); margin: 8px 0; }
table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 14px; }
th, td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
th { background: var(--bg-input); }

.gen-img { max-width: 100%; max-height: 460px; border-radius: var(--radius); display: block; }
.img-caption { font-size: 12px; color: var(--text-dim); margin-top: 6px; }

.fs-notice, .sys-notice { font-size: 13px; color: var(--text-dim); padding: 6px 18px; }

/* ---------- Статусы ---------- */
.status {
  display: none;
  max-width: 780px;
  margin: 0 auto 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.status.warn { background: rgba(245, 158, 11, 0.12); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.status.error { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); }
.status.info { background: var(--accent-soft); color: var(--accent-2); border: 1px solid rgba(139, 92, 246, 0.3); }

/* ============================================================
   ЧАТЫ (список)
   ============================================================ */
#chat-search {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}
#chat-search:focus { border-color: var(--accent); }

.chat-group-label { font-size: 12px; color: var(--text-dim); padding: 10px 6px 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 48px;
  transition: background 0.15s;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent-soft); }
.chat-title { flex: 1; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .pin-star { font-size: 13px; }
.chat-act { background: none; border: none; color: var(--text-dim); font-size: 14px; padding: 8px; border-radius: 8px; }
.chat-act:hover { background: var(--bg-hover); color: var(--text); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.empty-ico { font-size: 44px; opacity: 0.5; }

/* ============================================================
   IMAGE STUDIO
   ============================================================ */
.studio-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  max-width: 640px;
  margin: 0 auto;
}
#studio-prompt {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 84px;
}
#studio-prompt:focus { border-color: var(--accent); }
.studio-row { display: flex; gap: 10px; }
.studio-row label { flex: 1; font-size: 12px; color: var(--text-dim); display: flex; flex-direction: column; gap: 6px; }
.studio-row select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  color: var(--text);
  font-size: 14px;
  min-height: 44px;
}

.studio-result-card, .gen-card { max-width: 640px; margin: 14px auto; text-align: center; }
.studio-result-card img, .gen-card img { width: 100%; border-radius: var(--radius); display: block; }
.studio-result-card .msg-actions, .gen-card .msg-actions { justify-content: center; }

.section-title { font-size: 14px; color: var(--text-dim); margin: 22px 4px 10px; }
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.img-grid .cell { position: relative; border-radius: var(--radius-sm); overflow: hidden; aspect-ratio: 1; background: var(--bg-input); cursor: pointer; border: none; padding: 0; }
.img-grid .cell img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s; }
.img-grid .cell:hover img { transform: scale(1.05); }

/* ============================================================
   ПРОФИЛЬ
   ============================================================ */
#user-box { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; }
#user-avatar { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; }
.user-meta { flex: 1; min-width: 0; }
#user-name { font-weight: 600; font-size: 15px; }
#user-email { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#logout-btn { background: none; border: none; font-size: 18px; color: var(--text-dim); padding: 10px; }

#login-box { margin-bottom: 14px; }
#login-box .btn-primary { width: 100%; }

.profile-group { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; max-width: 640px; }
.group-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.field select, .field textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  min-height: 44px;
}
.field textarea { min-height: 70px; resize: vertical; }
.field select:focus, .field textarea:focus { border-color: var(--accent); }

.advanced { margin-top: 4px; }
.advanced summary { cursor: pointer; font-size: 13px; color: var(--text-dim); padding: 8px 0; }
.slider-row { display: flex; flex-direction: column; gap: 10px; padding: 10px 0; }
.slider-row label { font-size: 13px; color: var(--text-dim); display: flex; justify-content: space-between; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.provider-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.provider-row:last-child { border-bottom: none; }

.about { text-align: center; color: var(--text-dim); font-size: 12px; padding: 18px 0 8px; }

/* ============================================================
   МОДАЛКИ / SHEETS
   ============================================================ */
#auth-modal, #settings-modal {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-content {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  width: 100%;
  max-width: 420px;
  max-height: 86dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: sheetIn 0.25s ease;
}
@keyframes sheetIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header button { background: none; border: none; font-size: 18px; color: var(--text-dim); padding: 8px; }
.modal-note { font-size: 13px; color: var(--text-dim); margin-bottom: 14px; line-height: 1.5; }
.howto { font-size: 13px; color: var(--text-dim); background: var(--bg-input); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 12px; line-height: 1.55; }
.howto a { color: var(--accent-2); }
.key-row { margin-bottom: 12px; }
.key-row label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.key-row input {
  width: 100%;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.key-row input:focus { border-color: var(--accent); }
.modal-buttons { display: flex; gap: 10px; margin-top: 8px; }
.modal-buttons button { flex: 1; }

.auth-content { display: flex; flex-direction: column; gap: 10px; }
.auth-btn {
  width: 100%;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14.5px;
  min-height: 46px;
}
.auth-btn:hover { border-color: var(--accent); }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px; margin: 6px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-content input {
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.auth-content input:focus { border-color: var(--accent); }
#auth-switch { text-align: center; font-size: 13px; color: var(--accent-2); cursor: pointer; }
#auth-error { margin: 0; }

/* Bottom sheet */
.sheet {
  position: fixed; inset: 0; z-index: 130;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 80dvh;
  overflow-y: auto;
  padding: 10px 16px calc(20px + var(--sab));
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 12px; }
.sheet-box h3 { margin-bottom: 10px; }
.sheet-opt {
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; text-align: left;
  background: none; border: none;
  padding: 13px 10px;
  border-radius: var(--radius-sm);
  min-height: 52px;
}
.sheet-opt:hover { background: var(--bg-hover); }
.sheet-opt.active { background: var(--accent-soft); }
.sheet-opt small { color: var(--text-dim); font-size: 12.5px; }

/* ============================================================
   DESKTOP (>= 900px)
   ============================================================ */
@media (min-width: 900px) {
  #menu-btn { display: none; }
  #sidebar { display: flex; }
  .view { left: var(--sbw); padding-top: 0; }
  #topbar { min-height: 56px; }
  body.sb-collapsed .view { left: var(--sbw-c); }
  #welcome { padding: 12vh 0 22px; }
  .page-scroll { padding-bottom: 40px; }
  #menu-overlay { display: none !important; }
  body.sb-collapsed #sidebar { transform: none; }
}

@media (max-width: 899px) {
  #sidebar { display: none; }
  .modal-content { max-height: 88dvh; }
}

/* ============================================================
   ФИКСЫ ВЁРСТКИ (v2.1)
   ============================================================ */

/* Все view — фиксированный каркас без «плавания» */
.view { height: 100%; min-height: 0; overflow: hidden; }
.view > * { flex-shrink: 0; }
/* Единственное исключение: лента сообщений тянется и скроллится */
#view-home #messages { flex: 1 !important; }
#home-scroll, #chats-scroll, #create-scroll, #profile-scroll, #messages { min-height: 0; }

/* Композер не должен уезжать под клавиатуру */
#composer-zone { padding-bottom: calc(16px + var(--sab)); }

/* Home = чат: гибкий каркас — topbar / welcome / messages / composer */
#view-home { height: 100%; min-height: 0; }
#view-home #messages { flex: 1; min-height: 0; }
#view-home #welcome { flex-shrink: 0; }
#view-home #composer-zone { flex-shrink: 0; }

/* Онбординг поверх всего, скролл выключен пока открыт */
#onboarding[style*="flex"] ~ #app { filter: blur(0); }
body.onb-open #onboarding { display: flex !important; }
body.onb-open { overflow: hidden; }

/* Suggestions: маленькие, исчезают после первого сообщения */
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.sug {
  padding: 7px 13px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12.5px;
  color: var(--text-dim);
  min-height: 34px;
  transition: all 0.15s;
}
.sug:hover { color: var(--text); border-color: var(--accent); }

/* Информация о запросе (•••) */
.msg-meta { font-size: 11.5px; color: var(--text-dim); opacity: 0.7; margin-top: 4px; }

/* Быстрые действия — одинаковая высота карточек */
.quick { display: flex; align-items: center; }

/* Кнопка «Назад» заметнее */
#back-btn { font-size: 26px; width: 44px; height: 44px; }

/* Сообщения: и user, и ai — в одну колонку с аватаром, без сдвигов */
.msg { align-items: flex-start; }
.msg-body { min-width: 0; flex: 1; }
.msg.user .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .msg-actions { justify-content: flex-end; }

/* Статус внутри чата */
#status-chat { display: none; max-width: 780px; margin: 0 auto 8px; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; }

/* ============================================================
   AI WORKSPACE v3: Tools, Agents, Workflows, Files, Models, Память
   ============================================================ */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 11px;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge-free { background: rgba(52, 211, 153, 0.12); color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.badge-on { background: var(--accent-soft); color: var(--accent-2); border-color: rgba(139, 92, 246, 0.35); }

.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tool-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s, transform 0.12s;
}
.tool-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.tool-head { display: flex; align-items: center; gap: 9px; }
.tool-ico { font-size: 21px; }
.tool-name { flex: 1; font-weight: 600; font-size: 14px; min-width: 0; }
.tool-fav { background: none; border: none; color: var(--text-dim); font-size: 17px; padding: 4px 6px; }
.tool-fav.active { color: #fbbf24; }
.tool-desc { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; flex: 1; }
.tool-foot { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.tool-foot .btn-sm { margin-left: auto; }

.cat-row { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 10px; -webkit-overflow-scrolling: touch; }
.cat-row .pill { flex-shrink: 0; }

.tools-search, #tools-search, #chat-search, #palette-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}
#tools-search:focus { border-color: var(--accent); }

/* Агенты */
.agent-card.agent-active { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--bg-2)); }

/* Workflows */
.wf-mini { font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.wf-mini span { display: inline-block; margin-right: 4px; }
.wf-topic {
  flex: 1;
  min-width: 100px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.wf-topic:focus { border-color: var(--accent); }
.wf-status {
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.wf-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.wf-step {
  padding: 5px 10px;
  border-radius: 14px;
  font-size: 12px;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.wf-step.done { background: rgba(52, 211, 153, 0.12); color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.wf-step.cur { background: var(--accent-soft); color: var(--accent-2); border-color: var(--accent); animation: blink 1.4s infinite; }
.wf-msg { margin-top: 8px; font-size: 12.5px; color: var(--text-dim); }

/* Файлы: drag&drop */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 14px;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone.over { border-color: var(--accent); background: var(--accent-soft); }

/* Рекомендации инструментов */
.tool-suggest {
  max-width: 560px;
  margin: 0 auto 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13.5px;
}
.tool-suggest .sug-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.tool-suggest button {
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12.5px;
}
.tool-suggest button:hover { border-color: var(--accent); }

/* Палитра Cmd+K */
.palette {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 0;
}
.palette-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: sheetIn 0.2s ease;
}
#palette-input {
  margin: 0;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 16px;
  font-size: 16px;
}
.palette-results { max-height: 46vh; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 11px 10px;
  border-radius: 10px;
  font-size: 14px;
  min-height: 44px;
}
.palette-item:hover, .palette-item.sel { background: var(--bg-hover); }
.palette-item.sel { background: var(--accent-soft); }
.pal-ico { width: 24px; text-align: center; }
.pal-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-sub { font-size: 11.5px; color: var(--text-dim); }
.palette-hint { padding: 9px 14px; font-size: 11.5px; color: var(--text-dim); border-top: 1px solid var(--border); }

/* Триггер палитры в сайдбаре */
.palette-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 13.5px;
  min-height: 40px;
}
.palette-trigger:hover { border-color: var(--accent); color: var(--text); }
.palette-trigger kbd {
  font-family: inherit;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* Бренд-марка и лендинг */
.brand-mark {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
  filter: drop-shadow(0 0 18px rgba(139, 92, 246, 0.45));
}

/* Модели: карточки провайдеров */
.provider-card { margin-bottom: 0; }

/* Скрытые служебные элементы */
.hidden-select { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#provider-select, #model-select, #img-controls, #img-btn, #settings-btn, #settings-btn-top, #export-fab { display: none !important; }
