/* ============================================
   MedBot — Modern Medical Chat Interface
   Light Theme with Deep Twilight & Bright Teal
   ============================================ */

/* ---- Chat Container (Modern Medical Console) ---- */
.chat-container {
  display: flex;
  flex-direction: column;
  max-width: 960px;
  margin: 18px auto 24px;
  height: calc(100vh - var(--header-height) - 42px);
  width: calc(100% - 32px);
  background: #ffffff;
  border: 1.5px solid var(--border-primary);
  border-radius: 22px;
  box-shadow: 0 16px 48px rgba(3, 4, 94, 0.08), 0 0 0 1px rgba(0, 180, 216, 0.06);
  overflow: hidden;
  position: relative;
  animation: consoleEnter 0.45s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes consoleEnter {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---- Modern Medical Chat Header ---- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 14px 24px;
  background: linear-gradient(135deg, #03045e 0%, #0077b6 100%);
  border-bottom: 3px solid #00b4d8;
  box-shadow: 0 4px 20px rgba(3, 4, 94, 0.15);
  flex-shrink: 0;
  z-index: 10;
}

.doctor-info {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.doctor-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid #caf0f8;
  box-shadow: 0 0 14px rgba(0, 180, 216, 0.45);
}

.doctor-avatar svg {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 13px;
  height: 13px;
  background: #10b981;
  border-radius: 50%;
  border: 2.5px solid #03045e;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  50% { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
}

.doctor-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doctor-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.doctor-title-row h2 {
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.badge-verified {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 180, 216, 0.25);
  border: 1px solid rgba(144, 224, 239, 0.4);
  color: #caf0f8;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.doctor-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
}

.doctor-status-text {
  color: #caf0f8;
  font-weight: 500;
}

.status-divider {
  color: rgba(202, 240, 248, 0.4);
}

.badge-lang {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.32);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--radius-full);
}

/* Back Button (Mobile Header) */
.btn-chat-back {
  display: none;
}

.rx-btn-text-desktop {
  display: inline;
}

.rx-btn-text-mobile {
  display: none;
}

/* Action Button: End & Get Prescription */
.btn-rx-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  background: #ffffff;
  color: var(--bright-teal-blue);
  font-family: var(--font-primary);
  font-size: 0.82rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: 0 4px 14px rgba(3, 4, 94, 0.2);
  white-space: nowrap;
  text-decoration: none;
}

.btn-rx-action:hover {
  background: var(--light-cyan);
  color: var(--deep-twilight);
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(0, 180, 216, 0.4);
}

.btn-rx-action:active {
  transform: translateY(0);
}

/* ---- Messages Area ---- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  scroll-behavior: smooth;
  background: radial-gradient(circle at 85% 15%, rgba(202, 240, 248, 0.35), transparent 45%),
              linear-gradient(180deg, #f7fcfe 0%, #ffffff 100%);
}

/* ---- Message Bubbles ---- */
.message {
  display: flex;
  gap: 12px;
  max-width: 84%;
  animation: messageIn 0.35s ease forwards;
}

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

.message.doctor {
  align-self: flex-start;
}

.message.patient {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* Avatar Badges */
.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 4px;
}

.doctor-msg-avatar {
  background: #ffffff;
  border: 1.5px solid var(--border-primary);
  box-shadow: 0 2px 8px rgba(0, 119, 182, 0.12);
}

.patient-msg-avatar {
  background: linear-gradient(135deg, #0077b6, #00b4d8);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 119, 182, 0.2);
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.message-sender-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--bright-teal-blue);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.message-sender-name.patient-align {
  justify-content: flex-end;
  color: var(--text-tertiary);
}

.badge-mini-ai {
  background: var(--light-cyan);
  color: var(--bright-teal-blue);
  border: 1px solid var(--frosted-blue);
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 800;
}

/* Message Bubble Styling */
.message-bubble {
  padding: 15px 20px;
  font-size: 0.92rem;
  line-height: 1.7;
  word-break: break-word;
}

.message.doctor .message-bubble {
  background: #ffffff;
  border: 1px solid var(--border-primary);
  border-left: 3.5px solid var(--bright-teal-blue);
  border-radius: 4px 20px 20px 20px;
  color: var(--deep-twilight);
  box-shadow: 0 3px 14px rgba(3, 4, 94, 0.04);
}

.message.patient .message-bubble {
  background: linear-gradient(135deg, #caf0f8 0%, #daf4fb 100%);
  border: 1.5px solid var(--frosted-blue);
  border-radius: 20px 4px 20px 20px;
  color: var(--deep-twilight);
  font-weight: 500;
  box-shadow: 0 3px 14px rgba(0, 180, 216, 0.1);
}

.message-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.message.patient .message-time {
  text-align: right;
}

/* ---- Message Content Formatting ---- */
.message-bubble h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--bright-teal-blue);
  margin: var(--space-md) 0 var(--space-sm);
}

