.view--chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
}

.chat-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    flex: 1;
    min-height: 0;
}

.chat-sidebar {
    display: flex;
    flex-direction: column;
    gap: .55rem;
    padding: .85rem;
    border-right: 1px solid var(--border);
    background: rgba(4, 4, 4, 0.6);
    min-height: 0;
}

.chat-sidebar__title {
    margin: .25rem 0 0;
    font-size: .68rem;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 600;
}

#chat-sessions {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.chat-session-wrap {
    display: flex;
    align-items: center;
    gap: .25rem;
}

.chat-session {
    flex: 1;
    text-align: left;
    border: 1px solid transparent;
    background: var(--surface);
    color: var(--text-muted);
    border-radius: var(--radius-md);
    padding: .55rem .65rem;
    font-size: .8rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all .2s var(--ease);
}

.chat-session:hover {
    color: var(--text);
    border-color: var(--border);
}

.chat-session--active {
    border-color: var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
}

.chat-session__delete {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-subtle);
    cursor: pointer;
    flex-shrink: 0;
    font-size: .75rem;
}

.chat-session__delete:hover {
    background: rgba(248, 113, 113, 0.12);
    color: var(--danger);
}

.chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-welcome {
    max-width: 480px;
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
}

.chat-welcome h3 {
    margin: 0 0 .5rem;
    color: var(--text);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.chat-welcome ul {
    text-align: left;
    margin: 1.25rem auto 0;
    padding-left: 1.2rem;
    font-size: .88rem;
    line-height: 1.65;
    color: var(--text-subtle);
}

.chat-empty {
    text-align: center;
    color: var(--text-subtle);
    margin: auto;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: min(680px, 88%);
    padding: .8rem 1rem;
    border-radius: var(--radius-lg);
    line-height: 1.5;
    overflow: hidden;
    min-width: 0;
    font-size: .92rem;
}

.chat-msg--user {
    align-self: flex-end;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.chat-msg--assistant {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
}

.chat-msg__text {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-msg__media {
    margin-top: .6rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #000;
}

.chat-msg__media img {
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    display: block;
    cursor: zoom-in;
}

.chat-msg__actions {
    display: flex;
    gap: .45rem;
    padding: .45rem .6rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.chat-typing__dots {
    display: inline-flex;
    gap: .28rem;
}

.chat-typing__dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-subtle);
    animation: chat-dot 1.2s infinite ease-in-out;
}

.chat-typing__dots span:nth-child(2) { animation-delay: .15s; }
.chat-typing__dots span:nth-child(3) { animation-delay: .3s; }

@keyframes chat-dot {
    0%, 80%, 100% { opacity: .3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.chat-error {
    margin: 0 1rem;
    padding: .6rem .85rem;
    border-radius: var(--radius-md);
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.22);
    color: #fca5a5;
    font-size: .84rem;
}

.chat-composer {
    border-top: 1px solid var(--border);
    padding: .85rem 1.25rem calc(1rem + env(safe-area-inset-bottom, 0px));
    background: rgba(4, 4, 4, 0.85);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}

.chat-modes {
    display: flex;
    gap: .2rem;
    margin-bottom: .55rem;
    padding: .2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    width: fit-content;
}

.chat-mode {
    border: none;
    background: transparent;
    color: var(--text-subtle);
    padding: .35rem .75rem;
    border-radius: var(--radius-pill);
    font-size: .76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s var(--ease);
}

.chat-mode--active {
    background: var(--accent);
    color: #000;
    font-weight: 600;
}

.chat-mode-hint {
    margin: 0 0 .45rem;
    font-size: .72rem;
    color: var(--text-subtle);
}

.chat-ref-strip {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    margin-bottom: .5rem;
    padding: .55rem .65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}

.chat-ref-strip__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .5rem;
    flex-wrap: wrap;
}

.chat-ref-strip__label {
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.chat-ref-strip__hint {
    font-size: .66rem;
    color: var(--text-subtle);
}

.chat-ref-strip__slots {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.chat-ref-slot {
    position: relative;
    width: 88px;
    height: 88px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid var(--accent);
    background: #000;
    flex-shrink: 0;
}

.chat-ref-slot--empty {
    border: 1px dashed var(--border);
    background: var(--surface);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.chat-ref-slot--empty:hover {
    border-color: var(--border-strong);
}

.chat-ref-slot__add {
    font-size: 1.4rem;
    color: var(--text-subtle);
}

.chat-ref-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-ref-slot__badge {
    position: absolute;
    left: .28rem;
    bottom: .28rem;
    padding: .08rem .3rem;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: .58rem;
    font-weight: 700;
}

.chat-attach-preview {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: .4rem;
    padding: .5rem .6rem .5rem .75rem;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    max-width: 820px;
}

#chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    padding: .45rem 0;
    max-height: 120px;
    min-height: 24px;
    font-size: .92rem;
    min-width: 0;
}

#chat-input::placeholder {
    color: var(--text-subtle);
}