/* ============================================================
   Тема и токены. Светлая по умолчанию, тёмная через [data-theme].
   ============================================================ */
:root {
  --bg:        #ffffff;
  --bg-side:   #fafafa;
  --bg-elev:   #ffffff;
  --bg-hover:  #f2f2f2;
  --bg-active: #ececec;
  --border:    #ebebeb;
  --border-strong: #e0e0e0;
  --text:      #1a1a1a;
  --text-soft: #6b6b6b;
  --text-mute: #9a9a9a;
  --accent:    #7c5cff;      /* фиолетовый — выбранное */
  --accent-2:  #e0a93b;      /* янтарный — вторичный акцент (Combine) */
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.16);
}
[data-theme="dark"] {
  --bg:        #1a1a1c;
  --bg-side:   #161618;
  --bg-elev:   #232326;
  --bg-hover:  #2a2a2e;
  --bg-active: #313136;
  --border:    #2c2c30;
  --border-strong: #38383d;
  --text:      #ededed;
  --text-soft: #a8a8ad;
  --text-mute: #6f6f76;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app { display: grid; grid-template-columns: 264px 1fr; height: 100vh; }

/* ───────────── Sidebar ───────────── */
.sidebar {
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px 12px;
  gap: 12px;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 6px 2px; }
.brand-logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--text); color: var(--bg);
  display: grid; place-items: center; font-size: 14px; font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.2px; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 0 10px;
}
.search-box .icon { width: 16px; height: 16px; color: var(--text-mute); }
.search-box input {
  border: 0; outline: 0; background: transparent; color: var(--text);
  padding: 9px 0; flex: 1; font-size: 13px; font-family: inherit; min-width: 0;
}
.search-box input::placeholder { color: var(--text-mute); }

.side-actions { display: flex; gap: 8px; }
.side-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px; cursor: pointer;
  color: var(--text-soft); font-size: 13px; font-weight: 500; font-family: inherit;
  transition: background .12s, color .12s;
}
.side-btn:hover { background: var(--bg-hover); color: var(--text); }
.side-btn .icon { width: 15px; height: 15px; }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--text); color: var(--bg);
  border: 0; border-radius: var(--radius-sm); padding: 11px;
  font-weight: 600; font-size: 13px; cursor: pointer; font-family: inherit;
  transition: opacity .12s;
}
.new-chat:hover { opacity: .88; }
.new-chat .icon { width: 16px; height: 16px; }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 2px -4px; padding: 0 4px; }
.chat-list-label { font-size: 11px; font-weight: 600; color: var(--text-mute); text-transform: uppercase; letter-spacing: .5px; padding: 10px 8px 4px; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 9px; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-soft); font-size: 13px; white-space: nowrap; overflow: hidden;
}
.chat-item span { overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--bg-active); color: var(--text); font-weight: 500; }
.chat-item .del { margin-left: auto; opacity: 0; color: var(--text-mute); }
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: #e5484d; }

