:root {
    color-scheme: light;
    --accent: #4da8a9;
    --accent-strong: #247f81;
    --accent-soft: #e5f4f3;
    --accent-glow: rgba(77, 168, 169, 0.24);
    --background: #f4f8f7;
    --background-deep: #eaf2f0;
    --surface: rgba(255, 255, 255, 0.9);
    --surface-solid: #ffffff;
    --surface-muted: #eef4f2;
    --surface-hover: #e4efed;
    --text: #173536;
    --text-muted: #617777;
    --text-on-accent: #ffffff;
    --border: rgba(32, 89, 90, 0.13);
    --border-strong: rgba(36, 127, 129, 0.28);
    --danger: #a73b45;
    --danger-soft: #fae9eb;
    --focus: #f0ad2c;
    --shadow-sm: 0 8px 24px rgba(20, 66, 65, 0.08);
    --shadow-lg: 0 24px 70px rgba(20, 66, 65, 0.13);
    --glass-blur: blur(20px);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --accent: #62c3c2;
    --accent-strong: #8bd8d5;
    --accent-soft: #173b3c;
    --accent-glow: rgba(98, 195, 194, 0.2);
    --background: #101817;
    --background-deep: #0a1110;
    --surface: rgba(25, 36, 35, 0.91);
    --surface-solid: #192321;
    --surface-muted: #22302e;
    --surface-hover: #2a3a37;
    --text: #edf7f5;
    --text-muted: #9db0ad;
    --text-on-accent: #0c2424;
    --border: rgba(197, 232, 228, 0.1);
    --border-strong: rgba(98, 195, 194, 0.3);
    --danger: #ef7d86;
    --danger-soft: #48252b;
    --focus: #ffd166;
    --shadow-sm: 0 10px 28px rgba(0, 0, 0, 0.22);
    --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.38);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--background-deep);
    font-family: "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: clamp(16px, 2.4vh, 28px);
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: clamp(18px, 3vw, 36px) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    overflow: hidden;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 8%, var(--accent-glow), transparent 28%),
        radial-gradient(circle at 88% 88%, rgba(128, 181, 157, 0.14), transparent 30%),
        linear-gradient(145deg, var(--background), var(--background-deep));
    transition: color 180ms ease, background-color 180ms ease;
}

button,
textarea,
input {
    font: inherit;
}

button,
a,
label {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
input:focus-visible,
.attach-button:focus-within {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

button {
    touch-action: manipulation;
}

.skip-link {
    position: fixed;
    top: -64px;
    left: 18px;
    z-index: 200;
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text);
    background: var(--surface-solid);
    box-shadow: var(--shadow-sm);
}

.skip-link:focus {
    top: 14px;
}

.visually-hidden,
#upload {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.app-header,
#scroller,
#bodyWrapper {
    width: min(100%, 1120px);
    margin-inline: auto;
}

.app-header,
#bodyWrapper {
    min-width: 0;
}

.app-header {
    position: relative;
    z-index: 30;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.brand-block {
    max-width: 680px;
}

.brand-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 7px;
}

.brand-line strong {
    font-size: clamp(24px, 3vw, 32px);
    line-height: 1;
    letter-spacing: -0.035em;
}

.demo-badge {
    padding: 5px 9px 4px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.brand-block p,
.demo-intro p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.55;
}

#icons {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
}

.icon-button {
    display: grid;
    width: 44px;
    height: 44px;
    padding: 0;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    background-color: var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    backdrop-filter: var(--glass-blur);
    transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.icon-button:hover {
    border-color: var(--border-strong);
    background-color: var(--surface-solid);
    transform: translateY(-2px);
}

.icon-button img {
    width: 24px;
    height: 24px;
}

:root[data-theme="dark"] .icon-button img,
:root[data-theme="dark"] #dialogueInfoWrapper img {
    filter: invert(1) brightness(1.3);
}

.dark-theme {
    background-image: url("../resources/theme.svg");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 25px;
}

:root[data-theme="dark"] .dark-theme {
    background-image: url("../resources/sun.svg");
}

#dialogueInfoWrapper[hidden],
.modal[hidden],
.image-preview[hidden],
#stopButton[hidden] {
    display: none;
}

#dialogueInfoWrapper {
    position: absolute;
    top: 54px;
    right: 0;
    z-index: 40;
    display: grid;
    min-width: 250px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 18px 6px 18px 18px;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    backdrop-filter: var(--glass-blur);
}

#dialogueInfoWrapper a,
#dialogueInfoWrapper button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 12px;
    border: 0;
    border-radius: 11px;
    color: var(--text-muted);
    background: transparent;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: color 140ms ease, background-color 140ms ease;
}

#dialogueInfoWrapper a:hover,
#dialogueInfoWrapper button:hover {
    color: var(--text);
    background: var(--surface-hover);
}

#dialogueInfoWrapper img {
    width: 20px;
    height: 20px;
    opacity: 0.8;
}

#clearChatButton span {
    color: var(--danger);
}

#scroller {
    height: 100%;
    min-height: 0;
    padding: 2px clamp(4px, 1vw, 12px) 20px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: var(--accent) var(--surface-muted);
    scrollbar-gutter: stable;
    scrollbar-width: auto;
}

