/*=============== 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;
    position: relative;
}

/* 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 PARTICLES ===============*/
.wito__particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    transition: opacity 0.6s ease-out;
}

.wito__particles--hidden {
    opacity: 0;
}

.wito__particle {
    position: absolute;
    background-color: var(--title-color);
    clip-path: polygon(50% 0%, 60% 35%, 100% 50%, 60% 65%, 50% 100%, 40% 65%, 0% 50%, 40% 35%);
    opacity: 0;
}

@keyframes particleDrift1 {
    0%, 100% {
        transform: translateY(0) translateX(0) scale(0) rotate(0deg);
        opacity: 0;
    }
    15% {
        transform: translateY(-8px) translateX(4px) scale(1) rotate(15deg);
        opacity: 0.35;
    }
    50% {
        transform: translateY(-20px) translateX(-3px) scale(0.8) rotate(40deg);
        opacity: 0.2;
    }
    85% {
        transform: translateY(-35px) translateX(5px) scale(0.4) rotate(60deg);
        opacity: 0.05;
    }
}

@keyframes particleDrift2 {
    0%, 100% {
        transform: translateY(0) translateX(0) scale(0) rotate(0deg);
        opacity: 0;
    }
    15% {
        transform: translateY(-6px) translateX(-5px) scale(1) rotate(-20deg);
        opacity: 0.3;
    }
    50% {
        transform: translateY(-18px) translateX(4px) scale(0.7) rotate(-45deg);
        opacity: 0.18;
    }
    85% {
        transform: translateY(-30px) translateX(-2px) scale(0.3) rotate(-65deg);
        opacity: 0.04;
    }
}

@keyframes particleDrift3 {
    0%, 100% {
        transform: translateY(0) translateX(0) scale(0) rotate(0deg);
        opacity: 0;
    }
    15% {
        transform: translateY(-10px) translateX(2px) scale(1) rotate(10deg);
        opacity: 0.25;
    }
    50% {
        transform: translateY(-25px) translateX(-5px) scale(0.6) rotate(50deg);
        opacity: 0.15;
    }
    85% {
        transform: translateY(-40px) translateX(3px) scale(0.2) rotate(75deg);
        opacity: 0.03;
    }
}

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

@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 {
    position: relative;
    width: 44px;
    height: 24px;
    margin: 0.875rem 0;
}

.wito__sparkle {
    position: absolute;
    background-color: var(--title-color);
    clip-path: polygon(50% 0%, 60% 35%, 100% 50%, 60% 65%, 50% 100%, 40% 65%, 0% 50%, 40% 35%);
    opacity: 0;
}

/* Each sparkle gets unique size, position, timing, and float path */
.wito__sparkle--1 {
    width: 9px;
    height: 9px;
    left: 2px;
    top: 14px;
    animation: sparkleFloat1 2.8s infinite ease-in-out;
}

.wito__sparkle--2 {
    width: 7px;
    height: 7px;
    left: 20px;
    top: 4px;
    animation: sparkleFloat2 2.4s 0.6s infinite ease-in-out;
}

.wito__sparkle--3 {
    width: 8px;
    height: 8px;
    left: 34px;
    top: 12px;
    animation: sparkleFloat3 3s 1.2s infinite ease-in-out;
}

.wito__sparkle--4 {
    width: 6px;
    height: 6px;
    left: 12px;
    top: 2px;
    animation: sparkleFloat2 2.6s 0.4s infinite ease-in-out;
}

.wito__sparkle--5 {
    width: 7px;
    height: 7px;
    left: 26px;
    top: 16px;
    animation: sparkleFloat1 2.7s 0.9s infinite ease-in-out;
}

/* Float paths with different drift directions */
@keyframes sparkleFloat1 {
    0%, 100% {
        transform: translateY(0) scale(0) rotate(0deg);
        opacity: 0;
    }
    20% {
        transform: translateY(-3px) translateX(2px) scale(1) rotate(20deg);
        opacity: 1;
    }
    60% {
        transform: translateY(-8px) translateX(-1px) scale(0.7) rotate(45deg);
        opacity: 0.7;
    }
    85% {
        transform: translateY(-13px) translateX(1px) scale(0.3) rotate(60deg);
        opacity: 0.2;
    }
}

@keyframes sparkleFloat2 {
    0%, 100% {
        transform: translateY(0) scale(0) rotate(0deg);
        opacity: 0;
    }
    20% {
        transform: translateY(-2px) translateX(-2px) scale(1) rotate(-15deg);
        opacity: 1;
    }
    60% {
        transform: translateY(-9px) translateX(2px) scale(0.8) rotate(-40deg);
        opacity: 0.6;
    }
    85% {
        transform: translateY(-14px) translateX(0) scale(0.3) rotate(-55deg);
        opacity: 0.15;
    }
}

@keyframes sparkleFloat3 {
    0%, 100% {
        transform: translateY(0) scale(0) rotate(0deg);
        opacity: 0;
    }
    20% {
        transform: translateY(-4px) translateX(1px) scale(1) rotate(10deg);
        opacity: 1;
    }
    60% {
        transform: translateY(-10px) translateX(-2px) scale(0.6) rotate(35deg);
        opacity: 0.8;
    }
    85% {
        transform: translateY(-15px) translateX(1px) scale(0.2) rotate(50deg);
        opacity: 0.1;
    }
}

/*=============== 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;
    }
}
