.chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 215;
    pointer-events: none;
}

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

.chat-drawer-panel {
    position: relative;
    height: 100%;
    width: min(480px, 100vw);
    background: #f8fbff;
    color: #183247;
    display: flex;
    flex-direction: column;
    box-shadow: -24px 0 60px rgba(15, 23, 42, 0.18);
    transform: translateX(100%);
    transition: transform 220ms ease-out;
    pointer-events: auto;
    border-left: 1px solid rgba(148, 163, 184, 0.24);
}

.chat-drawer:not([hidden]) .chat-drawer-panel {
    transform: translateX(0);
}

.chat-drawer-resize-handle {
    position: absolute;
    top: 0;
    left: -3px;
    bottom: 0;
    width: 6px;
    cursor: ew-resize;
    background: transparent;
    z-index: 2;
    pointer-events: auto;
    transition: background 120ms ease-out;
}

.chat-drawer-resize-handle:hover,
.chat-drawer-resize-handle:focus-visible {
    background: rgba(61, 146, 115, 0.35);
    outline: none;
}

body.chat-drawer-resizing {
    user-select: none;
    cursor: ew-resize;
}

body.chat-drawer-resizing .chat-drawer-resize-handle {
    background: rgba(61, 146, 115, 0.5);
}

.chat-drawer-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 22px 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.24);
}

.chat-drawer-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.chat-drawer-title-block {
    min-width: 0;
}

.chat-drawer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-drawer-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid rgba(148, 163, 184, 0.32);
    background: rgba(255, 255, 255, 0.85);
    color: #183247;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
}

.chat-drawer-toolbar-btn:hover {
    background: rgba(255, 255, 255, 1);
    border-color: rgba(148, 163, 184, 0.5);
}

.chat-drawer-toolbar-btn.chat-drawer-new {
    border-color: rgba(61, 146, 115, 0.4);
    background: rgba(61, 146, 115, 0.1);
    color: #2e785d;
    margin-left: auto;
    margin-bottom: 0;
    margin-top: 0;
}

.chat-drawer-toolbar-btn.chat-drawer-new:hover {
    background: rgba(61, 146, 115, 0.2);
}

.chat-drawer-caret {
    color: #64748b;
    font-size: 0.7rem;
}

.chat-drawer-conversations-menu {
    position: relative;
}

.chat-drawer-conversations-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 10;
    width: min(320px, 80vw);
    max-height: 320px;
    overflow-y: auto;
    background: white;
    border: 1px solid rgba(148, 163, 184, 0.32);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
    padding: 6px;
}

.chat-drawer-conversations-popover[hidden] {
    display: none;
}

.chat-drawer-title {
    margin: 0 0 4px;
    font-size: 1.1rem;
}

.chat-drawer-context {
    margin: 0;
    color: #64748b;
    font-size: 0.85rem;
}

.chat-drawer-close {
    background: transparent;
    border: 0;
    color: #64748b;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
}

.chat-drawer-close:hover {
    background: rgba(148, 163, 184, 0.18);
    color: #183247;
}

.chat-drawer-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-drawer-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-drawer-list li {
    margin-bottom: 2px;
}

.chat-drawer-list-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: #183247;
    font-size: 0.9rem;
}

.chat-drawer-list-item:hover {
    background: rgba(148, 163, 184, 0.16);
}

.chat-drawer-list-item.is-active {
    background: rgba(61, 146, 115, 0.16);
    color: #2e785d;
    font-weight: 600;
}

.chat-drawer-list-empty,
.chat-drawer-list-loading {
    padding: 10px 12px;
    color: #64748b;
    font-size: 0.85rem;
}

.chat-drawer-thread {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-drawer-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-drawer-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 92%;
}

.chat-drawer-message--user {
    background: rgba(61, 146, 115, 0.12);
    align-self: flex-end;
}

.chat-drawer-message--assistant {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.24);
    align-self: flex-start;
}

.chat-drawer-message-role {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
}

.chat-drawer-message-content {
    white-space: pre-wrap;
    line-height: 1.45;
    font-size: 0.95rem;
}

.chat-drawer-citations {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 6px;
    border-top: 1px dashed rgba(148, 163, 184, 0.32);
}

.chat-drawer-citation-label {
    font-size: 0.75rem;
    color: #64748b;
    width: 100%;
}

.chat-drawer-citation {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(61, 146, 115, 0.12);
    color: #2e785d;
    font-size: 0.8rem;
    text-decoration: none;
}

.chat-drawer-citation:hover {
    background: rgba(61, 146, 115, 0.22);
}

.chat-drawer-inline-citation {
    color: #2e785d;
    text-decoration: underline;
    text-decoration-color: rgba(61, 146, 115, 0.4);
    text-underline-offset: 2px;
}

.chat-drawer-inline-citation:hover {
    text-decoration-color: #2e785d;
}

.chat-drawer-empty {
    color: #64748b;
    font-size: 0.9rem;
    text-align: center;
    padding: 32px 16px;
}

.chat-drawer-form {
    border-top: 1px solid rgba(148, 163, 184, 0.24);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-drawer-textarea {
    resize: none;
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.32);
    border-radius: 10px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.95rem;
    background: white;
    color: #183247;
}

.chat-drawer-textarea:focus {
    outline: none;
    border-color: #3d9273;
    box-shadow: 0 0 0 3px rgba(61, 146, 115, 0.18);
}

.chat-drawer-submit {
    align-self: flex-end;
    background: #2e785d;
    color: white;
    border: 0;
    border-radius: 10px;
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
}

.chat-drawer-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-drawer-submit:not(:disabled):hover {
    background: #266a51;
}

.topbar-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-main);
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 999px;
    padding: 5px 12px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
}

.topbar-action-btn:hover {
    background: rgba(255, 255, 255, 1);
    border-color: rgba(148, 163, 184, 0.5);
}

.topbar-action-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-drawer-trigger {
    background: rgba(61, 146, 115, 0.12);
    color: #2e785d;
    border: 1px solid rgba(61, 146, 115, 0.32);
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
}

.chat-drawer-trigger:hover {
    background: rgba(61, 146, 115, 0.22);
}

.chat-floating-toggle {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 190;
    width: 66px;
    height: 66px;
    border: 0;
    border-radius: 50%;
    background: #2e785d;
    color: #fff;
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.24), 0 4px 10px rgba(46, 120, 93, 0.25);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.14s ease-out, box-shadow 0.14s ease-out, transform 0.14s ease-out;
}

.chat-floating-toggle:hover {
    background: #266a51;
    box-shadow: 0 18px 38px rgba(15, 23, 42, 0.28), 0 5px 12px rgba(46, 120, 93, 0.28);
    transform: translateY(-1px);
}

.chat-floating-toggle:focus-visible {
    outline: 3px solid rgba(61, 146, 115, 0.28);
    outline-offset: 3px;
}

.chat-floating-toggle-icon {
    flex: 0 0 auto;
}

body.chat-drawer-open .chat-floating-toggle {
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
}

@media (max-width: 720px) {
    .chat-drawer-panel {
        width: 100vw;
    }
    .chat-drawer-conversations-popover {
        width: min(360px, calc(100vw - 32px));
    }
    .chat-floating-toggle {
        right: 18px;
        bottom: 18px;
        width: 60px;
        height: 60px;
    }
}
