/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  background: #ffffff;
  color: #111827;
  height: 100vh;
  overflow: hidden;
}

.font-ibm-plex {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

/* App Container */
.app-container {
  min-height: 100vh;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid #e5e7eb;
}

.header-content {
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  color: #111827;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.5;
}

.clear-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.clear-btn:hover {
  background: #f3f4f6;
  color: #111827;
}

/* ── Chat Container ── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
}

.messages-area {
  flex: 1;
  overflow-y: auto;
}

.messages-content {
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100%;
}

/* ── Welcome Screen ── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  min-height: 400px;
}

.welcome-icon {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 32px;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  color: #6b7280;
}

.welcome-title {
  color: #111827;
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 16px;
  line-height: 1.5;
}

.welcome-text {
  color: #6b7280;
  max-width: 448px;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Messages ── */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.message {
  display: flex;
  width: 100%;
}

.message.user { justify-content: flex-end; }
.message.ai   { justify-content: flex-start; }

.message-wrapper {
  max-width: 512px;
  display: flex;
  flex-direction: column;
}

.message.user .message-wrapper { align-items: flex-end; }
.message.ai   .message-wrapper { align-items: flex-start; }

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

.message.user .message-header { flex-direction: row-reverse; }

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: #111827;
  border-color: #111827;
  color: #ffffff;
}

.message.ai .message-avatar {
  background: #f3f4f6;
  border-color: #e5e7eb;
  color: #6b7280;
}

.message-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.message.user .message-info { flex-direction: row-reverse; }

.message-sender {
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
}

/* ── Preference Badge (shown on AI messages when prefs are active) ── */
.pref-badge {
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 400;
}

/* ── Message Bubbles ── */
.message-bubble {
  border-radius: 12px;
  padding: 12px 16px;
  word-wrap: break-word;
  max-width: 100%;
}

.message.user .message-bubble {
  background: #111827;
  color: #ffffff;
}

.message.ai .message-bubble {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  color: #111827;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-words;
  font-size: 14px;
  line-height: 1.6;
}

.message-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 4px;
  font-size: 12px;
  color: #9ca3af;
}

.message.user .message-footer { justify-content: flex-end; }
.message.ai   .message-footer { justify-content: flex-start; }

/* ── Loading Indicator ── */
.loading-indicator {
  display: flex;
  justify-content: flex-start;
}

.loading-bubble {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 32px;
  padding: 24px;
  max-width: 320px;
}

.loading-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.dot {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

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

.loading-text {
  color: #6b7280;
  font-size: 14px;
}

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

/* ── Input Area ── */
.input-area {
  border-top: 1px solid #e5e7eb;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
}

.input-content {
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px 24px;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Preference Controls Bar ── */
.preferences-bar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.pref-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.pref-label {
  color: #6b7280;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* Shared wrapper for custom dropdown arrow */
.select-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.select-wrapper::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #6b7280;
  pointer-events: none;
}

.pref-select {
  height: 34px;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  color: #111827;
  padding: 0 28px 0 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
}

.pref-select:focus {
  border-color: #9ca3af;
  box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.1);
}

.pref-select:hover { border-color: #9ca3af; }

/* ── Message Input Row ── */
.input-section {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.textarea-container {
  flex: 1;
  position: relative;
}

.message-textarea {
  width: 100%;
  min-height: 44px;
  max-height: 128px;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 12px 16px;
  color: #111827;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: all 0.2s ease;
}

.message-textarea::placeholder { color: #9ca3af; }

.message-textarea:focus {
  border-color: #9ca3af;
  box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.1);
}

.message-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f9fafb;
}

.send-button {
  height: 44px;
  width: 44px;
  background: #111827;
  border: none;
  border-radius: 8px;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  position: relative;
}

.send-button:hover:not(:disabled) { background: #1f2937; }
.send-button:disabled { opacity: 0.5; cursor: not-allowed; }

.loading-spinner { position: absolute; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #ffffff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ── Scrollbar ── */
.messages-area::-webkit-scrollbar       { width: 6px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 3px; }
.messages-area::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .header-content   { padding: 16px; }
  .messages-content { padding: 16px; gap: 20px; }
  .message-wrapper  { max-width: 85%; }
  .input-content    { padding: 16px; }
  .chat-form        { gap: 10px; }
  .preferences-bar  { gap: 8px; }
}

@media (max-width: 480px) {
  .header-title     { font-size: 16px; }
  .welcome-title    { font-size: 18px; }
  .message-wrapper  { max-width: 90%; }
  .message-bubble   { padding: 10px 12px; }
  .header-content   { padding: 12px; }
  .messages-content { padding: 12px; }
  .input-content    { padding: 12px; }
  .pref-label       { font-size: 12px; }
  .pref-select      { font-size: 12px; }
}
