﻿/* =========================================================
   WorkItemChat.css
   Goals:
   - Bootstrap-variable based (works across XAF themes)
   - Sticky header/footer
   - Header auto-hide actually returns space (no dead whitespace)
   - Desktop (wide): details panel always visible as side column
   - Mobile/portrait: details is a flyout drawer + backdrop
   ========================================================= */

/* ---------- Tokens (Bootstrap-first) ---------- */
.wachat-shell {
    --wachat-radius: .85rem;
    --wachat-border: var(--bs-border-color, #dee2e6);
    --wachat-bg: var(--bs-body-bg, #fff);
    --wachat-surface: var(--bs-tertiary-bg, #f8f9fa);
    --wachat-text: var(--bs-body-color, #212529);
    --wachat-muted: var(--bs-secondary-color, #6c757d);
    --wachat-shadow: 0 .35rem 1rem rgba(0, 0, 0, .08);
    --wachat-primary-rgb: var(--bs-primary-rgb, 13, 110, 253);
    --wachat-mine-bg: rgba(var(--wachat-primary-rgb), .12);
    --wachat-mine-border: rgba(var(--wachat-primary-rgb), .35);
    --wachat-theirs-bg: var(--wachat-surface);
    --wachat-theirs-border: rgba(0, 0, 0, .12);
    --wachat-header-h: 56px;
    --wachat-compose-h: 68px;
    height: 90vh; /* you said 90vh is working well */
}

/* ---------- Layout: default (mobile/tablet) ---------- */
.wachat-shell {
    position: relative;
    display: block;
}

/* Chat card */
.wachat-root {
    height: 85vh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--wachat-bg);
    color: var(--wachat-text);
    border: 1px solid var(--wachat-border);
    border-radius: var(--wachat-radius);
    overflow: hidden;
}

/* ---------- Header (sticky + collapsible) ---------- */
.wachat-header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .5rem .75rem;
    background: var(--wachat-surface);
    border-bottom: 1px solid var(--wachat-border);
    min-height: var(--wachat-header-h);
    transition: top .18s ease, max-height .18s ease, padding .18s ease, border .18s ease;
}

    .wachat-header.hidden {
        top: calc(-1 * var(--wachat-header-h)); /* shove sticky anchor above the viewport */
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
        border-bottom: 0;
        min-height: 0;
        overflow: hidden;
        /* REMOVE transform: translateY(-100%); */
    }


.wachat-title {
    font-weight: 600;
    display: flex;
    align-items: baseline;
    gap: .5rem;
    line-height: 1.2;
}

.wachat-context {
    font-weight: 500;
    font-size: .9rem;
    color: var(--wachat-muted);
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}

.wachat-status {
    font-weight: 600;
    font-size: .8rem;
    padding: .18rem .45rem;
    border-radius: 999px;
    border: 1px solid var(--wachat-border);
    background: var(--wachat-bg);
    color: var(--wachat-text);
}

.wachat-header-actions {
    display: inline-flex;
    gap: .5rem;
    align-items: center;
}

/* Generic icon button */
.wachat-icon-btn,
.wachat-send {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: .75rem;
    border: 1px solid var(--wachat-border);
    background: var(--wachat-bg);
    color: var(--wachat-text);
    cursor: pointer;
    user-select: none;
    transition: background .12s ease, border-color .12s ease, transform .05s ease;
}

    .wachat-icon-btn:hover {
        background: var(--wachat-surface);
    }

    .wachat-icon-btn:active,
    .wachat-send:active {
        transform: translateY(1px);
    }

    /* DevExpress dx-icon sizing */
    .wachat-icon-btn .dx-icon,
    .wachat-send .dx-icon {
        font-size: 20px;
        line-height: 1;
    }

/* ---------- Messages ---------- */
.wachat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: .75rem;
    background: var(--wachat-bg);
}

/* Empty state */
.wachat-empty {
    color: var(--wachat-muted);
    padding: .75rem;
    border: 1px dashed var(--wachat-border);
    border-radius: var(--wachat-radius);
    background: var(--wachat-surface);
}

/* Row alignment */
.wachat-row {
    display: flex;
    margin: .35rem 0;
}

    .wachat-row.mine {
        justify-content: flex-end;
    }

    .wachat-row.theirs {
        justify-content: flex-start;
    }

/* Bubble */
.wachat-bubble {
    max-width: min(720px, 92%);
    border-radius: var(--wachat-radius);
    padding: .55rem .65rem;
    border: 1px solid var(--wachat-theirs-border);
    background: var(--wachat-theirs-bg);
    box-shadow: 0 1px 0 rgba(0,0,0,.03);
}

.wachat-row.mine .wachat-bubble {
    background: var(--wachat-mine-bg);
    border-color: var(--wachat-mine-border);
}

/* Meta line */
.wachat-meta {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .25rem;
}

.wachat-name {
    font-weight: 700;
    font-size: .9rem;
}

.wachat-time {
    font-size: .8rem;
    color: var(--wachat-muted);
    white-space: nowrap;
}

.wachat-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.35;
}

/* ---------- Images ---------- */
.wachat-image-grid {
    margin-top: .5rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
}

@media (min-width: 520px) {
    .wachat-image-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.wachat-image-tile {
    position: relative;
    border-radius: .75rem;
    overflow: hidden;
    border: 1px solid var(--wachat-border);
    background: var(--wachat-bg);
    cursor: pointer;
}

    .wachat-image-tile img {
        width: 100%;
        height: 120px;
        object-fit: cover;
        display: block;
    }

.wachat-image-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: .35rem .5rem;
    font-size: .75rem;
    color: #fff;
    background: linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0));
    opacity: 0;
    transition: opacity .12s ease;
}

