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

/* Dark theme (default) */
:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #252525;
  --border: #333;
  --text: #e5e5e5;
  --text-dim: #888;
  --accent: #4f8cff;
  --accent-hover: #3a7af0;
  --accent-light: rgba(79, 140, 255, 0.1);
  --user-bg: #2a4a7f;
  --bot-bg: #1e1e1e;
  --card-bg: transparent;
  --success: #4caf50;
  --success-bg: #1b3a1b;
  --success-border: #2d5a2d;
  --warning: #ff9800;
  --warning-bg: #3a2e1b;
  --warning-border: #5a4a2d;
  --error: #f44336;
  --error-bg: #3a1b1b;
  --error-border: #5a2d2d;
}

/* Light theme */
[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f8f9fa;
  --surface2: #f0f0f0;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-dim: #666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: rgba(37, 99, 235, 0.08);
  --user-bg: #2563eb;
  --bot-bg: #f8f9fa;
  --card-bg: transparent;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
}

header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  position: relative;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

header p {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Theme toggle */
#theme-toggle {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  text-align: center;
  transition: background 0.2s;
}

#theme-toggle:hover {
  background: var(--border);
}

main#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

.message.bot {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
}

.message-content {
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 0.95rem;
  word-break: keep-all;
}

.message.bot .message-content {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.user .message-content {
  background: var(--user-bg);
  color: white;
  border-bottom-right-radius: 4px;
}

/* Result card - minimal style */
.result-card {
  background: var(--accent-light);
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 8px;
}

.result-card .code-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.result-card .code-badge {
  background: var(--accent);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85rem;
  font-family: monospace;
}

.result-card .code-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.confidence-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.confidence-high {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.confidence-medium {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid var(--warning-border);
}

.confidence-low {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error-border);
}

.result-card .section {
  margin-top: 8px;
}

.result-card .section-title {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-card .section-content {
  font-size: 0.9rem;
  line-height: 1.5;
}

.result-card .reason {
  color: var(--accent);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* Similar jobs */
.similar-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.similar-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-light);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.82rem;
  margin: 4px 4px 0 0;
}

.similar-item .sim-code {
  color: var(--accent);
  font-family: monospace;
  font-weight: 600;
}

.page-ref {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Uncertainty banner */
.uncertainty-banner {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

/* Loading */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

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

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Footer */
footer {
  padding: 12px 24px 16px;
  background: var(--bg);
}

#chat-form {
  display: flex;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 6px 6px 6px 4px;
  align-items: center;
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 10px 16px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

#chat-input:focus {
  outline: none;
}

#chat-input::placeholder {
  color: var(--text-dim);
}

#send-btn {
  background: var(--accent);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  transition: background 0.2s;
  flex-shrink: 0;
}

#send-btn:hover {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Scrollbar */
main::-webkit-scrollbar {
  width: 6px;
}

main::-webkit-scrollbar-track {
  background: transparent;
}

main::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Mobile */
@media (max-width: 640px) {
  .message {
    max-width: 95%;
  }

  header h1 {
    font-size: 1.1rem;
  }

  main#chat-area {
    padding: 16px;
  }

  footer {
    padding: 12px 16px;
  }

  #theme-toggle {
    right: 16px;
  }
}