.message-bubble h3:first-child {
  margin-top: 0;
}

.message-bubble p {
  margin-bottom: var(--space-sm);
}

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

.message-bubble ul, .message-bubble ol {
  padding-left: var(--space-lg);
  margin: var(--space-sm) 0;
}

.message-bubble li {
  margin-bottom: 5px;
}

.message-bubble strong {
  color: var(--bright-teal-blue);
  font-weight: 700;
}

.message-bubble em {
  color: var(--text-secondary);
}

.message-bubble code {
  background: var(--light-cyan);
  color: var(--deep-twilight);
  border: 1px solid var(--border-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* ---- System Messages ---- */
.message.system {
  align-self: center;
  max-width: 90%;
}

.message.system .message-bubble {
  background: #ffffff;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-full);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--bright-teal-blue);
  padding: 6px 18px;
  box-shadow: 0 2px 8px rgba(3, 4, 94, 0.04);
}

/* ---- Typing Indicator ---- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px 14px;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--bright-teal-blue);
  background: rgba(0, 119, 182, 0.06);
  border: 1px solid rgba(0, 119, 182, 0.16);
  border-radius: var(--radius-full);
  width: fit-content;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bright-teal-blue);
  animation: typingBounce 1.2s ease-in-out infinite;
}

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

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---- Voice Live Status Banner ---- */
.voice-status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px 14px;
  margin-bottom: 8px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.22);
  border-radius: var(--radius-full);
  color: #dc2626;
  font-size: 0.78rem;
  font-weight: 600;
  width: fit-content;
  animation: fadeIn 0.25s ease;
}

.voice-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  animation: statusPulse 1.5s infinite;
}

/* ---- Modern Chat Footer (Input Area) ---- */
.chat-input-area {
  background: #ffffff;
  border-top: 1.5px solid var(--border-primary);
  padding: 14px 22px;
  box-shadow: 0 -4px 20px rgba(3, 4, 94, 0.04);
  flex-shrink: 0;
  z-index: 10;
}

.chat-input-form {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Floating Input Dock */
.chat-input-wrapper {
  background: #f4fbfe;
  border: 1.5px solid var(--border-primary);
  border-radius: 28px;
  padding: 6px 8px 6px 20px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 2px 8px rgba(3, 4, 94, 0.03);
}

.chat-input-wrapper:focus-within {
  background: #ffffff;
  border-color: var(--bright-teal-blue);
  box-shadow: 0 0 0 4px rgba(0, 119, 182, 0.12), 0 4px 18px rgba(0, 119, 182, 0.08);
}

#chat-input {
  flex: 1;
  border: none !important;
  background: transparent !important;
  padding: 9px 0 !important;
  color: var(--deep-twilight) !important;
  font-family: var(--font-primary);
  font-size: 0.93rem;
  line-height: 1.5;
  resize: none;
  outline: none !important;
  box-shadow: none !important;
  max-height: 140px;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 3px;
}

/* Voice Typing Button */
.btn-voice {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--light-cyan);
  border: 1px solid var(--frosted-blue);
  color: var(--bright-teal-blue);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.btn-voice:hover {
  background: var(--turquoise-surf);
  border-color: var(--turquoise-surf);
  color: #ffffff;
  transform: scale(1.08);
}

.btn-voice .mic-icon {
  width: 19px;
  height: 19px;
  transition: transform var(--transition-fast);
}

.btn-voice.listening {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important;
  border-color: #dc2626 !important;
  color: #ffffff !important;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.5);
  animation: voicePulse 1.4s ease-in-out infinite;
}

@keyframes voicePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    transform: scale(1.08);
  }
}

.btn-voice.unsupported {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* Send Button */
.btn-send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: none;
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 3px 12px rgba(0, 119, 182, 0.3);
}

