/*=============== WITO CHAT STYLES ===============*/

.wito.section {
    padding-top: 7rem;
}

.wito__container {
    max-width: 800px;
    margin: 0 auto;
}

/*=============== CHAT AREA ===============*/
.wito__chat {
    background-color: var(--container-color);
    border-radius: 1rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 700px;
}

.wito__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

/* When welcome is shown, center it */
.wito__messages:has(.wito__welcome) {
    justify-content: center;
    align-items: center;
}

/* When conversation started, add gap between messages and align to top */
.wito__messages.wito__messages--active {
    gap: 1.5rem;
    justify-content: flex-start;
    align-items: stretch;
}

/*=============== WELCOME STATE ===============*/
.wito__welcome {
    text-align: center;
    max-width: 400px;
    animation: fadeIn 0.3s ease-out;
}

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

.wito__welcome-title {
    display: block;
    font-size: var(--h1-font-size);
    font-weight: var(--font-semi-bold);
    color: var(--title-color);
    margin-bottom: 0.75rem;
}

.wito__welcome-description {
    color: var(--text-color-light);
    font-size: var(--normal-font-size);
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

/*=============== SUGGESTIONS ===============*/
.wito__suggestions {
    text-align: center;
}

.wito__suggestions-label {
    display: block;
    font-size: var(--small-font-size);
    color: var(--text-color-light);
    margin-bottom: 0.75rem;
}

.wito__suggestions-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.wito__suggestion {
    padding: 0.5rem 1rem;
    background-color: var(--body-color);
    border: 1px solid var(--text-color-light);
    border-radius: 2rem;
    color: var(--text-color);
    font-size: var(--small-font-size);
    cursor: pointer;
    transition: all 0.2s;
}

.wito__suggestion:hover,
.wito__suggestion:focus-visible {
    background-color: var(--container-color);
    border-color: var(--title-color);
    color: var(--title-color);
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/*=============== MESSAGES ===============*/
.wito__message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: messageSlide 0.3s ease-out;
    max-width: 85%;
}

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

.wito__message--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.wito__message--assistant {
    align-self: flex-start;
}

.wito__message-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 1rem;
}

.wito__message--assistant .wito__message-icon {
    background: transparent;
    color: var(--title-color);
}

.wito__message--user .wito__message-icon {
    background: transparent;
    color: var(--title-color);
}

.wito__message-content {
    padding: 0;
    line-height: 1.5;
    font-size: var(--normal-font-size);
}

/* Markdown-rendered content (assistant messages) */
.wito__message-content p {
    margin: 0 0 0.5em;
}
.wito__message-content p:last-child {
    margin-bottom: 0;
}
.wito__message-content strong {
    font-weight: var(--font-semi-bold);
}
.wito__message-content em {
    font-style: italic;
}
.wito__message-content ul,
.wito__message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
    list-style-position: outside;
}
.wito__message-content ul {
    list-style-type: disc;
}
.wito__message-content ol {
    list-style-type: decimal;
}
.wito__message-content li {
    margin-bottom: 0.25em;
    display: list-item;
}
.wito__message-content code {
    background-color: var(--body-color);
    padding: 0.15em 0.4em;
    border-radius: 0.25rem;
    font-size: 0.9em;
}
.wito__message-content pre {
    margin: 0.5em 0;
    padding: 0.75rem 1rem;
    background-color: var(--body-color);
    border-radius: 0.5rem;
    overflow-x: auto;
    font-size: var(--small-font-size);
}
.wito__message-content pre code {
    background: none;
    padding: 0;
}
.wito__message-content a {
    color: var(--first-color);
    text-decoration: none;
}
.wito__message-content a:hover {
    text-decoration: none;
}

.wito__message--assistant .wito__message-content {
    background: transparent;
    color: var(--title-color);
}

.wito__message--user .wito__message-content {
    background: transparent;
    color: var(--title-color);
}

