/**
 * style.css
 * Chat Interface Styles
 * 
 * CDSSv2 - AI-First Clinical Decision Support System
 */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  background: #ece5dd;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

.chat-container {
  max-width: 480px;
  height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.chat-header {
  position: relative;
  background: #128c7e;
  color: #fff;
  padding: 16px 20px;
  font-weight: 700;
  font-size: 16px;
}

.chat-sub {
  font-weight: 400;
  font-size: 12px;
  opacity: 0.9;
  margin-top: 4px;
}

.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #e5ddd5;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4ccc4' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.bubble.user {
  background: #dcf8c6;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.bubble.bot {
  background: #fff;
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

.bubble strong {
  font-weight: 600;
}

.bubble em {
  font-style: italic;
}

.meta {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 6px;
  font-family: monospace;
}

/* Typing Indicator */
.bubble.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.bubble.typing .dot {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.bubble.typing .dot:nth-child(1) { animation-delay: 0s; }
.bubble.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.bubble.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Emergency Warning */
.emergency-warning {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
  color: white;
  padding: 14px 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(238, 90, 90, 0.3);
}

.emergency-warning .warning-icon {
  font-size: 24px;
}

.emergency-warning .warning-text {
  font-size: 13px;
  line-height: 1.4;
}

.emergency-warning strong {
  font-size: 14px;
}

/* Choice Buttons */
.choices-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.choice-btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 120px;
  padding: 12px 16px;
  background: #fff;
  border: 2px solid #075e54;
  border-radius: 20px;
  color: #075e54;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.choice-btn:hover {
  background: #075e54;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(7, 94, 84, 0.3);
}

.choice-btn:active {
  transform: translateY(0);
}

.choice-btn.choice-manual {
  flex: 1 1 100%;
  background: transparent;
  border-color: #999;
  color: #666;
  font-size: 12px;
}

.choice-btn.choice-manual:hover {
  background: #f5f5f5;
  border-color: #666;
  color: #333;
}

/* Input Area */
.chat-input-area {
  padding: 12px;
  background: #f0f0f0;
  border-top: 1px solid #ddd;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  background: white;
  border-radius: 24px;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s;
}

.input-wrapper:focus-within {
  box-shadow: 0 2px 8px rgba(7, 94, 84, 0.2);
}

.input-wrapper input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: none;
  border-radius: 20px;
  font-size: 15px;
  outline: none;
  background: transparent;
  box-shadow: none;
}

.input-wrapper input:focus {
  box-shadow: none;
}

.input-wrapper input:disabled {
  background: transparent;
  color: #999;
}

.icon-btn {
  position: relative;
  background: #075e54;
  border: none;
  color: white;
  cursor: pointer;
  padding: 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: #128c7e;
  transform: scale(1.05);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* Header Menu */
.header-menu {
  position: absolute;
  right: 12px;
  top: 12px;
}

.menu-toggle {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  transition: background 0.2s;
}

.menu-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  top: 36px;
  background-color: #fff;
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
  border-radius: 8px;
  overflow: hidden;
}

.dropdown-content a {
  color: #333;
  padding: 14px 18px;
  text-decoration: none;
  display: block;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.2s;
}

.dropdown-content a:hover {
  background-color: #f5f5f5;
}

.show {
  display: block;
}

/* Responsive */
@media (max-width: 480px) {
  .chat-container {
    max-width: 100%;
  }
  
  .bubble {
    max-width: 90%;
  }
  
  .choice-btn {
    flex: 1 1 100%;
  }
}

/* Scrollbar */
.chat-box::-webkit-scrollbar {
  width: 6px;
}

.chat-box::-webkit-scrollbar-track {
  background: transparent;
}

.chat-box::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.chat-box::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* ========================================
   Voice Input (Speech-to-Text) Styles
   ======================================== */

/* Voice Button Base */
.voice-btn {
  position: relative;
  background: #128c7e;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.voice-btn .mic-icon {
  transition: opacity 0.2s, transform 0.2s;
}

.voice-btn .voice-waves {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.2s;
}

.voice-btn .wave {
  width: 3px;
  height: 12px;
  background: white;
  border-radius: 2px;
  animation: none;
}

/* Voice Button States */

/* Listening State */
.voice-btn.listening {
  background: #e53935;
  animation: pulse-ring 1.5s ease-out infinite;
}

.voice-btn.listening .mic-icon {
  opacity: 0;
  transform: scale(0.5);
}

.voice-btn.listening .voice-waves {
  opacity: 1;
}

.voice-btn.listening .wave {
  animation: voice-wave 0.8s ease-in-out infinite;
}

.voice-btn.listening .wave:nth-child(1) {
  animation-delay: 0s;
  height: 8px;
}

.voice-btn.listening .wave:nth-child(2) {
  animation-delay: 0.15s;
  height: 16px;
}

.voice-btn.listening .wave:nth-child(3) {
  animation-delay: 0.3s;
  height: 8px;
}

/* Processing State (after speech ends, before send) */
.voice-btn.processing {
  background: #ff9800;
  pointer-events: none;
}

.voice-btn.processing .mic-icon {
  animation: spin 1s linear infinite;
}

/* Disabled/Unsupported State */
.voice-btn.unsupported {
  background: #999;
  cursor: not-allowed;
  opacity: 0.6;
}

.voice-btn.unsupported:hover {
  background: #999;
  transform: none;
}

/* Animations */
@keyframes voice-wave {
  0%, 100% {
    transform: scaleY(0.5);
    opacity: 0.5;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.5);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(229, 57, 53, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(229, 57, 53, 0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Voice Status Indicator */
.voice-status {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  white-space: nowrap;
  margin-bottom: 8px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.voice-status.show {
  opacity: 1;
  visibility: visible;
}

.voice-status::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.8);
}

/* Voice Transcript Preview */
.voice-transcript {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 10;
}

.voice-transcript.show {
  opacity: 1;
  visibility: visible;
}

.voice-transcript .interim {
  color: #aaa;
  font-style: italic;
}

/* Voice Permission Prompt */
.voice-permission-prompt {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.voice-permission-prompt.show {
  opacity: 1;
  visibility: visible;
}

.voice-permission-content {
  background: white;
  padding: 24px;
  border-radius: 16px;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.voice-permission-content h3 {
  margin: 0 0 12px;
  color: #333;
}

.voice-permission-content p {
  margin: 0 0 20px;
  color: #666;
  font-size: 14px;
  line-height: 1.5;
}

.voice-permission-content button {
  background: #128c7e;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.voice-permission-content button:hover {
  background: #075e54;
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .voice-transcript {
    left: 12px;
    right: 12px;
    bottom: calc(100% + 4px);
  }
}
