/* -- 0. IBM Plex Mono Font Faces ------------------------- */
@font-face {
    font-family: 'IBM Plex Mono';
    src: url('IBM_Plex_Mono/IBMPlexMono-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('IBM_Plex_Mono/IBMPlexMono-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('IBM_Plex_Mono/IBMPlexMono-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('IBM_Plex_Mono/IBMPlexMono-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* -- 1. global light theme palette ----------------------- */
:root {
    --bg-0: #ffffff;
    --bg-1: #f8f9fa;
    --bg-main: #f9e18b;
    --fg-0: #212529;
    --fg-dim: #6c757d;
    --accent: #372563;
    --header-purple: #372563;
    --scrollbar-track: transparent;
    --scrollbar-thumb: rgba(108, 117, 125, 0.5);
    --scrollbar-thumb-hover: rgba(108, 117, 125, 0.7);
    font-size: 16px;
}

/* -- 2. reset & typography ------------------------------- */
* {
    box-sizing: border-box;
    margin: 0;
}

/* Disable automatic phone number detection */
a[href^="tel:"] {
    pointer-events: none;
    color: inherit;
    text-decoration: none;
}

html,
body {
    height: 100%;
    /* overflow: hidden; */ /* REMOVED: This property was likely causing the mobile rendering issue. */
}

/* ✱ page itself never scrolls */
body {
    background: var(--bg-main);
    color: var(--fg-0);
    font-family: 'IBM Plex Mono', monospace;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1;
}

/* -- 3. full-viewport golden ratio layout ---------------- */
#app {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    display: grid;
    grid-template-columns: 38.2fr 61.8fr;
    /* Golden ratio */
    gap: 1rem;
    padding: 1rem;
}

/* -- 4. profile section ---------------------------------- */
#profile-section {
    background: var(--bg-0);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-height: 0;
    position: relative;
    isolation: isolate;
}

.profile-content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
}

.impressum-link-container {
    /* padding: 0 1.5rem 1.5rem 1.5rem; */
    margin-top: auto;
    text-align: center;
    /* border-top: 1px solid rgba(55, 37, 99, 0.1); */
    flex-shrink: 0;
}

/* Mobile impressum link - hidden on desktop */
.impressum-link-mobile {
    display: none;
}

.profile-description-column {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Desktop vertical layout */
.profile-header {
    text-align: center;
}

#avatar {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 1rem;
}

.profile-header h1 {
    font-size: 1.8rem;
    margin-bottom: -0.5rem;
    color: var(--header-purple);
}

.profile-description {
    font-size: 0.9rem;
    color: var(--fg-dim);
    line-height: 1.4;
    text-align: center;
    max-width: 45ch;
    /* Limit line length for readability on wide screens */
    margin-left: auto;
    margin-right: auto;
}

.affiliations,
.work-links,
.social-links {
    text-align: center;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {

    .affiliations,
    .work-links,
    .social-links {
        margin-bottom: 0.8rem;
    }

    .affiliations h3,
    .work-links h3,
    .social-links h3 {
        /* color: var(--header-purple); */
        /* font-size: 0.8rem; */
        margin-bottom: 0.1rem !important;
        /* font-weight: 600; */
        /* display: block; */
    }
}


.affiliations h3,
.work-links h3,
.social-links h3 {
    color: var(--header-purple);
    font-size: 1rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.affiliation-logos {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.affiliation {
    background: var(--header-purple);
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 500;
}

.work-icons,
.social-icons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.work-icons a,
.social-icons a {
    color: var(--header-purple);
    text-decoration: none;
    transition: all 0.2s;
    padding: 0.5rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.work-icons a:hover,
.social-icons a:hover {
    background-color: var(--header-purple);
    color: white;
}

/* All headers get purple color */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--header-purple);
    font-weight: 600;
}

/* -- Impressum Link Styling ----------------------------- */

.impressum-link {
    color: var(--header-purple);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    display: inline-block;
    opacity: 0.8;
}

.impressum-link:hover {
    background-color: var(--header-purple);
    color: white;
    opacity: 1;
}

/* -- START: Class-Based Toggle Logic -- */
#profile-section.impressum-is-active .profile-content,
#profile-section.impressum-is-active .impressum-link-container {
    display: none;
}

#profile-section.impressum-is-active .contact-details {
    display: flex;
}
/* -- END: Class-Based Toggle Logic -- */


