:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-2: #10131b;
  --panel: rgba(23, 27, 38, 0.82);
  --panel-solid: #161a24;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #eef1f7;
  --muted: #9aa3b5;
  --muted-2: #6f788b;
  --accent: #7c9cff;
  --accent-2: #9b7cff;
  --accent-ink: #081022;
  --danger: #ff7d8a;
  --ok: #55d6a0;
  --warn: #ffc86b;
  --user: linear-gradient(135deg, #5f7cff, #8a6bff);
  --assistant: rgba(255, 255, 255, 0.035);
  --radius: 18px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eef1f7;
    --bg-2: #e4e8f2;
    --panel: rgba(255, 255, 255, 0.78);
    --panel-solid: #ffffff;
    --line: rgba(16, 24, 40, 0.09);
    --line-strong: rgba(16, 24, 40, 0.16);
    --text: #111827;
    --muted: #5b6475;
    --muted-2: #7b8496;
    --accent: #3d5eea;
    --accent-2: #7a4fe0;
    --accent-ink: #ffffff;
    --danger: #c0263a;
    --ok: #0b8f63;
    --warn: #a86a00;
    --assistant: rgba(17, 24, 39, 0.035);
    --shadow: 0 20px 50px rgba(16, 24, 40, 0.14);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(900px 600px at 12% -10%, rgba(124, 156, 255, 0.18), transparent 60%),
    radial-gradient(800px 600px at 95% 0%, rgba(155, 124, 255, 0.14), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 18px; font-size: 13px; margin: 8px 0 0; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; flex-wrap: wrap; }

/* ---------- boot ---------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  justify-items: center;
  background: var(--bg);
  z-index: 50;
}

.boot-mark {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.boot-mark span { color: var(--accent); }

.boot-bar {
  width: 180px;
  height: 3px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
.boot-bar i {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: boot 1.1s ease-in-out infinite;
}
@keyframes boot {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ---------- login ---------- */

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}
.brand strong { display: block; font-size: 15px; letter-spacing: -0.01em; }
.brand span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px rgba(124, 156, 255, 0.28);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: -0.03em;
}
.login-card > .muted { margin: 0 0 22px; font-size: 14px; }

.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
@media (prefers-color-scheme: light) {
  input, select, textarea { background: rgba(255, 255, 255, 0.7); }
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 156, 255, 0.18);
  background: rgba(0, 0, 0, 0.24);
}
@media (prefers-color-scheme: light) {
  input:focus, select:focus, textarea:focus { background: #fff; }
}

textarea { resize: none; line-height: 1.5; }

/* ---------- buttons ---------- */

.btn {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 10px 24px rgba(124, 156, 255, 0.25);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.compact { padding: 8px 12px; font-size: 12px; }
.btn.wide { width: 100%; padding: 12px; }
.btn.icon-btn { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; font-size: 15px; }

/* ---------- app layout ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
}
.small-brand { margin: 0; gap: 10px; }
.small-brand .brand-mark { width: 32px; height: 32px; border-radius: 10px; font-size: 11px; }
.small-brand strong { font-size: 13px; }
.small-brand span { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; }

.side-search { padding: 0 12px 10px; }
.side-search input { border-radius: 10px; padding: 9px 11px; font-size: 12px; }

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.conv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
  background: transparent;
  color: var(--text);
  width: 100%;
}
.conv:hover { background: rgba(255, 255, 255, 0.055); }
.conv.active { background: rgba(124, 156, 255, 0.13); border-color: rgba(124, 156, 255, 0.24); }
.conv-main { min-width: 0; }
.conv-title {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-sub {
  display: block;
  font-size: 11px;
  color: var(--muted-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.conv-del {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 7px;
  width: 24px;
  height: 24px;
  font-size: 12px;
}
.conv:hover .conv-del, .conv.active .conv-del { opacity: 1; }
.conv-del:hover { background: rgba(255, 125, 138, 0.15); color: var(--danger); }

.conv-empty {
  color: var(--muted-2);
  font-size: 12px;
  text-align: center;
  padding: 26px 14px;
  line-height: 1.5;
}

.side-foot {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: grid;
  gap: 10px;
}
.user-box { display: grid; gap: 2px; min-width: 0; }
.user-box strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.user-box span { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.06em; }
.side-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.side-actions .btn { padding: 7px 8px; font-size: 11px; }

/* ---------- main ---------- */

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  min-height: 58px;
}
.model-picker { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.model-picker label { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
.model-picker select {
  width: auto;
  max-width: 460px;
  min-width: 160px;
  padding: 7px 30px 7px 10px;
  font-size: 12px;
  border-radius: 9px;
  background-color: rgba(0, 0, 0, 0.18);
}

.status { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px rgba(255, 200, 107, 0.12); }
.status.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(85, 214, 160, 0.12); }
.status.bad .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(255, 125, 138, 0.12); }

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px clamp(16px, 5vw, 64px) 18px;
  scroll-behavior: smooth;
}

