*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-2: #22223b;
  --border: #2e2e4a;
  --text: #f2f2fa;
  --text-muted: #9999aa;
  --accent: #9b91f9;
  --accent-btn: #5c52d9;
  --accent-btn-hover: #4f46c2;
  --error: #e05c5c;
  --user-bubble: #22223b;
  --butler-bubble: #1a1a2e;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* --- auth --- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-logo {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-error {
  color: var(--error);
  font-size: 0.88rem;
  background: rgba(224, 92, 92, 0.1);
  border: 1px solid rgba(224, 92, 92, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.auth-back {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  text-decoration: none;
}
.auth-back:hover { color: var(--text); }

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="email"],
input[type="text"] {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}
input:focus-visible { border-color: var(--accent); }

button[type="submit"],
#send-btn {
  padding: 12px;
  background: var(--accent-btn);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}
button[type="submit"]:hover,
#send-btn:hover { background: var(--accent-btn-hover); }

.auth-card button[type="submit"] { width: 100%; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: var(--font);
  padding: 6px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

/* --- chat shell --- */

.chat-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.butler { align-self: flex-start; align-items: flex-start; }

.msg-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.msg.butler .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* --- footer (SSE progress) --- */

.chat-footer {
  min-height: 28px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.footer-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- confirmation panel --- */

.chat-confirm {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.confirm-summary {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.confirm-params {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

.confirm-param {
  display: flex;
  gap: 6px;
}

.confirm-param-key {
  color: var(--text-muted);
  flex-shrink: 0;
}

.confirm-actions {
  display: flex;
  gap: 8px;
}

/* --- input bar --- */

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
#input:focus-visible { border-color: var(--accent); }

#send-btn {
  width: auto;
  padding: 10px 18px;
  flex-shrink: 0;
  align-self: flex-end;
}

/* --- icon buttons (attach, mic) --- */

.btn-icon {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 40px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  transition: color 0.15s, border-color 0.15s;
}
.btn-icon svg { display: block; width: 18px; height: 18px; }
.btn-icon:hover { color: var(--text); border-color: var(--text-muted); }
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon.recording {
  color: var(--error);
  border-color: var(--error);
  animation: pulse 1s ease-in-out infinite;
}

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

/* --- responsive --- */

@media (max-width: 600px) {
  .auth-card { padding: 28px 20px; }
  .msg { max-width: 92%; }
}

@media (pointer: coarse) {
  .btn-icon { width: 44px; height: 44px; }
  #send-btn { min-height: 44px; padding: 10px 20px; }
  #input { min-height: 44px; }
}
