/* Theme tokens */

:root {
    --font-sans: "Roboto", sans-serif;
    --font-mono: "Courier New", Courier, monospace;

    --radius-panel: 22px;
    --radius-message: 20px;

    --page-width: min(980px, calc(100vw - 24px));
    --input-reserved-height: 86px;
    --disclaimer-height: 1.55rem;
    --panel-top-gap: 1.25rem;
    --panel-bottom-gap: calc(var(--disclaimer-height) + 0.35rem);
}

/* Light theme */

:root,
:root:has(body.light-theme),
html.light-theme,
.light-theme {
    --bg-page: #ffffff;
    --text-page: #111827;
    --text-muted: #6b7280;
    --text-disabled: #8a8f98;

    --surface-panel: rgba(255, 255, 255, 0.88);
    --surface-glass: rgba(255, 255, 255, 0.58);
    --surface-control: rgba(235, 235, 235, 0.34);
    --surface-highlight: rgba(17, 24, 39, 0.055);
    --surface-pattern: rgba(17, 24, 39, 0.075);
    --surface-bot: #f0f2f5;
    --surface-error: #ffe1e1;
    --surface-loading: #e8ebef;
    --surface-loading-shimmer: #d5d9df;
    --surface-notice: rgba(255, 255, 255, 0.92);

    --border-subtle: rgba(20, 20, 20, 0.10);
    --border-glass: rgba(255, 255, 255, 0.72);
    --border-control-focus: rgba(20, 20, 20, 0.08);

    --highlight-glass: rgba(255, 255, 255, 0.85);

    --shadow-panel: rgba(0, 0, 0, 0.08);
    --shadow-floating: rgba(0, 0, 0, 0.16);
    --shadow-modal: rgba(0, 0, 0, 0.30);

    --scroll-thumb: rgba(20, 20, 20, 0.18);

    --accent: #2383ff;

    --message-image-filter: grayscale(0) brightness(1);
}

/* Dark theme */

:root:has(body.dark-theme),
html.dark-theme,
.dark-theme {
    --bg-page: #090b0f;
    --text-page: #e5e7eb;
    --text-muted: #9ca3af;
    --text-disabled: #777d88;

    --surface-panel: rgba(16, 19, 24, 0.88);
    --surface-glass: rgba(24, 28, 36, 0.56);
    --surface-control: rgba(10, 13, 18, 0.34);
    --surface-highlight: rgba(255, 255, 255, 0.07);
    --surface-pattern: rgba(255, 255, 255, 0.035);
    --surface-bot: #24272d;
    --surface-error: #5f1717;
    --surface-loading: #2b3038;
    --surface-loading-shimmer: #3a404a;
    --surface-notice: rgba(18, 21, 27, 0.94);

    --border-subtle: rgba(255, 255, 255, 0.09);
    --border-glass: rgba(255, 255, 255, 0.16);
    --border-control-focus: rgba(255, 255, 255, 0.08);

    --highlight-glass: rgba(255, 255, 255, 0.12);

    --shadow-panel: rgba(0, 0, 0, 0.08);
    --shadow-floating: rgba(0, 0, 0, 0.16);
    --shadow-modal: rgba(0, 0, 0, 0.30);

    --scroll-thumb: rgba(255, 255, 255, 0.18);

    --accent: #0a84ff;

    --message-image-filter: grayscale(0) invert(1);
}


/* Base */

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background-color: var(--bg-page);
    color: var(--text-page);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    height: auto;
}

body {
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    font-family: var(--font-sans);
}

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

* {
    margin: 0;
    padding: 0;
}

button,
textarea,
input,
select {
    font: inherit;
}

button {
    appearance: none;
    border: none;
    background: none;
}

a {
    color: inherit;
    text-decoration: none;
}

p {
    font-weight: 300;
}

strong {
    font-weight: 500;
}

ol,
ul {
    padding-left: 1.5rem;
    list-style-position: inside;
}

li p {
    display: inline;
}

hr {
    margin: 0.6rem 0;
    border: none;
    border-top: 1px solid currentColor;
    opacity: 0.25;
}


/* Tables and code */

