:root {
  --bg: #0a0a0a;
  --bg2: #141414;
  --bg3: #1e1e1e;
  --border: #2a2a2a;
  --fg: #f0f0f0;
  --muted: #9a9a9a;
  --faint: #6a6a6a;
  --accent: #ffffff;
  --red: #ff6b6b;
  --yellow: #ffd166;
  --radius: 8px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--fg); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { display: flex; flex-direction: column; }
.hidden { display: none !important; }

.view { flex: 1; display: flex; min-height: 0; }

/* ===== Кнопки ===== */
.btn {
  font-family: var(--sans); border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg3); color: var(--fg);
  padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: filter .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:hover { filter: brightness(1.2); }
.btn-primary { background: var(--fg); color: #0a0a0a; border-color: var(--fg); }
.btn-danger { background: transparent; color: var(--red); border-color: #5a2a2a; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; margin-top: 6px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== Алерты ===== */
.alert { border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.alert-error { background: rgba(255,107,107,.08); border: 1px solid #5a2a2a; color: var(--red); }

/* ===== Логин ===== */
#view-login { align-items: center; justify-content: center; padding: 24px; }
.login-box { width: 100%; max-width: 380px; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 28px 24px; }
.logo { font-family: var(--mono); font-size: 20px; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 13px; margin: 8px 0 20px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .composer textarea, select {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--fg); padding: 10px 12px; font-size: 14px; font-family: var(--sans); outline: none;
}
.field input:focus, .composer textarea:focus, select:focus { border-color: var(--muted); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 11px; margin: 16px 0; text-transform: uppercase; letter-spacing: 1px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.host-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.host-card-title { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.host-card-user { font-size: 14px; margin-bottom: 4px; }
.host-card-status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }

/* ===== Топбар ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--bg2); border-bottom: 1px solid var(--border); }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.logo-mini { font-family: var(--mono); color: var(--fg); font-weight: 700; }
.conn-user { font-size: 13px; color: var(--muted); }

/* ===== Подключения ===== */
#view-conn { flex-direction: column; }
.conn-wrap { flex: 1; overflow-y: auto; padding: 20px 16px; max-width: 560px; width: 100%; margin: 0 auto; }
.conn-title { font-size: 18px; font-family: var(--mono); margin-bottom: 6px; }
.conn-hint { font-size: 12px; color: var(--muted); margin-bottom: 18px; }
.host-list { display: flex; flex-direction: column; gap: 10px; }
.host-item { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.host-item:hover { border-color: var(--muted); background: var(--bg3); }
.host-item .h-user { font-size: 14px; font-weight: 600; }
.host-item .h-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.host-item .h-actions { margin-top: 10px; display: flex; gap: 8px; }
.h-del { background: transparent; border: 1px solid #3a2020; color: #f88; border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.h-del:hover { background: rgba(255,107,107,.1); }
.invite-row { margin-top: 24px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.empty { color: var(--faint); text-align: center; padding: 30px 10px; font-size: 13px; }

/* ===== Статус-точка ===== */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-on { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.dot-off { background: var(--faint); }
.dot-red { background: var(--red); }

/* ===== Чат: layout ===== */
#view-chat { }
#sidebar { flex: 0 0 320px; border-right: 1px solid var(--border); background: var(--bg2); display: flex; flex-direction: column; min-width: 0; }
#chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.side-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.side-host-wrap { flex: 1; min-width: 0; }
.side-host { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-status { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 2px; }

.proj-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.proj-row select { width: auto; flex: 1; padding: 5px 8px; font-size: 12px; background: var(--bg); }

.session-list { flex: 1; overflow-y: auto; padding: 8px; }
.session-item { padding: 10px 12px; border-radius: var(--radius); cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; }
.session-item:hover { background: var(--bg3); }
.session-item.active { background: var(--bg3); border-color: var(--muted); }
.session-item .s-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .s-preview { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.session-item .s-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.session-item .s-time { font-size: 10px; color: var(--faint); font-family: var(--mono); }
.session-item .s-del { background: transparent; border: none; color: var(--faint); cursor: pointer; font-size: 12px; padding: 2px 6px; }
.session-item .s-del:hover { color: var(--red); }
.side-new { margin: 8px; width: calc(100% - 16px); }

/* ===== Чат-хедер ===== */
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--bg2); }
.chat-title-wrap { flex: 1; min-width: 0; }
.chat-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }
.chat-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-head-right { display: flex; align-items: center; gap: 10px; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 14px; }

/* ===== Сообщения ===== */
.msg { max-width: 92%; display: flex; flex-direction: column; gap: 4px; }
.msg-user { align-self: flex-end; }
.msg-assistant { align-self: flex-start; }
.msg-bubble { padding: 9px 12px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.msg-user .msg-bubble { background: var(--fg); color: #0a0a0a; border-bottom-right-radius: 2px; font-weight: 500; }
.msg-assistant .msg-bubble { background: var(--bg2); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.msg-label { font-size: 10px; color: var(--faint); font-family: var(--mono); padding: 0 4px; }
.msg-error { align-self: flex-start; width: 100%; }
.msg-error .msg-bubble { background: rgba(255,107,107,.06); border: 1px solid #5a2a2a; color: var(--red); }
.msg-tool .msg-bubble { background: var(--bg); color: var(--muted); font-family: var(--mono); font-size: 12px; }

.thinking { color: var(--muted); font-size: 12px; font-family: var(--mono); display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.thinking .dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* markdown */
.msg-bubble pre { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; overflow-x: auto; margin: 6px 0; font-size: 12.5px; }
.msg-bubble code { font-family: var(--mono); font-size: 12px; }
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin: 6px 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 10px 0 6px; font-size: 1.1em; }
.msg-bubble a { color: #9ecbff; }
.msg-bubble blockquote { border-left: 3px solid var(--border); padding-left: 10px; color: var(--muted); margin: 6px 0; }

/* ===== Композер ===== */
.composer { border-top: 1px solid var(--border); background: var(--bg2); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer textarea { resize: none; font-family: var(--sans); line-height: 1.4; max-height: 140px; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.hint { font-size: 11px; color: var(--faint); font-family: var(--mono); }

/* ===== Тоггл ===== */
.toggle-wrap { display: inline-flex; align-items: center; cursor: pointer; }
.toggle-wrap input { display: none; }
.toggle { width: 32px; height: 18px; border-radius: 9px; background: var(--bg3); border: 1px solid var(--border); position: relative; transition: background .15s; }
.toggle::after { content: ''; position: absolute; top: 1px; left: 1px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: left .15s, background .15s; }
.toggle-wrap input:checked + .toggle { background: var(--muted); border-color: var(--muted); }
.toggle-wrap input:checked + .toggle::after { left: 15px; background: #0a0a0a; }

/* ===== Модалка ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal { width: 100%; max-width: 480px; background: var(--bg2); border: 1px solid var(--border); border-top-left-radius: 12px; border-top-right-radius: 12px; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal { border-radius: 12px; } }
.modal-title { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.modal-desc { font-size: 13px; color: var(--muted); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; font-family: var(--mono); white-space: pre-wrap; word-break: break-word; max-height: 180px; overflow-y: auto; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ===== Мобилка: одна колонка ===== */
@media (max-width: 899px) {
  #view-chat { flex-direction: column; }
  #sidebar { flex: 1; border-right: none; border-bottom: 1px solid var(--border); }
  #chat-main { flex: 1; }
  .hide-mobile { display: none !important; }
}
