/*
 * History and Gallery surfaces
 *
 * Ownership: docs/architecture/css-ownership.md
 * Loaded after custom.css while the published stylesheet is decomposed.
 */

.chat-history-shell[hidden] {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .chat-gallery-card__trigger:hover,
    .chat-gallery-card__trigger:focus-visible {
        transform: none;
    }
}

.chat-gallery-shell[hidden] {
    display: none !important;
}

.chat-history-shell,
.chat-gallery-shell {
    position: fixed;
    inset: 0;
    z-index: 1002;
}

.chat-gallery-shell {
    z-index: 1003;
}

.chat-history-shell__backdrop,
.chat-gallery-shell__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 7, 16, 0.88);
    backdrop-filter: blur(6px);
}

.chat-history-shell__panel,
.chat-gallery-shell__panel {
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(1120px, calc(100vw - 72px));
    height: min(88vh, 920px);
    margin: min(6vh, 48px) auto;
    background: rgba(10, 13, 28, 0.96);
    border: 1px solid rgba(120, 132, 220, 0.24);
    border-radius: 26px;
    box-shadow: 0 28px 72px rgba(5, 6, 14, 0.72);
    overflow: hidden;
}

.chat-gallery-shell__panel {
    width: min(1180px, calc(100vw - 56px));
}

.chat-history-shell__header,
.chat-gallery-shell__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 22px 24px 18px;
    border-bottom: 1px solid rgba(120, 132, 220, 0.16);
    background: rgba(12, 14, 29, 0.96);
}

.chat-history-shell__heading,
.chat-gallery-shell__heading {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.chat-history-shell__title,
.chat-gallery-shell__title {
    margin: 0;
    color: var(--color-text-primary);
    font-size: 1.55rem;
    line-height: 1.15;
}

.chat-history-shell__meta,
.chat-gallery-shell__meta {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.88rem;
    line-height: 1.5;
}

.chat-history-shell__actions,
.chat-gallery-shell__actions {
    display: grid;
    justify-items: end;
    gap: 10px;
    flex-shrink: 0;
}

.chat-history-shell__count,
.chat-gallery-shell__count {
    color: rgba(232, 244, 255, 0.72);
    font-size: 0.78rem;
    font-weight: 700;
}

.chat-history-shell__close,
.chat-gallery-shell__close {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(120, 132, 220, 0.26);
    background: rgba(18, 20, 38, 0.82);
    color: var(--color-text-primary);
    font-size: 0.84rem;
    font-weight: 700;
    cursor: pointer;
}

.chat-history-shell__body,
.chat-gallery-shell__body {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 16px;
    padding: 22px 24px 26px;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

.chat-history-shell__status,
.chat-gallery-shell__status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.chat-history-shell__note,
.chat-history-shell__feedback,
.chat-gallery-shell__note,
.chat-gallery-shell__feedback {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.86rem;
    line-height: 1.5;
}

.chat-history-shell__load,
.chat-gallery-shell__load {
    flex-shrink: 0;
}

.chat-history-shell__transcript {
    display: grid;
    gap: 0;
    min-width: 0;
    overflow: visible;
    width: min(100%, 880px);
    justify-self: center;
    grid-auto-rows: max-content;
    align-items: start;
}

.chat-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 18px;
}

.chat-gallery-card {
    display: block;
}

.chat-gallery-card__trigger {
    width: 100%;
    display: grid;
    gap: 14px;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(118, 174, 164, 0.18);
    border-radius: 6px;
    background: rgba(14, 27, 30, 0.56);
    cursor: pointer;
    text-align: left;
    color: inherit;
    transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.chat-gallery-card__trigger:hover,
.chat-gallery-card__trigger:focus-visible {
    border-color: rgba(218, 146, 88, 0.46);
    background: rgba(21, 40, 42, 0.82);
    transform: translateY(-1px);
    outline: none;
}

.chat-gallery-card__frame {
    display: block;
    aspect-ratio: 16 / 10;
    border-radius: 5px 5px 0 0;
    overflow: hidden;
    background: rgba(7, 10, 22, 0.78);
    border: 0;
}

.chat-gallery-card__image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-gallery-card__content {
    display: grid;
    gap: 6px;
    padding: 0 14px 14px;
}

.chat-gallery-card__title {
    margin: 0;
    color: var(--color-text-primary);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1rem;
    line-height: 1.3;
}

.chat-gallery-card__meta,
.chat-gallery-card__anchor {
    color: var(--color-text-muted);
    font-size: 0.74rem;
    line-height: 1.35;
}

.chat-gallery-card__anchor {
    color: #63aaa0;
    font-weight: 700;
}

.chat-gallery-card__excerpt {
    display: none;
}

.chat-gallery-viewer[hidden] {
    display: none !important;
}

.chat-gallery-viewer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 18px;
    background: rgba(7, 10, 22, 0.92);
    backdrop-filter: blur(6px);
}

.chat-gallery-viewer__dialog {
    position: relative;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    width: min(100%, 980px);
    height: 100%;
    gap: 16px;
    padding: 18px;
    border-radius: 6px;
    border: 1px solid rgba(118, 174, 164, 0.22);
    background: #0e1b1e;
    box-shadow: 0 24px 60px rgba(5, 6, 14, 0.6);
}

.chat-gallery-viewer__close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid rgba(120, 132, 220, 0.18);
    background: rgba(18, 20, 38, 0.9);
    color: var(--color-text-primary);
    cursor: pointer;
}