table {
    border-collapse: collapse;
    border-spacing: 0;
    border: none;
}

th,
td {
    padding: 0.25rem 0.5rem;
    border: 1px solid currentColor;
}

pre,
code {
    font-family: var(--font-mono);
}

pre {
    display: block;
    max-width: 100%;
    margin: 0.5rem 0;
    padding: 0.75rem 0.9rem;
    overflow-x: auto;
    text-wrap: auto;
    border-radius: 12px;
    background-color: var(--surface-highlight);
    font-size: 0.9rem;
}

code {
    padding: 0.05rem 0.25rem;
    border-radius: 5px;
    background-color: var(--surface-highlight);
}

pre code {
    padding: 0;
    background: transparent;
}


/* Binary background */

.binary-background {
    position: fixed;
    inset: 0;
    z-index: 0;

    padding: 1.5rem;
    overflow: hidden;

    color: var(--surface-pattern);
    font-family: var(--font-mono);
    font-size: clamp(0.7rem, 1.1vw, 1rem);
    line-height: 1.75;
    word-break: break-all;

    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}


/* Main layout */

.main-wrapper {
    position: relative;
    z-index: 1;

    display: block;

    width: var(--page-width);
    min-height: 100dvh;
    margin: 0 auto;
    padding: 0;
}

@media screen and (min-width: 1600px) {
    :root {
        --page-width: min(1280px, calc(100vw - 24px));
    }
}

.main-wrapper::before {
    content: "";
    position: fixed;
    top: var(--panel-top-gap);
    bottom: var(--panel-bottom-gap);
    left: 50%;
    z-index: 21;

    width: var(--page-width);

    transform: translateX(-50%);

    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-panel);
    background: transparent;

    box-shadow: 0 18px 50px var(--shadow-panel);

    pointer-events: none;
}


/* Header */

.header-wrapper {
    position: fixed;
    top: 2.1rem;
    left: 50%;
    right: auto;
    z-index: 30;

    display: flex;
    align-items: center;

    width: calc(var(--page-width) - 2rem);
    min-height: 4rem;
    padding: 0 1.1rem;

    transform: translateX(-50%);

    border: 1px solid var(--border-glass);
    border-radius: var(--radius-panel);
    background: var(--surface-glass);

    box-shadow:
        0 18px 45px var(--shadow-floating),
        inset 0 1px 0 var(--highlight-glass);

    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
}

#header-title {
    flex: 1;
    min-width: 0;

    overflow-x: auto;
    overflow-y: hidden;

    color: var(--text-page);
    font-size: 1.22rem;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: clip;

    scrollbar-width: none;
}

#header-title::-webkit-scrollbar {
    display: none;
}

.header-buttons {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.55rem;
    margin-left: auto;
}

.header-btn {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 2.35rem;
    height: 2.35rem;

    border-radius: 999px;
    background: var(--surface-control);
    color: var(--text-page);

    cursor: pointer;
    user-select: none;

    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);

    transition:
        transform 0.18s ease,
        background-color 0.25s ease,
        border-color 0.25s ease,
        box-shadow 0.25s ease,
        filter 0.25s ease;
}

.header-btn:hover {
    filter: brightness(1.02);
    transform: translateY(-1px);
}

.header-btn:active {
    transform: translateY(0) scale(0.96);
}

.header-btn i,
.input-send i {
    font-size: 1.15rem;
}

.input-send i {
    transform: translate(-7%, 2%);
}


/* Chat panel */

.chat-wrapper {
    position: relative;

    display: block;

    min-height: 100dvh;
    overflow: visible;

    border: none;
    border-radius: 0;
    background: transparent;

    box-shadow: none;

    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.chat-wrapper::before {
    content: "";
    position: fixed;
    top: var(--panel-top-gap);
    bottom: var(--panel-bottom-gap);
    left: 50%;
    z-index: 1;

    width: var(--page-width);

    transform: translateX(-50%);

    border-radius: var(--radius-panel);
    background: var(--surface-panel);

    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);

    pointer-events: none;
}

