* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, sans-serif;
    background: #f7f7fa;
    color: #20202a;
}

.topbar {
    min-height: 64px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    border-bottom: 1px solid #e8e8ee;
}

.topbar a,
.link-button {
    color: #565663;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}

.learner-shell,
.session-shell,
.auth-shell {
    width: min(760px, calc(100% - 32px));
    margin: 0 auto;
    padding: 56px 0;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.auth-card,
.lesson-card,
.mentor-message,
.complete-card {
    background: white;
    border: 1px solid #e5e5ec;
    border-radius: 22px;
    padding: 28px;
}

.auth-card { width: min(440px, 100%); }

.brand {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 34px;
}

h1 {
    font-size: clamp(32px, 5vw, 48px);
    margin: 0 0 12px;
}

h2 { margin-top: 0; }

.eyebrow {
    margin: 0 0 8px;
    color: #777784;
    font-size: 14px;
    font-weight: 600;
}

.muted { color: #777784; }

.lesson-card { margin-top: 38px; }

form {
    display: grid;
    gap: 18px;
}

.auth-card form { margin-top: 28px; }

label {
    display: grid;
    gap: 8px;
    font-weight: 600;
}

input,
textarea {
    width: 100%;
    border: 1px solid #cfcfd8;
    border-radius: 12px;
    padding: 13px 14px;
    background: white;
    font: inherit;
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

button,
.button-link {
    width: fit-content;
    border: 0;
    border-radius: 12px;
    padding: 13px 20px;
    background: #292735;
    color: white;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.mentor-message p {
    margin-bottom: 0;
    font-size: 21px;
    line-height: 1.55;
}

.answer-form {
    margin-top: 24px;
}

.error {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 10px;
    background: #fff0f0;
}

.complete-card { margin-top: 24px; }

@media (max-width: 600px) {
    .topbar { padding: 0 18px; }

    .learner-shell,
    .session-shell,
    .auth-shell {
        padding: 32px 0;
    }

    .auth-card,
    .lesson-card,
    .mentor-message,
    .complete-card {
        padding: 22px;
    }
}

.conversation-history {
    display: grid;
    gap: 14px;
    margin-bottom: 16px;
}

.dialogue-turn {
    border-radius: 18px;
    padding: 20px 22px;
}

.dialogue-turn--mentor {
    margin-right: 56px;
    background: white;
    border: 1px solid #e5e5ec;
}

.dialogue-turn--learner {
    margin-left: 56px;
    background: #ededf3;
}

.dialogue-turn p {
    margin: 0;
    font-size: 19px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.dialogue-turn .eyebrow {
    margin-bottom: 8px;
}

@media (max-width: 600px) {
    .dialogue-turn--mentor {
        margin-right: 18px;
    }

    .dialogue-turn--learner {
        margin-left: 18px;
    }
}

/* ===== MentorAI learner chat v1.1 ===== */

.chat-page {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #f4f5f9;
}

.chat-topbar {
    position: relative;
    z-index: 20;
    min-height: 68px;
    border-bottom: 1px solid #e3e4ea;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(18px);
}

.chat-topbar-inner {
    width: min(900px, calc(100% - 24px));
    min-height: 68px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
}

.chat-back,
.chat-settings summary {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #292735;
}

.chat-back {
    text-decoration: none;
}

.chat-back svg {
    width: 22px;
    height: 22px;
}

.chat-back:hover,
.chat-settings summary:hover {
    background: #f0f0f5;
}

.chat-heading {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.15;
}

.chat-heading strong {
    font-size: 15px;
    font-weight: 760;
}

.chat-heading span {
    max-width: 100%;
    margin-top: 4px;
    overflow: hidden;
    color: #7b7c88;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-settings {
    position: relative;
    justify-self: end;
}

.chat-settings summary {
    cursor: pointer;
    list-style: none;
}

.chat-settings summary::-webkit-details-marker {
    display: none;
}

.chat-settings summary svg {
    width: 21px;
    height: 21px;
}

.chat-settings-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: min(330px, calc(100vw - 24px));
    padding: 9px;
    border: 1px solid #e1e2e9;
    border-radius: 18px;
    background: white;
    box-shadow: 0 18px 55px rgba(24,25,35,.16);
}

.chat-setting-switch {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 11px 12px;
    border-radius: 12px;
}

.chat-setting-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.chat-setting-copy strong {
    font-size: 14px;
}

.chat-setting-copy small {
    color: #888995;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.3;
}

.switch-control {
    position: relative;
    width: 42px;
    height: 24px;
    flex: 0 0 42px;
}

.switch-control input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.switch-track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #d6d7df;
    transition: background .18s ease;
}

.switch-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 4px rgba(22,23,30,.22);
    transition: transform .18s ease;
}

.switch-control input:checked + .switch-track {
    background: #6658dc;
}

.switch-control input:checked + .switch-track::after {
    transform: translateX(18px);
}

.chat-setting-block {
    display: grid;
    gap: 7px;
    padding: 11px 12px;
    color: #60616d;
    font-size: 12px;
    font-weight: 650;
}

.chat-setting-block select {
    width: 100%;
    min-height: 40px;
    border: 1px solid #d8d9e1;
    border-radius: 10px;
    padding: 0 10px;
    background: white;
    color: #292a33;
    font: inherit;
}

.chat-pause-link {
    display: block;
    margin-top: 3px;
    padding: 11px 12px;
    border-radius: 11px;
    color: #5c50d7 !important;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.chat-pause-link:hover {
    background: #f3f1ff;
}


.chat-shell {
    height: calc(100vh - 68px);
    height: calc(100dvh - 68px);
    display: flex;
    flex-direction: column;
}

.chat-thread {
    width: min(880px, 100%);
    flex: 1 1 auto;
    min-height: 0;
    margin: 0 auto;
    overflow-y: auto;
    padding: 28px 18px 22px;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}


.message-row {
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 6px 0;
}

.message-row--mentor {
    justify-content: flex-start;
}

.message-row--learner {
    justify-content: flex-end;
    padding-left: 20%;
}

.message-row--current {
    margin-top: 11px;
}


.mentor-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    overflow: hidden;
    margin-bottom: 1px;
    border-radius: 50%;
    background: linear-gradient(145deg,#353347,#1d1c29);
    color: white;
    font-size: 11px;
    font-weight: 800;
    background-position: center;
    background-size: cover;
}


.message-column {
    max-width: 72%;
}

.message-row--learner .message-column {
    display: flex;
    justify-content: flex-end;
}


.message-bubble {
    position: relative;
    width: fit-content;
    max-width: 100%;
    padding: 10px 13px;
    border-radius: 17px;
    font-size: 16px;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(18,20,30,.05);
}

.message-bubble p {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-bubble--mentor {
    border: 1px solid #e1e2e8;
    border-bottom-left-radius: 5px;
    background: white;
    color: #20212a;
}

.message-bubble--learner {
    border-bottom-right-radius: 5px;
    background: #6658dc;
    color: white;
}


.message-bubble--mentor::before {
    content: "";
    position: absolute;
    bottom: -1px;
    left: -7px;
    width: 10px;
    height: 12px;
    background: white;
    border-left: 1px solid #e1e2e8;
    clip-path: polygon(100% 0,100% 100%,0 100%);
}

.message-bubble--learner::after {
    content: "";
    position: absolute;
    right: -7px;
    bottom: 0;
    width: 10px;
    height: 12px;
    background: #6658dc;
    clip-path: polygon(0 0,100% 100%,0 100%);
}


.message-tools {
    display: flex;
    align-items: center;
    min-height: 29px;
    margin-top: 6px;
}


.audio-action {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 6px;
    border: 0;
    border-radius: 999px;
    background: #f5f3ff;
    color: #5d50ce;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.audio-action:hover {
    background: #ece9ff;
}

.audio-action:disabled {
    opacity: .6;
    cursor: wait;
}

.audio-icon {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
}


.quick-intents {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 12px 0 3px 42px;
}

.quick-intent {
    min-height: 34px;
    padding: 6px 11px;
    border: 1px solid #d9d6f5;
    border-radius: 999px;
    background: #faf9ff;
    color: #5d51c7;
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
}

.quick-intent:hover {
    background: #f0edff;
}


.chat-composer {
    position: relative;
    z-index: 10;
    flex: 0 0 auto;
    border-top: 1px solid #e2e3e9;
    background: rgba(250,250,252,.97);
    backdrop-filter: blur(18px);
}

.chat-composer-inner {
    width: min(880px, calc(100% - 20px));
    margin: 0 auto;
    padding:
        9px 0
        max(9px, env(safe-area-inset-bottom));
}

.chat-status {
    min-height: 0;
    margin: 0 9px 5px;
    color: #737581;
    font-size: 12px;
}

.chat-status:empty {
    display: none;
}

.chat-answer-form {
    display: block;
    margin: 0;
}

.chat-input-shell {
    min-height: 52px;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 5px 5px 5px 13px;
    border: 1px solid #d7d8df;
    border-radius: 26px;
    background: white;
    box-shadow: 0 3px 15px rgba(26,27,38,.05);
}

.chat-input-shell:focus-within {
    border-color: #9187eb;
    box-shadow: 0 0 0 3px rgba(102,88,220,.09);
}

.chat-input-shell textarea {
    min-width: 0;
    min-height: 40px;
    max-height: 120px;
    flex: 1 1 auto;
    margin: 0;
    padding: 9px 2px 7px;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: #20212a;
    font-size: 16px;
    line-height: 1.4;
    overflow-y: auto;
}

.chat-input-shell textarea::placeholder {
    color: #999aa6;
}


.chat-input-actions {
    width: 88px;
    min-width: 88px;
    display: flex;
    flex: 0 0 88px;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}


.composer-icon-button,
.composer-send {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    display: grid;
    place-items: center;
    flex: 0 0 40px;
    padding: 0 !important;
    border: 0;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
}


.composer-icon-button {
    background: transparent;
    color: #636571;
}

.composer-icon-button:hover {
    background: #f0f1f5;
}

.composer-icon-button.is-recording {
    background: #fff0f1;
    color: #cf394c;
}


.composer-icon-button svg,
.composer-send svg {
    display: block;
    width: 20px;
    height: 20px;
    pointer-events: none;
}


.composer-send {
    background: #6658dc;
    color: white;
}

.composer-send:hover {
    background: #594dcc;
}

.composer-send:disabled {
    background: #d6d5e3;
    color: #9997aa;
    cursor: default;
}


@media (max-width: 640px) {

    .chat-topbar-inner {
        width: calc(100% - 12px);
    }

    .chat-thread {
        padding: 18px 10px 16px;
    }

    .message-row--learner {
        padding-left: 8%;
    }

    .message-column {
        max-width: 84%;
    }

    .mentor-avatar {
        width: 30px;
        height: 30px;
        flex-basis: 30px;
    }

    .message-bubble {
        font-size: 15.5px;
    }

    .quick-intents {
        margin-left: 38px;
    }

    .chat-composer-inner {
        width: calc(100% - 12px);
    }

}

.mentor-avatar.has-photo span {
    display: none;
}


/* MentorAI optimistic chat submit */

.optimistic-turn {
    display: flex;
    width: 100%;
    box-sizing: border-box;
    margin: 6px 0;
}

.optimistic-turn-learner {
    justify-content: flex-end;
    padding-left: 22%;
}

.optimistic-learner-bubble {
    position: relative;
    max-width: 640px;
    padding: 10px 14px;
    border-radius: 18px 18px 4px 18px;
    background:
        var(--mentor-accent, #6557e8);
    color: #fff;
    line-height: 1.42;
    overflow-wrap: anywhere;
}

.optimistic-turn-mentor {
    align-items: flex-end;
    gap: 8px;
    padding-right: 22%;
}

.optimistic-mentor-avatar {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #252535;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.optimistic-mentor-pending {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid rgba(20, 20, 40, 0.09);
    border-radius: 18px 18px 18px 4px;
    background: #fff;
    color: inherit;
}

.optimistic-mentor-label {
    font-size: 14px;
    opacity: 0.68;
}

.mentor-thinking-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.mentor-thinking-dots > span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.3;
    animation:
        mentor-thinking-dot 1.1s infinite ease-in-out;
}

.mentor-thinking-dots > span:nth-child(2) {
    animation-delay: 0.14s;
}

.mentor-thinking-dots > span:nth-child(3) {
    animation-delay: 0.28s;
}

@keyframes mentor-thinking-dot {
    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.28;
    }

    30% {
        transform: translateY(-3px);
        opacity: 0.85;
    }
}

.composer-send.is-sending svg {
    display: none;
}

.composer-send.is-sending::after {
    content: "";
    width: 15px;
    height: 15px;
    box-sizing: border-box;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation:
        mentor-send-spinner 0.7s linear infinite;
}

@keyframes mentor-send-spinner {
    to {
        transform: rotate(360deg);
    }
}

.chat-answer-form.is-awaiting-mentor {
    pointer-events: none;
}

.chat-answer-form.is-awaiting-mentor textarea {
    opacity: 0.72;
}

@media (max-width: 720px) {
    .optimistic-turn-learner {
        padding-left: 10%;
    }

    .optimistic-turn-mentor {
        padding-right: 10%;
    }
}
