h1,
h2,
h3,
h4,
h5,
h6 {
    scroll-margin-top: var(--main-menu-top);
}

code {
    scrollbar-width: thin;
    font-size: 0.85em;
}

body {
    display: flex;
    flex-direction: column;
    overflow-y: scroll;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    scrollbar-width: thin;

}

nav {
    position: fixed;
    top: 0;
    z-index: 100;
    background-color: var(--nav-background);
    height: var(--main-menu-top);
    min-height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    width: 100%;
}

#logo img {
    height: 50px;
    margin-top: 10px;
    width: auto;
}

nav svg {
    color: var(--nav-text);
    fill: var(--nav-text);
    height: 30px;
    width: 30px;
    display: block;
}

.navigation-left {
    display: flex;
    align-items: center;
    margin-left:12px;
    gap: 10px;
}

.navigation-right {
    padding: 5px;
    align-items: center;
    display: flex;
    margin-right: 5px;
    gap: 10px;
}

.navigation-right a {
    cursor: pointer;
}


.base-container {
    width: 100%;
    max-width: var(--width);
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

.default-container {
    max-width: 100%;
    width: var(--width);
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    padding: 0 20px;
    top: var(--main-menu-top);
    position: relative;
    height: 0;


}

.chat-container {
    padding-top: var(--main-menu-top);
    overflow-wrap: anywhere;
}

#responses {
    width: 100%;
    max-width: var(--width);
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    overflow: visible;
    padding: 0px 10px calc(20px + var(--prompt-height, 120px));
    scrollbar-width: thin;
    white-space: normal;
    margin-top: 0;
    margin-bottom: 20px;
    scrollbar-color: var(--nav-background) transparent;
}

#prompt {
    color: var(--text-main);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    width: 100%;
    box-sizing: border-box;
    padding: 10px 0;
    background-color: var(--background-body);
}

#prompt > form,
#prompt > #image-preview,
#prompt > .actions {
    width: 100%;
    max-width: var(--width);
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

@media (max-width: 840px) {
    .chat-container,
    #prompt > form,
    #prompt > #image-preview,
    #prompt > .actions {
        padding-left: 12px;
        padding-right: 12px;
    }
}

.image-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    margin-bottom: 8px;
}

.image-preview-item {
    position: relative;
    width: 54px;
    height: 54px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--background-alt);
}

.image-preview-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
}

.image-preview-remove {
    all: unset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 1px;
    right: 1px;
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
    width: 22px;
    height: 22px;
    padding: 0;
    line-height: 1;
    border-radius: 999px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.45);
    font-size: 14px;
    font-weight: 600;
    transition: background-color 120ms ease, transform 120ms ease, border-color 120ms ease;
}

.image-preview-remove:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: rgba(255, 255, 255, 0.7);
}

.image-preview-remove:active {
    transform: scale(0.95);
}

.image-preview-remove:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.image-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.image-preview-modal-image {
    max-width: min(90vw, 1200px);
    max-height: 85vh;
    width: auto;
    height: auto;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    background: #111;
}

.image-preview-modal-close {
    all: unset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 18px;
    right: 18px;
    cursor: pointer;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.35);
    width: 32px;
    height: 32px;
    padding: 0;
    line-height: 1;
    border-radius: 16px;
    font-size: 16px;
}

.content {
    scrollbar-width: thin;
    margin-bottom: 0px;
}

/* Keep action row spacing consistent across plain-text (user) and markdown (assistant) content. */
.content > :last-child {
    margin-bottom: 0;
}

.markdown-table {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.markdown-table table {
  width: max-content; 
  min-width: 600px;
  border-collapse: collapse;
}

.markdown-table {
  overscroll-behavior-x: contain;
}


.user-message,
.assistant-message,
.tool-message {
    scroll-margin-top: var(--main-menu-top);
    padding: 10px 0;
}


#responses p {
    margin-top: 0;
}

.responses-anchor-spacer {
    height: 0;
    pointer-events: none;
}

.copy-button {
    cursor: pointer;
    padding: 4px;
    font-size: 12px;
    color: var(--text-main);
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--background-alt) 86%, transparent);
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

pre code.copyable-code {
    position: relative;
    display: block;
}

pre code.copyable-code .copy-button {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    z-index: 2;
    width: 24px;
    height: 24px;
    padding: 0;
}

pre code.copyable-code .copy-button svg {
    width: 20px;
    height: 20px;
}

pre code.copyable-code .copy-button:hover {
    background: color-mix(in srgb, var(--background) 88%, transparent);
}

.loading-spinner {
    margin-top: 10px;
    pointer-events: none;
    width: 1.5em;
    height: 1.5em;
    border: 0.4em solid transparent;
    border-color: var(--focus);
    border-top-color: var(--selection);
    border-radius: 50%;
    animation: loadingspin 1s linear infinite;
    position: fixed;
    top: 50%;
    left: calc(50% - 12px);
}

.loading-model {
    pointer-events: none;
    width: 1em;
    height: 1em;
    border: 0.2em solid transparent;
    border-color: var(--focus);
    border-top-color: var(--selection);
    border-radius: 50%;
    animation: loadingspin 1s linear infinite;
}


@keyframes loadingspin {
    100% {
        transform: rotate(360deg);
    }
}

.actions button {
    all: unset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.actions button.hidden {
    display: none;
}

.actions svg {
    fill: var(--selection);
    width: 40px;
    height: 40px;
}

#abort svg {
    fill: var(--flash-error-color);
    width: 40px;
    height: 40px;
}

.actions button:disabled svg {
    fill: var(--selection);
    cursor: not-allowed;
    opacity: 0.2;
    /* Optional: makes the button look faded */
}

.actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
}

.actions-left {
    display: flex;
    justify-content: left;
    gap: 10px;
}

.actions-right {
    display: flex;
    justify-content: right;
    gap: 10px;
}

.page-chat textarea {
    resize: none;
}

.page-profile textarea {
    height: 315px;
    resize: vertical;
    overflow-y: hidden;
}

pre code {
    display: block;
    padding: 1em;
    overflow: auto;
    scrollbar-width: thin;
}

.menu-open {
    display: none;
}

/** on models sm: 576px */
@media (max-width: 575px) {
    #select-model {
        max-width: 200px;
    }
}

#select-model::-webkit-scrollbar {
    display: none;

}


#scroll-to-bottom {
    justify-content: center;
    align-items: center;
    display: none;
    position: fixed;
    right: 20px;
    bottom: 150px;
    z-index: 60;
    cursor: pointer;
}

#scroll-to-bottom svg {
    background-color: var(--background-body);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    border: 0px solid transparent;
    fill: var(--text-muted);
}

#message {
    height: 60px;
    overflow: auto;
    display: none;
}

/* on screens with small height make the chat textarea smaller */
@media (max-height: 800px) {
    #message {
        height: 60px;
    }
}

.message-actions {
    display: flex;
    gap: 0.5em;
    margin-top: 0.5em;
}

.message-actions svg {
    color: var(--nav-text);
    fill: var(--nav-text);
    width: 15px;
    height: 15px;
}

.edit-form {
    margin-top: 10px;
}

.edit-textarea {
    width: 100%;
    min-height: 60px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--background-alt);
    color: var(--text-main);
    resize: vertical;
    box-sizing: border-box;
}

.edit-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    justify-content: flex-end;
}

.edit-cancel, .edit-send {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--button-base);
    color: var(--text-main);
    cursor: pointer;
    font-size: 14px;
}

.edit-cancel:hover, .edit-send:hover {
    background-color: var(--button-hover);
}

.edit-send {
    background-color: var(--links);
    color: white;
    border-color: var(--links);
}

.edit-send:hover {
    background-color: var(--focus);
}

.edit-send:disabled {
    background-color: #666;
    color: #999;
    cursor: not-allowed;
}

.action-link {
    background-color: var(--nav-background);
    color: var(--nav-text);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background-color 0.3s;
    white-space: nowrap;
    height: 100%;
}

.action-link:hover {
    background-color: rgba(var(--nav-background-rgb), 0.75);
    text-decoration: none;
}

.action-link[disabled]{
    background-color: var(--nav-background);
    color: var(--text-muted);
    cursor: not-allowed;
}

a.is-disabled-link {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
}

.role {
    font-weight: 900;
    font-size: 1.1em;
    margin-top: 0;
    margin-bottom: 2px;
    display: flex;
    gap: 5px;
    align-items: anchor-center;
}

.role_user {
}

.role_assistant {
    color: dimgray;
}

.role_tool {
    color: dimgray;
}

.assistant-status {
    margin-top: 0;
    margin-bottom: 6px;
    font-size: 0.92em;
    color: var(--text-muted);
}

.role_tool.tool-toggle {
    cursor: pointer;
    user-select: none;
}

.role_tool.tool-toggle::after {
    content: " ▸";
    font-size: 0.9em;
    opacity: 0.7;
}

.role_tool.tool-toggle[aria-expanded="true"]::after {
    content: " ▾";
}

.tool-call-body {
    margin-top: 4px;
}

.thinking-block {
    margin: 4px 0;
}

.thinking-toggle {
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
    list-style: none;
}

.thinking-toggle::-webkit-details-marker {
    display: none;
}

.thinking-toggle::after {
    content: " ▸";
    font-size: 0.9em;
    opacity: 0.7;
}

.thinking-block[open] > .thinking-toggle::after {
    content: " ▾";
}

.thinking-body {
    margin-top: 4px;
}

.thinking-text {
    margin: 0;
}

.tool-message pre {
    background: rgba(0, 0, 0, 0.03);
    border: none;
    border-radius: 4px;
    padding: 0;
    overflow-x: auto;
    white-space: pre-wrap;
    margin-top: 6px;
}

table {
    border-collapse: collapse;
    margin-bottom: 10px;
    width: 100%;
    table-layout: auto;
    overflow-x: scroll;
}

#captcha-img {
    cursor: pointer;
}

/**
 * dialog page 
 */
.page-dialogs {
    overflow-x: hidden;
    overflow-y: scroll;
}

.page-dialogs .default-container {
    height: calc(100svh - var(--main-menu-top));
    min-height: calc(100svh - var(--main-menu-top));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.dialogs-toolbar {
    flex: 0 0 auto;
    padding-top: 0;
    padding-bottom: 8px;
    background: var(--background-body);
}

.dialogs-toolbar h3 {
    margin: 1.25em 0 8px;
}

#dialogs-search-form {
    margin: 0;
}

#dialogs-search-input {
    width: 100%;
    box-sizing: border-box;
}

.dialogs-scroll-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.dialogs-scroll-area::-webkit-scrollbar {
    display: none;
}

.dialogs {
    max-width: 100%;
}

#load-more-dialogs {
    margin-top: 8px;
}

.dialog {
    display: flex;
    gap: 0.3em;
}

.dialog a {
    display: inline-block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
}

a.delete svg {
    fill: var(--flash-error-color);
    height: 24px;
    width: 24px;
}

.pagination {
    margin-top: 10px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: 5px;
}

.hidden {
    display: none;
}

.katex { 
    font-size: 1.2em; 
}

.katex-display { overflow: auto hidden }

a {
    word-break: break-all;
    overflow-wrap: anywhere;
}
