@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600&display=swap');

/* ========================================
   INLINE CHAT LAYOUT - CLEAN & MINIMAL
   Version 2.0 - Refactored shared styles
   ======================================== */

#stem-chat {
    margin: 0;
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    z-index: 100;
    position: relative;
    width: 100%;
    height: 80dvh;
    max-height: 800px;
    display: flex;
    flex-direction: column;
}

/* Main container - styled to distinguish from page */
#stem-chat #chat-container {
    display: none;
    position: relative;
    background-color: #ffffff;
    width: 100%;
    height: 100%;
    flex-direction: column;
    overflow: hidden;
    border-radius: 16px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

#stem-chat #chat-container-inner {
    background-color: #ffffff;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Hide bubble in inline mode */
#stem-chat #chat-bubble {
    display: none;
}

#stem-chat.chat-open #chat-container {
    display: flex;
}

#stem-chat.chat-closed {
    display: none;
}

/* ========================================
   CHAT HEADER - HIDDEN
   ======================================== */

#stem-chat .chat-header {
    display: none;
}

/* ========================================
   CHAT CONVERSATION AREA
   ======================================== */

#stem-chat .chat-conversation {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    padding: 1.5rem;
    background: #fafbfc;
    scroll-behavior: smooth;
}

/* Custom scrollbar */
#stem-chat .chat-conversation::-webkit-scrollbar {
    width: 6px;
}

#stem-chat .chat-conversation::-webkit-scrollbar-track {
    background: transparent;
}

#stem-chat .chat-conversation::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

#stem-chat .chat-conversation::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ========================================
   CHAT MESSAGES
   ======================================== */

#stem-chat .stem-chat-message {
    padding: 0.5rem 0;
    margin: 0;
    display: block;
    width: 100%;
    font-weight: 400;
    font-size: 16px;
    line-height: 1.6;
    word-wrap: break-word;
}

/* Bot messages - plain text, no background */
#stem-chat .stem-chat-message-bot {
    background: transparent;
    color: #374151;
    padding: 0.5rem 0;
    margin: 0;
    text-align: left;
    opacity: 0;
    animation: fadeInMessage 0.6s ease-out forwards;
}

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

/* User messages - speech bubble style */
#stem-chat .stem-chat-message-user {
    background: #322BA1;
    color: #ffffff;
    padding: 0.875rem 1.25rem;
    margin: 0.5rem 0 0.5rem auto;
    border-radius: 18px;
    max-width: 80%;
    width: fit-content;
    align-self: flex-end;
    text-align: left;
    opacity: 0;
    animation: fadeInUser 0.3s ease-out forwards;
}

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

/* Typing indicator - only for API calls */
#stem-chat .stem-chat-message.is-typing {
    background: transparent;
    min-height: auto;
    display: flex;
    align-items: center;
    padding: 0.5rem 0;
}

#stem-chat .stem-chat-message .dots {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 4px;
}

#stem-chat .stem-chat-message .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #9ca3af;
    animation: 1.4s bounce ease-in-out infinite;
}

#stem-chat .stem-chat-message .dot:nth-child(2) {
    animation-delay: 0.2s;
}

#stem-chat .stem-chat-message .dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Hide headings in chat */
#stem-chat .stem-chat-message-bot h2,
#stem-chat .stem-chat-message-bot h3 {
    display: none;
}

/* Project ideas list styling in chat */
#stem-chat .stem-chat-message-bot ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

#stem-chat .stem-chat-message-bot ol li {
    margin-bottom: 0.75rem;
    line-height: 1.6;
    color: #374151;
}

/* Link styling in chat */
#stem-chat .stem-chat-message-bot a {
    color: #2563eb;
    text-decoration: underline;
}

#stem-chat .stem-chat-message-bot a:hover {
    color: #1d4ed8;
}

/* ========================================
   SEARCH RESULTS - SHARED STYLING
   Used in both chat and single page
   ======================================== */

.stem-search-result {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.stem-search-result:hover {
    border-color: #d1d5db;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.stem-search-result-image {
    flex-shrink: 0;
    width: 120px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
}

.stem-search-result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.stem-search-result-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stem-search-result-content .main-link {
    color: #2563eb;
    font-weight: 500;
    font-size: 15px;
    line-height: 1.4;
    text-decoration: none;
    transition: color 0.2s ease;
}

.stem-search-result-content .main-link:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.stem-search-result-content p {
    color: #6b7280;
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

.stem-search-result-content .sub-link {
    color: #9ca3af;
    font-weight: 400;
    font-size: 13px;
    text-decoration: none;
}

/* ========================================
   SEARCH RESULTS - CHAT-SPECIFIC ANIMATION
   Animation only applies in chat
   ======================================== */

#stem-chat .stem-search-result {
    opacity: 0;
    animation: fadeInResult 0.5s ease-out forwards;
}

/* Stagger the animation for each search result in chat */
#stem-chat .stem-search-result:nth-child(1) {
    animation-delay: 0.1s;
}

#stem-chat .stem-search-result:nth-child(2) {
    animation-delay: 0.2s;
}

#stem-chat .stem-search-result:nth-child(3) {
    animation-delay: 0.3s;
}

#stem-chat .stem-search-result:nth-child(4) {
    animation-delay: 0.4s;
}

#stem-chat .stem-search-result:nth-child(5) {
    animation-delay: 0.5s;
}

#stem-chat .stem-search-result:nth-child(6) {
    animation-delay: 0.6s;
}

#stem-chat .stem-search-result:nth-child(7) {
    animation-delay: 0.7s;
}

#stem-chat .stem-search-result:nth-child(8) {
    animation-delay: 0.8s;
}