.chat-wrapper::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 20;

    box-sizing: border-box;

    border-top: var(--panel-top-gap) solid var(--bg-page);
    border-bottom: var(--panel-bottom-gap) solid var(--bg-page);

    background: transparent;

    pointer-events: none;
}

.messages-wrapper {
    position: relative;
    z-index: 2;

    display: flex;
    flex-direction: column;
    gap: 0.85rem;

    min-height: 100dvh;
    height: auto;
    overflow: visible;

    padding:
        7.6rem
        1.25rem
        calc(var(--input-reserved-height) + var(--disclaimer-height) + 2.25rem);

    scroll-behavior: auto;
    scroll-padding-bottom: calc(var(--input-reserved-height) + 1rem);
}

.messages-wrapper::after {
    display: none;
    content: none;
}


/* Messages */

.message-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.55rem;
    width: 100%;
}

.message-wrapper.human {
    justify-content: flex-end;
}

.message-wrapper.bot,
.message-wrapper.error,
.message-wrapper.loading {
    justify-content: flex-start;
}

.message-image-wrapper {
    position: relative;
    flex: 0 0 auto;

    width: 38px;
    height: 38px;
    overflow: hidden;

    border-radius: 50%;
    object-fit: cover;

    box-shadow: 0 4px 16px var(--shadow-panel);
}

.message-wrapper.human .message-image-wrapper {
    display: none;
}

.message-image {
    width: 100%;
    height: 100%;
    filter: var(--message-image-filter);
}

.message-image.do-not-invert {
    filter: none;
}

.message-image-wrapper.bot {
    background-color: var(--surface-bot);
}

.message-image-wrapper.error {
    background-color: var(--surface-error);
}

.message-image-wrapper.loading {
    background-color: var(--surface-loading);
}

.message-image-wrapper.loading .message-image,
.message-image-wrapper.loading::after {
    display: none;
}

.message-text-wrapper {
    max-width: 66.666%;
    min-width: 0;
    padding: 0.72rem 0.9rem 0.46rem;

    overflow-wrap: anywhere;

    border-radius: var(--radius-message);
    color: var(--text-page);
    font-size: 1rem;
    line-height: 1.45;
}

.message-text-wrapper.bot {
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: 7px;
    background-color: var(--surface-bot);
}

.message-text-wrapper.human {
    border-bottom-right-radius: 7px;
    background-color: var(--accent);
    color: #ffffff;
}

.message-text-wrapper.error {
    border-bottom-left-radius: 7px;
    background-color: var(--surface-error);
}

.message-text-wrapper.loading {
    position: relative;

    min-width: min(18rem, 66.666%);
    min-height: 3.15rem;
    overflow: hidden;

    border-bottom-left-radius: 7px;
    background: var(--surface-loading);
    color: transparent;
}

.message-text-wrapper.loading::after {
    content: "";
    position: absolute;
    inset: 0;

    width: 250%;
    height: 100%;

    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--surface-loading-shimmer) 22%,
        var(--surface-loading) 50%,
        var(--surface-loading-shimmer) 78%,
        transparent 100%
    );

    animation: loadingShimmer 1.6s infinite ease-in-out;
    transform: translateX(-70%);
}

.message-text-wrapper.human a,
.message-text-wrapper.human code,
.message-text-wrapper.human .message-time {
    color: inherit;
}

.message-text-wrapper.human code,
.message-text-wrapper.human pre {
    background: rgba(255, 255, 255, 0.16);
}

.message-text {
    display: block;
}

.message-text > * + * {
    margin-top: 0.55rem;
}

.message-text-wrapper table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.message-text-wrapper table tr:nth-child(even) {
    background-color: var(--surface-highlight);
}

.think {
    margin: 0.5em 0;
    padding: 0.55em 0.7em;

    border: 1px dashed currentColor;
    border-radius: 12px;

    font-style: italic;
    opacity: 0.68;
    max-height: 400rem;
    overflow: hidden;

    transition:
        max-height 0.55s ease,
        opacity 0.55s ease;
}

.think::before {
    content: "💭 Denkprozess:";
    display: block;
    margin-bottom: 0.5em;
    font-style: italic;
    cursor: pointer;
    user-select: none;
}

