:root {
  color-scheme: dark;
  --bg: #07111a;
  --panel: #0d1722;
  --panel-2: #111f2d;
  --line: #223344;
  --text: #e8f0f8;
  --muted: #93a8bc;
  --accent: #58b2ff;
  --accent-soft: rgba(88, 178, 255, 0.12);
  --success: #7ad38b;
  --warning: #e5c66f;
  --danger: #ef8f8f;
}

* {
  box-sizing: border-box;
}

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

button,
textarea,
input {
  font: inherit;
}

#app {
  min-height: 100vh;
}

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #0a141e;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.sidebar-actions,
.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.input,
.textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 11px 12px;
}

.button,
.icon-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #07111a;
  font-weight: 600;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow: auto;
}

.session-item {
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.session-item:hover,
.session-item.active {
  background: var(--panel);
  border-color: var(--line);
}

.session-title {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100vh;
}

.main-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.header-copy h2 {
  margin: 0;
  font-size: 1rem;
}

.header-copy p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.thread {
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message-row {
  display: flex;
}

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

.message-row.assistant,
.message-row.system {
  justify-content: flex-start;
}

.bubble {
  width: min(820px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px 16px;
}

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

.bubble-header,
.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.bubble-header {
  margin-bottom: 10px;
}

.bubble-footer {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.76rem;
  flex-wrap: wrap;
}

.bubble-role {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.bubble-content {
  color: var(--text);
  line-height: 1.6;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.bubble-content p {
  margin: 0 0 12px;
}

.bubble-content p:last-child {
  margin-bottom: 0;
}

.bubble-content h1,
.bubble-content h2,
.bubble-content h3,
.bubble-content h4 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.bubble-content ul,
.bubble-content ol {
  margin: 0 0 12px 18px;
}

.bubble-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.bubble-content th,
.bubble-content td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.bubble-content pre {
  margin: 0;
  padding: 14px;
  background: #081018;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.code-block {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.code-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0a121a;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.code-copy {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 6px;
}

.tool-indicators {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  border: 1px solid rgba(88, 178, 255, 0.2);
}

.composer {
  border-top: 1px solid var(--line);
  padding: 18px 24px 22px;
  background: rgba(10, 20, 30, 0.92);
  backdrop-filter: blur(16px);
}

.composer-shell {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.composer-tools {
  display: flex;
  gap: 8px;
  align-items: center;
}

.textarea {
  min-height: 120px;
  resize: vertical;
}

.helper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.empty-state {
  margin: auto;
  max-width: 720px;
  width: 100%;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.empty-state h3 {
  color: var(--text);
  margin-bottom: 8px;
}

.upload-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .main-header,
  .thread,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }
}
