/* ===== ./styles.css ===== */

/* Basic resets and layout */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: -webkit-fill-available; /* iOS viewport height fix */
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; /* Added system fonts */
    font-size: 16px;
    line-height: 1.6;
    color: #343a40; /* Slightly darker default text */
    background-color: #f8f9fa;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Header Styles */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #dee2e6; /* Standard bootstrap border */
    height: 60px;
    background: white;
    z-index: 1030; /* Bootstrap fixed-top z-index */
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); /* Subtle shadow */
}

.language-switcher {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #95C11F;
    font-weight: bold;
}

.language-switcher a,
.language-switcher span {
    color: #95C11F;
    text-decoration: none;
    margin: 0 5px;
}

.language-switcher a.active {
    text-decoration: underline;
}

.logo {
    height: 40px;
    width: auto;
    display: block;
}

/* Chat Container Styles */
.chat-container {
    flex: 1;
    padding: 1rem;
    padding-top: 75px; /* Space below fixed header (header height + margin) */
    padding-bottom: 1rem;
    overflow-y: auto; /* Changed from visible to auto to avoid unnecessary scrollbars */
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    /* Adjust height for safe area insets (iOS) */
    min-height: calc(100vh - 60px);
    min-height: calc(100vh - 60px - env(safe-area-inset-bottom));
}

/* Doctor Area Styles */
.doctor-area {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 0.8rem; /* Slightly reduced gap */
    max-width: 100%;
    margin-top: auto; /* Push to bottom */
}

.doctor-image {
    width: 85px; /* Slightly smaller */
    height: auto;
    align-self: flex-end;
    margin-bottom: 0;
    flex-shrink: 0;
    border-radius: 50%; /* Make doctor image round */
    object-fit: cover; /* Ensure image covers the area well */
    border: 2px solid white; /* Add a small border */
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Messages Container Styles */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex-grow: 1;
    padding-bottom: 10px; /* Space at the very bottom */
    width: calc(100% - 85px - 0.8rem); /* Adjust width based on image and gap */
}

/* Message Bubble Styles */
.message-bubble {
    padding: 0.8rem 1.1rem; /* Adjusted padding */
    background-color: #E0F0B8; /* Slightly adjusted green */
    border-radius: 18px; /* More rounded */
    border-bottom-left-radius: 4px; /* Give it a chat bubble tail feel */
    max-width: 100%; /* Allow full width within its container */
    word-wrap: break-word;
    align-self: flex-start;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
    opacity: 0;
    transform: translateY(10px);
    animation: fadeInSlideUp 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) forwards; /* Smoother animation */
    position: relative; /* Needed for pseudo-elements if added */
    margin-bottom: 5px; /* Add small space between bubbles */
}

@keyframes fadeInSlideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Content within the bubble */
.message-content {
    font-size: 0.95rem; /* Slightly smaller text */
    color: #212529; /* Bootstrap default dark text */
}

/* Image within bubble */
.message-content img.howto-image,
.message-content img.image-preview {
    display: block;
    max-width: 100%;
    max-height: 250px; /* Allow slightly taller images */
    margin: 0.75rem auto;
    border-radius: 0.5rem;
    border: 1px solid #ced4da; /* Standard border color */
}

/* Markdown Formatting Styles */
.message-content h1, .message-content h2, .message-content h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-top: 0.5rem;
    margin-bottom: 0.3rem;
    color: #495057; /* Darker gray heading */
}

.message-content ul, .message-content ol {
    margin-left: 1.25rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    padding-left: 1rem; /* Add padding for bullet points */
}

.message-content li {
    margin-bottom: 0.3rem;
}

.message-content strong {
    font-weight: 700;
    color: #343a40;
}

.message-content em {
    font-style: italic;
}

.message-content br {
    content: "";
    display: block;
    margin-bottom: 0.3em; /* Smaller space for <br> */
}

.message-content a {
    color: #007bff; /* Standard link color */
    text-decoration: underline;
}
.message-content a:hover {
    color: #0056b3;
}

/* Consent Text Style */
.consent-text {
    font-size: 0.75rem; /* Smaller font size */
    color: #6c757d; /* Gray color */
    margin-top: 0.75rem;
    margin-bottom: 0.5rem; /* Space before button */
    text-align: center; /* Center align */
    padding: 0 5px; /* Add padding */
}
.consent-text a {
    color: #6c757d;
    text-decoration: underline;
}
.consent-text a:hover {
    color: #495057;
}


/* Input Field Styles */
.input-group {
    margin-top: 0.75rem;
    display: flex; /* Use flex for potential multiple inputs */
    flex-direction: column;
    gap: 0.5rem; /* Space between multiple inputs */
}

.chat-input {
    width: 100%;
    padding: 0.7rem 0.9rem; /* Adjusted padding */
    border: 1px solid #ced4da; /* Standard border */
    border-radius: 0.5rem; /* Less rounded */
    font-size: 0.95rem;
    font-family: inherit;
    background-color: #ffffff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

.chat-input:focus {
    outline: none;
    border-color: #80bdff; /* Bootstrap focus color */
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); /* Bootstrap focus shadow */
}