.think.collapsed {
    max-height: 2.55em;
    opacity: 0.5;
}

.message-time {
    display: block;

    margin-top: 0.38rem;

    color: var(--text-muted);
    font-size: 0.72rem;
    text-align: left;

    opacity: 0.72;
}

.message-text-wrapper.human .message-time {
    color: rgba(255, 255, 255, 0.82);
    text-align: right;
}

.message-time.loading {
    color: transparent;
}

.message-text.loading,
.message-text.loading *,
.message-time.loading,
.message-time.loading * {
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

@keyframes loadingShimmer {
    0% {
        transform: translateX(-100%);
        opacity: 0.22;
    }

    40% {
        transform: translateX(-25%);
        opacity: 0.55;
    }

    80% {
        transform: translateX(15%);
        opacity: 0.22;
    }

    100% {
        transform: translateX(100%);
        opacity: 0.22;
    }
}


/* Floating input */

.input-wrapper {
    position: fixed;
    left: 50%;
    right: auto;
    bottom: calc(var(--disclaimer-height) + 0.95rem);
    z-index: 25;

    display: flex;
    align-items: flex-end;
    gap: 0.55rem;

    width: calc(var(--page-width) - 2rem);
    padding: 0.85rem;

    transform: translateX(-50%);

    border: 1px solid var(--border-glass);
    border-radius: 26px;
    background: var(--surface-glass);

    box-shadow:
        0 18px 45px var(--shadow-floating),
        inset 0 1px 0 var(--highlight-glass);

    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
}

.input-field {
    width: 100%;
    min-height: 2.65rem;
    max-height: 10.5rem;
    padding: 0.58rem 0.85rem;

    resize: none;
    overflow-y: auto;

    border: 0;
    border-radius: 18px;
    outline: none;
    box-shadow: inset 0 0 0 1px transparent;

    background: var(--surface-control);
    color: var(--text-page);
    font-size: 1rem;
    line-height: 1.35;
}

.input-field:focus {
    box-shadow: inset 0 0 0 1px var(--border-control-focus);
}

.input-field:disabled {
    color: var(--text-disabled);
}

.input-send {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;

    width: 2.65rem;
    height: 2.65rem;

    border-radius: 999px;
    background-color: var(--accent);
    color: #ffffff;

    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;

    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);

    transition:
        transform 0.18s ease,
        background-color 0.25s ease,
        border-color 0.25s ease,
        box-shadow 0.25s ease,
        filter 0.25s ease;
}

.input-send:hover {
    filter: brightness(1.02);
    transform: translateY(-1px);
}

.input-send:active {
    transform: translateY(0) scale(0.96);
}

.input-send.deactivated,
.input-send:disabled {
    background-color: var(--text-disabled);
    color: rgba(255, 255, 255, 0.76);
    cursor: not-allowed;
    pointer-events: none;
    filter: none;
    transform: none;
}


/* Notice layer */

.notice-layer {
    position: fixed;
    inset: 0;
    z-index: 9999;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 1rem;
    background: rgba(0, 0, 0, 0.50);
}

.notice-card {
    width: min(620px, 92vw);
    padding: 1.25rem 1.55rem;

    border: 1px solid var(--border-subtle);
    border-radius: 18px;
    background: var(--surface-notice);
    color: var(--text-page);

    box-shadow: 0 18px 60px var(--shadow-modal);
}

.notice-heading {
    margin: 0 0 10px;
    font-size: 1.5em;
    font-weight: 700;
}

.notice-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.notice-action {
    padding: 0.55rem 0.95rem;

    border-radius: 999px;
    color: #ffffff;

    cursor: pointer;
    transition: background-color 0.2s ease;
}

.notice-action.confirm {
    background-color: #28a745;
}

.notice-action.confirm:hover {
    background-color: #218838;
}

.notice-action.cancel {
    background-color: #dc3545;
}

.notice-action.cancel:hover {
    background-color: #c82333;
}


/* Disclaimer */

.disclaimer {
    position: fixed;
    left: 50%;
    bottom: 0.15rem;
    z-index: 35;

    width: var(--page-width);
    padding: 0.25rem 0.75rem 0;

    transform: translateX(-50%);

    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.2;
    text-align: center;
}

