/* ============================================
   Medication Chat Styles
   AI medication chat UI — purple gradient theme
   ============================================ */

/* Chat View Container */
.medication-chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
}

/* Experimental Badge Banner */
.chat-experimental-badge {
    background: linear-gradient(135deg, #f0c808 0%, #e6a817 100%);
    color: #4a3800;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    padding: 6px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-shrink: 0;
}

.chat-experimental-badge i {
    font-size: 0.8rem;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    max-height: 400px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d4bfea;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9d4edd;
}

/* Individual Message Row */
.chat-message {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    animation: chatMessageSlide 0.3s ease-out;
}

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

/* Avatar */
.chat-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7b2cbf 0%, #9d4edd 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.chat-message.user .chat-avatar {
    background: linear-gradient(135deg, #9d4edd 0%, #c77dff 100%);
}

/* Message Bubble */
.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}

.chat-message.assistant .chat-bubble {
    background: #f0e6ff;
    color: #2c3e50;
    border-bottom-left-radius: 4px;
}

.chat-message.user .chat-bubble {
    background: linear-gradient(135deg, #7b2cbf 0%, #9d4edd 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Markdown content inside assistant bubbles */
.chat-bubble p {
    margin: 0 0 0.4em 0;
}
.chat-bubble p:last-child {
    margin-bottom: 0;
}
.chat-bubble strong {
    font-weight: 600;
    color: #5a189a;
}
.chat-bubble ul, .chat-bubble ol {
    margin: 0.3em 0;
    padding-left: 1.2em;
}
.chat-bubble li {
    margin-bottom: 0.15em;
}
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0.5em 0 0.2em 0;
    color: #5a189a;
}
.chat-bubble code {
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.85em;
}

/* Source attribution tag */
.chat-source-tag {
    display: inline-block;
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(93, 26, 155, 0.1);
    color: #7b2cbf;
    margin-top: 6px;
    font-weight: 500;
}

/* Typing Indicator */
.chat-bubble.typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
    background: #f0e6ff;
}

.chat-bubble.typing .typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9d4edd;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.chat-bubble.typing .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-bubble.typing .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Audio Button on Assistant Messages */
.btn-chat-audio {
    background: none;
    border: none;
    color: #9d4edd;
    font-size: 0.8rem;
    padding: 2px 6px;
    margin-top: 4px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-chat-audio:hover {
    background: rgba(157, 78, 221, 0.1);
    color: #7b2cbf;
}

.btn-chat-audio.playing {
    color: #7b2cbf;
    animation: micPulse 1.5s infinite;
}

/* Disclaimer */
.chat-disclaimer {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.75rem;
    font-style: italic;
    color: #6c757d;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 16px 8px;
    flex-shrink: 0;
}

.chat-disclaimer i {
    color: #6c757d;
    font-size: 0.85rem;
    margin-top: 1px;
    flex-shrink: 0;
}

/* Input Area */
.chat-input-area {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 40px;
    max-height: 100px;
    resize: none;
    background: white;
}

.chat-input:focus {
    border-color: #9d4edd;
    box-shadow: 0 0 0 3px rgba(157, 78, 221, 0.15);
}

.chat-input::placeholder {
    color: #adb5bd;
}

/* Send Button */
.btn-chat-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7b2cbf 0%, #9d4edd 100%);
    border: none;
    color: white;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.btn-chat-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(123, 44, 191, 0.4);
}

.btn-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mic Button */
.btn-chat-mic {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: #e0e0e0;
    border: none;
    color: #495057;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.btn-chat-mic:hover:not(:disabled) {
    background: #d0d0d0;
}

.btn-chat-mic:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-chat-mic.listening {
    background: #dc3545;
    color: white;
    animation: micPulse 1.5s infinite;
}

.btn-chat-mic.playing {
    background: #dc3545;
    color: white;
}

.btn-chat-mic.playing:hover {
    background: #c82333;
}

/* Voice Mode (full-screen voice interface) */
.chat-voice-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 32px;
    gap: 24px;
}

.chat-voice-mode .btn-chat-mic {
    width: 80px;
    height: 80px;
    font-size: 1.75rem;
    background: linear-gradient(135deg, #7b2cbf 0%, #9d4edd 100%);
    color: white;
    box-shadow: 0 4px 16px rgba(123, 44, 191, 0.3);
}

.chat-voice-mode .btn-chat-mic:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(123, 44, 191, 0.5);
}

