/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --user-bubble: #4f46e5;
  --user-bubble-text: #ffffff;
  --ai-bubble: #f1f5f9;
  --ai-bubble-text: #1e293b;
  --danger: #ef4444;
  --recording: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
  background: var(--surface-2);
  color: var(--text);
  line-height: 1.6;
}

/* ===== Layout ===== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* ===== Header ===== */
.app-header {
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 1.4rem;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.beta-badge {
  background: rgba(255,255,255,0.2);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: 0.05em;
}

.header-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name {
  font-size: 0.82rem;
  opacity: 0.85;
}

.logout-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.logout-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ===== Chat Area ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  scroll-behavior: smooth;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== Message Bubbles ===== */
.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
}

.message.user {
  flex-direction: row-reverse;
  margin-left: auto;
}

.avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message.user .avatar {
  background: var(--primary);
  color: #fff;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant .bubble {
  background: var(--ai-bubble);
  color: var(--ai-bubble-text);
  border-top-left-radius: 4px;
}

.message.user .bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-top-right-radius: 4px;
}

/* typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s 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%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ===== Input Area ===== */
.input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 12px 16px 16px;
  background: var(--surface);
}

.input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.voice-status {
  min-height: 20px;
  font-size: 0.8rem;
  color: var(--recording);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.voice-status.active::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--recording);
  border-radius: 50%;
  animation: pulse 1s infinite;
}

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

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px 8px 14px;
  transition: border-color 0.15s;
}

.input-row:focus-within {
  border-color: var(--primary);
}

.message-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.5;
}

.message-input::placeholder {
  color: var(--text-muted);
}

.icon-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:active {
  transform: scale(0.93);
}

.voice-btn {
  background: var(--primary-light);
  color: var(--primary);
}

.voice-btn:hover {
  background: #ddd6fe;
}

.voice-btn.recording {
  background: #fee2e2;
  color: var(--recording);
  animation: recordingPulse 1.5s infinite;
}

@keyframes recordingPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

.send-btn {
  background: var(--primary);
  color: #fff;
}

.send-btn:hover {
  background: var(--primary-hover);
}

.send-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

kbd {
  font-size: 0.68rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: monospace;
}

/* ===== Scrollbar ===== */
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .message { max-width: 95%; }
  .app-header h1 { font-size: 1rem; }
}
