:root {
  --bg: #ffffff;
  --panel: #f7f7f9;
  --panel-2: #eeeef2;
  --border: #e6e6ec;
  --text: #1c1d22;
  --muted: #8b8b95;
  --accent: #6d5efc;
  --accent-2: #5a4ce0;
  --accent-weak: #efecff;
  --danger: #e5484d;
  --ok: #2e9e6b;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 10px 30px rgba(20, 20, 40, .10);
  /* dark sidebar */
  --side-bg: #1b1c22;
  --side-text: #e7e7ec;
  --side-muted: #9595a1;
  --side-hover: #2a2b34;
  --side-active: rgba(109, 94, 252, .26);
  --side-border: #2e2f3a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
}
form { margin: 0; }
button { font-family: inherit; }
svg.lucide { width: 18px; height: 18px; flex-shrink: 0; }

/* ===== App shell ===== */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 268px; flex-shrink: 0;
  background: var(--side-bg); color: var(--side-text);
  border-right: 1px solid var(--side-border);
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px; transition: width .15s ease;
}
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 34px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 16px; letter-spacing: .18em; color: #fff; padding: 2px 4px; min-width: 0; }

/* sidebar icon buttons */
.sidebar .icon { color: var(--side-muted); }
.sidebar .icon:hover { background: var(--side-hover); color: var(--side-text); }
.sidebar .icon.danger:hover { background: rgba(229, 72, 77, .18); color: #ff8d90; }

.icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; text-decoration: none; flex-shrink: 0;
}
.icon:hover { background: var(--panel-2); color: var(--text); }
.icon.danger:hover { background: #fdecec; color: var(--danger); }
.icon svg.lucide { width: 17px; height: 17px; }

.new-session button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 10px;
  background: transparent; color: #62d29a; border: none;
  font: inherit; font-size: 15px; text-align: left; cursor: pointer;
}
.new-session button svg.lucide { color: #62d29a; }
.new-session button:hover { background: rgba(98, 210, 154, .14); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  color: var(--side-text); text-decoration: none;
  width: 100%; background: transparent; border: none;
  font: inherit; font-size: 15px; cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--side-hover); }
.nav-item svg.lucide { color: var(--side-muted); width: 18px; }

.divider { height: 1px; background: var(--side-border); margin: 8px 2px; }

