:root {
    --visual-viewport-height: 100dvh;
    --visual-viewport-width: 100vw;
    --visual-viewport-offset-top: 0px;
    --visual-viewport-offset-left: 0px;
    --mobile-footer-height: calc(1.9rem + env(safe-area-inset-bottom, 0px));
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    background: url('../img/404_background.png') no-repeat center center fixed;
    background-size: cover;
    font-family: Arial, sans-serif;
    color: #fff;
}

.ui-dialog {
    box-sizing: border-box;
    max-width: calc(100vw - 2rem);
    box-shadow: 0 0 30px rgba(0, 191, 255, 0.8);
    border: 2px solid #0080c0;
    background: rgba(5, 5, 15, 0.92);
    backdrop-filter: blur(3px);
}

.ui-dialog-titlebar {
    display: flex;
    align-items: center;
    background: #000c1a;
    color: #00bfff;
    border: none;
}

.ui-dialog .ui-dialog-title {
    float: none;
    flex: 0 1 auto;
    width: auto;
    margin: 0;
}

.ui-dialog .ui-dialog-content {
    overflow: hidden;
}

.ui-dialog .ui-dialog-titlebar-reset {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: none;
    border: none;
    color: #00bfff;
    font-size: 1.2em;
    line-height: 1;
    cursor: pointer;
    margin-left: 0.5em;
}

.ui-widget-content {
    color: #aaa;
}

.ui-dialog .ui-dialog-titlebar-reset:hover {
    color: #44cc44;
}

#loginForm label,
#loginForm input,
#loginForm button {
    display: block;
    margin: 10px auto;
    width: 80%;
}

#loginForm input {
    padding: 10px;
    border: none;
    border-radius: 5px;
}

#loginForm button {
    background-color: #00bfff;
    color: #001018;
    border: none;
    border-radius: 5px;
    padding: 10px;
    cursor: pointer;
}

#chatDialog {
    display: none;
    font-size: 14px;
}

.chat-window {
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 4rem);
    overflow: hidden;
}

.chat-window .ui-dialog-titlebar {
    flex: 0 0 auto;
}

.chat-window #chatDialog {
    display: flex !important;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0 !important;
}

.chat-window #chatMessagesViewport {
    flex: 1 1 auto;
    min-height: 0;
}

/* Chat log styling */
#chatMessagesViewport {
    position: relative;
    box-sizing: border-box;
    height: min(600px, calc(100dvh - 170px));
    min-height: 180px;
    margin-bottom: 10px;
}

#chatMessages {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: #111;
    padding: 10px;
    border: 1px solid #00bfff;
    margin: 0;

    display: flex;
    flex-direction: column;
    gap: 8px;
}

#scrollToLatest {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid #00bfff;
    border-radius: 50%;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.55);
    background: #001a2b;
    color: #00bfff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

#scrollToLatest:hover,
#scrollToLatest:focus-visible {
    background: #00bfff;
    color: #001018;
}

#scrollToLatest:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

#scrollToLatest[hidden] {
    display: none;
}

/* Bubble base */
.bubble {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 20px;
    word-wrap: break-word;
    position: relative;
    line-height: 1.4;
}

/* User (blue) bubbles on the right */
.bubble.user {
    align-self: flex-end;
    background: #007aff;
    color: #fff;
    border-bottom-right-radius: 5px;
}

/* Assistant (gray) bubbles on the left */
.bubble.assistant {
    align-self: flex-start;
    background: #444444;
    color: #fff;
    border-bottom-left-radius: 5px;
    min-width: 17px;
}

.bubble.assistant.run-error {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid #ff6b6b;
    background: #351b1b;
}

.run-error-message {
    color: #fff;
}

.run-retry {
    min-height: 36px;
    padding: 6px 14px;
    border: 1px solid #ff8a8a;
    border-radius: 999px;
    background: transparent;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.run-retry:hover,
.run-retry:focus-visible {
    background: #ff6b6b;
    color: #111;
}

.run-retry:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.bubble.assistant img {
    width: 100%;
}

#chatComposer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

#chatInput {
    box-sizing: border-box;
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    padding: 10px;
    font-size: 16px;
}

#chatSend {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid #00bfff;
    border-radius: 5px;
    background: #00bfff;
    color: #001018;
    cursor: pointer;
}

#accessDenied {
    box-sizing: border-box;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.9);
    color: #ff4444;
    font-size: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    text-align: center;
    padding: 20px;
    white-space: pre-wrap;
    font-family: monospace;
}

#connectingIndicator {
    box-sizing: border-box;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.9);
    color: #44cc44;
    font-size: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    text-align: center;
    padding: 20px;
    white-space: pre-wrap;
    font-family: monospace;
}

.bubble.assistant.typing {
    position: relative;
}

.typing-dots {
    display: inline-flex;
    gap: 0.25rem;
    align-items: flex-end;
    height: 0.2rem;
}

.dot {
    width: 0.2rem;
    height: 0.2rem;
    border-radius: 9999px;
    background: rgba(148 163 184 / 0);
    animation: wave 1s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: 0s;      }
