:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --user-bubble: #4f46e5;
  --user-text: #ffffff;
  --bot-bubble: #ffffff;
  --code-bg: #f1f5f9;
  --error: #dc2626;
  --listening: #ef4444;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #131a2e;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #232c45;
    --accent: #818cf8;
    --accent-text: #0b1020;
    --user-bubble: #4338ca;
    --user-text: #ffffff;
    --bot-bubble: #182039;
    --code-bg: #0b1020;
    --error: #f87171;
    --listening: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.5em; margin: 0; }

.logo {
  font-size: 40px;
  color: var(--accent);
  line-height: 1;
}

/* Login */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-card h1 { margin: 4px 0 0; font-size: 24px; }
.login-card p { margin: 0; }
.login-card input {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
}
.primary {
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* Chat layout */
.chat {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  max-width: 50%;
}
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 18px;
}
.icon-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 0 24px;
}

.msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 6px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.error {
  border-color: var(--error);
  color: var(--error);
}
.msg.pending::after {
  content: "▍";
  animation: blink 1s steps(2) infinite;
  color: var(--muted);
}
@keyframes blink { 50% { opacity: 0; } }

.msg pre {
  background: var(--code-bg);
  border-radius: 10px;
  padding: 10px;
  overflow-x: auto;
  white-space: pre;
  margin: 6px 0;
  font-size: 14px;
}
.msg code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
}
.msg :not(pre) > code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 5px;
}

.msg-tools {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.msg-tools button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 4px;
}

/* Attachments: tray above the composer and thumbnails inside messages */
.attachments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.chip {
  position: relative;
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: 11px;
  text-align: center;
  color: var(--muted);
}
.chip img { width: 100%; height: 100%; object-fit: cover; }
.chip.uploading { opacity: 0.5; }
.chip.failed { border-color: var(--error); color: var(--error); }
.chip .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: rgb(0 0 0 / 60%);
  color: #fff;
  font-size: 12px;
  line-height: 22px;
  padding: 0;
}
.chip .label {
  padding: 2px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.msg-files a { color: inherit; }
.msg-files img {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: 12px;
}
.file-pill {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgb(255 255 255 / 18%);
  font-size: 14px;
  text-decoration: none;
}
.msg.assistant .file-pill { background: var(--code-bg); }

/* Claude worker job card */
.job-card { display: flex; flex-direction: column; gap: 8px; white-space: normal; }
.job-title { font-weight: 600; }
.job-card.running .job-title, .job-card.queued .job-title { color: var(--accent); }
.job-card.error .job-title { color: var(--error); }
.job-steps {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.job-steps li { margin: 2px 0; }
.job-card details summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.job-approval {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  white-space: pre-wrap;
}
.job-approval > div { flex-basis: 100%; font-size: 14px; }
.job-approval button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-weight: 600;
}
.job-approval button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.job-result { white-space: pre-wrap; }
.msg a { color: var(--accent); }
.msg.user a { color: inherit; }

/* In-app preview of sites the worker made */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  border-bottom: 1px solid var(--border);
}
.viewer-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  color: var(--muted);
}
.viewer iframe {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
}

.status {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  padding: 4px 12px;
}
.status.listening { color: var(--listening); font-weight: 600; }

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 160px;
  padding: 11px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.4;
}
.attach, .mic, .send {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  font-size: 20px;
}
.attach {
  width: 36px;
  background: transparent;
  font-size: 22px;
}
.mic {
  background: var(--bg);
  border: 1px solid var(--border);
}
.mic.listening {
  background: var(--listening);
  border-color: var(--listening);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--listening) 50%, transparent); }
  50% { box-shadow: 0 0 0 10px transparent; }
}
.send {
  background: var(--accent);
  color: var(--accent-text);
}
.send:disabled { opacity: 0.5; }