.chat-voice-mode .btn-chat-mic.listening {
    background: #dc3545;
    box-shadow: 0 0 0 8px rgba(220, 53, 69, 0.2);
    animation: micPulse 1.5s infinite;
}

/* Voice Waveform Visualizer */
.chat-voice-waveform {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 40px;
    min-width: 120px;
}

.chat-voice-waveform .waveform-bar {
    width: 4px;
    background: linear-gradient(180deg, #7b2cbf 0%, #9d4edd 100%);
    border-radius: 2px;
    transition: height 0.1s ease;
    height: 6px;
    min-height: 4px;
}

.chat-voice-waveform.active .waveform-bar {
    animation: waveformPulse 0.6s ease-in-out infinite alternate;
}

.chat-voice-waveform.active .waveform-bar:nth-child(1) { animation-delay: 0s; }
.chat-voice-waveform.active .waveform-bar:nth-child(2) { animation-delay: 0.1s; }
.chat-voice-waveform.active .waveform-bar:nth-child(3) { animation-delay: 0.2s; }
.chat-voice-waveform.active .waveform-bar:nth-child(4) { animation-delay: 0.15s; }
.chat-voice-waveform.active .waveform-bar:nth-child(5) { animation-delay: 0.05s; }
.chat-voice-waveform.active .waveform-bar:nth-child(6) { animation-delay: 0.25s; }
.chat-voice-waveform.active .waveform-bar:nth-child(7) { animation-delay: 0.12s; }

/* Nudge Banner */
.chat-nudge-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    margin: 0 16px 8px;
    background: #e7f3ff;
    border: 1px solid #b8d4ff;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #1a5276;
    flex-shrink: 0;
    animation: chatMessageSlide 0.3s ease-out;
}

.chat-nudge-banner i {
    color: #3498db;
    font-size: 0.9rem;
    margin-top: 1px;
    flex-shrink: 0;
}

.chat-nudge-banner .btn-close {
    font-size: 0.6rem;
    padding: 4px;
    margin-left: auto;
    flex-shrink: 0;
    opacity: 0.6;
}

.chat-nudge-banner .btn-close:hover {
    opacity: 1;
}

/* Summary Section */
.chat-summary-section {
    margin: 0 16px 8px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-summary-section .summary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f8f3ff;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #7b2cbf;
    transition: background 0.2s;
}

.chat-summary-section .summary-header:hover {
    background: #f0e6ff;
}

.chat-summary-section .summary-header i {
    transition: transform 0.3s;
}

.chat-summary-section .summary-header.expanded i {
    transform: rotate(180deg);
}

.chat-summary-section .summary-body {
    padding: 12px 14px;
    font-size: 0.82rem;
    line-height: 1.5;
    color: #495057;
    border-top: 1px solid #e0e0e0;
    max-height: 200px;
    overflow-y: auto;
}

/* Purple outline button (matching app theme) */
.btn-outline-purple {
    color: #7b2cbf;
    border-color: #7b2cbf;
    background: transparent;
}
.btn-outline-purple:hover:not(:disabled) {
    background: #7b2cbf;
    border-color: #7b2cbf;
    color: white;
}
.btn-outline-purple:disabled {
    opacity: 0.5;
}

/* Show More / Load More Link */
.chat-show-more {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background: none;
    border: none;
    color: #7b2cbf;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s;
    width: 100%;
}

.chat-show-more:hover {
    color: #9d4edd;
    text-decoration: underline;
}

/* ============================================
   Animations
   ============================================ */

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

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

@keyframes micPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }
}

@keyframes waveformPulse {
    0% {
        height: 6px;
    }
    100% {
        height: 32px;
    }
}

/* ============================================
   Desktop (>1024px)
   ============================================ */
@media (min-width: 1025px) {
    .chat-messages {
        max-height: 300px;
    }

    .chat-voice-mode .btn-chat-mic {
        width: 80px;
        height: 80px;
        font-size: 1.75rem;
    }
}

/* ============================================
   Tablet (768px - 1024px)
   ============================================ */
@media (min-width: 768px) and (max-width: 1024px) {
    .chat-messages {
        max-height: 250px;
        padding: 12px;
    }

    .chat-bubble {
        font-size: 0.88rem;
    }

    .chat-voice-mode .btn-chat-mic {
        width: 72px;
        height: 72px;
        font-size: 1.5rem;
    }
}

/* ============================================
   Mobile (<768px)
   ============================================ */