.chat-gallery-viewer__media {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    min-height: 0;
}

.chat-gallery-viewer__nav {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(120, 132, 220, 0.18);
    background: rgba(18, 20, 38, 0.9);
    color: var(--color-text-primary);
    cursor: pointer;
}

.chat-gallery-viewer__nav:disabled {
    opacity: 0.45;
    cursor: default;
}

.chat-gallery-viewer__image {
    width: 100%;
    max-height: min(62vh, 640px);
    object-fit: contain;
    border-radius: 5px;
    border: 1px solid rgba(118, 174, 164, 0.16);
    background: #071013;
}

.chat-gallery-viewer__content {
    display: grid;
    gap: 12px;
    align-content: start;
}

.chat-gallery-viewer__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.chat-gallery-viewer__title {
    margin: 0 0 6px;
    color: var(--color-text-primary);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.2rem;
    line-height: 1.25;
}

.chat-gallery-viewer__meta {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
}

.chat-gallery-viewer__excerpt {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.chat-history-turn {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 0;
    margin-top: 16px;
    padding: 22px 0 8px;
    border-top: 1px solid rgba(118, 174, 164, 0.14);
    background: transparent;
}

.chat-history-turn__label {
    margin: 0;
    color: #da9258;
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
}

.chat-history-message {
    display: grid;
    gap: 8px;
    padding: 10px 0 18px 18px;
    border: 0;
    border-left: 2px solid rgba(118, 174, 164, 0.3);
    border-radius: 0;
    background: transparent;
    min-width: 0;
    overflow: hidden;
    height: auto;
    min-height: max-content;
    align-self: start;
}

.chat-history-message--assistant {
    border-left-color: rgba(218, 146, 88, 0.62);
}

.chat-history-message--user {
    border-left-color: rgba(99, 170, 160, 0.62);
}

.chat-history-message--system {
    border-left-style: dashed;
    border-left-color: rgba(158, 176, 173, 0.38);
}

.chat-history-message__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    flex-wrap: wrap;
}

.chat-history-message__author {
    color: var(--color-text-primary);
    font-size: 0.82rem;
    line-height: 1.3;
}