.sidebar-footer { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.foot-btn {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: transparent; border: 0; cursor: pointer; font-family: inherit;
  color: var(--text-soft); font-size: 13px; padding: 7px 8px; border-radius: var(--radius-sm);
}
.foot-btn:hover { background: var(--bg-hover); color: var(--text); }
.foot-btn .icon { width: 16px; height: 16px; }
.key-status { margin-left: auto; color: var(--text-mute); font-family: var(--mono); }
.key-status.ok { color: #30a46c; }

.icon-btn {
  background: transparent; border: 0; cursor: pointer; color: var(--text-soft);
  width: 34px; height: 34px; border-radius: var(--radius-sm); display: grid; place-items: center;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.ghost:disabled { opacity: .4; cursor: default; }

/* ───────────── Main ───────────── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
}
.model-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 7px 10px 7px 8px; cursor: pointer;
  font-family: inherit; color: var(--text); font-weight: 600; font-size: 13px;
  box-shadow: var(--shadow); transition: background .12s;
}
.model-pill:hover { background: var(--bg-hover); }
.model-pill-icon {
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  background: var(--bg-active); color: var(--text-soft);
  border-radius: 6px; padding: 3px 6px;
}
.model-pill .chev { width: 15px; height: 15px; color: var(--text-mute); }
.topbar-title { color: var(--text-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; gap: 4px; }

.tag {
  font-size: 9.5px; font-weight: 600; letter-spacing: .4px;
  text-transform: uppercase; color: var(--text-mute);
  background: var(--bg-active); border-radius: 999px; padding: 3px 7px;
}

/* ───────────── Chat ───────────── */
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.welcome {
  margin: auto; text-align: center; max-width: 440px; padding: 40px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.welcome-logo {
  width: 56px; height: 56px; border-radius: 16px; margin-bottom: 8px;
  background: var(--text); color: var(--bg); display: grid; place-items: center; font-size: 26px;
}
.welcome h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.4px; }
.welcome p { color: var(--text-soft); margin: 0; line-height: 1.5; }

.messages { max-width: 760px; width: 100%; margin: 0 auto; padding: 24px 20px 8px; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; gap: 12px; }
.msg .avatar {
  width: 28px; height: 28px; border-radius: 8px; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; font-family: var(--mono);
}
.msg.user .avatar { background: var(--accent); color: #fff; }
.msg.assistant .avatar { background: var(--bg-active); color: var(--text-soft); }
.msg .body { flex: 1; min-width: 0; padding-top: 3px; }
.msg .role { font-weight: 600; font-size: 12px; color: var(--text-soft); margin-bottom: 4px; }
.msg .content { line-height: 1.65; word-wrap: break-word; }
.msg .content p { margin: 0 0 10px; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content pre {
  background: var(--bg-side); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 10px 0;
}
.msg .content code { font-family: var(--mono); font-size: 12.5px; }
.msg .content :not(pre) > code { background: var(--bg-active); padding: 1px 5px; border-radius: 5px; }
.msg .content pre code { background: none; padding: 0; }
.cursor-blink { display: inline-block; width: 7px; height: 15px; background: var(--text); vertical-align: text-bottom; animation: blink 1s steps(2) infinite; border-radius: 1px; }
@keyframes blink { 50% { opacity: 0; } }

/* ───────────── Composer ───────────── */
.composer-wrap { padding: 8px 20px 18px; max-width: 760px; width: 100%; margin: 0 auto; }
.composer {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 8px 8px 8px 6px; box-shadow: var(--shadow);
  transition: border-color .12s;
}
.composer:focus-within { border-color: var(--text-mute); }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font-family: inherit; font-size: 14.5px; line-height: 1.5; padding: 8px 4px; max-height: 220px;
}
.composer textarea::placeholder { color: var(--text-mute); }
.send-btn {
  width: 36px; height: 36px; border-radius: 11px; border: 0; cursor: pointer;
  background: var(--text); color: var(--bg); display: grid; place-items: center; flex: none;
  transition: opacity .12s;
}
.send-btn:hover { opacity: .88; }
.send-btn:disabled { opacity: .3; cursor: default; }
.composer-hint { display: flex; align-items: center; gap: 7px; justify-content: center; color: var(--text-mute); font-size: 11.5px; margin-top: 9px; }
.composer-hint .dot { opacity: .5; }

/* ───────────── Overlays / picker / modal ───────────── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.18); z-index: 50; }
[data-theme="dark"] .overlay { background: rgba(0,0,0,.5); }
.overlay.center { display: grid; place-items: center; }

.picker {
  position: absolute; top: 58px; left: 18px; width: 460px; max-width: calc(100vw - 36px);
  max-height: 70vh; background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 16px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
}
.picker-head { padding: 12px; border-bottom: 1px solid var(--border); }
.picker-head .search-box { background: var(--bg); }
.picker-body { overflow-y: auto; padding: 6px; }
.group-label {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 10px 6px; font-weight: 700; font-size: 13px;
}
.group-label .count { margin-left: auto; color: var(--text-mute); font-weight: 500; font-size: 12px; }
.group-icon { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--text-soft); }
.model-row {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
}
.model-row:hover { background: var(--bg-hover); }
.model-row.active { background: var(--bg-active); }
.model-row .mr-icon {
  width: 26px; height: 26px; border-radius: 7px; flex: none; display: grid; place-items: center;
  background: var(--bg-active); color: var(--text-soft); font-family: var(--mono); font-size: 10px; font-weight: 700;
}
.model-row .mr-text { min-width: 0; flex: 1; }
.model-row .mr-name { font-weight: 600; font-size: 13.5px; }
.model-row .mr-id { font-family: var(--mono); font-size: 11px; color: var(--text-mute); margin-top: 1px; }
.model-row .check { color: var(--accent); width: 17px; height: 17px; opacity: 0; }
.model-row.active .check { opacity: 1; }

.modal {
  width: 440px; max-width: calc(100vw - 32px);
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 20px;
}
.modal-head { display: flex; align-items: center; margin-bottom: 16px; }
.modal-head h2 { font-size: 16px; margin: 0; flex: 1; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: inherit; font-size: 13.5px; background: var(--bg); color: var(--text); outline: 0;
}
.field input:focus { border-color: var(--text-mute); }
.field small { display: block; color: var(--text-mute); font-size: 11.5px; margin-top: 6px; line-height: 1.4; }
.field small code { font-family: var(--mono); background: var(--bg-active); padding: 1px 4px; border-radius: 4px; }
.modal-foot { display: flex; justify-content: flex-end; }
.btn-primary {
  background: var(--text); color: var(--bg); border: 0; cursor: pointer; font-family: inherit;
  font-weight: 600; font-size: 13.5px; padding: 10px 18px; border-radius: var(--radius-sm); transition: opacity .12s;
}
.btn-primary:hover { opacity: .88; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; transition: all .2s; z-index: 100; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ───────────── Auth screen ───────────── */
.auth-screen { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 20px; }
.auth-card {
  position: relative; width: 380px; max-width: 100%;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow); padding: 32px 28px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.brand-logo.big { width: 48px; height: 48px; border-radius: 14px; font-size: 22px; margin: 0 auto 12px; }
.auth-title { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.auth-tagline { color: var(--text-soft); font-size: 13px; margin-top: 3px; }
.auth-tabs { display: flex; gap: 4px; background: var(--bg-side); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; padding: 8px; border: 0; border-radius: 8px; cursor: pointer; font-family: inherit;
  font-size: 13px; font-weight: 600; color: var(--text-soft); background: transparent; transition: all .12s;
}
.auth-tab.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .field { margin: 0; }
.auth-error { color: #e5484d; font-size: 12.5px; background: rgba(229,72,77,.08); border: 1px solid rgba(229,72,77,.2); border-radius: 8px; padding: 8px 10px; }
.btn-primary.wide { width: 100%; padding: 11px; font-size: 14px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0 14px; color: var(--text-mute); font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.google-btn-wrap { display: flex; justify-content: center; min-height: 0; }
.theme-corner { position: absolute; top: 14px; right: 14px; }

/* ───────────── Account modal extras ───────────── */
.modal.account { width: 480px; }
.account-email { font-weight: 600; font-size: 13px; color: var(--text-soft); margin-bottom: 16px; word-break: break-all; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-family: var(--mono); font-size: 12.5px; }
.copy-btn {
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text-soft);
  border-radius: var(--radius-sm); padding: 0 12px; cursor: pointer; font-family: inherit;
  font-size: 12.5px; font-weight: 500; white-space: nowrap; transition: background .12s;
}
.copy-btn:hover { background: var(--bg-hover); color: var(--text); }
.copy-btn.small { padding: 7px 12px; margin-top: 8px; }
.snippet {
  background: var(--bg-side); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-family: var(--mono); font-size: 12px; line-height: 1.7;
  overflow-x: auto; margin: 0; color: var(--text); white-space: pre;
}
.usage { background: var(--bg-side); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 18px; }
.usage-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 9px; }
.usage-head span:last-child { font-family: var(--mono); color: var(--text-soft); }
.usage-bar { height: 7px; background: var(--bg-active); border-radius: 99px; overflow: hidden; }
.usage-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.usage-fill.full { background: #e5484d; }
.usage small { display: block; color: var(--text-mute); font-size: 11.5px; margin-top: 8px; }
.modal-foot.spread { justify-content: space-between; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border-strong); color: var(--text-soft);
  border-radius: var(--radius-sm); padding: 9px 16px; cursor: pointer; font-family: inherit;
  font-size: 13px; font-weight: 500; transition: background .12s;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-ghost.danger:hover { color: #e5484d; border-color: rgba(229,72,77,.4); }
.foot-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ───────────── Admin ───────────── */
.admin-entry { width: 100%; justify-content: flex-start; padding-left: 11px; }
.admin-screen { position: fixed; inset: 0; z-index: 40; display: grid; grid-template-columns: 320px 1fr; background: var(--bg); }
.admin-side { background: var(--bg-side); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px; gap: 10px; min-width: 0; }
.admin-side-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.admin-side-head span { flex: 1; }
.admin-users { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; margin: 0 -4px; padding: 0 4px; }
.admin-user { padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.admin-user:hover { background: var(--bg-hover); }
.admin-user.active { background: var(--bg-active); }
.au-email { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.au-meta { font-size: 11.5px; color: var(--text-mute); margin-top: 2px; }
.admin-empty, .admin-loading { padding: 28px 16px; text-align: center; color: var(--text-mute); font-size: 13px; }

.admin-main { overflow-y: auto; display: flex; flex-direction: column; }
.admin-placeholder { margin: auto; color: var(--text-mute); }
.admin-content { display: flex; flex-direction: column; min-height: 0; }
.admin-head { display: flex; align-items: center; gap: 14px; padding: 16px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.admin-head-title { font-weight: 700; font-size: 15px; }
.admin-head-sub { color: var(--text-soft); font-size: 12.5px; margin-top: 2px; }
.btn-ghost.small { padding: 6px 12px; font-size: 12.5px; }

.conv-list { max-width: 820px; width: 100%; margin: 0 auto; padding: 16px 22px; display: flex; flex-direction: column; gap: 8px; }
.conv-item { border: 1px solid var(--border-strong); border-radius: 12px; padding: 12px 14px; cursor: pointer; transition: background .12s; }
.conv-item:hover { background: var(--bg-hover); }
.conv-preview { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--text-mute); font-size: 11.5px; margin-top: 6px; }
.conv-meta span:first-child { font-family: var(--mono); }

.thread { max-width: 820px; width: 100%; margin: 0 auto; padding: 22px; display: flex; flex-direction: column; gap: 22px; }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .admin-screen { grid-template-columns: 1fr; }
}