/* -- Contact Details Styling ---------------------------- */
.contact-details {
    /* REMOVED position: absolute and related props */
    width: 100%;
    height: 100%; /* Fill the parent flex container */
    background: var(--bg-0);
    padding: 1.5rem;
    display: none; /* Hidden by default */
    flex-direction: column;
}

.contact-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.back-button {
    background: none;
    border: 1px solid var(--header-purple);
    color: var(--header-purple);
    /* font-size: 1.2rem; */
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    /* font-weight: bold; */
    line-height: 1;
}

.back-button:hover {
    background-color: var(--header-purple);
    color: white;
}

.contact-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex: 1; /* Allow content to grow and fill space */
    text-align: center;
}

.contact-content h2 {
    color: var(--header-purple);
    font-size: 1.8rem;
    margin-bottom: 2rem;
    font-weight: 600;
}

.contact-info {
    color: var(--fg-0);
    line-height: 1.8;
    font-size: 1rem;
}

.contact-info p {
    margin: 0.3rem 0;
}

.contact-info p:first-child {
    color: var(--header-purple);
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

/* -- 5. chat section ------------------------------------- */
#chat-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.chat-header {
    margin: 0;
    padding: 0.75rem 1rem;
    background: var(--bg-0);
    flex-shrink: 0;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    isolation: isolate;
}

.chat-header h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--header-purple);
}

#samples {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

#samples .sample {
    background: transparent;
    color: var(--header-purple);
    border: 1px solid var(--header-purple);
    border-radius: 999px;
    padding: 0.2rem 0.7rem;
    cursor: pointer;
    font-size: 0.75rem;
    font-family: 'IBM Plex Mono', monospace;
    transition: all 0.2s;
}

#samples .sample:hover {
    background-color: var(--header-purple);
    color: white;
}

/* -- 6. chat area ---------------------------------------- */
#chat {
    flex: 1;
    margin: 1rem 0;
    padding: 1rem;
    background: var(--bg-0);
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-height: 0;
    position: relative;
    isolation: isolate;
}

/* -- Cross-Browser Custom Scrollbars -------------------- */

/* Define consistent scrollbar colors */
:root {
    /* Set the track to the card's background color. This is the key for the Firefox fix. */
    --scrollbar-track: var(--bg-0);
    --scrollbar-thumb: rgba(108, 117, 125, 0.5);
    --scrollbar-thumb-hover: rgba(108, 117, 125, 0.7);
}

#profile-section,
#chat {
    /* -- Firefox scrollbar styling -- */
    /* By setting the track color to the card's background, the sharp corner it draws becomes invisible. */
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* -- WebKit browsers (Chrome, Safari) scrollbar styling -- */
/* This creates an "inset" scrollbar that sits inside the card's padding area */
#profile-section::-webkit-scrollbar,
#chat::-webkit-scrollbar {
    width: 14px;
    /* A bit wider to accommodate the border trick */
}

#profile-section::-webkit-scrollbar-track,
#chat::-webkit-scrollbar-track {
    /* The track itself is invisible in WebKit */
    background: transparent;
}

#profile-section::-webkit-scrollbar-thumb,
#chat::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 10px;
    /* The border is the same color as the card, creating the "inset" padding effect */
    border: 4px solid var(--bg-0);
    background-clip: padding-box;
    /* Ensures the border doesn't get painted over by the thumb's background */
}

#profile-section::-webkit-scrollbar-thumb:hover,
#chat::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}


