

/* css/chat.css */


/* css/chat.css */

:root {
    /* =====================================================
       BRAND / PRIMARY
       ===================================================== */

    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #60a5fa;
    --color-secondary: #0f172a;
    --color-secondary-light: #1e293b;
    --color-accent: #06b6d4;
    --color-accent-light: #22d3ee;

    /* =====================================================
       TEXT
       ===================================================== */

    --color-text: #e2e8f0;
    --color-text-muted: #a8b5c7;
    --color-text-light: #7f8ea3;
    --color-text-inverse: #ffffff;

    /* =====================================================
       PAGE BACKGROUNDS
       ===================================================== */

    --color-background: #172337;
    --color-background-soft: #1c2a3d;
    --color-background-muted: #243449;

    /* =====================================================
       SURFACES / CARDS / PANELS
       ===================================================== */

    --color-surface: #1e2d42;
    --color-surface-soft: #223349;
    --color-surface-hover: #283b53;
    --color-surface-active: #2b4568;

    /* =====================================================
       BORDERS
       ===================================================== */

    --color-border: #31445c;
    --color-border-light: #283a50;
    --color-border-strong: #405672;

    /* =====================================================
       INTERACTION
       ===================================================== */

    --color-hover: #263b57;
    --color-active: #294b78;
    --color-focus: rgba(37, 99, 235, 0.28);

    /* =====================================================
       STATUS COLORS
       ===================================================== */

    --color-success: #22c55e;
    --color-success-light: #16452b;
    --color-warning: #f59e0b;
    --color-warning-light: #533a12;
    --color-danger: #ef4444;
    --color-danger-light: #542027;
    --color-info: #38bdf8;
    --color-info-light: #16455a;

    /* =====================================================
       TYPOGRAPHY
       ===================================================== */

    --font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-md: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-2xl: 32px;
    --font-size-3xl: 42px;
    --font-size-4xl: 56px;

    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --font-weight-extrabold: 800;

    /* =====================================================
       LAYOUT
       ===================================================== */

    --container-width: 1280px;
    --content-width: 1180px;
    --header-height: 72px;

    /* =====================================================
       SPACING
       ===================================================== */

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
    --space-20: 80px;

    /* =====================================================
       RADIUS
       ===================================================== */

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* =====================================================
       SHADOWS
       ===================================================== */

    --shadow-sm: 0 1px 3px rgba(2, 8, 23, 0.12);
    --shadow-md: 0 8px 24px rgba(2, 8, 23, 0.16);
    --shadow-lg: 0 16px 40px rgba(2, 8, 23, 0.22);
    --shadow-xl: 0 24px 60px rgba(2, 8, 23, 0.30);

    /* =====================================================
       TRANSITIONS
       ===================================================== */

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}


/* =========================================================
   WSPACE AI — SHARED CHAT
   ========================================================= */

.wspace-chat,
.wspace-chat *,
.wspace-chat *::before,
.wspace-chat *::after {
    box-sizing: border-box;
}


/* =========================================================
   HIDDEN ELEMENTS
   ========================================================= */

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


/* =========================================================
   CHAT CONTAINER
   ========================================================= */

.wspace-chat {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99999;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
}


/* =========================================================
   CHAT TOGGLE
   ========================================================= */

/* =========================================================
   CHAT TOGGLE — HIGH VISIBILITY / CTA
   ========================================================= */

.wspace-chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--color-primary);
    color: #ffffff;
    cursor: pointer;
    box-shadow:
        0 8px 24px rgba(37, 99, 235, 0.30),
        0 4px 10px rgba(15, 23, 42, 0.18);
    transition:
        transform 0.25s ease,
        box-shadow 0.25s ease,
        background 0.25s ease;
    isolation: isolate;
    animation: wspace-chat-float 3.2s ease-in-out infinite;
}

/* Expanding attention ring */
.wspace-chat-toggle::before {
    content: "";
    position: absolute;
    inset: -7px;
    border: 2px solid var(--color-primary-light);
    border-radius: 50%;
    opacity: 0;
    z-index: -1;
    animation: wspace-chat-ring 3.2s ease-out infinite;
}

