/* Reset and base styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #7c3aed;
  --primary-light: #a78bfa;
  --primary-dark: #5b21b6;
  --secondary: #3b82f6;
  --bg-light: #f8fafc;
  --bg-dark: #1e293b;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-light: #f8fafc;
  --border: #e2e8f0;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-light);
  -webkit-font-smoothing: antialiased;
}

/* Common layout */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header styles */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  padding: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 800px;
  margin: 0 auto;
}

.header-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.header-title {
  font-size: 1.25rem;
  font-weight: 600;
  flex: 1;
}

.header-controls {
  display: flex;
  gap: 0.5rem;
}

.header-select {
  padding: 0.375rem 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 0.875rem;
  cursor: pointer;
}

.header-select option {
  background: var(--bg-dark);
  color: white;
}

/* Messages area */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  word-wrap: break-word;
}

.message-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.message-assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.25rem;
}

.message-content {
  font-size: 0.9375rem;
}

.message-content p {
  margin-bottom: 0.5rem;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content code {
  background: rgba(0, 0, 0, 0.1);
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.875em;
}

.message-content pre {
  background: var(--bg-dark);
  color: var(--text-light);
  padding: 0.75rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

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

.message-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.message-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1rem;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.message-action-btn:hover {
  opacity: 1;
}

.message-image {
  max-width: 100%;
  border-radius: 0.5rem;
  margin-top: 0.5rem;
}

/* Loading dots animation */
.loading-dots {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

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

/* Suggestion chips */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem;
  justify-content: center;
}

.suggestion-chip {
  background: white;
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

/* Input area */
.input-container {
  padding: 1rem;
  background: white;
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  gap: 0.5rem;
  max-width: 800px;
  margin: 0 auto;
}

.input-textarea {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  font-size: 1rem;
  resize: none;
  min-height: 48px;
  max-height: 150px;
  font-family: inherit;
  line-height: 1.4;
}

.input-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.input-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all 0.2s;
}

.input-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-mic {
  background: var(--bg-light);
  color: var(--text-secondary);
}

.btn-mic:hover:not(:disabled) {
  background: var(--border);
}

.btn-mic.recording {
  background: #dc2626;
  color: white;
  animation: recording-pulse 0.8s ease-in-out infinite;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.3);
}

@keyframes recording-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.3);
  }
  50% {
    transform: scale(1.1);
    box-shadow: 0 0 0 8px rgba(220, 38, 38, 0.2), 0 0 20px rgba(220, 38, 38, 0.4);
  }
}

.btn-send {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
}

/* Login page */
.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

.login-card {
  background: white;
  border-radius: 1rem;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.login-logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 1rem;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.login-subtitle {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-input {
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.login-input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-btn {
  padding: 0.875rem 1.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.login-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.login-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.login-error {
  color: var(--error);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Profiles page */
.profiles-container {
  min-height: 100vh;
  padding: 2rem;
  background: var(--bg-light);
}

.profiles-header {
  text-align: center;
  margin-bottom: 2rem;
}

.profiles-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.profiles-subtitle {
  color: var(--text-secondary);
}

.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  max-width: 600px;
  margin: 0 auto 2rem;
}

.profile-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.profile-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.15);
}

.profile-emoji {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.profile-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.profile-age {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.profile-card.add-new {
  border-style: dashed;
  color: var(--text-secondary);
}

.profile-card.add-new:hover {
  color: var(--primary);
}

/* Create profile form */
.create-profile-form {
  background: white;
  border-radius: 1rem;
  padding: 1.5rem;
  max-width: 400px;
  margin: 0 auto;
  display: none;
}

.create-profile-form.active {
  display: block;
}

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.form-input, .form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Chat app layout */
.chat-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.empty-state-emoji {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.empty-state-text {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* New chat button */
.btn-new-chat {
  position: fixed;
  bottom: 100px;
  right: 1rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 1.5rem;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
  transition: all 0.2s;
  z-index: 50;
}

.btn-new-chat:hover {
  transform: scale(1.1);
}

/* Responsive */
@media (max-width: 640px) {
  .header-title {
    font-size: 1rem;
  }

  .header-select {
    font-size: 0.75rem;
    padding: 0.25rem 0.375rem;
  }

  .message {
    max-width: 90%;
  }

  .profiles-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* KaTeX math */
.katex-display {
  margin: 0.5rem 0;
  overflow-x: auto;
}
