:root {
  --bg: #0d1117;
  --bg-elevated: #111827;
  --panel: #11161f;
  --panel-strong: #171d28;
  --line: rgba(148, 163, 184, 0.15);
  --line-strong: rgba(148, 163, 184, 0.24);
  --text: #eef2f7;
  --muted: #93a1b5;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.18);
  --bot-bubble: #2a4772;
  --user-bubble: #18202d;
  --selection-bubble: #20324b;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", sans-serif;
  overflow: hidden;
}

body {
  background:
    radial-gradient(circle at top left, rgba(79, 140, 255, 0.12), transparent 24%),
    radial-gradient(circle at bottom right, rgba(45, 212, 191, 0.08), transparent 20%),
    linear-gradient(180deg, #0a0f16 0%, var(--bg) 100%);
}

.app-shell {
  display: grid;
  grid-template-columns: 840px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.sidebar,
.chat-panel {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: rgba(12, 17, 24, 0.92);
  border-right: 1px solid var(--line);
}

.sidebar-head,
.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.sidebar-head h1,
.chat-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.sidebar-copy,
.chat-subtitle,
.sidebar-meta,
.chat-meta,
.dialog-preview,
.dialog-snippet,
.dialog-time,
.message-time {
  color: var(--muted);
}

.sidebar-copy,
.chat-subtitle {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.4;
}

.sidebar-meta,
.chat-meta {
  padding: 10px 18px 0;
  font-size: 12px;
}

.dialog-list {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 14px;
}

.dialog-card {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(23, 29, 40, 0.72);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.dialog-card:hover {
  background: rgba(29, 38, 53, 0.84);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.dialog-card.active {
  background: rgba(33, 52, 84, 0.85);
  border-color: rgba(79, 140, 255, 0.46);
  box-shadow: inset 0 0 0 1px rgba(79, 140, 255, 0.22);
}

.dialog-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.dialog-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.dialog-title {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
}

.dialog-snippet {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.badge.open {
  background: rgba(16, 185, 129, 0.18);
  color: #b6f5d7;
}

.badge.closed {
  background: rgba(148, 163, 184, 0.14);
  color: #d6dce6;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(13, 17, 23, 0.7);
}

.chat-head {
  padding: 14px 18px 12px;
}

.chat-meta {
  padding: 0;
  text-align: right;
  white-space: nowrap;
}

.chat-stream {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 14px 14px;
}

.dialog-list,
.chat-stream {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.34) transparent;
}

.dialog-list::-webkit-scrollbar,
.chat-stream::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.dialog-list::-webkit-scrollbar-track,
.chat-stream::-webkit-scrollbar-track {
  background: transparent;
}

.dialog-list::-webkit-scrollbar-thumb,
.chat-stream::-webkit-scrollbar-thumb {
  border-radius: 999px;
  border: 2px solid transparent;
  background: rgba(148, 163, 184, 0.34);
  background-clip: padding-box;
}

.dialog-list::-webkit-scrollbar-thumb:hover,
.chat-stream::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.48);
  background-clip: padding-box;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 55vh;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 8px;
  font-size: 18px;
  color: var(--text);
}

.message-row {
  display: flex;
  margin-bottom: 6px;
}

.message-row.user {
  justify-content: flex-start;
}

.message-row.bot,
.message-row.system {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(560px, 62%);
  padding: 8px 10px 7px;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.18);
  line-height: 1.34;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}

.message-row.bot .message-bubble {
  background: var(--bot-bubble);
  border-color: rgba(110, 168, 255, 0.24);
}

.message-row.user .message-bubble {
  background: var(--user-bubble);
}

.message-row.selection .message-bubble {
  background: var(--selection-bubble);
}

.message-bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  min-height: 14px;
}

.message-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #d8e2f1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.message-time {
  font-size: 10px;
  line-height: 1;
  margin-left: auto;
}

.message-text a {
  color: #8ab4ff;
  text-decoration: none;
}

.message-text a:hover {
  text-decoration: underline;
}

.ghost-button {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ghost-button:hover {
  background: rgba(79, 140, 255, 0.1);
  border-color: rgba(79, 140, 255, 0.32);
}

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

@media (max-width: 860px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar,
  .chat-panel {
    min-height: auto;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    grid-template-rows: auto auto auto;
  }

  .dialog-list {
    max-height: 42vh;
  }

  .chat-panel {
    grid-template-rows: auto auto;
  }

  .chat-stream {
    max-height: none;
    min-height: 42vh;
  }

  .message-bubble {
    max-width: 86%;
  }
}
