:root { color-scheme: dark; }
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  background: #18181b;
  color: #f4f4f5;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
header {
  padding: env(safe-area-inset-top, 16px) 16px 12px;
  border-bottom: 1px solid #27272a;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header.settings-header { padding: env(safe-area-inset-top, 16px) 0 12px; margin-bottom: 12px; border-bottom: 1px solid #27272a; }
header h1 { font-size: 17px; margin: 0; font-weight: 600; }
header button {
  background: none; border: none; color: #a1a1aa; font-size: 14px; padding: 4px 8px;
}
#context-select {
  background: none; border: none; color: #f4f4f5; font-size: 17px; font-weight: 600;
  font-family: inherit; padding: 4px 24px 4px 0;
}

#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#workgroup-view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 16px; }

.hidden { display: none !important; }

#login-screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px;
}
#login-screen p { color: #a1a1aa; text-align: center; max-width: 320px; font-size: 14px; }
.login-title { font-size: 20px; margin: 0; }
.btn {
  background: #f4f4f5; color: #18181b; border: none; border-radius: 10px;
  padding: 14px 24px; font-size: 16px; font-weight: 600; min-width: 220px;
}
.btn:active { opacity: 0.8; }
.btn-secondary { background: #27272a; color: #f4f4f5; }
input[type="text"], input[type="password"] {
  background: #27272a; border: 1px solid #3f3f46; color: #f4f4f5; border-radius: 8px;
  padding: 12px; font-size: 16px; min-width: 220px;
}

#chat-screen { flex: 1; display: none; flex-direction: column; min-height: 0; }
#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; font-size: 15px; line-height: 1.4; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: #3b82f6; color: white; }
.msg.assistant { align-self: flex-start; background: #27272a; }
.msg.error { align-self: flex-start; background: #7f1d1d; }
.msg.pending { align-self: flex-start; background: #27272a; color: #a1a1aa; }

#composer {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 16px calc(env(safe-area-inset-bottom, 12px) + 12px);
  border-top: 1px solid #27272a;
}
#mode-toggle { display: flex; gap: 6px; }
#mode-toggle button {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid #3f3f46; background: #27272a;
  color: #a1a1aa; font-size: 13px;
}
#mode-toggle button.active { background: #3b82f6; color: white; border-color: #3b82f6; }
#input-row { display: flex; gap: 8px; }
#input-row textarea {
  flex: 1; resize: none; background: #27272a; border: 1px solid #3f3f46; color: #f4f4f5;
  border-radius: 10px; padding: 10px 12px; font-size: 16px; font-family: inherit; max-height: 120px;
}
#send-btn {
  background: #3b82f6; color: white; border: none; border-radius: 10px; padding: 0 18px; font-weight: 600;
}
#send-btn:disabled { opacity: 0.5; }
.hint { font-size: 12px; color: #71717a; }
.hint-spaced { margin-top: 8px; }

#attach-btn {
  background: #27272a; border: 1px solid #3f3f46; border-radius: 10px; font-size: 18px;
  padding: 0 10px; color: #f4f4f5;
}
#image-preview-row {
  display: flex; align-items: center; gap: 8px; background: #27272a; border-radius: 8px;
  padding: 6px 8px; margin-bottom: 4px;
}
#image-preview { max-height: 60px; max-width: 100px; border-radius: 6px; object-fit: cover; }
#image-remove-btn { background: none; border: none; color: #f87171; font-size: 14px; margin-left: auto; }

.suggestion-chip {
  align-self: flex-start; background: #1e293b; border: 1px solid #334155; border-radius: 10px;
  padding: 8px 12px; font-size: 13px; display: flex; align-items: center; gap: 10px; max-width: 85%;
}
.suggestion-chip button {
  background: #3b82f6; color: white; border: none; border-radius: 6px; padding: 4px 10px; font-size: 12px;
}
.suggestion-chip button.dismiss { background: #3f3f46; }

#settings-screen {
  flex: 1; display: none; flex-direction: column; min-height: 0; overflow-y: auto; padding: 16px;
}
#settings-screen h2 { font-size: 13px; text-transform: uppercase; color: #71717a; margin: 20px 0 8px; }
#settings-screen h2:first-of-type { margin-top: 0; }
.banner {
  background: #451a03; border: 1px solid #92400e; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #27272a; border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 6px;
}
.list-item .meta { font-size: 12px; color: #71717a; }
.list-item button { background: none; border: none; color: #f87171; font-size: 13px; }
#memory-add { display: flex; gap: 8px; margin-top: 8px; }
#memory-add input { flex: 1; }
#memory-add button { background: #3b82f6; color: white; border: none; border-radius: 8px; padding: 0 14px; }
.stat-row { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; border-bottom: 1px solid #27272a; }

.workgroup-card {
  background: #27272a; border-radius: 10px; padding: 12px; margin-bottom: 10px;
}
.workgroup-card .wg-title { font-weight: 600; font-size: 14px; }
.workgroup-card .wg-desc { font-size: 12px; color: #a1a1aa; margin: 4px 0 8px; }
.workgroup-card textarea {
  width: 100%; background: #18181b; border: 1px solid #3f3f46; color: #f4f4f5; border-radius: 8px;
  padding: 8px; font-size: 14px; font-family: inherit; resize: vertical; min-height: 44px; margin-bottom: 8px;
}
.workgroup-card button.run-btn {
  background: #3b82f6; color: white; border: none; border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 600;
}
.workgroup-card button.run-btn:disabled { opacity: 0.5; }

.run-card {
  background: #1e293b; border: 1px solid #334155; border-radius: 10px; padding: 12px; margin-bottom: 10px; font-size: 13px;
}
.run-card .run-task { color: #a1a1aa; margin-bottom: 6px; }
.run-card .run-result { white-space: pre-wrap; margin-bottom: 8px; max-height: 300px; overflow-y: auto; }
.run-card .run-log { font-size: 11px; color: #71717a; margin-bottom: 8px; }
.run-card .run-actions { display: flex; gap: 8px; }
.run-card button.accept { background: #3b82f6; color: white; border: none; border-radius: 6px; padding: 5px 12px; font-size: 12px; }
.run-card button.reject { background: #3f3f46; color: white; border: none; border-radius: 6px; padding: 5px 12px; font-size: 12px; }
.run-card button.copy { background: #27272a; border: 1px solid #3f3f46; color: #f4f4f5; border-radius: 6px; padding: 5px 12px; font-size: 12px; }
.run-card .run-badge { display: inline-block; font-size: 10px; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; margin-bottom: 6px; }
.run-badge.pending { background: #78350f; color: #fbbf24; }
.run-badge.accepted { background: #14532d; color: #4ade80; }

#model-select-row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
#model-select-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #a1a1aa; }
#model-select-row select {
  background: #27272a; border: 1px solid #3f3f46; color: #f4f4f5; border-radius: 8px; padding: 8px; font-size: 14px;
}

#usage-log { margin-top: 10px; max-height: 240px; overflow-y: auto; }
.usage-row {
  display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: #a1a1aa;
  padding: 5px 0; border-bottom: 1px solid #27272a;
}
.usage-row .usage-cost { color: #f4f4f5; font-weight: 600; }