.dot:nth-child(2) { animation-delay: 0.33s;   }
.dot:nth-child(3) { animation-delay: 0.66s;   }

@keyframes wave {
    0%   { transform: translateY(0);    background: rgba(255 255 255 / 0);   }
    50%  { transform: translateY(-0.5rem); background: rgba(255 255 255 / 0.8); }
    100% { transform: translateY(0);    background: rgba(255 255 255 / 0);   }
}

footer {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 1000;
    padding: 0.5rem 1rem;
    border-top-right-radius: 0.25rem;
    background-color: rgba(0, 0, 0, 0);
    color: #ccc;
    font-size: 0.75rem;
    line-height: 1.2;
    opacity: 0.8;
}


/* Mobile portrait and short landscape screens use the visual viewport. Keeping
   the composer in the dialog's flex layout lets the message list shrink above
   an on-screen keyboard instead of being covered by it. */
@media only screen and (max-width: 600px),
       only screen and (orientation: landscape) and (max-height: 600px) {
    .ui-dialog {
        position: fixed !important;
        top: var(--visual-viewport-offset-top) !important;
        left: var(--visual-viewport-offset-left) !important;
        display: flex;
        flex-direction: column;
        width: var(--visual-viewport-width) !important;
        max-width: var(--visual-viewport-width);
        height: calc(var(--visual-viewport-height) - var(--mobile-footer-height)) !important;
        max-height: calc(var(--visual-viewport-height) - var(--mobile-footer-height));
        margin: 0;
        padding: 0;
        overflow: hidden;
        border-radius: 0;
    }

    .ui-dialog .ui-dialog-titlebar {
        box-sizing: border-box;
        flex: 0 0 auto;
        padding: 0.4em 1em;
    }

    .ui-dialog .ui-dialog-title {
        font-size: 1.2em;
    }

    .ui-dialog .ui-dialog-content {
        box-sizing: border-box;
        flex: 1 1 auto;
        width: auto !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        padding: 0;
    }

    .login-window .ui-dialog-content {
        overflow-y: auto;
    }

    .chat-window #chatDialog {
        display: flex !important;
        flex-direction: column;
        overflow: hidden;
    }

    #chatMessagesViewport {
        flex: 1 1 auto;
        width: auto;
        height: auto !important;
        min-height: 0;
        margin: 0;
    }

    #chatMessages {
        width: 100%;
        height: 100% !important;
        min-height: 0;
        padding: 8px;
    }

    #scrollToLatest {
        right: max(12px, env(safe-area-inset-right, 0px));
        bottom: 12px;
        width: 44px;
        height: 44px;
    }

    #chatComposer {
        box-sizing: border-box;
        flex: 0 0 auto;
        gap: 8px;
        width: 100%;
        padding: 8px max(8px, env(safe-area-inset-right, 0px)) 8px max(8px, env(safe-area-inset-left, 0px));
        border-top: 1px solid #00bfff;
        background: rgba(0, 0, 0, 0.96);
    }

    #chatInput {
        position: static;
        min-height: 44px;
        padding: 10px 12px;
        border: 1px solid #777;
        border-radius: 6px;
        background: #111;
        color: #fff;
    }

    #chatSend {
        min-width: 64px;
        min-height: 44px;
        padding: 0 12px;
    }

    .bubble {
        max-width: 85%;
        padding: 12px 16px;
        font-size: 1em;
        line-height: 1.5;
    }

    .bubble.user {
        border-bottom-right-radius: 8px;
    }

    .bubble.assistant {
        border-bottom-left-radius: 8px;
    }

    .run-retry {
        min-height: 44px;
        padding: 8px 16px;
    }

    .ui-dialog .ui-dialog-titlebar-reset {
        margin-left: 0.5em;
        font-size: 1.4em;
    }

    footer {
        box-sizing: border-box;
        top: calc(var(--visual-viewport-offset-top) + var(--visual-viewport-height) - var(--mobile-footer-height));
        bottom: auto;
        left: var(--visual-viewport-offset-left);
        display: flex;
        align-items: center;
        width: var(--visual-viewport-width);
        height: var(--mobile-footer-height);
        padding: 0.25rem max(1rem, env(safe-area-inset-right, 0px)) calc(0.25rem + env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
        background: rgba(5, 5, 15, 0.96);
    }
}

@media only screen and (orientation: landscape) and (max-height: 600px) {
    .ui-dialog .ui-dialog-titlebar {
        padding: 0.3em 0.8em;
    }

    .ui-dialog .ui-dialog-title,
    .ui-dialog .ui-dialog-titlebar-reset {
        font-size: 1.1em;
    }

    .bubble {
        max-width: 80%;
        padding: 10px 14px;
        font-size: 0.95em;
    }
}

.video-container {
    position: relative;
    display: inline-block;
    line-height: 0;       /* no extra descender gap */
}

.video-preview {
    display: block;
    max-width: 100%;
}

.video-icon {
    position: absolute;
    top: 15px;
    right: 10px;
    font-size: 1em;
    pointer-events: none;
    opacity: 0.7;
}

/* make icon more visible on hover */
.video-container:hover .video-icon {
    opacity: 1;
}