@media (max-width: 767px) {
    .medication-chat-view {
        border-radius: 0;
    }

    .chat-messages {
        max-height: calc(45vh - 200px);
        padding: 10px;
        gap: 8px;
    }

    .chat-bubble {
        font-size: 0.8rem;
        padding: 8px 12px;
        max-width: 85%;
        line-height: 1.4;
    }

    .chat-avatar {
        width: 24px;
        height: 24px;
        min-width: 24px;
        font-size: 0.65rem;
    }

    .chat-message {
        gap: 6px;
    }

    .chat-input-area {
        padding: 8px 10px;
        gap: 6px;
    }

    .chat-input {
        padding: 6px 12px;
        font-size: 0.85rem;
        min-height: 36px;
        border-radius: 18px;
    }

    .btn-chat-send,
    .btn-chat-mic {
        width: 38px;
        height: 38px;
        min-width: 38px;
        font-size: 0.85rem;
    }

    .chat-disclaimer {
        margin: 0 10px 6px;
        padding: 8px 10px;
        font-size: 0.7rem;
    }

    .chat-nudge-banner {
        margin: 0 10px 6px;
        padding: 8px 10px;
        font-size: 0.75rem;
    }

    .chat-summary-section {
        margin: 0 10px 6px;
    }

    .chat-experimental-badge {
        font-size: 0.7rem;
        padding: 4px 10px;
    }

    .chat-voice-mode {
        padding: 24px 16px;
        gap: 20px;
    }

    .chat-voice-mode .btn-chat-mic {
        width: 70px;
        height: 70px;
        font-size: 1.5rem;
    }

    .chat-voice-waveform {
        height: 32px;
        min-width: 100px;
    }

    .chat-voice-waveform .waveform-bar {
        width: 3px;
    }

    .btn-chat-audio {
        font-size: 0.7rem;
        padding: 2px 4px;
    }
}

/* ============================================
   Small Phone (<480px)
   ============================================ */
@media (max-width: 479px) {
    .chat-messages {
        max-height: calc(40vh - 180px);
        padding: 8px;
        gap: 6px;
    }

    .chat-bubble {
        font-size: 0.78rem;
        padding: 7px 10px;
        border-radius: 14px;
    }

    .chat-avatar {
        width: 22px;
        height: 22px;
        min-width: 22px;
        font-size: 0.6rem;
    }

    .chat-input-area {
        padding: 6px 8px;
        gap: 4px;
    }

    .chat-input {
        padding: 5px 10px;
        font-size: 0.8rem;
        min-height: 34px;
    }

    .btn-chat-send,
    .btn-chat-mic {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 0.8rem;
    }

    .chat-voice-mode .btn-chat-mic {
        width: 64px;
        height: 64px;
        font-size: 1.35rem;
    }

    .chat-disclaimer {
        font-size: 0.65rem;
        padding: 6px 8px;
        margin: 0 8px 4px;
    }

    .chat-nudge-banner {
        font-size: 0.7rem;
        padding: 6px 8px;
        margin: 0 8px 4px;
    }

    .chat-summary-section {
        margin: 0 8px 4px;
    }

    .chat-summary-section .summary-header {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .chat-summary-section .summary-body {
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    .chat-experimental-badge {
        font-size: 0.65rem;
        padding: 3px 8px;
    }

    .chat-voice-waveform {
        height: 28px;
        gap: 2px;
    }

    .chat-voice-waveform .waveform-bar {
        width: 3px;
    }
}

/* ============================================
   Accessibility
   ============================================ */
.btn-chat-send:focus-visible,
.btn-chat-mic:focus-visible,
.btn-chat-audio:focus-visible,
.chat-input:focus-visible,
.chat-show-more:focus-visible {
    outline: 3px solid #7b2cbf;
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .chat-message,
    .chat-nudge-banner {
        animation: none;
    }

    .chat-bubble.typing .typing-dot {
        animation: none;
        opacity: 0.6;
    }

    .btn-chat-mic.listening {
        animation: none;
        box-shadow: 0 0 0 4px rgba(220, 53, 69, 0.3);
    }

    .chat-voice-waveform.active .waveform-bar {
        animation: none;
        height: 16px;
    }

    .btn-chat-audio.playing {
        animation: none;
    }
}

/* ============================================
   Print — hide chat entirely
   ============================================ */
@media print {
    .medication-chat-view {
        display: none !important;
    }
}