.wachat-image-tile:hover .wachat-image-overlay {
    opacity: 1;
}

/* ---------- Lightbox ---------- */
.wachat-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

    .wachat-lightbox img {
        max-width: 96vw;
        max-height: 92vh;
        border-radius: var(--wachat-radius);
        border: 1px solid rgba(255,255,255,.18);
    }

/* ---------- Compose (sticky) ---------- */
.wachat-compose {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: .5rem;
    align-items: end;
    padding: .6rem .75rem;
    background: var(--wachat-surface);
    border-top: 1px solid var(--wachat-border);
    min-height: var(--wachat-compose-h);
}

.wachat-input {
    resize: none;
    min-height: 44px;
    max-height: 160px;
    padding: .6rem .75rem;
    border-radius: .85rem;
    border: 1px solid var(--wachat-border);
    background: var(--wachat-bg);
    color: var(--wachat-text);
    outline: none;
    width: 100%;
    line-height: 1.25;
}

    .wachat-input:focus {
        border-color: rgba(var(--wachat-primary-rgb), .55);
        box-shadow: 0 0 0 .2rem rgba(var(--wachat-primary-rgb), .15);
    }

/* Attach label looks like a button */
label.wachat-icon-btn {
    margin: 0;
}

/* Send button: filled */
.wachat-send {
    border-color: rgba(var(--wachat-primary-rgb), .35);
    background: rgba(var(--wachat-primary-rgb), .25);
}

    .wachat-send:hover {
        background: rgba(var(--wachat-primary-rgb), .32);
    }

    .wachat-send:disabled {
        opacity: .45;
        cursor: not-allowed;
        transform: none;
    }

/* ---------- Drawer (mobile flyout) ---------- */
.wachat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 9000;
}

.wachat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(420px, 92vw);
    height: 100vh;
    background: var(--wachat-bg);
    border-left: 1px solid var(--wachat-border);
    box-shadow: var(--wachat-shadow);
    z-index: 9001;
    transform: translateX(110%);
    transition: transform .18s ease;
    display: flex;
    flex-direction: column;
}

    .wachat-drawer.open {
        transform: translateX(0);
    }

.wachat-drawer-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem .75rem;
    background: var(--wachat-surface);
    border-bottom: 1px solid var(--wachat-border);
}

.wachat-drawer-title {
    font-weight: 700;
    flex: 1;
}

.wachat-drawer-body {
    overflow: auto;
    padding: .75rem;
}

/* Meta grid */
.wachat-meta-grid {
    display: grid;
    gap: .65rem;
}

.wachat-kv {
    border: 1px solid var(--wachat-border);
    background: var(--wachat-bg);
    border-radius: .75rem;
    padding: .55rem .6rem;
}

/* Description in drawer */
.wachat-kv-full {
    grid-column: 1 / -1;
}

.wachat-desc {
    white-space: pre-wrap;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    border-radius: .5rem;
    padding: .75rem;
    line-height: 1.35;
    max-height: 14rem;
    overflow: auto;
}

.wachat-k {
    font-size: .72rem;
    color: var(--wachat-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: .15rem;
}

.wachat-v {
    font-weight: 600;
    color: var(--wachat-text);
    word-break: break-word;
}

/* =========================================================
   Desktop: always-visible info panel
   Only collapse to flyout on smaller screens
   ========================================================= */
@media (min-width: 992px) {
    .wachat-shell {
        display: grid;
        grid-template-columns: 1fr 380px;
        gap: .75rem;
        align-items: stretch;
    }

    /* On desktop the drawer becomes a normal side panel */
    .wachat-drawer {
        position: sticky;
        top: 0;
        height: 100%;
        width: auto;
        transform: none !important;
        z-index: 1;
        border-radius: var(--wachat-radius);
        border: 1px solid var(--wachat-border);
        box-shadow: none;
    }

    /* Backdrop never shown on desktop */
    .wachat-backdrop {
        display: none !important;
    }

    /* The "Details" toggle button is not needed on desktop */
    .wachat-details-btn {
        display: none !important;
    }

    .wachat-close-btn {
        display: none !important;
    }
}
