/*************************************************
 * ENGLISHDOOR - MOBILE-FIRST CSS
 * Optimized for 90% mobile usage
 * Colors: #4A90E2 (Blue), #7ED321 (Green), #F7DC6F (Yellow)
 *************************************************/

/*************************************************
 * RESET & BASE
 *************************************************/
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f2f6fb;
  color: #1f2d3d;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/*************************************************
 * HEADER - Abstract gradient with 3 colors
 *************************************************/
header {
  background: linear-gradient(
    135deg,
    #4A90E2 0%,
    #7ED321 50%,
    #F7DC6F 100%
  );
  padding: 20px 16px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

/* Abstract pattern overlay */
header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 40% 20%, rgba(0, 0, 0, 0.05) 0%, transparent 40%);
  pointer-events: none;
}

header h1 {
  font-size: 32px;
  font-weight: 700;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
  margin: 0;
  position: relative;
  z-index: 1;
  letter-spacing: -0.5px;
}

/*************************************************
 * MAIN APP CONTAINER
 *************************************************/
#app {
  max-width: 100%;
  padding: 16px;
  margin: 0 auto;
  padding-bottom: 180px; /* Space for avatar + progress bar */
}

/*************************************************
 * CREDITS DISPLAY - Top of page, always visible
 *************************************************/
#credits-container {
  background: white;
  border-radius: 12px;
  padding: 10px 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 8px;
}

.credit-item {
  text-align: center;
  flex: 1;
}

.credit-item .icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.credit-item .count {
  font-size: 20px;
  font-weight: 700;
  color: #4A90E2;
  display: block;
}

.credit-item .label {
  font-size: 12px;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/*************************************************
 * CHAT CONTAINER - Mobile optimized
 *************************************************/
#chat {
  background: white;
  border-radius: 12px;
  padding: 16px;
  height: calc(100vh - 400px);
  min-height: 300px;
  max-height: 500px;
  overflow-y: auto;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar for mobile */
#chat::-webkit-scrollbar {
  width: 4px;
}

#chat::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 2px;
}

#chat::-webkit-scrollbar-thumb {
  background: #4A90E2;
  border-radius: 2px;
}

/*************************************************
 * CHAT MESSAGES
 *************************************************/
.message {
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
  word-wrap: break-word;
}

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

.message .user {
  font-weight: 700;
  color: #4A90E2;
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.message .tutor {
  font-weight: 700;
  color: #7ED321;
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.message-text {
  background: #f8f9fa;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.5;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  width: fit-content;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7ED321;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/*************************************************
 * CONTROLS - Input area (mobile optimized)
 *************************************************/
#controls {
  background: white;
  padding: 12px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  gap: 8px;
  align-items: center;
}

#messageInput {
  flex: 1;
  padding: 14px 16px;
  font-size: 16px; /* Prevent zoom on iOS */
  border: 2px solid #e9ecef;
  border-radius: 24px;
  outline: none;
  transition: border-color 0.3s ease;
  font-family: inherit;
}

#messageInput:focus {
  border-color: #4A90E2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

/*************************************************
 * BUTTONS - Mobile touch optimized
 *************************************************/
button {
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px; /* Touch target size */
  min-width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Send button */
button.send-btn {
  background: #4A90E2;
  color: white;
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

button.send-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 6px rgba(74, 144, 226, 0.3);
}

/* Voice button */
#voiceBtn {
  background: white;
  color: #4A90E2;
  border: 2px solid #4A90E2;
  font-size: 20px;
  padding: 12px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#voiceBtn:active {
  transform: scale(0.95);
  background: #4A90E2;
  color: white;
}

#voiceBtn.recording {
  background: #e74c3c;
  color: white;
  border-color: #e74c3c;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(231, 76, 60, 0);
  }
}

/*************************************************
 * RECORDING STATUS
 *************************************************/
#recordingStatus {
  background: #fff5f5;
  color: #e74c3c;
  padding: 12px 16px;
  border-radius: 8px;
  margin-top: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  display: none;
  animation: fadeIn 0.3s ease;
}

#recordingStatus.active {
  display: block;
}

/*************************************************
 * VOICE CREDITS DISPLAY
 *************************************************/
#voice-credits {
  background: #f8f9fa;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13px;
  color: #6c757d;
  font-weight: 600;
  white-space: nowrap;
}

/* Tutor avatar is now in the header — styled inline in index.html */

/*************************************************
 * PROGRESS BAR - Bottom fixed
 *************************************************/
#progress-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  padding: 12px 16px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  z-index: 999;
}

#progress-label {
  font-size: 12px;
  color: #6c757d;
  margin-bottom: 6px;
  text-align: center;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#progress-bar {
  width: 100%;
  height: 12px;
  background: #e9ecef;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #7ED321 0%, #4A90E2 100%);
  border-radius: 6px;
  transition: width 0.5s ease;
  position: relative;
  overflow: hidden;
}

/* Shimmer effect on progress */
#progress-fill::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

#progress-text {
  font-size: 11px;
  color: #6c757d;
  margin-top: 4px;
  text-align: center;
}

/*************************************************
 * TABLET (min 600px)
 *************************************************/
@media (min-width: 600px) {
  header h1 {
    font-size: 38px;
  }

  #app {
    max-width: 600px;
    padding: 20px;
  }

  #chat {
  }

  /* avatar is inline, no fixed positioning override needed */

  button {
    min-height: 52px;
  }
}

/*************************************************
 * DESKTOP (min 900px)
 *************************************************/
@media (min-width: 900px) {
  header h1 {
    font-size: 42px;
  }

  #app {
    max-width: 900px;
    padding: 24px;
  }



  #controls {
    padding: 16px;
  }

  #messageInput {
    font-size: 15px;
    padding: 16px 20px;
  }

  /* avatar is inline, no fixed positioning override needed */

  /* Hover effects on desktop */
  button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(74, 144, 226, 0.4);
  }

  button:active {
    transform: scale(0.98);
  }
}

/*************************************************
 * LARGE DESKTOP (min 1200px)
 *************************************************/
@media (min-width: 1200px) {
  #app {
    max-width: 1000px;
  }


}

/*************************************************
 * ACCESSIBILITY & UTILITIES
 *************************************************/
.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;
}

/* Focus styles for keyboard navigation */
*:focus-visible {
  outline: 3px solid #4A90E2;
  outline-offset: 2px;
}

/* Prevent text selection on buttons */
button {
  user-select: none;
  -webkit-user-select: none;
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  #progress-container {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/*************************************************
 * LOADING SPINNER
 *************************************************/
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/*************************************************
 * TOAST NOTIFICATIONS
 *************************************************/
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2d3d;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  animation: toastIn 0.3s ease;
}

.toast.success {
  background: #7ED321;
}

.toast.error {
  background: #e74c3c;
}

.toast.warning {
  background: #F7DC6F;
  color: #1f2d3d;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/*************************************************
 * MOBILE FIX — input sempre visível sem scroll
 *************************************************/
@media (max-width: 768px) {
  #app {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
    padding-bottom: 0;
  }

  #credits-container {
    flex-shrink: 0;
    margin-bottom: 0;
  }

  #chat {
    flex: 1;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin-bottom: 0;
    border-radius: 0;
    box-shadow: none;
  }

  #recordingStatus {
    flex-shrink: 0;
  }

  #controls {
    flex-shrink: 0;
    border-radius: 0;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    margin-bottom: 0;
  }
}
