:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #15191f;
  --surface-2: #1b2028;
  --surface-3: #222933;
  --line: #2c3440;
  --line-soft: #202832;
  --text: #edf1f5;
  --muted: #9aa6b2;
  --muted-2: #778391;
  --accent: #31c48d;
  --accent-2: #1f8f68;
  --blue: #6aa9ff;
  --warn: #e9b949;
  --danger: #ef6262;
  --shadow: 0 18px 48px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button, input, textarea { font: inherit; }

button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover { border-color: #4b5a69; background: var(--surface-3); }
button:disabled { cursor: not-allowed; opacity: .56; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b0d11;
  color: var(--text);
  border-radius: 7px;
  padding: 11px 12px;
  outline: none;
}

input:focus, textarea:focus { border-color: var(--accent-2); }
textarea { resize: none; min-height: 52px; max-height: 180px; line-height: 1.45; }

.hidden { display: none !important; }

.auth-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 17, 21, .96);
}

.auth-box {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-box h1 { font-size: 28px; margin: 0; }
.auth-box p { margin: 0 0 4px; color: var(--muted); }
.auth-box label { color: var(--muted); font-size: 13px; }
.auth-error { min-height: 20px; color: var(--danger); font-size: 13px; }

.password-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.password-field button { min-width: 58px; }

.shell {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.sidebar {
  background: var(--surface);
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.sidebar { border-right: 1px solid var(--line); }

.brand, .topbar, .modal header {
  min-height: 72px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.brand p, .status, .section-title {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

#newConversation {
  font-size: 16px;
  line-height: 1;
}

.panel, .settings section {
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.user-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.current-user { font-weight: 650; }

.list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.conversations {
  min-height: 0;
  overflow: auto;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: center;
}

.conversation {
  width: 100%;
  min-height: 40px;
  text-align: left;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.delete-conversation {
  width: 34px;
  height: 34px;
  padding: 0;
  opacity: .55;
  color: var(--muted);
}

.delete-conversation:hover {
  opacity: 1;
  color: var(--danger);
  border-color: rgba(239, 98, 98, .45);
}

.conversation:hover {
  color: var(--text);
  background: var(--surface-2);
}

.conversation.active {
  border-color: rgba(49, 196, 141, .45);
  background: rgba(49, 196, 141, .09);
  color: var(--text);
}

.chat {
  min-width: 0;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.topbar { background: rgba(21, 25, 31, .88); }
.title { font-weight: 700; }

.topbar-actions {
  display: flex;
  gap: 8px;
}

.chat-state {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 3px;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted-2);
}

.state-dot.connected { background: var(--accent); }
.state-dot.busy { background: var(--warn); animation: blink 1s infinite; }
.state-dot.error { background: var(--danger); }

.messages {
  min-height: 0;
  height: 100%;
  padding: 22px clamp(18px, 4vw, 52px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  margin: auto;
  max-width: 420px;
  text-align: center;
  color: var(--muted);
}

.empty-state div {
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.empty-state p { margin: 0; }

.message {
  max-width: min(780px, 86%);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  white-space: pre-wrap;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.message.user {
  margin-left: auto;
  background: #14382f;
  border-color: #235f4c;
}

.message.assistant {
  margin-right: auto;
  background: var(--surface-2);
}

.message.system {
  max-width: 100%;
  align-self: center;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  padding: 4px 8px;
}

.message.pending {
  min-width: 190px;
  color: var(--muted);
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
  animation: typing 1.1s infinite ease-in-out;
}

.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

.composer {
  flex: 0 0 auto;
  padding: 14px clamp(18px, 4vw, 52px) 18px;
  border-top: 1px solid var(--line);
  background: rgba(21, 25, 31, .96);
}

.activity {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(233, 185, 73, .45);
  animation: pulse 1.4s infinite;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
}

#sendButton {
  min-width: 92px;
  height: 52px;
  background: var(--accent-2);
  border-color: var(--accent-2);
}

#sendButton:hover { background: #27a97b; }

h2, h3 { margin: 0; }
h2 { font-size: 18px; }
h3 {
  font-size: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

dl {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 8px 12px;
  margin: 0;
  font-size: 13px;
}

dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }

.accounts, .commands { display: grid; gap: 10px; }

.account {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px;
}

.ok { color: var(--accent); }
.bad { color: var(--danger); }

pre {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d11;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, .5);
}

.modal {
  position: fixed;
  top: 72px;
  right: 28px;
  z-index: 40;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 104px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal header {
  min-height: 60px;
}

.modal-body {
  min-height: 0;
  overflow: auto;
}

.modal-body section {
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(233, 185, 73, .45); }
  70% { box-shadow: 0 0 0 8px rgba(233, 185, 73, 0); }
  100% { box-shadow: 0 0 0 0 rgba(233, 185, 73, 0); }
}

@keyframes blink {
  50% { opacity: .45; }
}

@keyframes typing {
  0%, 80%, 100% { transform: translateY(0); opacity: .42; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 1040px) {
  .shell { grid-template-columns: 280px minmax(0, 1fr); }
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .shell { height: auto; min-height: 100dvh; grid-template-columns: 1fr; overflow: visible; }
  .sidebar { height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat { height: calc(100dvh - 260px); min-height: 520px; }
  .composer-row { grid-template-columns: 1fr; }
  #sendButton { width: 100%; }
  .message { max-width: 100%; }
  .modal {
    top: 16px;
    right: 16px;
    left: 16px;
    width: auto;
    max-height: calc(100dvh - 32px);
  }
}
