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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-message-user: #0f3460;
  --bg-message-claude: #2d2d44;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0a0;
  --accent: #e94560;
  --accent-dim: #c73e54;
  --border: #333;
  --success: #4ade80;
  --warning: #fbbf24;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

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

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

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

#status {
  display: flex;
  align-items: center;
  gap: 12px;
}

#connection-status {
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}

#connection-status.connected {
  background: var(--success);
  color: #000;
}

#connection-status.disconnected {
  background: var(--accent);
  color: #fff;
}

#connection-status.connecting {
  background: var(--warning);
  color: #000;
}

#reset-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

#reset-btn:hover {
  opacity: 1;
}

/* Chat container */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Messages */
.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--bg-message-user);
  border-bottom-right-radius: 4px;
}

.message.claude {
  align-self: flex-start;
  background: var(--bg-message-claude);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 6px 12px;
}

.message.error {
  align-self: center;
  background: var(--accent-dim);
  color: #fff;
  font-size: 0.85rem;
}

/* Thinking/Tool indicator */
.thinking {
  align-self: flex-start;
  padding: 10px 14px;
  color: var(--text-secondary);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
}

.thinking .dots {
  display: inline-flex;
  gap: 4px;
}

.thinking .dot {
  width: 6px;
  height: 6px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.thinking .dot:nth-child(1) { animation-delay: 0s; }
.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Tool indicator */
.tool-indicator {
  align-self: flex-start;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent);
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin: 4px 0;
}

/* Streaming message */
.message.streaming {
  position: relative;
}

.message.streaming::after {
  content: '▌';
  animation: blink 1s step-end infinite;
}

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

/* Footer / Input */
footer {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

#input-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}

#input:focus {
  outline: none;
  border-color: var(--accent);
}

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

#send-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

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

/* Code blocks */
.message pre {
  background: var(--bg-primary);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.85rem;
  margin: 8px 0;
}

.message code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
}

.message pre code {
  background: none;
  padding: 0;
}

/* Safe area for iPhone */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  footer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* Responsive */
@media (max-width: 600px) {
  .message {
    max-width: 90%;
  }

  header h1 {
    font-size: 1rem;
  }
}