.btn-send:hover:not(:disabled) {
  box-shadow: 0 5px 20px rgba(0, 119, 182, 0.45);
  transform: scale(1.08);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-send svg {
  width: 18px;
  height: 18px;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .chat-container {
    margin: 0;
    width: 100%;
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  .chat-header {
    padding: 10px 14px;
  }

  .doctor-avatar {
    width: 40px;
    height: 40px;
  }

  .doctor-title-row h2 {
    font-size: 0.95rem;
  }

  .chat-messages {
    padding: var(--space-md);
    gap: var(--space-md);
  }

  .message {
    max-width: 92%;
  }
}

@media (max-width: 680px) {
  /* Hide redundant app header on mobile in chat view for native app immersion */
  body.chat-page-body #app-header,
  #app:has(.chat-container) #app-header {
    display: none !important;
  }

  .chat-main-view {
    padding: 0 !important;
    margin: 0 !important;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .chat-container {
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  /* Chat Header */
  .chat-header {
    padding: 8px 10px;
    gap: 8px;
    border-bottom: 2px solid #00b4d8;
  }

  .btn-chat-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.14);
    text-decoration: none;
    transition: background 0.2s ease;
    flex-shrink: 0;
  }

  .btn-chat-back:hover,
  .btn-chat-back:active {
    background: rgba(255, 255, 255, 0.26);
  }

  .doctor-info {
    gap: 8px;
    min-width: 0;
    flex: 1;
  }

  .doctor-avatar {
    width: 38px;
    height: 38px;
  }

  .status-dot {
    width: 10px;
    height: 10px;
    border-width: 2px;
  }

  .doctor-meta {
    gap: 1px;
    min-width: 0;
    overflow: hidden;
  }

  .doctor-title-row {
    gap: 6px;
  }

  .doctor-title-row h2 {
    font-size: 0.94rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .badge-verified {
    font-size: 0.58rem;
    padding: 1px 6px;
    gap: 2px;
    flex-shrink: 0;
  }

  .doctor-status-row {
    font-size: 0.7rem;
    gap: 5px;
  }

  .doctor-status-text {
    white-space: nowrap;
  }

  .badge-lang {
    font-size: 0.62rem;
    padding: 1px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
  }

  /* Responsive End Consultation Button */
  .rx-btn-text-desktop {
    display: none;
  }

  .rx-btn-text-mobile {
    display: inline;
  }

  .btn-rx-action {
    padding: 7px 11px;
    font-size: 0.78rem;
    gap: 5px;
    flex-shrink: 0;
  }

  .btn-rx-action svg {
    width: 14px;
    height: 14px;
  }

  /* Message List & Bubbles */
  .chat-messages {
    padding: 12px 10px;
    gap: 12px;
  }

  .message {
    max-width: 96%;
    gap: 8px;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 0.72rem;
    margin-top: 2px;
  }

  .doctor-msg-avatar svg {
    width: 16px;
    height: 16px;
  }

  .message-sender-name {
    font-size: 0.68rem;
    margin-bottom: 2px;
  }

  .message-bubble {
    padding: 10px 13px;
    font-size: 0.88rem;
    line-height: 1.55;
    border-radius: 4px 16px 16px 16px;
  }

  .message.patient .message-bubble {
    border-radius: 16px 4px 16px 16px;
  }

  .message-bubble h3 {
    font-size: 0.92rem;
    margin: 6px 0 4px;
  }

  .message-bubble p {
    margin-bottom: 6px;
  }

  .message-bubble ul,
  .message-bubble ol {
    padding-left: 18px;
    margin: 4px 0;
  }

  .message-bubble li {
    margin-bottom: 3px;
  }

  /* Input Footer Area */
  .chat-input-area {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 4px));
    background: #ffffff;
    border-top: 1px solid var(--border-primary);
  }

  .chat-input-wrapper {
    padding: 4px 6px 4px 12px;
    border-radius: 22px;
    gap: 6px;
    align-items: center;
  }

  #chat-input {
    font-size: 16px; /* Prevents auto-zoom on mobile safari/chrome */
    padding: 6px 0;
    min-height: 24px;
    max-height: 96px;
    line-height: 1.35;
  }

  #chat-input::placeholder {
    font-size: 0.82rem;
  }

  .chat-input-controls {
    gap: 5px;
    padding-bottom: 0;
  }

  .btn-voice,
  .btn-send {
    width: 35px;
    height: 35px;
    min-width: 35px;
  }

  .btn-voice .mic-icon,
  .btn-send svg {
    width: 17px;
    height: 17px;
  }
}

@media (max-width: 380px) {
  .badge-verified-text {
    display: none;
  }

  .doctor-status-text,
  .status-divider {
    display: none;
  }

  .doctor-avatar {
    width: 34px;
    height: 34px;
  }

  .btn-chat-back {
    width: 30px;
    height: 30px;
    min-width: 30px;
  }

  .btn-rx-action {
    padding: 6px 9px;
    font-size: 0.72rem;
  }
}