/* Soft outer glow */
.wspace-chat-toggle::after {
    content: "";
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.35);
    z-index: -1;
    animation: wspace-chat-glow 3.2s ease-out infinite;
}

/* Icon */
.wspace-chat-toggle svg {
    width: 27px;
    height: 27px;
    stroke-width: 2.3;
    transition:
        transform 0.25s ease,
        stroke-width 0.25s ease;
}

/* Hover */
.wspace-chat-toggle:hover {
    transform: translateY(-3px) scale(1.06);
    box-shadow:
        0 12px 30px rgba(37, 99, 235, 0.38),
        0 6px 14px rgba(15, 23, 42, 0.20);
    animation-play-state: paused;
}

.wspace-chat-toggle:hover::before,
.wspace-chat-toggle:hover::after {
    animation-play-state: paused;
}

.wspace-chat-toggle:hover svg {
    transform: scale(1.08);
    stroke-width: 2.5;
}

/* Keyboard accessibility */
.wspace-chat-toggle:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 4px rgba(255, 255, 255, 0.95),
        0 0 0 7px var(--color-primary),
        0 10px 28px rgba(37, 99, 235, 0.35);
}

/* =========================================================
   CHAT ATTENTION ANIMATIONS
   ========================================================= */

@keyframes wspace-chat-float {
    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

@keyframes wspace-chat-ring {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }

    15% {
        opacity: 0.75;
    }

    55% {
        transform: scale(1.18);
        opacity: 0;
    }

    100% {
        transform: scale(1.18);
        opacity: 0;
    }
}

@keyframes wspace-chat-glow {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }

    15% {
        box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.18);
    }

    45% {
        box-shadow: 0 0 0 11px rgba(37, 99, 235, 0);
    }
}


/* =========================================================
   UNREAD BADGE
   ========================================================= */

.wspace-chat-unread {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 21px;
    height: 21px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border: 2px solid #ffffff;
    border-radius: 999px;
    background: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 3px 8px rgba(239, 68, 68, 0.35);
    z-index: 3;
}

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


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 1199px) {
    .wspace-chat-toggle {
        display: flex;
    }
}


/* =========================================================
   SMALL PHONES
   ========================================================= */

@media (max-width: 480px) {
    .wspace-chat-toggle {
        width: 56px;
        height: 56px;
    }

    .wspace-chat-toggle svg {
        width: 25px;
        height: 25px;
    }

    .wspace-chat-unread {
        top: -2px;
        right: -2px;
        min-width: 20px;
        height: 20px;
        font-size: 10px;
    }
}


/* =========================================================
   VERY SMALL PHONES
   ========================================================= */

@media (max-width: 360px) {
    .wspace-chat-toggle {
        width: 52px;
        height: 52px;
    }

    .wspace-chat-toggle svg {
        width: 23px;
        height: 23px;
    }

    .wspace-chat-unread {
        min-width: 19px;
        height: 19px;
        padding: 0 5px;
        font-size: 10px;
    }
}


/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    .wspace-chat-toggle,
    .wspace-chat-toggle::before,
    .wspace-chat-toggle::after {
        animation: none;
    }

    .wspace-chat-toggle {
        transition: none;
    }
}

/* =========================================================
   CHAT WINDOW
   ========================================================= */

.wspace-chat-window {
    width: 390px;
    height: 580px;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    isolation: isolate;
    animation: wspace-chat-enter 180ms ease-out;
}

@keyframes wspace-chat-enter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


/* =========================================================
   CHAT TOP BAR
   ========================================================= */

.wspace-chat-topbar {
    flex: 0 0 auto;
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0;
    padding: 14px 16px;
    background: var(--color-secondary);
    border-bottom: 1px solid var(--color-border);
}

.wspace-chat-topbar-info {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 0;
    padding: 0;
}

.wspace-chat-avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.wspace-chat-avatar svg {
    width: 18px;
    height: 18px;
}