.chat-input.is-invalid { /* Style for validation errors */
    border-color: #dc3545; /* Bootstrap danger color */
}
.chat-input.is-invalid:focus {
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.chat-input:disabled {
    background-color: #e9ecef; /* Disabled background */
    cursor: not-allowed;
    opacity: 0.7;
}


/* Button Container Styles */
.buttons {
    margin-top: 1rem;
    display: flex; /* Use flex for multiple buttons */
    flex-direction: column; /* Stack buttons vertically */
    gap: 0.5rem; /* Space between buttons */
}

/* Button Styles */
.btn,
.chat-button {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 9999px; /* Pill shape */
    background-color: #95C11F; /* Main button color */
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1rem; /* Slightly smaller button text */
    font-weight: bold;
    text-align: center;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn:hover,
.chat-button:hover {
    background-color: #86af1b; /* Darker hover color */
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn:active,
.chat-button:active {
    transform: scale(0.98); /* Slight press effect */
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Secondary Button Style */
.btn-secondary,
.chat-button-secondary {
    background-color: #6c757d; /* Bootstrap secondary color */
    color: white;
}
.btn-secondary:hover,
.chat-button-secondary:hover {
    background-color: #5a6268;
}

/* Disabled Button Styles */
.btn:disabled,
.chat-button:disabled,
.btn-disabled {
    background-color: #b0c98d;
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Spinner / Loader Styles */
.spinner-container {
    /* No margin/text-align needed, flexbox handles it */
    display: inline-block; /* Keep it inline-block for context */
}

/* Styles for the thumbnail in the 'analyzing' step */
.analyzing-thumbnail-container {
    display: inline-block; /* Allows it to sit alongside text/spinner */
    vertical-align: middle;
    /* margin-right is handled by flex gap */
    animation: fadeInSlideUp 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}

.analyzing-thumbnail {
    width: 120px; /* Increased size */
    height: 120px; /* Increased size */
    border-radius: 12px; /* Larger radius for larger image */
    object-fit: cover;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

/* Special layout for the 'analyzing' bubble content */
.message-bubble[data-msg-id='analyzing'] .message-content {
    display: flex;
    flex-direction: column; /* Stack items vertically */
    align-items: flex-start;   /* Align content to the left */
    gap: 10px;             /* Space between top row and text */
}

/* Align the image in the 'ask_photo' bubble to the left */
.message-bubble[data-msg-id='ask_photo'] .howto-image {
    margin-left: 0;
    margin-right: 0;
}

.analyzing-top-row {
    display: flex;
    align-items: center;
    gap: 15px;
}

.analyzing-thumbnail {
    width: 120px;
    height: 120px;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.message-bubble[data-msg-id='analyzing'] .message-text-content {
    text-align: center; /* Center the "Analyzing..." text */
}

.loader {
    width: 28px; /* Slightly larger */
    height: 28px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-bottom-color: #78A01A; /* Darker shade of main green */
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    /* margin-left: 8px; */ /* Center if used alone */
    animation: rotation 0.8s linear infinite;
}
/* Added spinner within text */
.message-text-content .loader {
    width: 18px;
    height: 18px;
    border-width: 2px;
    margin-left: 5px;
    vertical-align: -3px; /* Align better with text */
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error Bubble Specific Styles */
.error-bubble {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    border-bottom-left-radius: 18px; /* Reset tail for error */
}

.error-bubble .message-content h1,
.error-bubble .message-content strong {
     color: #721c24;
}

.error-bubble .btn,
.error-bubble .chat-button {
    background-color: #dc3545;
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.error-bubble .btn:hover,
.error-bubble .chat-button:hover {
    background-color: #c82333;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.error-bubble .btn:disabled,
.error-bubble .chat-button:disabled {
    background-color: #f5c6cb;
    opacity: 0.65;
    box-shadow: none;
}


/* Responsive Adjustments */
@media (max-width: 640px) {
    .doctor-image {
        width: 65px; /* Even smaller image */
    }
     .messages-container {
         width: calc(100% - 65px - 0.8rem); /* Adjust width */
     }

    .message-bubble {
        padding: 0.7rem 1rem;
    }

    body {
        font-size: 15px;
    }

    .header {
        height: 55px;
    }
     .chat-container {
        padding-top: 70px; /* Adjust for header */
        min-height: calc(100vh - 55px);
        min-height: calc(100vh - 55px - env(safe-area-inset-bottom));
    }
     .chat-input, .btn, .chat-button {
         font-size: 0.9rem; /* Slightly smaller controls */
     }
     .consent-text {
         font-size: 0.7rem;
     }

}

/* Safe Area Padding for iOS */
@supports(padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    .header {
         padding-left: max(1rem, env(safe-area-inset-left));
         padding-right: max(1rem, env(safe-area-inset-right));
    }
    .chat-container {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}