:root {
  color-scheme: light dark;
  --bg: #0f1117;
  --panel: #171b26;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #9aa4b8;
  --accent: #5b8cff;
  --danger: #ff6b6b;
  --user: #1f2937;
  --assistant: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: linear-gradient(180deg, #0b0d13, var(--bg));
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--danger);
  margin: 0;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
}

.auth-card h1 {
  margin: 0;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d111a;
  color: var(--text);
  font: inherit;
  padding: 12px 14px;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
}

button {
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 600;
  padding: 12px 18px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.link-button {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 0;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(23, 27, 38, 0.85);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar-header,
.sidebar-footer {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-footer {
  margin-top: auto;
  border-bottom: none;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

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

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.conversation-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation-item:hover,
.conversation-item.active {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.conversation-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item small {
  color: var(--muted);
  font-size: 0.75rem;
}

.delete-conversation {
  background: transparent;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 0.85rem;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 24px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
}

.header p {
  margin: 0;
  color: var(--muted);
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0;
  overflow-y: auto;
  padding-right: 4px;
}

.message {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message.user {
  background: var(--user);
  align-self: flex-end;
  max-width: 85%;
}

.message.assistant {
  background: var(--assistant);
  align-self: flex-start;
  max-width: 85%;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}

.composer-tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.composer-tools button {
  width: 44px;
  height: 44px;
  padding: 0;
  background: #0d111a;
  border: 1px solid var(--border);
}

.composer-tools button.recording {
  background: #5c1d1d;
  border-color: var(--danger);
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.preview-image,
.message-image {
  max-width: 240px;
  max-height: 240px;
  border-radius: 12px;
  display: block;
  margin-top: 8px;
}

.message-text {
  white-space: pre-wrap;
}

textarea {
  resize: vertical;
  min-height: 72px;
  border: none;
  background: transparent;
  padding: 0;
}

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

  .sidebar {
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .conversation-list {
    max-height: 180px;
  }
}