.wspace-chat-title {
    min-width: 0;
    margin: 0;
    padding: 0;
}

.wspace-chat-title strong {
    display: block;
    overflow: hidden;
    margin: 0;
    padding: 0;
    color: var(--color-text-inverse);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wspace-chat-title span {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0 0;
    padding: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

.wspace-chat-title span svg {
    width: 7px;
    height: 7px;
    fill: var(--color-success);
    color: var(--color-success);
}


/* =========================================================
   CLOSE
   ========================================================= */

.wspace-chat-close {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        color var(--transition-fast),
        border-color var(--transition-fast);
}

.wspace-chat-close:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border);
    color: var(--color-text-inverse);
}

.wspace-chat-close:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow:
        0 0 0 3px var(--color-focus);
}

.wspace-chat-close svg {
    width: 16px;
    height: 16px;
}


/* =========================================================
   TABS
   ========================================================= */

.wspace-chat-tabs {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: 0;
    padding: 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.wspace-chat-tab {
    position: relative;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin: 0;
    padding: 0 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--color-text-muted);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition:
        color var(--transition-fast),
        background-color var(--transition-fast),
        border-color var(--transition-fast);
}

.wspace-chat-tab:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.wspace-chat-tab:focus-visible {
    outline: none;
    box-shadow:
        inset 0 0 0 2px var(--color-focus);
}

.wspace-chat-tab.is-active {
    color: var(--color-primary-light);
    border-bottom-color: var(--color-primary);
}

.wspace-chat-tab svg {
    width: 15px;
    height: 15px;
}

.wspace-chat-history-count {
    min-width: 19px;
    height: 19px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-full);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-family: var(--font-family);
    font-size: 10px;
    font-weight: var(--font-weight-bold);
    line-height: 1;
    box-shadow:
        0 2px 5px rgba(2, 8, 23, 0.16);
}

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

/* =========================================================
   PANELS
   ========================================================= */

.wspace-chat-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: none;
    flex-direction: column;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.wspace-chat-panel.is-active {
    display: flex;
}


/* =========================================================
   CHAT INTAKE
   ========================================================= */

.wspace-chat-guest {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
    padding: 22px;
    scrollbar-width: thin;
    scrollbar-color:
        var(--color-border-strong)
        transparent;
}

.wspace-chat-welcome {
    margin: 0 0 22px;
    padding: 0;
}

.wspace-chat-welcome h3 {
    margin: 0 0 7px;
    padding: 0;
    color: var(--color-text);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}

.wspace-chat-welcome p {
    margin: 0;
    padding: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: 1.55;
}


/* =========================================================
   FORM FIELDS
   ========================================================= */

.wspace-chat-field {
    position: relative;
    margin: 0 0 14px;
    padding: 0;
}

.wspace-chat-field label {
    display: block;
    margin: 0 0 6px;
    padding: 0;
    color: var(--color-text);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
}


/* =========================================================
   INPUTS + SELECT
   ========================================================= */

.wspace-chat-field input,
.wspace-chat-field select {
    width: 100%;
    height: 44px;
    display: block;
    margin: 0;
    padding: 0 40px 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    outline: none;
    background-color: var(--color-background-soft);
    color: var(--color-text);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    line-height: 1.4;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast),
        background-color var(--transition-fast),
        transform var(--transition-fast);
}

.wspace-chat-field input::placeholder {
    color: var(--color-text-light);
}

.wspace-chat-field input:hover,
.wspace-chat-field select:hover {
    border-color: var(--color-border-strong);
}

.wspace-chat-field input:focus,
.wspace-chat-field select:focus {
    border-color: var(--color-primary);
    background-color: var(--color-background);
    box-shadow:
        0 0 0 3px var(--color-focus);
}

.wspace-chat-field select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding-right: 40px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
        linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
    background-position:
        calc(100% - 17px) 19px,
        calc(100% - 12px) 19px;
    background-size:
        5px 5px,
        5px 5px;
    background-repeat: no-repeat;
}

