:root {
  --bg: #ffffff;
  --sidebar: #f8f9fb;
  --border: #e7e9ee;
  --text: #16181d;
  --muted: #6b7280;
  --soft: #f2f4f7;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --dark: #16181d;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(17, 24, 39, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex-shrink: 0; }

/* ---------- Логотип ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
}

/* ---------- Страница входа ---------- */
.auth-page { min-height: 100%; display: grid; place-items: center; padding: 24px; background: linear-gradient(180deg, #fafbff, #fff); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--border); border-radius: 20px; padding: 36px 32px; box-shadow: var(--shadow); }
.auth-card .brand { justify-content: center; font-size: 22px; margin-bottom: 6px; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tabs button { border: 0; background: transparent; padding: 9px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.tabs button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: #374151; }
.input {
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; background: #fff; outline: none;
  transition: border-color .15s, box-shadow .15s; width: 100%;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600;
  background: var(--dark); color: #fff; transition: opacity .15s, transform .05s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { opacity: .9; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--soft); opacity: 1; }
.error-box { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; display: none; }
.error-box.show { display: block; }

/* ---------- Каркас приложения ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 272px; flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 4px;
}
.sidebar .brand { padding: 6px 8px 14px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; border: 0; background: transparent;
  padding: 10px 12px; border-radius: 10px; text-align: left; font-weight: 500; color: #30343c;
}
.nav-item:hover { background: #eceef3; }
.nav-item.active { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.06); color: var(--text); font-weight: 600; }
.nav-item.new-chat { border: 1px solid var(--border); background: #fff; margin-bottom: 8px; font-weight: 600; }
.nav-item.new-chat:hover { background: var(--soft); }
.history-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 16px 12px 6px; }
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px 8px 12px; border-radius: 9px;
  color: #30343c; cursor: pointer; font-size: 14px;
}
.chat-item:hover { background: #eceef3; }
.chat-item.active { background: #e6e8ef; font-weight: 600; }
.chat-item .title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item .act { border: 0; background: transparent; padding: 3px; border-radius: 6px; color: var(--muted); opacity: 0; display: grid; place-items: center; }
.chat-item:hover .act, .chat-item.active .act { opacity: 1; }
.chat-item .act:hover { background: #d9dce5; color: var(--text); }
.chat-list .empty-list { color: var(--muted); font-size: 13px; padding: 6px 12px; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 10px 8px 2px; border-top: 1px solid var(--border); margin-top: 6px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }
.user-box .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; padding: 7px; border-radius: 8px; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: #eceef3; color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 58px; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.model-select { border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; background: #fff; font-weight: 500; outline: none; }

.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }
.scroll { flex: 1; overflow-y: auto; }
.page { max-width: 980px; margin: 0 auto; padding: 32px 24px 48px; width: 100%; }
.page h2 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.02em; }
.page .lead { color: var(--muted); margin: 0 0 24px; }

/* ---------- Чат ---------- */
#view-chat { flex-direction: column; }
.messages { flex: 1; overflow-y: auto; }
.messages-inner { max-width: 780px; margin: 0 auto; padding: 28px 20px 12px; }
.welcome { text-align: center; padding: 12vh 0 20px; }
.welcome .brand-mark { width: 54px; height: 54px; border-radius: 16px; margin: 0 auto 16px; }
.welcome h2 { font-size: 28px; margin: 0 0 6px; letter-spacing: -0.02em; }
.welcome p { color: var(--muted); margin: 0 0 28px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 620px; margin: 0 auto; }
.suggestion { border: 1px solid var(--border); background: #fff; border-radius: 12px; padding: 12px 14px; text-align: left; color: #30343c; font-size: 14px; }
.suggestion:hover { background: var(--soft); }
.suggestion b { display: block; color: var(--text); margin-bottom: 2px; }

.msg { display: flex; gap: 14px; margin-bottom: 26px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--soft); padding: 11px 16px; border-radius: 18px; max-width: 80%; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .bot-icon { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; display: grid; place-items: center; flex-shrink: 0; margin-top: 2px; }
.msg.assistant .body { flex: 1; min-width: 0; line-height: 1.65; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.body p { margin: 0 0 12px; }
.body p:last-child { margin-bottom: 0; }
.body h1, .body h2, .body h3, .body h4 { margin: 18px 0 8px; line-height: 1.3; }
.body h1 { font-size: 22px; } .body h2 { font-size: 19px; } .body h3 { font-size: 17px; }
.body ul, .body ol { margin: 0 0 12px; padding-left: 22px; }
.body li { margin: 3px 0; }
.body a { color: var(--accent); }
.body blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--border); color: #4b5563; }
.body code { background: var(--soft); padding: 2px 6px; border-radius: 6px; font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.body pre { background: #0f1117; color: #e5e7eb; border-radius: 12px; margin: 0 0 14px; overflow: hidden; }
.body pre code { display: block; background: transparent; padding: 14px 16px; overflow-x: auto; color: inherit; font-size: 13px; line-height: 1.55; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 7px 12px 7px 16px; background: #1b1e27; font-size: 12px; color: #9ca3af; }
.copy-btn { border: 0; background: transparent; color: #9ca3af; font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.copy-btn:hover { color: #fff; background: #2a2e3a; }
.body table { border-collapse: collapse; margin: 0 0 12px; }
.body td, .body th { border: 1px solid var(--border); padding: 6px 10px; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #c4c8d2; animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

.composer-wrap { padding: 8px 20px 14px; flex-shrink: 0; }
.composer {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--border); border-radius: 20px; padding: 8px 8px 8px 16px; background: #fff;
  box-shadow: var(--shadow); transition: border-color .15s;
}
.composer:focus-within { border-color: #c7cbd6; }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; max-height: 220px; padding: 8px 0; line-height: 1.5; background: transparent; }
.send-btn { width: 38px; height: 38px; border-radius: 12px; border: 0; background: var(--dark); color: #fff; display: grid; place-items: center; }
.send-btn:disabled { background: #d1d5db; cursor: not-allowed; }
.hint { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---------- Карточки ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; background: #fff; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; background: #fff; }
.panel h3 { margin: 0 0 16px; font-size: 16px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 34px; background: #6366f1; border-radius: 6px 6px 2px 2px; min-height: 2px; position: relative; }
.bar.zero { background: #e5e7eb; }
.bar-col .d { font-size: 11px; color: var(--muted); }
.bar-col .n { font-size: 11px; color: #374151; font-weight: 600; }
.hbar-row { display: grid; grid-template-columns: 220px 1fr 40px; gap: 12px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.hbar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar { height: 10px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.hbar > div { height: 100%; background: #6366f1; border-radius: 99px; }
.muted { color: var(--muted); }

/* ---------- Генерация фото ---------- */
.notice { display: flex; gap: 10px; align-items: flex-start; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 12px 14px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; }
.gen-form { display: flex; flex-direction: column; gap: 12px; }
.gen-form textarea { min-height: 92px; resize: vertical; }
.gen-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; background: var(--soft); padding: 4px; border-radius: 10px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-size: 14px; color: var(--muted); font-weight: 500; }
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.shot { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.shot img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--soft); display: block; cursor: zoom-in; }
.shot .cap { padding: 10px 12px; font-size: 13px; color: #374151; display: flex; gap: 6px; align-items: flex-start; }
.shot .cap span { flex: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.shot.loading .ph { aspect-ratio: 1; display: grid; place-items: center; background: linear-gradient(90deg, #f3f4f6, #eceef3, #f3f4f6); background-size: 200% 100%; animation: shimmer 1.4s infinite; color: var(--muted); font-size: 14px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.lightbox { position: fixed; inset: 0; background: rgba(15, 17, 23, .8); display: none; place-items: center; z-index: 50; padding: 24px; }
.lightbox.show { display: grid; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 12px; }

/* ---------- Плагины ---------- */
.plugins { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.plugin { display: flex; gap: 14px; align-items: flex-start; }
.plugin .ico { width: 42px; height: 42px; border-radius: 12px; background: var(--soft); display: grid; place-items: center; font-size: 21px; flex-shrink: 0; }
.plugin .info { flex: 1; }
.plugin .info b { display: block; margin-bottom: 3px; }
.plugin .info p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.plugin.disabled { opacity: .6; }
.tag { font-size: 11px; font-weight: 600; background: var(--soft); color: var(--muted); padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: middle; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d1d5db; border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:disabled + span { cursor: not-allowed; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--dark); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.backdrop { display: none; }

/* ---------- Мобильная версия ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 30; }
  .menu-btn { display: grid; }
  .suggestions { grid-template-columns: 1fr; }
  .hbar-row { grid-template-columns: 120px 1fr 34px; }
  .topbar { padding: 0 12px; }
}

/* ---------- Баланс ---------- */
.nav-balance { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--soft); border-radius: 999px; padding: 2px 8px; font-variant-numeric: tabular-nums; }
.nav-item.active .nav-balance { background: var(--soft); }
.balance-card { padding: 20px 22px; margin-bottom: 18px; }
.balance-card .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.balance-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.amounts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.amounts button { border: 1px solid var(--border); background: #fff; border-radius: 10px; padding: 9px 14px; font-weight: 600; }
.amounts button:hover { background: var(--soft); }
.amounts button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.amount-input { max-width: 200px; }
.panel .notice { margin-bottom: 14px; }
.small { font-size: 13px; margin: 12px 0 0; }
.small a, .hint a, .auth-legal a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Документы ---------- */
.legal-links { display: flex; flex-direction: column; gap: 4px; padding: 10px 8px 0; font-size: 12px; color: var(--muted); }
.legal-links a { color: inherit; text-decoration: none; }
.legal-links a:hover { color: var(--text); text-decoration: underline; }
.auth-legal { text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 18px 0 0; }
