:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e2e2e7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1d23;
    --text: #f2f2f4;
    --muted: #9aa0ab;
    --border: #2a2e37;
  }
}

* {
  box-sizing: border-box;
}

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

h1 {
  font-size: 1.25rem;
  margin: 0 0 4px;
}

.subtitle {
  margin: 0 0 16px;
  font-size: 0.85rem;
  color: var(--muted);
}

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

#login-view {
  max-width: 360px;
  margin: 48px auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#login-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

#login-form input,
#chat-form input {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.error {
  color: #dc2626;
  font-size: 0.85rem;
  margin-top: 8px;
}

#chat-view {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 32px);
}

#chat-view header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

#logout-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
}

.autoplay-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.autoplay-toggle input {
  margin: 0;
}

.speak-button {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 6px;
  background: transparent;
  border: none;
  color: inherit;
  font-size: 0.9rem;
  vertical-align: middle;
  cursor: pointer;
}

.bubble.assistant .speak-button {
  color: var(--muted);
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}

.bubble.card {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--accent);
  max-width: 90%;
}

.bubble.card p {
  margin: 6px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.bubble.card .card-params {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  word-break: break-word;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.card-actions button {
  padding: 6px 14px;
  font-size: 0.9rem;
}

.card-actions button.reject {
  background: transparent;
  color: #dc2626;
  border: 1px solid #dc2626;
}

.card-status {
  font-size: 0.9rem;
  font-weight: 600;
}

.card-status.approved {
  color: #16a34a;
}

.card-status.rejected {
  color: #dc2626;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 280px;
}

.bubble.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
}

.bubble.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.bubble.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.bubble.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

#chat-form {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#chat-form input {
  flex: 1;
}

#mic-button {
  flex: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  line-height: 1;
  padding: 10px 14px;
}

#mic-button.recording {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}

#mic-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (min-width: 768px) {
  #chat-view {
    height: calc(100dvh - 96px);
    margin-top: 48px;
  }
}