@media screen and (max-width: 900px) {
    .disclaimer {
        font-size: 0.6rem;
    }
}


/* Transitions */

html,
body,
.chat-wrapper,
.chat-wrapper::before,
.chat-wrapper::after,
.main-wrapper::before,
.message-text-wrapper,
.input-field,
.header-wrapper,
#header-title,
.header-btn,
.message-image-wrapper,
.message-wrapper,
.input-send,
.disclaimer,
.binary-background {
    transition:
        color 0.35s ease-in-out,
        background-color 0.35s ease-in-out,
        border-color 0.35s ease-in-out,
        box-shadow 0.35s ease-in-out;
}


/* Mobile layout */

@media screen and (max-width: 720px) {
    :root {
        --page-width: 100vw;
        --panel-top-gap: 0;
        --panel-bottom-gap: var(--disclaimer-height);
    }

    body {
        background-color: var(--surface-panel);
    }

    .binary-background,
    .main-wrapper::before,
    .chat-wrapper::before,
    .chat-wrapper::after {
        display: none;
        content: none;
    }

    .main-wrapper,
    .chat-wrapper {
        width: 100vw;
        min-height: 100dvh;
        background: transparent;
    }

    .header-wrapper {
        top: 0.35rem;
        width: calc(100vw - 1.3rem);
        min-height: 3.65rem;
        padding: 0 0.9rem;
    }

    .messages-wrapper {
        padding:
            5.45rem
            0.75rem
            calc(var(--input-reserved-height) + var(--disclaimer-height) + 1.35rem);

        scroll-padding-bottom: calc(var(--input-reserved-height) + var(--disclaimer-height));
    }

    .message-text-wrapper {
        max-width: 82%;
    }

    .message-text-wrapper.loading {
        min-width: min(16rem, 82%);
    }

    .input-wrapper {
        bottom: calc(var(--disclaimer-height) + 0.65rem);
        width: calc(100vw - 1.3rem);
    }

    .disclaimer {
        bottom: 0;

        width: 100vw;
        min-height: var(--disclaimer-height);
        padding: 0.25rem 0.4rem;

        background: var(--bg-page);
        color: var(--text-muted);

        font-size: 0.58rem;
        line-height: 1.2;
        text-align: center;

        white-space: normal;
        overflow-wrap: anywhere;
    }
}


/* Embedded layout */

body.embedded {
    --page-width: 100vw;
    --panel-top-gap: 0;
    --panel-bottom-gap: var(--disclaimer-height);
    background: var(--surface-panel);
}

body.embedded .binary-background,
body.embedded .main-wrapper::before,
body.embedded .chat-wrapper::before,
body.embedded .chat-wrapper::after {
    display: none;
    content: none;
}

body.embedded .main-wrapper,
body.embedded .chat-wrapper {
    width: 100vw;
    min-height: 100dvh;
    background: transparent;
}

body.embedded .header-wrapper {
    top: 0.35rem;
    width: calc(100vw - 1.3rem);
    min-height: 3.65rem;
    padding: 0 0.9rem;
}

body.embedded .messages-wrapper {
    padding:
        5.45rem
        0.75rem
        calc(var(--input-reserved-height) + var(--disclaimer-height) + 1.35rem);

    scroll-padding-bottom: calc(var(--input-reserved-height) + var(--disclaimer-height));
}

body.embedded .message-text-wrapper {
    max-width: 82%;
}

body.embedded .message-text-wrapper.loading {
    min-width: min(16rem, 82%);
}

body.embedded .input-wrapper {
    bottom: calc(var(--disclaimer-height) + 0.65rem);
    width: calc(100vw - 1.3rem);
}

body.embedded .disclaimer {
    bottom: 0;

    width: 100vw;
    min-height: var(--disclaimer-height);
    padding: 0.25rem 0.4rem;

    background: var(--bg-page);
    color: var(--text-muted);

    font-size: 0.58rem;
    line-height: 1.2;
    text-align: center;

    white-space: normal;
    overflow-wrap: anywhere;
}