.empty {
  position: absolute;
  inset: 58px 0 108px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}
.empty > * { pointer-events: auto; }
.empty-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 16px 40px rgba(124, 156, 255, 0.28);
  margin-bottom: 6px;
}
.empty h2 { margin: 0; font-size: clamp(22px, 3vw, 30px); letter-spacing: -0.03em; }
.empty p { margin: 0; max-width: 520px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chips button {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 99px;
  padding: 8px 13px;
  font-size: 12px;
  cursor: pointer;
}
.chips button:hover { color: var(--text); border-color: var(--accent); }

.msg {
  display: grid;
  gap: 8px;
  margin: 0 auto 26px;
  max-width: 880px;
  animation: rise 0.25s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg-head { display: flex; align-items: center; gap: 9px; font-size: 11px; color: var(--muted-2); }
.msg-avatar {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
}
.msg.assistant .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }
.msg.user { justify-items: end; }
.msg.user .msg-head { flex-direction: row-reverse; }
.msg.user .msg-bubble {
  background: var(--user);
  color: #fff;
  border-color: transparent;
  border-bottom-right-radius: 6px;
  box-shadow: 0 10px 30px rgba(95, 124, 255, 0.25);
}
.msg-bubble {
  max-width: min(760px, 100%);
  border: 1px solid var(--line);
  background: var(--assistant);
  border-radius: 16px;
  padding: 13px 16px;
  line-height: 1.62;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.msg.user .msg-bubble { max-width: min(640px, 92%); }

.msg-bubble p { margin: 0 0 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble .gap { height: 6px; }
.msg-bubble strong { color: var(--text); }
.msg.user .msg-bubble strong { color: #fff; }
.msg-bubble code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
}
.msg.user .msg-bubble code { background: rgba(0, 0, 0, 0.18); border-color: transparent; }
.msg-bubble pre {
  margin: 10px 0;
  padding: 13px 14px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid var(--line);
  overflow-x: auto;
}
.msg-bubble pre code { background: transparent; border: 0; padding: 0; font-size: 12.5px; line-height: 1.55; }
.msg-bubble a { color: var(--accent); }
.msg.user .msg-bubble a { color: #fff; text-decoration: underline; }
.msg-meta { font-size: 10.5px; color: var(--muted-2); }
.msg.user .msg-meta { text-align: right; }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.msg-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }

.composer {
  border-top: 1px solid var(--line);
  padding: 12px clamp(16px, 5vw, 64px) 14px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.12));
}
.composer textarea {
  max-height: 220px;
  min-height: 46px;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.2);
}
@media (prefers-color-scheme: light) {
  .composer textarea { background: rgba(255, 255, 255, 0.8); }
}
.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.composer-buttons { display: flex; gap: 7px; }

/* ---------- dialog ---------- */

.dialog {
  width: min(680px, 92vw);
  max-height: 86vh;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 0;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(4, 6, 12, 0.62); backdrop-filter: blur(4px); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.dialog-head h2 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.tabs { display: flex; gap: 6px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { padding: 18px; }
.tab-panel h3 { margin: 20px 0 10px; font-size: 13px; letter-spacing: 0.01em; }
.tab-panel h3:first-child { margin-top: 0; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.info-grid > div {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.025);
  display: grid;
  gap: 3px;
  min-width: 0;
}
.info-grid strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.stack { display: grid; gap: 10px; }

.users-list { display: grid; gap: 7px; }
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 11px;
}
.user-row .who { flex: 1; min-width: 0; display: grid; gap: 1px; }
.user-row .who strong { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.user-row .who span { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.05em; }
.user-row .btn { padding: 5px 9px; font-size: 11px; }

.usage-models { display: grid; gap: 5px; margin: 12px 0; }
.usage-model {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px dashed var(--line);
  padding: 5px 0;
}
.usage-model span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- responsive ---------- */

.mobile-only { display: none; }
.sidebar-scrim { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); padding: 8px; gap: 0; }
  .sidebar {
    position: fixed;
    z-index: 30;
    top: 8px;
    bottom: 8px;
    left: 8px;
    width: min(320px, 86vw);
    transform: translateX(calc(-100% - 16px));
    transition: transform 0.22s ease;
  }
  .app.sidebar-open .sidebar { transform: none; }
  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
  }
  .app.sidebar-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .mobile-only { display: inline-grid; }
  .main { border-radius: 18px; }
  .chat { padding: 20px 14px 12px; }
  .composer { padding: 10px 14px 12px; }
  .model-picker select { max-width: 100%; min-width: 0; }
  .status span:last-child { display: none; }
  .empty { inset: 58px 0 120px; }
}

@media (max-width: 480px) {
  .login-card { padding: 22px; border-radius: 18px; }
  .side-actions { grid-template-columns: 1fr; }
  .msg-bubble { font-size: 13.5px; }
}