.wspace-chat-field select:invalid {
    color: var(--color-text-light);
}

.wspace-chat-field select option {
    background: var(--color-surface);
    color: var(--color-text);
}

.wspace-chat-field select option:disabled {
    color: var(--color-text-light);
}


/* =========================================================
   DEPARTMENT FIELD
   ========================================================= */

.wspace-chat-field:has(#chat-department) {
    margin-bottom: 16px;
}

.wspace-chat-field:has(#chat-department) label {
    display: flex;
    align-items: center;
    gap: 6px;
}

.wspace-chat-field:has(#chat-department) label::before {
    content: "";
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10);
}

#chat-department {
    height: 48px;
    border-color: var(--color-border-strong);
    background-color: var(--color-background);
    font-weight: var(--font-weight-medium);
    box-shadow: var(--shadow-sm);
}

#chat-department:hover {
    border-color: var(--color-primary);
    background-color: var(--color-background-soft);
}

#chat-department:focus {
    border-color: var(--color-primary);
    background-color: var(--color-background);
    box-shadow:
        0 0 0 3px var(--color-focus),
        var(--shadow-sm);
}


/* =========================================================
   OTHER TOPIC FIELD
   ========================================================= */

#chat-topic-group {
    margin-top: -2px;
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-soft);
    animation: wspace-topic-enter 160ms ease-out;
}

#chat-topic-group[hidden] {
    display: none !important;
}

#chat-topic-group label {
    margin-bottom: 7px;
}

#chat-topic {
    background: var(--color-background);
}

#chat-topic:focus {
    background: var(--color-background);
}

@keyframes wspace-topic-enter {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* =========================================================
   LOGGED-IN CLIENT FIELDS
   ========================================================= */

#wspace-chat-guest-fields[hidden] {
    display: none !important;
}


/* =========================================================
   START BUTTON
   ========================================================= */

.wspace-chat-start {
    width: 100%;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 8px 0 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition:
        background-color var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}

.wspace-chat-start:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.wspace-chat-start:active {
    transform: translateY(0);
}

.wspace-chat-start:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px var(--color-focus),
        var(--shadow-md);
}

.wspace-chat-start svg {
    width: 16px;
    height: 16px;
}


/* =========================================================
   ACTIVE CHAT BODY
   ========================================================= */

.wspace-chat-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.wspace-chat-body[hidden] {
    display: none !important;
}

.wspace-chat-body:not([hidden]) {
    display: flex;
}


/* =========================================================
   MESSAGE AREA
   ========================================================= */

.wspace-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
    padding: 18px 16px 20px;
    background: var(--color-background);
    scrollbar-width: thin;
    scrollbar-color:
        var(--color-border-strong)
        transparent;
}


/* =========================================================
   DATE SEPARATOR
   ========================================================= */

.wspace-chat-date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 8px 0 16px;
    padding: 0;
}

.wspace-chat-date-divider::before,
.wspace-chat-date-divider::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--color-border);
}

.wspace-chat-date-divider span {
    flex: 0 0 auto;
    padding: 4px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    background: var(--color-surface);
    color: var(--color-text-light);
    font-size: 10px;
    font-weight: var(--font-weight-semibold);
    line-height: 1.2;
    white-space: nowrap;
}


/* =========================================================
   MESSAGE ROW
   ========================================================= */

.wspace-chat-message {
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0 0 14px;
    padding: 0;
}

.wspace-chat-message.client,
.wspace-chat-message.guest {
    justify-content: flex-end;
}

.wspace-chat-message.admin,
.wspace-chat-message.ai {
    justify-content: flex-start;
}


/* =========================================================
   SENDER AVATAR
   ========================================================= */

.wspace-chat-message-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 0 2px;
    padding: 0;
    border-radius: var(--radius-full);
    background: var(--color-secondary-light);
    color: var(--color-text);
    font-size: 11px;
}

