* {
  box-sizing: border-box;
}

:root {
  --bg: #eef1f6;
  --main-surface: #f8fafc;
  --sidebar: #ffffff;
  --sidebar-hover: #eef2f9;
  --border: #d1d9e6;
  --text: #111827;
  --muted: #64748b;
  --user-bg: #e0f2ec;
  --assistant-bg: transparent;
  --card: #ffffff;
  --card-elevated: #f1f5f9;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --row-max: 768px;
  --font: "Sora", system-ui, -apple-system, sans-serif;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.app {
  display: flex;
  height: 100vh;
  max-height: 100dvh;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  padding: 10px 8px 12px;
}

.sb-top {
  padding: 6px 6px 10px;
}

.btn-newchat {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-newchat:hover {
  background: var(--sidebar-hover);
}

.btn-newchat-icon {
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1;
}

.sb-label {
  padding: 8px 12px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.sb-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 4px 8px;
}

.conv-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item:hover {
  background: var(--sidebar-hover);
}

.conv-item.active {
  background: #dbeafe;
  color: #1e3a5f;
}

.sb-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.sb-foot-note {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--main-surface);
}

.topbar {
  min-height: 48px;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar);
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.model-pill {
  font-size: 0.95rem;
  font-weight: 600;
}

.model-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 120px;
}

.welcome {
  max-width: var(--row-max);
  margin: 0 auto;
  padding: 48px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.65;
}

.welcome strong {
  display: block;
  color: var(--text);
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.msg-row {
  max-width: var(--row-max);
  margin: 0 auto 28px;
  display: flex;
  gap: 16px;
  animation: fade 0.2s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-row.user {
  background: var(--user-bg);
  margin-left: -16px;
  margin-right: -16px;
  padding: 24px 16px;
  max-width: none;
}

.msg-inner {
  max-width: var(--row-max);
  margin: 0 auto;
  width: 100%;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  margin-top: 2px;
}

.msg-row.assistant .msg-avatar {
  background: #5436da;
  color: #fff;
}

.msg-row.user .msg-avatar {
  background: #0d9488;
  color: #fff;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

.msg-text {
  font-size: 1rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-sources {
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

.msg-sources span {
  color: var(--muted);
}

.typing-row .msg-text {
  color: var(--muted);
  font-style: italic;
}

.preset-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--card);
  max-height: min(38vh, 280px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.preset-bar.collapsed .preset-body {
  display: none;
}

.preset-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 6px;
  gap: 12px;
}

.preset-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.preset-toggle {
  font-size: 0.72rem;
  font-family: inherit;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}

.preset-toggle:hover {
  text-decoration: underline;
}

.preset-body {
  overflow-y: auto;
  padding: 0 16px 12px;
  max-width: calc(var(--row-max) + 32px);
  margin: 0 auto;
  width: 100%;
}

.preset-cat {
  margin-bottom: 14px;
}

.preset-cat:last-child {
  margin-bottom: 4px;
}

.preset-cat-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1.35;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  min-height: 52px;
}

.preset-btn:hover:not(:disabled) {
  background: var(--sidebar-hover);
  border-color: #94a3b8;
  box-shadow: var(--shadow-sm);
}

.preset-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.preset-letter {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.preset-snippet {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--muted);
  font-weight: 400;
}

.composer-wrap {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px 20px;
  background: linear-gradient(to top, var(--main-surface) 75%, rgba(248, 250, 252, 0));
}

.composer {
  max-width: var(--row-max);
  margin: 0 auto;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-md);
}

#messageInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  outline: none;
  padding: 8px 0;
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-send:active:not(:disabled) {
  transform: scale(0.96);
}

.btn-send:disabled {
  opacity: 0.45;
  cursor: wait;
}

.composer-hint {
  margin: 10px 8px 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .preset-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .preset-bar {
    max-height: min(42vh, 320px);
  }
}
