:root {
  --bg: #fbf7f1;
  --surface: #ffffff;
  --border: #ecdfd0;
  --text: #2a231b;
  --muted: #8a7c6a;
  --sun-1: #ff9d3d;
  --sun-2: #ff5f6d;
  --user-bubble: #2a231b;
  --user-text: #fff8ef;
  --assistant-bubble: #fff2e2;
  --danger: #d1453b;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --surface: #221c16;
    --border: #382e23;
    --text: #f5ece0;
    --muted: #a9998454;
    --muted: #b3a48f;
    --assistant-bubble: #2c2319;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: linear-gradient(135deg, var(--sun-1), var(--sun-2));
  color: white;
  flex-shrink: 0;
}

.brand h1 { font-size: 18px; margin: 0; }
.tagline { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.provider-select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  max-width: 40%;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg { display: flex; }
.msg-user { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }
.msg-error .bubble { background: #fdecea; color: var(--danger); border: 1px solid #f3c6c1; }

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg-assistant .bubble {
  background: var(--assistant-bubble);
  border-bottom-left-radius: 4px;
}

.provider-tag {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

.attachment {
  display: block;
  max-width: 220px;
  border-radius: 10px;
  margin-bottom: 6px;
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.attachment-preview.hidden { display: none; }
.attachment-preview img { height: 40px; border-radius: 8px; }
.attachment-preview .remove-btn {
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  margin-left: auto;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.icon-btn {
  border: none;
  background: var(--bg);
  border: 1px solid var(--border);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn.recording {
  background: var(--danger);
  color: white;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.hidden { display: none !important; }

#text-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14.5px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  max-height: 120px;
}
#text-input:focus { outline: 2px solid var(--sun-1); }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--sun-1), var(--sun-2));
  color: white;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.5; cursor: default; }

.status-line {
  min-height: 18px;
  margin: 0;
  padding: 0 20px 10px;
  font-size: 12px;
  color: var(--muted);
}