.wspace-chat-message.admin .wspace-chat-message-avatar,
.wspace-chat-message.ai .wspace-chat-message-avatar,
.wspace-chat-message.client .wspace-chat-message-avatar,
.wspace-chat-message.guest .wspace-chat-message-avatar {
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.wspace-chat-message-avatar svg {
    width: 13px;
    height: 13px;
}


/* =========================================================
   MESSAGE CONTENT
   ========================================================= */

.wspace-chat-message-content {
    min-width: 0;
    max-width: 78%;
    display: flex;
    flex-direction: column;
}

.wspace-chat-message.client .wspace-chat-message-content,
.wspace-chat-message.guest .wspace-chat-message-content {
    align-items: flex-end;
}

.wspace-chat-message.admin .wspace-chat-message-content,
.wspace-chat-message.ai .wspace-chat-message-content {
    align-items: flex-start;
}


/* =========================================================
   SENDER NAME
   ========================================================= */

.wspace-chat-message-sender {
    display: block;
    max-width: 100%;
    overflow: hidden;
    margin: 0 0 4px;
    padding: 0 3px;
    color: var(--color-text-muted);
    font-size: 10px;
    font-weight: var(--font-weight-semibold);
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* =========================================================
   BUBBLE
   ========================================================= */

.wspace-chat-bubble {
    position: relative;
    max-width: 100%;
    margin: 0;
    padding: 10px 11px 7px;
    border-radius: 15px;
    font-size: var(--font-size-sm);
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.wspace-chat-message.client .wspace-chat-bubble,
.wspace-chat-message.guest .wspace-chat-bubble {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border-bottom-right-radius: 4px;
}

.wspace-chat-message.admin .wspace-chat-bubble,
.wspace-chat-message.ai .wspace-chat-bubble {
    background: var(--color-surface-soft);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}


/* =========================================================
   TIME INSIDE BUBBLE
   ========================================================= */

.wspace-chat-message-time {
    display: block;
    width: 100%;
    margin: 5px 0 0;
    padding: 0;
    text-align: right;
    font-size: 9px;
    line-height: 1.2;
    font-weight: var(--font-weight-medium);
    opacity: .72;
}

.wspace-chat-message.admin .wspace-chat-message-time,
.wspace-chat-message.ai .wspace-chat-message-time {
    color: var(--color-text-muted);
}

.wspace-chat-message.client .wspace-chat-message-time,
.wspace-chat-message.guest .wspace-chat-message-time {
    color: var(--color-text-inverse);
}


/* =========================================================
   COMPOSER
   ========================================================= */

.wspace-chat-composer {
    flex: 0 0 auto;
    min-height: 62px;
    height: auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0;
    padding: 10px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

.wspace-chat-composer textarea {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 40px;
    height: 40px;
    max-height: 110px;
    display: block;
    resize: none;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    outline: none;
    background: var(--color-background-soft);
    color: var(--color-text);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    line-height: 1.4;
    visibility: visible;
    opacity: 1;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.wspace-chat-composer textarea::placeholder {
    color: var(--color-text-light);
}

.wspace-chat-composer textarea:hover {
    border-color: var(--color-border-strong);
}

.wspace-chat-composer textarea:focus {
    border-color: var(--color-primary);
    box-shadow:
        0 0 0 3px var(--color-focus);
}

.wspace-chat-composer button {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}

.wspace-chat-composer button:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.wspace-chat-composer button:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px var(--color-focus);
}

.wspace-chat-composer button svg {
    width: 16px;
    height: 16px;
}


/* =========================================================
   HISTORY
   ========================================================= */

.wspace-chat-history {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
    padding: 16px;
    background: var(--color-background);
    scrollbar-width: thin;
    scrollbar-color:
        var(--color-border-strong)
        transparent;
}

.wspace-chat-history-empty {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 24px;
    text-align: center;
}

.wspace-chat-history-empty-icon {
    width: 54px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 0 14px;
    padding: 0;
    border-radius: var(--radius-full);
    background: var(--color-surface-soft);
    color: var(--color-primary-light);
}

.wspace-chat-history-empty-icon svg {
    width: 21px;
    height: 21px;
}

.wspace-chat-history-empty h3 {
    margin: 0 0 7px;
    padding: 0;
    color: var(--color-text);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
}

.wspace-chat-history-empty p {
    max-width: 270px;
    margin: 0 0 18px;
    padding: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: 1.5;
}

.wspace-chat-history-start {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0 16px;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast),
        transform var(--transition-fast);
}

.wspace-chat-history-start:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    transform: translateY(-1px);
}


/* =========================================================
   HISTORY ITEMS
   ========================================================= */

.wspace-chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
}

.wspace-chat-history-item {
    width: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 13px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast),
        transform var(--transition-fast);
}