.chat-history-message__time {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.chat-history-message__content {
    color: #d7dfdc;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1rem;
    line-height: 1.7;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-history-message__content > :not(img) {
    max-width: 74ch;
}

.chat-history-message__content pre,
.chat-history-message__content code,
.chat-history-message__content a {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-history-message__content p:last-child,
.chat-history-message__content ul:last-child,
.chat-history-message__content ol:last-child {
    margin-bottom: 0;
}

.chat-history-message__image {
    display: block;
    width: 100%;
    max-width: min(520px, 100%);
    border-radius: 6px;
    border: 1px solid rgba(118, 174, 164, 0.18);
    cursor: pointer;
    margin-bottom: 12px;
}

.chat-history-message__actions {
    margin-top: 10px;
}

.chat-consult-view[data-consult-view-panel="history"] .chat-campaign-space-shell__panel,
.chat-consult-view[data-consult-view-panel="gallery"] .chat-campaign-space-shell__panel {
    width: min(100%, 1040px);
    margin: 0 auto;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
}

.chat-consult-view[data-consult-view-panel="history"] .chat-history-shell__header,
.chat-consult-view[data-consult-view-panel="gallery"] .chat-gallery-shell__header {
    align-items: end;
    padding: 4px 0 24px;
    border-bottom: 1px solid rgba(218, 146, 88, 0.2);
    background: transparent;
}

.chat-memory-surface__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    color: #da9258;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
}

.chat-consult-view[data-consult-view-panel="history"] .chat-history-shell__heading,
.chat-consult-view[data-consult-view-panel="gallery"] .chat-gallery-shell__heading {
    gap: 6px;
}

.chat-consult-view[data-consult-view-panel="history"] .chat-history-shell__title,
.chat-consult-view[data-consult-view-panel="gallery"] .chat-gallery-shell__title {
    color: #edf2ec;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(1.55rem, 2.4vw, 2.15rem);
    line-height: 1.18;
}

.chat-consult-view[data-consult-view-panel="history"] .chat-history-shell__body,
.chat-consult-view[data-consult-view-panel="gallery"] .chat-gallery-shell__body {
    padding: 18px 0 28px;
}

.chat-history-message.is-gallery-focus {
    border-left-color: #da9258;
    background: rgba(218, 146, 88, 0.08);
    outline: 1px solid rgba(218, 146, 88, 0.2);
    outline-offset: 6px;
}

@media (max-width: 991px) {
    .chat-consult-panel[data-consult-active-view="history"],
    .chat-consult-panel[data-consult-active-view="gallery"] {
        width: 100%;
    }

    .chat-consult-panel[data-consult-active-view="history"] .chat-campaign-space__header,
    .chat-consult-panel[data-consult-active-view="gallery"] .chat-campaign-space__header {
        padding-bottom: 6px;
        margin-bottom: 4px;
    }

    .chat-consult-panel[data-consult-active-view="history"] .chat-campaign-space__meta,
    .chat-consult-panel[data-consult-active-view="gallery"] .chat-campaign-space__meta {
        display: none;
    }

    .chat-consult-panel[data-consult-active-view="history"] .chat-campaign-space__title,
    .chat-consult-panel[data-consult-active-view="gallery"] .chat-campaign-space__title {
        font-size: 1.05rem;
        line-height: 1.2;
    }

    .chat-consult-panel[data-consult-active-view="history"] .chat-consult-panel__tabs,
    .chat-consult-panel[data-consult-active-view="gallery"] .chat-consult-panel__tabs {
        margin-bottom: 4px;
    }

    .chat-history-shell__panel,
    .chat-gallery-shell__panel {
        width: 100%;
        height: auto;
        margin: 0;
        border-radius: 0;
    }

    .chat-history-shell__header,
    .chat-gallery-shell__header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px 12px 10px;
    }

    .chat-consult-view[data-consult-view-panel="history"] .chat-history-shell__header,
    .chat-consult-view[data-consult-view-panel="gallery"] .chat-gallery-shell__header {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-history-shell__title,
    .chat-gallery-shell__title {
        font-size: 1.05rem;
    }

    .chat-history-shell__actions,
    .chat-gallery-shell__actions {
        justify-items: stretch;
    }

    .chat-history-shell__close,
    .chat-gallery-shell__close {
        justify-content: center;
        min-height: 46px;
    }

    .chat-history-shell__body,
    .chat-gallery-shell__body {
        padding: 14px;
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    }

    .chat-history-shell__transcript {
        width: 100%;
    }

    .chat-history-message {
        padding: 10px 0 18px 14px;
        max-width: 100%;
    }

    .chat-history-message__header {
        flex-direction: column;
        gap: 6px;
    }

    .chat-history-message__time {
        white-space: normal;
    }

    .chat-history-message__content {
        font-size: 0.96rem;
        line-height: 1.68;
    }

    .chat-history-message__content > :not(img) {
        max-width: none;
    }

    .chat-gallery-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    .chat-gallery-viewer {
        padding: 0;
    }

    .chat-gallery-viewer__dialog {
        width: 100%;
        height: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        padding: 56px 16px 18px;
    }

    .chat-gallery-viewer__media {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto;
    }

    .chat-gallery-viewer__nav {
        width: 100%;
        min-height: 44px;
        order: 2;
    }

    .chat-gallery-viewer__image {
        max-height: 52vh;
    }

    .chat-gallery-viewer__header {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-consult-view[data-consult-view-panel="history"],
    .chat-consult-view[data-consult-view-panel="gallery"] {
        padding: 8px 16px 24px;
    }

    .chat-consult-view[data-consult-view-panel="history"] .chat-history-shell__header,
    .chat-consult-view[data-consult-view-panel="gallery"] .chat-gallery-shell__header {
        padding: 4px 0 18px;
    }

    .chat-consult-view[data-consult-view-panel="history"] .chat-history-shell__body,
    .chat-consult-view[data-consult-view-panel="gallery"] .chat-gallery-shell__body {
        padding: 12px 0 max(24px, env(safe-area-inset-bottom));
    }

    .chat-history-shell__panel,
    .chat-gallery-shell__panel {
        height: 100%;
        min-height: 0;
    }

    .chat-history-shell__body,
    .chat-gallery-shell__body {
        min-height: 0;
    }
}
