/* ===== Galaxy AI Page - Clean White Theme ===== */

.ai-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: #ffffff;
  color: #1a1a1a;
  overflow: hidden;
  z-index: 1000;
}

.ai-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden; /* Contains flex children securely */
}

/* ===== Screen Reader Utilities ===== */
.ai-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ===== Header ===== */
.ai-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  background: #ffffff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  position: relative;
}

.ai-back-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  color: #666666;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  z-index: 1;
}

.ai-back-button:hover, .ai-back-button:focus-visible {
  background: rgba(0, 0, 0, 0.05);
  color: #1a1a1a;
  outline: 2px solid #5856d6;
  outline-offset: -2px;
}

.ai-header-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.ai-header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5856d6 0%, #ff2d55 100%);
  color: #ffffff;
}

.ai-header-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: #1a1a1a;
}

/* ===== Messages Area ===== */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
}

.ai-messages::-webkit-scrollbar {
  width: 6px;
}
.ai-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}
.ai-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

.ai-scroll-anchor {
  height: 1px;
  flex-shrink: 0;
}

/* ===== Messages ===== */
.ai-message {
  display: flex;
  animation: fadeIn 0.3s ease-out;
  max-width: 85%;
}

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

.ai-message-welcome {
  animation: welcomeEntrance 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes welcomeEntrance {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.ai-message-assistant {
  align-self: flex-start;
  justify-content: flex-start;
}

.ai-message-content {
  padding: 1rem 1.25rem;
  border-radius: 1.125rem;
  line-height: 1.6;
  font-size: 0.9375rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai-message-user .ai-message-content {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  color: #1a1a1a;
  border-bottom-right-radius: 0.25rem;
}

.ai-message-assistant .ai-message-content {
  background: #ffffff;
  color: #1a1a1a;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom-left-radius: 0.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.ai-message-error .ai-message-content {
  background: #fff0f0;
  border-color: #ffd0d0;
  color: #cc0000;
}

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

.ai-typewriter {
  position: relative;
}

.ai-typewriter-layout {
  visibility: hidden;
}

.ai-typewriter-visible {
  position: absolute;
  inset: 0;
}

.ai-typewriter-active p:last-child::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 0.15rem;
  vertical-align: -0.12em;
  background: currentColor;
  border-radius: 1px;
  animation: typewriterCursor 0.7s steps(1, end) infinite;
}

@keyframes typewriterCursor {
  0%, 45% { opacity: 0.75; }
  46%, 100% { opacity: 0; }
}

/* Message Attachments display */
.ai-message-attachments-display {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(0,0,0,0.08);
}
.ai-msg-att-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  background: rgba(255,255,255,0.6);
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid rgba(0,0,0,0.05);
}
.ai-msg-att-name {
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Loading Dots ===== */
.ai-loading-dots {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.ai-loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #999999;
  animation: loadingDot 1.4s infinite ease-in-out;
}
.ai-loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes loadingDot {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== Composer Footer Area ===== */
.ai-input-container {
  flex-shrink: 0;
  padding: 1rem 1.5rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  background: #ffffff;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.ai-composer-wrapper {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.ai-error-text, .ai-warning-text {
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
  padding-left: 0.5rem;
}
.ai-error-text { color: #e63946; }
.ai-warning-text { color: #f59e0b; }

.ai-composer {
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 1.5rem;
  transition: all 0.2s ease;
}
.ai-composer:focus-within {
  border-color: #5856d6;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(88, 86, 214, 0.08);
}

/* Active Attachments Styling */
.ai-composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem 0;
}
.ai-attachment-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.25rem 0.25rem 0.5rem;
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 0.75rem;
  max-width: 160px;
}
.ai-att-thumb, .ai-att-icon {
  width: 24px;
  height: 24px;
  border-radius: 0.375rem;
  object-fit: cover;
}
.ai-att-icon {
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}
.ai-att-name {
  font-size: 0.75rem;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.ai-att-remove {
  background: transparent;
  border: none;
  color: #999;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  display: flex;
}
.ai-att-remove:hover {
  background: #ffe6e6;
  color: #e63946;
}

/* Composer Input Row */
.ai-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  padding: 0.5rem;
}

.ai-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.ai-icon-btn:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.05);
  color: #1a1a1a;
}
.ai-icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-composer-input {
  flex: 1;
  min-height: 40px;
  height: 40px;
  max-height: 180px;
  padding: 0.5rem 0.5rem;
  background: transparent;
  border: none;
  resize: none;
  outline: none;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  color: #1a1a1a;
  box-sizing: border-box; /* CRITICAL: prevents height ballooning */
  scrollbar-width: none;
}
.ai-composer-input::-webkit-scrollbar {
  display: none;
}
.ai-composer-input::placeholder {
  color: #999999;
}
.ai-composer-input:disabled {
  opacity: 0.6;
}

/* Live Voice Mode */
.ai-voice-mode {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.5rem;
  height: 40px;
  flex: 1;
}
.ai-voice-dot {
  width: 12px;
  height: 12px;
  background: #5856d6;
  border-radius: 50%;
  animation: pulseRecord 1.5s infinite;
  flex-shrink: 0;
}
@keyframes pulseRecord {
  0% { box-shadow: 0 0 0 0 rgba(230, 57, 70, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(230, 57, 70, 0); }
  100% { box-shadow: 0 0 0 0 rgba(230, 57, 70, 0); }
}
.ai-voice-status {
  font-weight: 500;
  color: #1a1a1a;
  flex: 1;
  min-width: 0;
}
.ai-voice-status-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-voice-progress {
  display: block;
  width: min(240px, 100%);
  height: 3px;
  margin-top: 0.3rem;
  overflow: hidden;
  background: rgba(88, 86, 214, 0.14);
  border-radius: 999px;
}
.ai-voice-progress-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5856d6, #ff2d55);
  border-radius: inherit;
  transition: width 0.45s ease;
}
.ai-voice-end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.7rem;
  background: rgba(230, 57, 70, 0.08);
  border: 1px solid rgba(230, 57, 70, 0.18);
  color: #c92f3b;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
}
.ai-voice-end:hover { background: rgba(230, 57, 70, 0.14); }
.ai-voice-speaking .ai-voice-dot { background: #ff2d55; }
.ai-voice-connecting .ai-voice-dot { background: #999; }

/* Send / Stop Buttons */
.ai-composer-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding-right: 2px;
}
.ai-send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5856d6 0%, #ff2d55 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(88, 86, 214, 0.25);
}
.ai-send-button:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(88, 86, 214, 0.35);
}
.ai-send-button:active:not(:disabled) {
  transform: scale(0.95);
}
.ai-send-button:disabled {
  background: #e0e0e0;
  color: #999999;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}
.ai-stop-button {
  background: #1a1a1a;
  box-shadow: none;
}
.ai-stop-button:hover:not(:disabled) {
  background: #333333;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
  .ai-header {
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  }
  .ai-back-button span {
    display: none;
  }
  .ai-messages {
    padding: 1rem;
  }
  .ai-message {
    max-width: 90%;
  }
  .ai-input-container {
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  }
  .ai-icon-btn {
    width: 38px;
    height: 38px;
  }
  .ai-composer-input {
    font-size: 1rem; /* Prevent iOS Zoom */
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  .ai-message { animation: none; }
  .ai-message-welcome { animation: none; }
  .ai-typewriter-active p:last-child::after { animation: none; }
  .ai-loading-dots span { animation: none; opacity: 0.6; }
  .ai-voice-dot { animation: none; }
  .ai-voice-progress-fill { transition: none; }
  .ai-send-button { transition: none; }
  .ai-send-button:hover:not(:disabled) { transform: none; }
}

/* Standalone-page reset; the reference React app supplies these globally. */
html, body { margin: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
button, textarea { font-family: inherit; }
[hidden] { display: none !important; }
.ai-page { position: fixed; inset: 0; }
.ai-container, .ai-messages, .ai-voice-mode { min-height: 0; min-width: 0; }
.ai-composer-input { min-width: 0; }
.ai-message { flex-shrink: 0; min-width: 0; }
.ai-message-content { min-width: 0; }
.ai-header-content { white-space: nowrap; }
button:focus-visible { outline: 2px solid #5856d6; outline-offset: 2px; }

@media (max-width: 380px) {
  .ai-header-content { gap: 0.5rem; }
  .ai-header-title { font-size: 1rem; }
  .ai-header-icon { width: 30px; height: 30px; }
  .ai-back-button { padding: 0.5rem; }
}