.sessions { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px; }
.session { display: flex; align-items: center; border-radius: 10px; }
.session:hover { background: var(--side-hover); }
.session.active { background: var(--side-active); }
.session-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 9px 10px; color: var(--side-text); text-decoration: none; }
.session-link svg.lucide { color: var(--side-muted); width: 17px; height: 17px; }
.session.active .session-link svg.lucide { color: #b3a8ff; }
.session-link .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session .del { display: flex; }
.session .icon.danger { opacity: 0; }
.session:hover .icon.danger, .session.active .icon.danger { opacity: 1; }

/* user / profile menu */
.usermenu { position: relative; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu:hover summary, .usermenu[open] summary { background: var(--side-hover); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: rgba(109, 94, 252, .28); color: #cdc4ff; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.uname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { transition: transform .15s; color: var(--side-muted); }
.usermenu[open] .chev { transform: rotate(180deg); }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; width: 234px; z-index: 50;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 8px; border: none; background: transparent;
  color: var(--text); text-decoration: none; font: inherit; cursor: pointer; text-align: left;
}
.menu a:hover, .menu button:hover { background: var(--panel-2); }
.menu svg.lucide { width: 16px; height: 16px; color: var(--muted); }

/* ===== Collapsed sidebar ===== */
body.sidebar-collapsed .sidebar { width: 62px; padding: 12px 9px; }
body.sidebar-collapsed .sidebar .label { display: none; }
body.sidebar-collapsed .brand { display: none; }
body.sidebar-collapsed .side-top { justify-content: center; }
body.sidebar-collapsed .new-session button,
body.sidebar-collapsed .nav-item,
body.sidebar-collapsed .usermenu summary,
body.sidebar-collapsed .session-link { justify-content: center; gap: 0; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .session .del { display: none; }
body.sidebar-collapsed .uname, body.sidebar-collapsed .chev { display: none; }

/* ===== Content / chat ===== */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 18px; min-height: 58px; border-bottom: 1px solid var(--border); }
.chat-head .title { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.chat-head .title svg.lucide { color: var(--muted); }
.chat-head .title strong { font-size: 16px; }
.chat-head .title input {
  flex: 1; min-width: 0; border: 1px solid transparent; background: transparent;
  font-size: 16px; font-weight: 600; color: var(--text); padding: 5px 8px; border-radius: 8px;
}
.chat-head .title input:hover { background: var(--panel-2); }
.chat-head .title input:focus { outline: none; background: var(--bg); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.actions { display: flex; align-items: center; gap: 6px; }
.actions .head-form { display: flex; }
.model-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); background: var(--panel-2); padding: 5px 10px; border-radius: 20px; }
.model-chip svg.lucide { width: 13px; height: 13px; }
.icon.toggle.on { background: var(--accent-weak); color: var(--accent-2); }
.toggle[data-flag="focus_show"].on { color: #3f7b9a; background: #e6eff5; }
.toggle[data-flag="state_show"].on { color: #9a7b3f; background: #f5efe1; }
.toggle[data-flag="debug_show"].on { color: var(--accent-2); background: var(--accent-weak); }

#log { flex: 1; overflow-y: auto; padding: 22px 18px; display: flex; flex-direction: column; gap: 12px; }

.msg { max-width: min(760px, 80%); width: fit-content; padding: 11px 15px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.mode-mind { font-style: italic; color: #585863; background: #faf9ff; border-color: #e7e2fb; border-left: 3px solid #c5bcf7; }
.mode-narrator { align-self: center; max-width: min(680px, 88%); background: #fbf7ef; border-color: #ece0c9; }
.msg.error { align-self: center; background: #fdecec; color: var(--danger); border: 1px solid #f4c9cb; font-size: 14px; }

/* ряд ответа: иконка типа слева + облако + действия */
.turn { display: flex; align-items: flex-start; gap: 8px; align-self: flex-start; max-width: min(840px, 86%); }
.turn .msg, .turn .marker { max-width: 100%; width: fit-content; }
.turn .mode-narrator { align-self: flex-start; }
.user-turn { align-self: flex-end; }
.turn-ico { flex-shrink: 0; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; color: var(--muted); margin-top: 3px; }
.turn-ico svg.lucide { width: 18px; height: 18px; }
.marker-row.state .turn-ico { color: #9a7b3f; }
.marker-row.focus .turn-ico { color: #3f7b9a; }
.turn-actions { display: flex; gap: 2px; align-self: center; opacity: 0; transition: opacity .12s; }
.turn:hover .turn-actions { opacity: 1; }
.turn-actions .icon { width: 28px; height: 28px; }
.turn-actions .icon svg.lucide { width: 15px; height: 15px; }

/* модальное окно редактирования сообщения */
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(20, 20, 40, .45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay[hidden] { display: none; }
.modal { width: min(720px, 100%); background: var(--bg); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-title { font-weight: 600; font-size: 15px; }
.modal-area { width: 100%; min-height: 220px; max-height: 60vh; resize: vertical; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; font: inherit; font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text); }
.modal-area:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }

.marker { align-self: flex-start; width: fit-content; max-width: min(760px, 80%); font-size: 15px; color: var(--text); background: var(--panel); border: 1px dashed var(--border); border-radius: 16px; border-bottom-left-radius: 5px; padding: 11px 15px; white-space: pre-wrap; line-height: 1.5; }
.marker.debug { font-size: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; max-width: min(680px, 88%); }
/* видимость меток и дебага управляется тумблерами (классы на #log) */
#log .turn.marker-row.state, #log .turn.marker-row.focus, #log .turn.debug-row { display: none; }
#log.show-state .turn.marker-row.state { display: flex; }
#log.show-focus .turn.marker-row.focus { display: flex; }
#log.show-debug .turn.debug-row { display: flex; }

.thinking { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; border-bottom-left-radius: 5px; padding: 13px 16px; display: inline-flex; gap: 5px; }
.thinking .dot { width: 7px; height: 7px; border-radius: 50%; background: #b3b3bd; animation: blink 1.4s infinite both; }
.thinking .dot:nth-child(2) { animation-delay: .2s; }
.thinking .dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.empty { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty svg.lucide { width: 34px; height: 34px; color: #c7c7d0; }
.empty p { margin: 0; }

/* composer */
.composer { border-top: 1px solid var(--border); padding: 12px 18px 16px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.modes { display: flex; gap: 2px; align-items: center; flex-shrink: 0; }
.modes label { width: 40px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 11px; color: var(--muted); cursor: pointer; }
.modes label:hover { background: var(--panel-2); color: var(--text); }
.modes input { display: none; }
.modes label:has(input:checked) { background: var(--accent-weak); color: var(--accent-2); }
.modes label svg.lucide { width: 20px; height: 20px; }
.composer textarea {
  flex: 1; resize: none; max-height: 200px; min-height: 44px;
  padding: 11px 14px; border: 1px solid var(--border); border-radius: 14px;
  font: inherit; line-height: 1.4; background: var(--bg);
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }

button.primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--accent); color: #fff; border: none; border-radius: 13px; padding: 0 18px; height: 44px; font-weight: 600; cursor: pointer; }
button.primary:hover { background: var(--accent-2); }
button.primary:disabled { opacity: .5; cursor: default; }
#send { width: 44px; padding: 0; flex-shrink: 0; }
#send svg.lucide { width: 20px; height: 20px; }
.temp-ctl { display: inline-flex; align-items: center; gap: 1px; flex-shrink: 0; }
.temp-ctl .icon { width: 30px; height: 44px; }
.temp-ctl > svg.lucide { color: var(--muted); width: 16px; height: 16px; }
.chip-temp { display: inline-flex; align-items: center; gap: 3px; margin-left: 7px; padding-left: 8px; border-left: 1px solid #d6d6dc; }
.chip-temp svg.lucide { width: 12px; height: 12px; }
.chip-tokens { display: inline-flex; align-items: center; gap: 3px; margin-left: 7px; padding-left: 8px; border-left: 1px solid #d6d6dc; }
.chip-tokens svg.lucide { width: 12px; height: 12px; }
.btn-ghost { display: inline-flex; align-items: center; height: 44px; padding: 0 18px; border-radius: 13px; color: var(--muted); text-decoration: none; border: 1px solid var(--border); background: transparent; font: inherit; cursor: pointer; }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.danger-zone { display: flex; }
.btn-danger { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 11px; background: #fff; color: var(--danger); border: 1px solid #f0c4c6; font: inherit; cursor: pointer; }
.btn-danger:hover { background: #fdecec; }
.btn-danger svg.lucide { width: 17px; height: 17px; }

/* ===== Auth ===== */
body.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #f1eeff, #fafafa); }
.auth-card { width: 348px; background: var(--bg); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); padding: 30px; display: flex; flex-direction: column; gap: 14px; }
.auth-brand { display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; letter-spacing: .2em; color: var(--accent); }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }

/* ===== Forms ===== */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input:not([type]), textarea, select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
input[type=range] { accent-color: var(--accent); width: 100%; padding: 0; margin-top: 4px; }

.page-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.page-body > * { width: 100%; max-width: 1100px; }
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.settings-form > * { width: 100%; }
.settings-form textarea { resize: none; line-height: 1.5; }
.muted-note { margin: 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { display: inline-flex; align-items: center; gap: 7px; border: none; background: none; padding: 11px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab svg.lucide { width: 16px; height: 16px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-2); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.card { width: 100%; max-width: 1100px; background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 2px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.card h2 svg.lucide { width: 17px; height: 17px; color: var(--accent); }
.inline { display: flex; gap: 22px; align-items: flex-end; flex-wrap: wrap; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }
.opt { color: #b7b7c0; font-weight: 400; }
.form-actions { width: 100%; max-width: 1100px; display: flex; gap: 10px; align-items: center; }
.form-actions .right { margin-left: auto; }
/* профиль и настройки сессии используют .page-body / .settings-form */
.banner { padding: 10px 13px; border-radius: 10px; font-size: 13px; }
.banner.error { background: #fdecec; color: var(--danger); }
.banner.ok { background: #e6f6ee; color: var(--ok); }
