#interface-chat-root {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 800;
    display: grid;
    justify-items: end;
    gap: 0.5rem;
}

#interface-chat-root[hidden] {
    display: none;
}

.app-chat-launcher,
.app-chat-inspector {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.25rem;
    height: 3.25rem;
    border: 1px solid #5b6672;
    border-radius: 50%;
    background: #252b32;
    box-shadow: 0 0.625rem 1.5rem rgba(0, 0, 0, 0.32);
    cursor: pointer;
}

.app-chat-launcher:hover,
.app-chat-launcher:focus-visible,
.app-chat-inspector:hover,
.app-chat-inspector:focus-visible,
.app-chat-inspector[aria-pressed="true"] {
    border-color: #1592db;
    background: #303741;
    outline: none;
}

.app-chat-inspector {
    width: 2.5rem;
    height: 2.5rem;
    margin-right: 0.375rem;
    color: #e6eaf0;
    font-size: 1.125rem;
    font-weight: 700;
}

.app-chat-inspector[aria-pressed="true"] {
    box-shadow: 0 0 0 0.1875rem rgba(21, 146, 219, 0.24), 0 0.625rem 1.5rem rgba(0, 0, 0, 0.32);
}

.app-chat-launcher img {
    width: 2rem;
    height: 2rem;
    object-fit: contain;
}

.app-chat-panel {
    display: grid;
    grid-template-rows: 0.75rem auto minmax(0, 1fr) auto;
    width: min(23rem, calc(100vw - 2rem));
    height: min(32rem, calc(100vh - 2rem));
    min-height: min(20rem, calc(100vh - 2rem));
    max-height: calc(100vh - 2rem);
    border: 1px solid #525d69;
    border-radius: 0.5rem;
    background: #20252b;
    box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.42);
    color: #ffffff;
    overflow: hidden;
}

.app-chat-resize-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 0.75rem;
    background: #252b32;
    cursor: ns-resize;
    touch-action: none;
}

.app-chat-resize-handle::before {
    width: 2.5rem;
    height: 0.1875rem;
    border-radius: 0.1875rem;
    background: #66717d;
    content: '';
}

.app-chat-resize-handle:hover::before,
.app-chat-resize-handle:focus-visible::before {
    background: #1592db;
}

.app-chat-resize-handle:focus-visible {
    outline: 1px solid #1592db;
    outline-offset: -1px;
}

body.app-chat-resizing {
    cursor: ns-resize;
    user-select: none;
}

.app-chat-panel[hidden],
.app-chat-launcher[hidden],
.app-chat-inspector[hidden] {
    display: none;
}

.app-chat-inspector-highlight {
    position: fixed;
    z-index: 1899;
    border: 2px solid #1592db;
    border-radius: 0.375rem;
    background: rgba(21, 146, 219, 0.08);
    box-shadow: 0 0 0 0.25rem rgba(21, 146, 219, 0.22), 0 0.5rem 1.25rem rgba(0, 0, 0, 0.28);
    pointer-events: none;
}

.app-chat-inspector-highlight[hidden] {
    display: none;
}

body.app-interface-inspector-active {
    cursor: help;
}

.app-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 3.5rem;
    border-bottom: 1px solid #3a424c;
    background: #252b32;
    padding: 0.625rem 0.75rem;
}

.app-chat-identity {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
}

.app-chat-identity img {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    object-fit: contain;
}

.app-chat-identity div {
    display: grid;
    gap: 0.125rem;
    min-width: 0;
}

.app-chat-identity strong {
    overflow: hidden;
    color: #ffffff;
    font-size: 0.875rem;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-chat-identity span {
    color: #9faab7;
    font-size: 0.6875rem;
}

.app-chat-close,
.app-chat-header-inspector,
.app-chat-settings-button,
.app-chat-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    cursor: pointer;
}

.app-chat-close,
.app-chat-header-inspector,
.app-chat-settings-button {
    background: transparent;
    color: #cbd4df;
    font-size: 0.75rem;
    font-weight: 700;
}

.app-chat-close:hover,
.app-chat-close:focus-visible,
.app-chat-header-inspector:hover,
.app-chat-header-inspector:focus-visible,
.app-chat-settings-button:hover,
.app-chat-settings-button:focus-visible {
    border-color: #525d69;
    background: #303741;
    color: #ffffff;
    outline: none;
}

.app-chat-settings {
    position: relative;
}

.app-chat-settings-button {
    font-size: 1rem;
    line-height: 1;
}

.app-chat-settings-menu {
    position: absolute;
    top: calc(100% + 0.375rem);
    right: 0;
    z-index: 1;
    width: 9.5rem;
    border: 1px solid #525d69;
    border-radius: 0.375rem;
    background: #252b32;
    box-shadow: 0 0.625rem 1.5rem rgba(0, 0, 0, 0.32);
    padding: 0.375rem;
}

.app-chat-settings-menu[hidden] {
    display: none;
}

