:root {
  --bg: #0e1015; --panel: #161a22; --panel2: #1e232d; --line: #2a303c;
  --text: #e8eaf0; --muted: #8d95a6; --accent: #8b7cff; --accent-d: #6e5ff0;
  --danger: #ff6b6b; --ok: #4cc38a; --user: #26304a; --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

#app { display: flex; height: 100dvh; }
#nav { width: 190px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; flex-shrink: 0; }
.brand { font-size: 18px; font-weight: 700; padding: 6px 10px 16px; color: var(--accent); }
#nav button { display: flex; align-items: center; gap: 10px; background: none; border: 0;
  padding: 10px 12px; border-radius: 10px; text-align: left; color: var(--muted); }
#nav button:hover { background: var(--panel2); color: var(--text); }
#nav button.active { background: var(--panel2); color: var(--text); box-shadow: inset 3px 0 var(--accent); }
#main { flex: 1; min-width: 0; overflow: auto; }

.btn { background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent-d); border-color: var(--accent-d); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=number], input[type=password], input[type=url], select, textarea {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; }

.page { max-width: 920px; margin: 0 auto; padding: 22px 20px 40px; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { flex: 1; font-size: 22px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.tag { display: inline-block; background: var(--panel2); border-radius: 20px; padding: 1px 9px; font-size: 12px; color: var(--muted); margin: 4px 4px 0 0; }

.av { width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 700; color: #fff; object-fit: cover; }
.av.big { width: 88px; height: 88px; font-size: 32px; }
.av.sm { width: 34px; height: 34px; font-size: 14px; }

.char-card { display: flex; flex-direction: column; gap: 10px; }
.char-card .tagline { color: var(--muted); font-size: 13px; min-height: 38px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* чаты */
.split { display: flex; height: 100%; }
.list { width: 300px; border-right: 1px solid var(--line); overflow: auto; flex-shrink: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 14px; position: sticky;
  top: 0; background: var(--bg); z-index: 1; }
.chat-item { display: flex; gap: 10px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.chat-item:hover, .chat-item.active { background: var(--panel); }
.chat-item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex-wrap: wrap; }
.chat-head select { width: auto; max-width: 170px; padding: 5px 8px; }
.back { display: none; }
#msgs { flex: 1; overflow: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 760px; width: 100%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .wrap { min-width: 0; max-width: 100%; }
.msg.user .wrap { display: flex; flex-direction: column; align-items: flex-end; }
.meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.bubble { background: var(--panel2); padding: 9px 13px; border-radius: 4px 14px 14px 14px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); border-radius: 14px 4px 14px 14px; }
.bubble em { color: #b9b2ff; }
.bubble.pending::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.tools { display: flex; gap: 2px; margin-top: 3px; opacity: .55; align-items: center; font-size: 13px; }
.msg:hover .tools { opacity: 1; }
.tools button { background: none; border: 0; padding: 2px 7px; border-radius: 6px; color: var(--muted); }
.tools button:hover { background: var(--panel2); color: var(--text); }
.edit-box textarea { min-height: 90px; }
#composer { display: flex; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
#composer textarea { min-height: 44px; max-height: 160px; resize: none; }
#composer .btn { align-self: flex-end; height: 44px; }

/* формы */
.lore-row { background: var(--panel2); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.err { background: var(--danger); }
.switch { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--text); margin: 0; }
.switch input { width: auto; }

#modal-root .back-drop { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 10; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; width: min(520px, 100%); max-height: 90dvh; overflow: auto; }
.modal h2 { margin-bottom: 6px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--line); padding: 10px 18px; border-radius: 12px; z-index: 20; opacity: 0;
  transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { border-color: var(--danger); color: var(--danger); }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  #nav { width: 100%; flex-direction: row; border-right: 0; border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .brand { display: none; }
  #nav button { flex-direction: column; gap: 0; padding: 6px 8px; font-size: 11px; align-items: center; text-align: center; }
  #nav button.active { box-shadow: none; color: var(--accent); }
  .ico { font-size: 18px; }
  .list { width: 100%; border-right: 0; }
  .split[data-open="1"] .list { display: none; }
  .split[data-open="0"] .pane { display: none; }
  .back { display: inline-block; }
  .page { padding: 16px 14px 30px; }
  .grid { grid-template-columns: 1fr; }
}