#scroller::-webkit-scrollbar {
    width: 10px;
}

#scroller::-webkit-scrollbar-track {
    border-radius: 999px;
    background: var(--surface-muted);
}

#scroller::-webkit-scrollbar-thumb {
    border: 2px solid var(--surface-muted);
    border-radius: 999px;
    background: var(--accent);
    background-clip: padding-box;
}

#textInput::-webkit-scrollbar {
    width: 5px;
}

#textInput::-webkit-scrollbar-track {
    background: transparent;
}

#textInput::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--accent);
}

.demo-intro {
    position: relative;
    padding: clamp(18px, 3vw, 28px);
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    backdrop-filter: var(--glass-blur);
}

.demo-intro::after {
    position: absolute;
    right: -42px;
    bottom: -74px;
    width: 190px;
    height: 190px;
    border: 30px solid var(--accent-soft);
    border-radius: 50%;
    content: "";
    opacity: 0.8;
    pointer-events: none;
}

.demo-intro h1 {
    position: relative;
    z-index: 1;
    max-width: 700px;
    margin: 0 0 7px;
    font-size: clamp(21px, 3vw, 30px);
    line-height: 1.2;
    letter-spacing: -0.03em;
}

.demo-intro p,
.example-list {
    position: relative;
    z-index: 1;
}

.example-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.example-list button {
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    color: var(--accent-strong);
    background: var(--surface-solid);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(20, 66, 65, 0.05);
    transition: color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.example-list button:hover {
    color: var(--text-on-accent);
    background: var(--accent);
    transform: translateY(-1px);
}

.chatbot__overview {
    padding-top: clamp(20px, 3vh, 32px);
}

.chatlist {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.userInput,
.assistant-message,
.bot__output1 {
    width: fit-content;
    max-width: min(76%, 780px);
    overflow-wrap: anywhere;
}

.userInput {
    display: grid;
    justify-items: end;
    margin-left: auto;
}

.assistant-message {
    display: grid;
    justify-items: start;
}

.message-content,
.bot__output,
.bot__output1 {
    padding: 13px 16px;
    white-space: pre-wrap;
    font-size: clamp(14px, 1.4vw, 16px);
    line-height: 1.55;
    box-shadow: var(--shadow-sm);
}

.message-content {
    border: 1px solid var(--border);
    border-radius: 20px 6px 20px 20px;
    color: var(--text);
    background: var(--surface-solid);
}

.bot__output,
.bot__output1 {
    border: 1px solid transparent;
    border-radius: 6px 20px 20px 20px;
    color: var(--text-on-accent);
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.bot__output1 {
    display: block;
}

.message-text {
    white-space: pre-wrap;
}

.message-image {
    display: block;
    max-width: min(100%, 520px);
    max-height: 360px;
    margin-bottom: 10px;
    border-radius: 14px;
    object-fit: contain;
}

.message-meta {
    display: flex;
    gap: 8px;
    padding: 0 8px;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

[data-status="error"] .bot__output {
    color: #fff;
    background: linear-gradient(135deg, var(--danger), #7f2931);
}

.message-action {
    margin: 6px 8px 0;
    border: 0;
    color: var(--accent-strong);
    background: transparent;
    cursor: pointer;
}

.regenerate {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background-image: url("../resources/regenerate.svg");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 19px;
    opacity: 0.7;
    transition: opacity 140ms ease, background-color 140ms ease, transform 140ms ease;
}

.regenerate:hover {
    background-color: var(--surface-hover);
    opacity: 1;
    transform: rotate(-18deg);
}

:root[data-theme="dark"] .regenerate {
    filter: invert(1);
}

.retry {
    padding: 5px 0;
    font-weight: 650;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.typing-indicator {
    display: block;
    width: 7px;
    height: 7px;
    margin: 7px 20px;
    border-radius: 50%;
    color: currentColor;
    background: currentColor;
    box-shadow: -16px 0 currentColor, 16px 0 currentColor;
    animation: typingPulse 1s infinite ease-in-out;
}

#bodyWrapper {
    position: relative;
    z-index: 20;
    min-height: 0;
}

footer {
    display: grid;
    gap: 8px;
}

#chatForm {
    display: grid;
    grid-template-areas:
        "preview"
        "composer"
        "feedback";
    width: 100%;
}

#inputBar {
    grid-area: composer;
    display: grid;
    grid-template-columns: auto minmax(120px, 1fr) auto auto;
    align-items: end;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    backdrop-filter: var(--glass-blur);
}

.attach-button,
#sendBtn,
#stopButton {
    min-height: 44px;
}

.attach-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 210px;
    padding: 10px 14px;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-size: 13px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 150ms ease, background-color 150ms ease;
}

.attach-button:hover {
    border-color: var(--accent);
    background: var(--surface-hover);
}

#textInput {
    width: 100%;
    min-height: 44px;
    max-height: 160px;
    padding: 11px 8px 8px;
    overflow-y: auto;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    line-height: 1.4;
    resize: none;
}

