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

:root {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface2: #2e2e2e;
  --border: #3a3a3a;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #4a9eff;
  --user-bg: #1e3a5f;
  --assistant-bg: #242424;
  --thinking-bg: #1e2820;
  --thinking-text: #7fb87f;
  --approval-bg: #2e2416;
  --approval-border: #7a5c1a;
}

html, body, #root {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

#root {
  display: flex;
  justify-content: center;
}

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1024px;
  height: 100%;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  user-select: none;
}

.header img {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

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

.header-version {
  font-size: 13px;
  color: var(--text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.enabled  { background: #4caf50; box-shadow: 0 0 4px #4caf5088; }
.status-dot.disabled { background: #f44336; box-shadow: 0 0 4px #f4433688; }

.header-user {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  cursor: pointer;
  transition: border-color 0.15s;
  flex-shrink: 0;
}

.header-user:hover { border-color: var(--accent); color: var(--text); }

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 40px;
  width: min(420px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}

.login-logo img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
}

.login-logo-text {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.login-card h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.login-field input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-field input:focus { border-color: var(--accent); }
.login-field input.error { border-color: #f44336; }

.login-error {
  font-size: 13px;
  color: #f44336;
  min-height: 18px;
}

.login-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  padding: 11px;
  transition: opacity 0.15s;
}

.login-btn:disabled { opacity: 0.4; cursor: default; }
.login-btn:not(:disabled):hover { opacity: 0.85; }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.message.user, .message.assistant, .message.thinking, .message.approval { align-self: flex-start; align-items: flex-start; }

.message-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.message.user .message-bubble {
  background: var(--user-bg);
  border-radius: 2px 12px 12px 12px;
}

.message.assistant .message-bubble {
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  border-radius: 2px 12px 12px 12px;
}

.message.thinking .message-bubble {
  background: var(--thinking-bg);
  border: 1px solid #2a3a2a;
  border-radius: 2px 12px 12px 12px;
  color: var(--thinking-text);
  font-size: 13px;
  font-family: 'SF Mono', Consolas, monospace;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.thinking-elapsed {
  font-size: 12px;
  color: var(--text-dim);
  font-family: inherit;
}

.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* Markdown in assistant bubbles */
.message.assistant .message-bubble p { margin-bottom: 0.6em; }
.message.assistant .message-bubble p:last-child { margin-bottom: 0; }
.message.assistant .message-bubble pre {
  background: var(--surface2);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
  margin: 0.4em 0;
}
.message.assistant .message-bubble code {
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.message.assistant .message-bubble pre code { background: none; padding: 0; }
.message.assistant .message-bubble h1,
.message.assistant .message-bubble h2,
.message.assistant .message-bubble h3 { margin: 0.6em 0 0.3em; font-size: 1em; font-weight: 700; }
.message.assistant .message-bubble ul,
.message.assistant .message-bubble ol { padding-left: 1.4em; margin: 0.3em 0; }
.message.assistant .message-bubble a { color: var(--accent); word-break: break-all; }
.message.assistant .message-bubble blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.8em;
  color: var(--text-dim);
  margin: 0.4em 0;
}

/* Approval card */
.message.approval .message-bubble {
  background: var(--approval-bg);
  border: 1px solid var(--approval-border);
  border-radius: 2px 12px 12px 12px;
}

.approval-question { margin-bottom: 10px; white-space: pre-wrap; }
.approval-buttons { display: flex; gap: 8px; }
.approval-buttons button {
  padding: 5px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
}
.approval-buttons button:disabled { opacity: 0.4; cursor: default; }
.btn-yes { background: #2a6a3a; color: #a0e0b0; }
.btn-no  { background: #5a2a2a; color: #e0a0a0; }
.approval-answered { font-size: 12px; color: var(--text-dim); font-style: italic; }

.message-elapsed { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* Input area */
.input-area {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-area textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 9px 12px;
  resize: none;
  outline: none;
  min-height: 40px;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
.input-area textarea:focus { border-color: var(--accent); }
.input-area textarea::placeholder { color: var(--text-dim); }

.send-btn {
  align-self: flex-end;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  height: 40px;
  padding: 0 18px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn:not(:disabled):hover { opacity: 0.85; }

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
}