.message {
    margin: 0.5rem 0;
    line-height: 1.45;
    display: flex;
    width: 100%;
}

.user {
    margin-right: auto;
}

.bot {
    margin-left: auto;
    margin-top: 0.3rem;
}

.user,
.bot {
    max-width: 80%;
    padding: 0.6rem 0.9rem;
    border-radius: 10px;
    background: var(--bg-1);
    width: fit-content;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.user {
    background: var(--header-purple);
    color: #fff;
}

.bot {
    background: var(--bg-1);
    color: var(--fg-0);
}

/* Streaming message styles */
.message.streaming {
    text-align: left;
}

.message.bot.streaming .typing-cursor {
  animation: blink 1s step-end infinite;
  color: var(--header-purple);
}
@keyframes blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* Error message styles */
.error-message {
    color: red;
}

.warning-message {
    color: orange;
}

.cancelled-message {
    color: #888;
}

.refresh-button {
    background: none;
    border: 1px solid #ccc;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    cursor: pointer;
    margin-left: 0.5rem;
}

/* -- 7. input row ---------------------------------------- */
form#prompt-form {
    display: flex;
    margin: 0;
    padding: 0.75rem 1rem;
    background: var(--bg-0);
    gap: 0.5rem;
    flex-shrink: 0;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    isolation: isolate;
}

form input {
    flex: 1;
    background: var(--bg-0);
    border: 1px solid #dee2e6;
    color: var(--fg-0);
    padding: 0.55rem 0.8rem;
    border-radius: 6px;
    outline: none;
}

form input:focus {
    border-color: var(--header-purple);
    box-shadow: 0 0 0 2px rgba(55, 37, 99, 0.2);
}