#stem-chat .stem-search-result:nth-child(9) {
    animation-delay: 0.9s;
}

#stem-chat .stem-search-result:nth-child(10) {
    animation-delay: 1s;
}

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

/* ========================================
   USER INPUT AREA - Fixed at bottom
   ======================================== */

#stem-chat .chat-user-input {
    padding: 1.5rem;
    background-color: #ffffff;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
    position: relative;
    border-radius: 0 0 16px 16px;
}

#stem-chat .chat-user-message {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    max-width: 100%;
}

#stem-chat .chat-user-input input[type="text"] {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 400;
    font-size: 15px;
    line-height: 1.5;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    background: #ffffff;
}

#stem-chat .chat-user-input input[type="text"]:focus {
    outline: none;
    border-color: #322BA1;
    box-shadow: 0 0 0 3px rgba(50, 43, 161, 0.1);
}

#stem-chat .chat-user-input input[type="text"]::placeholder {
    color: #9ca3af;
}

#stem-chat .chat-user-input button[type="submit"] {
    background: linear-gradient(135deg, #322BA1 0%, #4A3FC7 100%);
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 8px rgba(50, 43, 161, 0.2);
}

#stem-chat .chat-user-input button[type="submit"]:hover:not(:disabled) {
    background: linear-gradient(135deg, #4A3FC7 0%, #5E51DB 100%);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(50, 43, 161, 0.3);
}

#stem-chat .chat-user-input button[type="submit"]:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

#stem-chat .chat-user-input button[type="submit"]::after {
    content: "→";
    color: white;
    font-size: 20px;
    font-weight: 600;
    line-height: 1;
}

/* ========================================
   USER OPTIONS (Button Choices)
   ======================================== */

#stem-chat .chat-user-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

#stem-chat .chat-user-option {
    padding: 0.625rem 1.25rem;
    border: 2px solid #322BA1;
    border-radius: 24px;
    background-color: #ffffff;
    color: #322BA1;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    line-height: 1.5;
    transition: all 0.2s ease;
}

#stem-chat .chat-user-option:hover,
#stem-chat .chat-user-option:focus {
    background-color: #322BA1;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(50, 43, 161, 0.25);
}

#stem-chat .chat-user-option:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(50, 43, 161, 0.2);
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

#stem-chat .show-for-sr {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0,0,0,0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.hidden {
    display: none !important;
}

/* ========================================
   SEARCH RESULTS OVERLAY - Hidden
   ======================================== */

#stem-chat-search-results {
    display: none !important;
}

/* ========================================
   PROJECT RESEARCH SINGLE PAGE
   For use with [stem-results] shortcode in Bricks
   ======================================== */

/* Results container */
.stem-results-container {
    font-family: 'Montserrat', sans-serif;
    max-width: 1000px;
    margin: auto;
}

/* Headings in results */
.stem-results-container h2 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    margin-top: 2.5rem;
    color: #322BA1;
    font-weight: 600;
}

.stem-results-container h2:first-child {
    margin-top: 0;
}

.stem-results-container h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    margin-top: 2rem;
    color: #374151;
    font-weight: 600;
}

/* Project ideas section */
.stem-project-ideas ol {
    list-style: decimal;
    padding-left: 2rem;
    margin: 1rem 0;
}

.stem-project-ideas ol li {
    padding-bottom: 1rem;
    line-height: 1.6;
    color: #374151;
}

/* Legacy container styles for old template */
.container-stem-chat {
    max-width: 1000px;
    padding: 0 2rem;
    margin: 0 auto;
}

.container-stem-chat h2 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: #1f2937;
    font-weight: 600;
}

.container-stem-chat h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #374151;
    font-weight: 600;
}

.container-stem-chat ol {
    list-style: decimal;
    padding-left: 2rem;
    margin: 1rem 0;
}

.container-stem-chat ol li {
    padding-bottom: 1rem;
    line-height: 1.6;
}

.project-research-header {
    padding: 2rem;
    background: #f9fafb;
    margin-bottom: 2rem;
    border-bottom: 1px solid #e5e7eb;
}

.project-research-header .container-stem-chat {
    padding: 0;
    max-width: none;
}

.project-research-header a {
    display: inline-block;
}

.project-research-header a img {
    width: 240px;
    height: auto;
}

.project-research-footer {
    background: #f9fafb;
    padding: 3rem 0;
    margin-top: 3rem;
    border-top: 1px solid #e5e7eb;
}

.single-project_research #header[role="banner"],
.single-project_research #header[role="banner"] + hr {
    display: none;
}

.single-project_research #stem-search-results {
    padding-bottom: 2rem;
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media only screen and (max-width: 768px) {
    #stem-chat {
        max-height: 100vh;
    }

    #stem-chat .stem-chat-message {
        font-size: 15px;
    }

    #stem-chat .stem-chat-message-user {
        max-width: 85%;
        padding: 0.75rem 1rem;
    }

    #stem-chat .chat-user-input {
        padding: 1rem;
    }

    #stem-chat .chat-user-input input[type="text"] {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.625rem 0.875rem;
    }

    #stem-chat .chat-user-input button[type="submit"] {
        width: 32px;
        height: 32px;
    }

    .stem-search-result {
        flex-direction: column;
        gap: 0.75rem;
    }

    .stem-search-result-image {
        width: 100%;
        height: 150px;
    }

    .container-stem-chat {
        padding: 0 1rem;
    }
}

@media only screen and (max-width: 480px) {
    #stem-chat .stem-chat-message {
        font-size: 14px;
    }

    #stem-chat .stem-chat-message-user {
        padding: 0.625rem 0.875rem;
    }

    #stem-chat .chat-user-option {
        font-size: 13px;
        padding: 0.5rem 1rem;
    }
}