#textInput::placeholder {
    color: var(--text-muted);
    opacity: 0.8;
}

#sendBtn {
    display: grid;
    width: 46px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 13px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    box-shadow: 0 8px 20px var(--accent-glow);
    cursor: pointer;
    transition: opacity 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

#sendBtn:hover:not(:disabled) {
    box-shadow: 0 10px 26px var(--accent-glow);
    transform: translateY(-2px);
}

#sendBtn:disabled {
    cursor: wait;
    opacity: 0.42;
}

#sendBtn img {
    width: 23px;
    height: 23px;
    filter: brightness(0) invert(1);
}

:root[data-theme="dark"] #sendBtn img {
    filter: brightness(0) saturate(100%);
}

#stopButton {
    padding: 0 14px;
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: var(--danger);
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
}

.image-preview {
    grid-area: preview;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: min(100%, 520px);
    padding: 9px 11px;
    margin: 0 0 8px 10px;
    border: 1px solid var(--border);
    border-radius: 15px;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.image-preview img {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    object-fit: cover;
}

.image-preview span {
    overflow: hidden;
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview button {
    padding: 8px;
    border: 0;
    color: var(--danger);
    background: transparent;
    cursor: pointer;
}

.form-error,
.request-status {
    grid-area: feedback;
    min-height: 18px;
    margin: 6px 12px 0;
    font-size: 12px;
    line-height: 18px;
    text-align: center;
}

.form-error {
    color: var(--danger);
}

.request-status {
    color: var(--text-muted);
}

.form-error:empty,
.request-status:empty {
    visibility: hidden;
}

.disclaimer {
    padding-inline: 12px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.45;
    text-align: center;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 150;
    display: grid;
    padding: 20px;
    place-items: center;
    background: rgba(5, 16, 15, 0.58);
    backdrop-filter: blur(10px);
}

#modal-content {
    width: min(100%, 760px);
    padding: clamp(24px, 5vw, 40px);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text);
    background: var(--surface-solid);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

#modal-content h2 {
    margin: 0;
    font-size: clamp(18px, 3vw, 24px);
    line-height: 1.45;
}

#modal-content a {
    color: var(--accent-strong);
}

#acceptBtn {
    min-height: 44px;
    padding: 10px 22px;
    margin-top: 22px;
    border: 0;
    border-radius: 12px;
    color: var(--text-on-accent);
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    font-weight: 700;
    cursor: pointer;
}

.toast-region {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 200;
    pointer-events: none;
}

.toast {
    max-width: min(380px, calc(100vw - 36px));
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: #fff;
    background: #243b3a;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    line-height: 1.45;
    animation: toastIn 180ms ease-out;
}

.toast-error {
    background: #7e3037;
}

@keyframes typingPulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 1; }
}

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

@media (max-width: 760px) {
    body {
        gap: 14px;
        padding: 16px 12px max(10px, env(safe-area-inset-bottom));
    }

    .app-header {
        align-items: center;
    }

    .brand-block p {
        max-width: 440px;
        font-size: 12px;
    }

    .demo-intro {
        border-radius: 20px;
    }

    .userInput,
    .assistant-message,
    .bot__output1 {
        max-width: 88%;
    }

    #inputBar {
        grid-template-columns: minmax(0, 1fr) auto auto;
        border-radius: 18px;
    }

    .attach-button {
        grid-column: 1 / -1;
        justify-self: start;
        max-width: min(100%, 300px);
        min-height: 38px;
        padding: 8px 11px;
    }

    #textInput {
        padding-left: 4px;
    }
}

@media (max-width: 480px) {
    body {
        padding-inline: 10px;
    }

    .brand-block p {
        max-width: 230px;
    }

    .brand-line strong {
        font-size: 23px;
    }

    #icons {
        gap: 6px;
    }

    .icon-button {
        width: 40px;
        height: 40px;
        border-radius: 12px;
    }

    #dialogueInfoWrapper {
        top: 48px;
        right: 0;
        width: min(290px, calc(100vw - 20px));
    }

    .demo-intro {
        padding: 17px;
    }

    .demo-intro h1 {
        max-width: 260px;
        font-size: 21px;
    }

    .example-list {
        flex-wrap: nowrap;
        padding-bottom: 4px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .example-list::-webkit-scrollbar {
        display: none;
    }

    .example-list button {
        flex: 0 0 auto;
    }

    .chatlist {
        gap: 14px;
    }

    .userInput,
    .assistant-message,
    .bot__output1 {
        max-width: 94%;
    }

    .message-content,
    .bot__output,
    .bot__output1 {
        padding: 11px 13px;
        border-radius: 17px;
        font-size: 14px;
    }

    .message-content {
        border-top-right-radius: 5px;
    }

    .bot__output,
    .bot__output1 {
        border-top-left-radius: 5px;
    }

    #inputBar {
        gap: 7px;
        padding: 8px;
        border-radius: 16px;
    }

    #sendBtn {
        width: 44px;
    }

    #stopButton {
        padding-inline: 10px;
        font-size: 12px;
    }

    .image-preview {
        width: calc(100% - 12px);
        margin-left: 6px;
    }

    .toast-region {
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