form button {
    background: var(--accent);
    border: none;
    color: #fff;
    font-size: 1.1rem;
    width: 48px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

form button:hover {
    opacity: 0.85;
}


/* -- 8. responsive design -------------------------------- */
@media (max-width: 672px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
        min-height: 100vh; /* Fallback for older browsers */
        min-height: 100dvh;
        padding: 0.5rem;
        gap: 0.5rem;
    }

    /* Mobile profile header layout - three columns (smaller) */
    #profile-section {
        order: 1;
        padding: 0.75rem;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .profile-content {
        flex-direction: row;
        align-items: flex-end;
        justify-content: center;
        gap: 0.75rem;
        padding: 0;
    }

    /* Show mobile impressum link */
    .impressum-link-mobile {
        display: block;
        /* margin-top: 0.5rem; */
    }

    .impressum-link-mobile .impressum-link {
        font-size: 0.7rem;
        padding: 0 !important;
        opacity: 0.7;
    }

    .impressum-link-mobile .impressum-link:hover {
        background-color: transparent;
        color: var(--header-purple);
    }

    /* Hide desktop impressum link on mobile */
    .impressum-link-container {
        display: none;
    }

    /* Column 1: Avatar and name */
    .profile-content .profile-header,
    .profile-header {
        flex: 0 0 auto;
        text-align: center;
        margin: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    #avatar {
        width: 50px;
        height: 50px;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    /* Column 2: Description */
    .profile-description {
        flex: 1;
        text-align: center;
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Column 3: All icons combined */
    .profile-icons {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        align-items: center;
        justify-content: center;
    }

    .profile-content .profile-header h1,
    .profile-header h1 {
        font-size: max(1.2rem, 4vw);
        margin-bottom: 0.25rem;
    }

    .profile-description {
        font-size: max(0.75rem, 2.5vw);
        line-height: 1.3;
    }

    /* Chat interface font scaling */
    .chat-header h2 {
        font-size: max(0.9rem, 3vw);
    }

    #samples .sample {
        font-size: max(0.7rem, 2vw);
    }

    .message {
        font-size: max(0.85rem, 2.2vw);
    }

    form input {
        font-size: max(0.85rem, 2.2vw);
    }

    form button {
        font-size: max(1rem, 2.5vw);
    }

    /* Affiliate and social link font scaling */
    .affiliations h3,
    .work-links h3,
    .social-links h3 {
        font-size: max(0.9rem, 2.5vw);
    }

    /* Hide section headings on mobile */
    .affiliations h3,
    .work-links h3,
    .social-links h3 {
        display: none;
    }

    /* Hide affiliations logos on mobile */
    .affiliations {
        display: none;
    }

    /* Keep work and social icons visible */
    .work-links,
    .social-links {
        margin: 0;
    }

    .work-icons,
    .social-icons {
        display: flex;
        flex-direction: column;
        gap: 0.3rem;
        align-items: center;
    }

    .work-icons a,
    .social-icons a {
        padding: 0.2rem;
    }

    /* Hide summary and research question buttons on mobile */
    .sample:nth-child(4),
    .sample:nth-child(5) {
        display: none;
    }

    /* Chat components */
    .chat-header {
        order: 2;
    }

    #chat {
        order: 3;
        margin: 0;
        flex: 1;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Smaller prompt form */
    form#prompt-form {
        order: 4;
        margin: 0;
        padding: 0.5rem 0.75rem;
    }

    form input {
        padding: 0.4rem 0.6rem;
        font-size: 16px;
    }

    form button {
        width: 40px;
        font-size: max(0.9rem, 2.2vw);
    }

    #chat-section {
        display: contents;
    }

    /* -- START: Mobile Contact Details Styles -- */
    .contact-details {
        padding: 0.5rem;
    }

    .contact-header {
        margin-bottom: 0.25rem;
    }

    .contact-content h2 {
        font-size: max(0.9rem, 3.5vw);
        margin-bottom: 0.5rem;
    }

    .contact-info {
        font-size: max(0.7rem, 2.2vw);
        line-height: 1.3;
    }

    .contact-info p:first-child {
        font-size: max(0.75rem, 2.5vw);
        margin-bottom: 0.25rem;
    }

    .contact-info p {
        margin: 0.15rem 0;
    }

    .contact-info br + p {
        margin-top: 0.5rem;
    }

    .back-button {
        width: 24px;
        height: 24px;
        font-size: 0.9rem;
    }
    /* -- END: Mobile Contact Details Styles -- */
}

/* -- 9. Extra small screens (below 375px) --------------- */
@media (max-width: 374px) {

    /* Horizontal layout for profile section */
    #profile-section {
        padding: 0.5rem;
    }

    .profile-content {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        justify-content: space-between;
        padding: 0;
    }

    /* Avatar and name together horizontally */
    .profile-content .profile-header,
    .profile-header {
        flex-direction: row;
        gap: 0.4rem;
        align-items: center;
        flex: 0 0 auto;
    }

    #avatar {
        width: 40px;
        height: 40px;
    }

    /* Keep name visible but make it smaller */
    .profile-content .profile-header h1,
    .profile-header h1 {
        display: block !important;
        font-size: max(0.9rem, 3vw);
        margin: 0;
        white-space: nowrap;
    }

    /* Hide description */
    .profile-description {
        display: none;
    }

    /* Compact icons in horizontal row */
    .profile-icons {
        flex-direction: row;
        gap: 0.3rem;
        flex: 0 0 auto;
    }

    /* Hide section headings and stack icons tightly */
    .affiliations,
    .work-links,
    .social-links {
        margin: 0;
    }

    .affiliations h3,
    .work-links h3,
    .social-links h3 {
        display: none;
    }

    .work-icons,
    .social-icons {
        flex-direction: row;
        gap: 0.2rem;
    }

    .work-icons a,
    .social-icons a {
        padding: 0.15rem;
    }

    /* Hide affiliation logos to save space */
    .affiliations {
        display: none;
    }


    #samples .sample {
        font-size: max(0.65rem, 2vw);
        padding: 0.15rem 0.5rem;
    }
}