.wspace-chat-history-item:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border-strong);
    transform: translateY(-1px);
}

.wspace-chat-history-item:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow:
        0 0 0 3px var(--color-focus);
}

.wspace-chat-history-item-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--color-surface-soft);
    color: var(--color-primary-light);
}

.wspace-chat-history-item-icon svg {
    width: 15px;
    height: 15px;
}

.wspace-chat-history-item-content {
    min-width: 0;
}
.wspace-chat-history-item-title-row {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 4px;
    padding: 0;
}

.wspace-chat-history-item-title {
    min-width: 0;
    flex: 1 1 auto;
    display: block;
    overflow: hidden;
    margin: 0;
    padding: 0;
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* =========================================================
   UNREAD BADGE — HISTORY ITEM
   ========================================================= */

.wspace-chat-history-item-unread {
    flex: 0 0 auto;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: var(--color-danger);
    color: var(--color-text-inverse);
    font-family: var(--font-family);
    font-size: 10px;
    font-weight: var(--font-weight-bold);
    line-height: 1;
    white-space: nowrap;
    box-shadow:
        0 2px 6px rgba(2, 8, 23, 0.18);
}

.wspace-chat-history-item-preview {
    overflow: hidden;
    margin: 0;
    padding: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wspace-chat-history-item-date {
    margin: 0;
    padding: 0;
    color: var(--color-text-light);
    font-size: 11px;
    white-space: nowrap;
}

.wspace-chat-history-item-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-light);
}

.wspace-chat-history-item-arrow svg {
    width: 15px;
    height: 15px;
}


/* =========================================================
   BACK TO CHAT HISTORY
   ========================================================= */

.wspace-chat-history-back {
    flex: 0 0 auto;
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0 16px;
    border: 0;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    text-align: left;
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        color var(--transition-fast);
}

.wspace-chat-history-back:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.wspace-chat-history-back:focus-visible {
    outline: none;
    box-shadow:
        inset 0 0 0 2px var(--color-focus);
}

.wspace-chat-history-back svg {
    width: 14px;
    height: 14px;
}


/* =========================================================
   SCROLLBARS
   ========================================================= */

.wspace-chat-messages::-webkit-scrollbar,
.wspace-chat-history::-webkit-scrollbar,
.wspace-chat-guest::-webkit-scrollbar {
    width: 6px;
}

.wspace-chat-messages::-webkit-scrollbar-track,
.wspace-chat-history::-webkit-scrollbar-track,
.wspace-chat-guest::-webkit-scrollbar-track {
    background: transparent;
}

.wspace-chat-messages::-webkit-scrollbar-thumb,
.wspace-chat-history::-webkit-scrollbar-thumb,
.wspace-chat-guest::-webkit-scrollbar-thumb {
    border-radius: var(--radius-full);
    background: var(--color-border-strong);
}


/* =========================================================
   TABLET + PHONE
   < 1200px
   DEFAULT = FLOATING ICON ONLY
   ========================================================= */