/* Smooth content updates during streaming */
.wito__message-content {
    transition: opacity 0.1s ease-out;
}

/*=============== TYPING INDICATOR ===============*/
.wito__typing {
    display: flex;
    gap: 4px;
    padding: 0.875rem 0;
    background: transparent;
    width: fit-content;
}

.wito__typing-dot {
    width: 5px;
    height: 5px;
    background-color: var(--title-color);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.wito__typing-dot:nth-child(1) { animation-delay: 0s; }
.wito__typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wito__typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-4px);
    }
}

/*=============== INPUT FORM ===============*/
.wito__form {
    padding: 1rem 1.5rem 1.5rem;
}

.wito__input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.wito__input {
    flex: 1;
    padding: 0.875rem 1rem;
    background-color: var(--body-color);
    border: 2px solid transparent;
    border-radius: 1.5rem;
    color: var(--text-color);
    font-size: var(--normal-font-size);
    font-family: var(--body-font);
    transition: border-color 0.3s;
}

.wito__input:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--title-color) 80%, transparent);
}

.wito__input::placeholder {
    color: var(--text-color-light);
}

.wito__send {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--body-color);
    border: none;
    border-radius: 50%;
    color: var(--title-color);
    font-size: 1.25rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.wito__send:hover:not(.wito__send--inactive) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.wito__send:active:not(.wito__send--inactive) {
    transform: translateY(0);
}

.wito__send:disabled {
    cursor: not-allowed;
    transform: none;
}

/* Inactive state - same background as input, arrow tinted/muted */
.wito__send--inactive {
    background-color: var(--body-color);
    color: var(--text-color-light);
    cursor: default;
}

/* Reset button - matches send button style, shown after first message */
.wito__reset {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--body-color);
    border: none;
    border-radius: 50%;
    color: var(--text-color-light);
    font-size: 1.25rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, color 0.2s, background 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.wito__reset:hover {
    color: var(--title-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.wito__reset:active {
    transform: translateY(0);
}

.wito__reset--hidden {
    display: none;
}

/* Retry button - shown when streaming fails */
.wito__retry-btn {
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    background-color: var(--first-color);
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s;
}

.wito__retry-btn:hover {
    background-color: var(--first-color-alt);
    transform: translateY(-2px);
}

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

/*=============== RESPONSIVE ===============*/
@media screen and (max-width: 576px) {
    .wito.section {
        padding-top: 4rem;
    }

    .wito.section .section__subtitle {
        padding-inline: 1.25rem;
    }

    .wito__chat {
        height: 600px;
        border-radius: 0.75rem;
    }

    .wito__messages {
        padding: 1rem;
    }

    .wito__message {
        max-width: 90%;
        gap: 0.5rem;
    }

    .wito__message-icon {
        width: 20px;
        height: 20px;
        font-size: 0.85rem;
    }

    .wito__message-content {
        font-size: var(--normal-font-size);
    }

    .wito__form {
        padding: 0.75rem 1rem 1rem;
    }

    .wito__input-wrapper {
        gap: 0.5rem;
    }

    /* 1rem (16px) on input prevents iOS zoom on focus; placeholder matches response text size */
    .wito__input {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    .wito__input::placeholder {
        font-size: var(--small-font-size);
    }

    .wito__send,
    .wito__reset {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .wito__welcome-title {
        font-size: var(--h2-font-size);
    }

    .wito__welcome-description {
        font-size: var(--small-font-size);
    }

    .wito__suggestion {
        padding: 0.4rem 0.75rem;
        font-size: var(--smaller-font-size);
    }
}

/*=============== SCROLLBAR (HIDDEN) ===============*/
.wito__messages {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.wito__messages::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Hide header when keyboard is actually open on mobile.
   Uses .keyboard-open class set via visualViewport API for reliable detection. */
@media screen and (max-width: 1023px) {
    body.keyboard-open .header {
        transform: translateY(calc(100% + 2rem));
        visibility: hidden;
        pointer-events: none;
    }
}