.app-chat-clear-button {
    width: 100%;
    min-height: 2rem;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    background: transparent;
    color: #dce3eb;
    cursor: pointer;
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    text-align: left;
}

.app-chat-clear-button:hover,
.app-chat-clear-button:focus-visible {
    border-color: #525d69;
    background: #303741;
    color: #ffffff;
    outline: none;
}

.app-chat-clear-button:disabled {
    cursor: default;
    opacity: 0.5;
}

.app-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 0 0 auto;
}

.app-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    min-height: 0;
    overflow-y: auto;
    padding: 0.75rem;
    scrollbar-color: #566372 transparent;
    scrollbar-width: thin;
}

.app-chat-messages::-webkit-scrollbar {
    width: 0.375rem;
}

.app-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.app-chat-messages::-webkit-scrollbar-thumb {
    border-radius: 0.375rem;
    background: #566372;
}

.app-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #748190;
}

.app-chat-message {
    width: fit-content;
    max-width: 88%;
    border: 1px solid #3a424c;
    border-radius: 0.5rem;
    background: #2a3038;
    padding: 0.625rem 0.75rem;
}

.app-chat-message.assistant {
    align-self: flex-start;
}

.app-chat-message.pending {
    opacity: 0.7;
}

.app-chat-message.user {
    align-self: flex-end;
    border-color: #c6d8f3;
    background: #edf2fc;
}

.app-chat-message p {
    margin: 0;
    color: #e6eaf0;
    font-size: 0.8125rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.app-chat-message-title {
    display: block;
    margin-bottom: 0.25rem;
    color: #ffffff;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.app-chat-message.user p {
    color: #203a63;
}

.app-chat-message-footer {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.375rem;
    margin-top: 0.375rem;
}

.app-chat-message.user .app-chat-message-footer {
    justify-content: flex-end;
}

.app-chat-message-time {
    color: #929eac;
    font-size: 0.625rem;
    line-height: 1.2;
    white-space: nowrap;
}

.app-chat-copy-button-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.375rem;
    height: 1.375rem;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    background: transparent;
    color: #aeb8c4;
    cursor: pointer;
    padding: 0;
    font-size: 0.75rem;
    line-height: 1;
}

.app-chat-copy-button-small:hover,
.app-chat-copy-button-small:focus-visible {
    border-color: #566372;
    background: #303741;
    color: #ffffff;
    outline: none;
}

.app-chat-message.user .app-chat-message-time {
    color: #667995;
}

.app-chat-message.user .app-chat-copy-button-small {
    color: #526987;
}

.app-chat-message.user .app-chat-copy-button-small:hover,
.app-chat-message.user .app-chat-copy-button-small:focus-visible {
    border-color: #9fb5d5;
    background: #dce6f6;
    color: #203a63;
}

.app-chat-choices {
    display: grid;
    gap: 0.375rem;
    margin-top: 0.625rem;
}

.app-chat-choices button {
    min-height: 2rem;
    border: 1px solid #566372;
    border-radius: 0.375rem;
    background: #303741;
    color: #dce3eb;
    cursor: pointer;
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    text-align: left;
}

.app-chat-choices button:hover,
.app-chat-choices button:focus-visible {
    border-color: #1592db;
    color: #ffffff;
    outline: none;
}

.app-chat-choices button:disabled {
    cursor: default;
    opacity: 0.55;
}

.app-chat-composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 0.5rem;
    border-top: 1px solid #3a424c;
    background: #252b32;
    padding: 0.625rem;
}

.app-chat-composer[hidden] {
    display: none;
}

.app-chat-input {
    width: 100%;
    min-height: 2.25rem;
    max-height: 6rem;
    border: 1px solid #525d69;
    border-radius: 0.375rem;
    background: #171b20;
    color: #ffffff;
    padding: 0.5rem 0.625rem;
    font: inherit;
    font-size: 0.8125rem;
    line-height: 1.35;
    resize: none;
}

.app-chat-input:focus {
    border-color: #1592db;
    outline: none;
}

.app-chat-input::placeholder {
    color: #8793a1;
}

.app-chat-send {
    background: #1592db;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
}

.app-chat-send:hover,
.app-chat-send:focus-visible {
    background: #38a9ed;
    outline: none;
}

.app-chat-send:disabled {
    background: #4a535d;
    color: #89939e;
    cursor: default;
}

body.app-chat-ai-available .materials-stage-save-reminder {
    right: 5rem;
}

@media (max-width: 520px) {
    #interface-chat-root {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .app-chat-panel {
        width: calc(100vw - 1.5rem);
        height: min(30rem, calc(100vh - 1.5rem));
        min-height: min(20rem, calc(100vh - 1.5rem));
        max-height: calc(100vh - 1.5rem);
    }

    body.app-chat-ai-available .materials-stage-save-reminder {
        right: 4.75rem;
        max-width: calc(100vw - 5.5rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-chat-inspector-highlight {
        transition: none;
    }
}