@media (max-width: 1199px) {

    .wspace-chat {
        right: 24px;
        bottom: 24px;
    }

    .wspace-chat-toggle {
        display: flex;
    }

    .wspace-chat-window {
        position: absolute;
        right: 0;
        bottom: 70px;
        width: min(390px, calc(100vw - 32px));
        height: min(580px, calc(100dvh - 100px));
        display: none;
    }

    .wspace-chat.is-open .wspace-chat-window {
        display: flex;
    }

    .wspace-chat.is-open .wspace-chat-toggle {
        display: none;
    }

    .wspace-chat.is-closed .wspace-chat-window {
        display: none;
    }

    .wspace-chat.is-closed .wspace-chat-toggle {
        display: flex;
    }
}


/* =========================================================
   DESKTOP + LAPTOP
   >= 1200px
   DEFAULT = LARGE OPEN CHAT
   ========================================================= */

@media (min-width: 1200px) {

    .wspace-chat {
        right: 32px;
        bottom: 32px;
    }

    .wspace-chat-toggle {
        display: none;
    }

    .wspace-chat-window {
        width: 460px;
        height: 680px;
        display: flex;
    }

    .wspace-chat.is-open .wspace-chat-window {
        display: flex;
    }

    .wspace-chat.is-open .wspace-chat-toggle {
        display: none;
    }

    .wspace-chat.is-closed .wspace-chat-window {
        display: none;
    }

    .wspace-chat.is-closed .wspace-chat-toggle {
        display: flex;
    }
}


/* =========================================================
   PHONE — FULL-SCREEN CHAT WHEN OPEN
   <= 768px
   ========================================================= */
/* =========================================================
   PHONE — FULL-SCREEN CHAT + LOCK BACKGROUND
   <= 768px
   ========================================================= */

@media (max-width: 768px) {

    /*
     * CLOSED STATE
     * Keep the chat button floating normally.
     */
    .wspace-chat {
        right: 24px;
        bottom: 24px;
    }

    /*
     * OPEN STATE
     * The chat becomes the entire viewport.
     */
    .wspace-chat.is-open {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        min-width: 100vw;
        min-height: 100dvh;
        margin: 0;
        padding: 0;
        z-index: 99999;
        overflow: hidden;
        overscroll-behavior: none;
        touch-action: manipulation;
    }

    /*
     * FULL-SCREEN CHAT WINDOW
     */
    .wspace-chat.is-open .wspace-chat-window {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        min-width: 100vw;
        min-height: 100dvh;
        max-width: none;
        max-height: none;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        overflow: hidden;
        overscroll-behavior: none;
    }

    /*
     * HIDE FLOATING BUTTON WHILE CHAT IS OPEN.
     */
    .wspace-chat.is-open .wspace-chat-toggle {
        display: none;
    }

    /*
     * HARD-LOCK THE PAGE BEHIND THE CHAT.
     *
     * overflow alone can still allow touch scrolling on
     * some mobile browsers. Fixed positioning prevents the
     * document itself from moving while the chat is open.
     */
    html:has(.wspace-chat.is-open),
    body:has(.wspace-chat.is-open) {
        width: 100%;
        height: 100%;
        overflow: hidden !important;
        overscroll-behavior: none !important;
        touch-action: none;
    }

    /*
     * Keep the chat itself interactive and allow its own
     * internal scroll areas to work.
     */
    .wspace-chat.is-open,
    .wspace-chat.is-open .wspace-chat-window,
    .wspace-chat.is-open .wspace-chat-panel {
        touch-action: auto;
    }

    /*
     * Prevent scroll chaining from chat scroll areas
     * into the page behind it.
     */
    .wspace-chat.is-open .wspace-chat-guest,
    .wspace-chat.is-open .wspace-chat-messages,
    .wspace-chat.is-open .wspace-chat-history {
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
}


/* =========================================================
   SMALL PHONES
   ========================================================= */

@media (max-width: 480px) {
    .wspace-chat {
        right: 16px;
        bottom: 16px;
    }

    .wspace-chat-toggle {
        width: 52px;
        height: 52px;
    }

    .wspace-chat-window {
        right: 0;
        bottom: 64px;
        width: calc(100vw - 32px);
        height: min(580px, calc(100dvh - 92px));
        max-height: none;
    }


    .wspace-chat-topbar {
        min-height: 66px;
        padding: 12px 14px;
    }

    .wspace-chat-avatar {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .wspace-chat-guest {
        padding: 16px;
    }

    .wspace-chat-welcome {
        margin-bottom: 18px;
    }

    .wspace-chat-field {
        margin-bottom: 12px;
    }

    .wspace-chat-field input,
    .wspace-chat-field select {
        height: 43px;
    }

    #chat-department {
        height: 46px;
    }

    #chat-topic-group {
        padding: 10px;
    }

    .wspace-chat-messages {
        padding: 14px 12px 18px;
    }

    .wspace-chat-message-content {
        max-width: 84%;
    }

    .wspace-chat-message-avatar {
        width: 28px;
        height: 28px;
        flex-basis: 28px;
    }

    .wspace-chat-history {
        padding: 12px;
    }

    .wspace-chat-history-item {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 9px;
        padding: 12px;
    }

    .wspace-chat-history-item-date {
        display: none;
    }
}


/* =========================================================
   VERY SMALL PHONES
   ========================================================= */

@media (max-width: 360px) {
    .wspace-chat {
        right: 12px;
        bottom: 12px;
    }

    .wspace-chat-window {
        width: calc(100vw - 24px);
    }

    .wspace-chat-tab {
        padding: 0 8px;
        gap: 5px;
        font-size: var(--font-size-xs);
    }

    .wspace-chat-tab svg {
        width: 13px;
        height: 13px;
    }

    .wspace-chat-history-count {
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        font-size: 9px;
    }

    .wspace-chat-guest {
        padding: 14px;
    }

    .wspace-chat-welcome h3 {
        font-size: var(--font-size-md);
    }

    .wspace-chat-welcome p {
        font-size: var(--font-size-xs);
    }

    .wspace-chat-start {
        height: 44px;
    }
}


/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    .wspace-chat-window,
    #chat-topic-group {
        animation: none;
    }

    .wspace-chat-toggle,
    .wspace-chat-close,
    .wspace-chat-tab,
    .wspace-chat-start,
    .wspace-chat-history-start,
    .wspace-chat-history-item {
        transition: none;
    }
}





























.wspace-chat-message {
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0 0 14px;
    padding: 0;
}

.wspace-chat-message-content {
    min-width: 0;
    max-width: 78%;
    display: flex;
    flex-direction: column;
}

.wspace-chat-bubble {
    position: relative;
    display: block;
    max-width: 100%;
    margin: 0;
    padding: 10px 11px 7px;
    border-radius: 15px;
    font-size: var(--font-size-sm);
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.wspace-chat-message.client .wspace-chat-bubble,
.wspace-chat-message.guest .wspace-chat-bubble {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border-bottom-right-radius: 4px;
}

.wspace-chat-message.admin .wspace-chat-bubble,
.wspace-chat-message.ai .wspace-chat-bubble {
    background: var(--color-surface-soft);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}



















/* =========================================================
   CLOSED CONVERSATION
   ========================================================= */

.wspace-chat-closed {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 16px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    text-align: center;
}

.wspace-chat-closed[hidden] {
    display: none !important;
}

.wspace-chat-closed-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    border-radius: var(--radius-full);
    background: var(--color-background-soft);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.wspace-chat-closed-icon svg {
    width: 16px;
    height: 16px;
}

.wspace-chat-closed-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
}

.wspace-chat-closed-content strong {
    margin: 0;
    padding: 0;
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    line-height: 1.35;
}

.wspace-chat-closed-content span {
    max-width: 310px;
    margin: 0;
    padding: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-regular);
    line-height: 1.5;
}

.wspace-chat-new {
    width: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 2px 0 0;
    padding: 9px 14px;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-family: var(--font-family);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    line-height: 1.2;
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}

.wspace-chat-new:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.wspace-chat-new:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px var(--color-focus),
        var(--shadow-sm);
}

.wspace-chat-new svg {
    width: 15px;
    height: 15px;
}

.wspace-chat-new:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px var(--color-focus),
        var(--shadow-sm);
}