:root {
    color-scheme: light;
    --cream: #FBF7F2;
    --cream-2: #F2E8DC;
    --ink: #24162F;
    --muted: #6B5F75;
    --plum: #5B2A86;
    --plum-2: #6D35A3;
    --gold: #D9A441;
    --line: #E9E1F2;
    --green: #1F9D6A;
    --shadow-card: 0 18px 55px rgba(44, 27, 58, 0.14);
    --chat-viewport-height: 100dvh;
}

* {
    box-sizing: border-box;
}

body.chat-app-body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--ink);
    background-color: #FCF7F1;
    background-image:
        radial-gradient(1200px 620px at 10% 8%, rgba(91, 42, 134, .14), rgba(91, 42, 134, 0) 58%),
        radial-gradient(980px 520px at 88% 10%, rgba(217, 164, 65, .18), rgba(217, 164, 65, 0) 54%),
        radial-gradient(1100px 560px at 82% 80%, rgba(91, 42, 134, .09), rgba(91, 42, 134, 0) 60%),
        radial-gradient(820px 420px at 18% 88%, rgba(217, 164, 65, .13), rgba(217, 164, 65, 0) 54%),
        linear-gradient(180deg, #FFFDFB 0%, #FCF7F1 42%, #F2E8DC 100%);
}

a {
    color: var(--plum);
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

.chat-shell-outer,
.chat-launch-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 0;
}

.chat-shell-card,
.chat-launch-card {
    width: min(1100px, calc(100vw - 32px));
    border-radius: 28px;
    background: rgba(255, 255, 255, .86);
    border: 1px solid rgba(233, 225, 242, .92);
    backdrop-filter: blur(14px);
    box-shadow: var(--shadow-card);
}

.chat-launch-card {
    width: min(520px, calc(100vw - 32px));
    padding: 28px;
}

.chat-logo {
    width: 180px;
    max-width: 70%;
    margin-bottom: 20px;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 12px;
}

.chat-alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin: 14px 0;
}

.chat-alert-error {
    background: #fff1f2;
    color: #8a1538;
    border: 1px solid #ffd5dc;
}

.chat-form-stack {
    display: grid;
    gap: 14px;
}

.chat-form-stack label {
    display: grid;
    gap: 6px;
}

.chat-form-stack input {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    background: white;
}

.chat-primary-button {
    border: 0;
    border-radius: 14px;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--plum), var(--plum-2));
    color: white;
    cursor: pointer;
    font-weight: 700;
}

.chat-shell-card {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    width: 100%;
    height: 100vh;
    border-radius: 0;
    overflow: hidden;
}

.chat-sidebar {
    border-right: 1px solid rgba(233, 225, 242, .92);
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    background:
        radial-gradient(140% 80% at 0% 0%, rgba(217,164,65,.16), rgba(217,164,65,0) 48%),
        radial-gradient(120% 100% at 100% 12%, rgba(91,42,134,.14), rgba(91,42,134,0) 52%),
        linear-gradient(180deg, #fffdfb 0%, #f7efe6 100%);
}

.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 8px;
}

.chat-sidebar-header__meta,
.chat-sidebar-header__actions,
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-sidebar-header__meta {
    min-width: 0;
}

.chat-sidebar-header .chat-logo {
    width: 120px;
    margin: 0;
    filter: drop-shadow(0 8px 14px rgba(217,164,65,.12));
}

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

.chat-list-search {
    padding: 14px 14px 16px;
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    justify-content: center;
    background:
        linear-gradient(180deg, rgba(251,247,242,.99) 0%, rgba(251,247,242,.96) 72%, rgba(251,247,242,0) 100%);
    backdrop-filter: blur(10px);
}

.chat-list-search-input {
    width: min(100%, 236px);
    border: 1px solid rgba(91,42,134,.14);
    border-radius: 999px;
    padding: 13px 18px;
    background:
        linear-gradient(180deg, rgba(255,255,255,.99), rgba(250,245,252,.95));
    color: var(--ink);
    box-shadow:
        0 14px 28px rgba(44,27,58,.08),
        inset 0 1px 0 rgba(255,255,255,.82);
}

.chat-list-search-input::placeholder {
    color: rgba(107,95,117,.88);
}

.chat-list-search-input:focus {
    outline: none;
    border-color: rgba(91,42,134,.28);
    box-shadow:
        0 14px 30px rgba(44,27,58,.09),
        0 0 0 4px rgba(91,42,134,.08);
}

.chat-list-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 10px 18px;
}

.chat-list-group-title {
    padding: 2px 8px 0;
    color: rgba(91,42,134,.72);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.chat-list-item {
    display: block;
    position: relative;
    padding: 14px;
    border-radius: 18px;
    background: rgba(255,255,255,.55);
    border: 1px solid rgba(233,225,242,.82);
    color: var(--ink);
}

.chat-list-item-agent {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 2px;
    padding: 13px 14px;
    border-radius: 22px;
    background:
        linear-gradient(180deg, rgba(255,255,255,.98), rgba(249,243,251,.92));
    border: 1px solid rgba(91,42,134,.10);
    box-shadow:
        0 12px 26px rgba(44,27,58,.05),
        inset 0 1px 0 rgba(255,255,255,.72);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.chat-list-item-agent:hover {
    transform: translateY(-1px);
    border-color: rgba(91,42,134,.24);
    box-shadow:
        0 18px 34px rgba(44,27,58,.09),
        0 0 0 1px rgba(217,164,65,.12);
}

.chat-avatar-wrap {
    flex: 0 0 auto;
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 999px;
    object-fit: cover;
    display: block;
    border: 2px solid rgba(255,255,255,.95);
    background: rgba(255,255,255,.9);
    box-shadow:
        0 10px 22px rgba(44,27,58,.10),
        0 0 0 1px rgba(91,42,134,.08);
}

.chat-list-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-list-item.is-active {
    border-color: rgba(91,42,134,.28);
    box-shadow:
        0 20px 38px rgba(44,27,58,.12),
        0 0 0 1px rgba(91,42,134,.08);
    background:
        linear-gradient(180deg, rgba(255,255,255,.99), rgba(245,236,249,.96));
}

.chat-list-item.has-unread {
    border-color: rgba(91,42,134,.22);
    box-shadow:
        0 14px 28px rgba(91,42,134,.09),
        0 0 0 1px rgba(217,164,65,.15);
}

.chat-list-title {
    font-weight: 700;
    margin-bottom: 2px;
    font-size: 16px;
    letter-spacing: -.01em;
}

.chat-list-preview {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.chat-list-unread-dot {
    position: absolute;
    top: 10px;
    right: 10px;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: linear-gradient(135deg, #1f9d6a, #39b981);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    box-shadow:
        0 0 0 4px rgba(31,157,106,.12),
        0 10px 20px rgba(31,157,106,.22);
}

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.chat-header {
    padding: 24px 24px 18px;
    border-bottom: 1px solid rgba(233,225,242,.92);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.chat-header--customer {
    justify-content: flex-start;
}

.chat-header-actions-right {
    margin-left: auto;
}

.chat-header-profile {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
    text-align: left;
}

.chat-header-copy {
    min-width: 0;
}

.chat-header-consult-copy {
    margin-top: 2px;
    font-size: 13px;
    line-height: 1.25;
}

.chat-header-avatar {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    object-fit: cover;
    border: 1px solid rgba(233,225,242,.92);
    background: rgba(255,255,255,.9);
    flex: 0 0 auto;
}

.chat-header h1 {
    margin: 0;
    font-size: 16px;
    line-height: 1.2;
}

.chat-mobile-only {
    display: none !important;
}

#chat-sidebar-close {
    display: none;
}

.chat-consult-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chat-consult-stop {
    background: #fff1f2;
    border-color: #ffd5dc;
    color: #8a1538;
}

.chat-inline-alert {
    margin: 16px 24px 0;
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 14px;
}

.chat-inline-alert.is-success {
    background: #eefaf4;
    border: 1px solid #cfeede;
    color: #196544;
}

.chat-inline-alert.is-error {
    background: #fff1f2;
    border: 1px solid #ffd5dc;
    color: #8a1538;
}

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

.chat-bubble {
    max-width: min(72%, 540px);
    padding: 14px 16px;
    border-radius: 20px 20px 20px 6px;
    background: white;
    border: 1px solid rgba(233,225,242,.92);
    box-shadow: 0 10px 28px rgba(44,27,58,.06);
    display: flex;
    flex-direction: column;
}

.chat-bubble.is-mine {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(91,42,134,.92), rgba(109,53,163,.94));
    color: white;
    border-radius: 20px 20px 6px 20px;
}

.chat-bubble img {
    max-width: 260px;
    border-radius: 14px;
    display: block;
    margin-bottom: 8px;
}

.chat-bubble-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-bubble time {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    opacity: .7;
    text-align: right;
    align-self: flex-end;
}

.chat-composer {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 18px 24px 18px;
    border-top: 1px solid rgba(233,225,242,.92);
    position: relative;
    background: rgba(255,255,255,.96);
}

.chat-icon-button {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: white;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
}

.chat-icon-glyph {
    display: block;
    width: 20px;
    height: 20px;
}

.chat-home-link,
.chat-profile-trigger {
    color: var(--plum);
    box-shadow: 0 10px 24px rgba(44,27,58,.08);
}

.chat-file-button {
    position: relative;
    overflow: hidden;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    padding: 0;
    font-size: 16px;
}

.chat-composer textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px 56px 14px 16px;
    background: white;
    min-height: 52px;
    max-height: 220px;
    resize: none;
    overflow-y: hidden;
    line-height: 1.45;
}

.chat-typing-indicator {
    min-height: 24px;
    padding: 0 18px 8px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.chat-send-button {
    position: absolute;
    right: 30px;
    bottom: 24px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--plum), var(--plum-2));
    color: white;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    font-weight: 800;
    font-size: 20px;
    line-height: 1;
    z-index: 2;
    box-shadow: 0 10px 24px rgba(44,27,58,.18);
}

@media (max-width: 920px) {
    html,
    body.chat-app-body,
    .chat-shell-outer,
    .chat-shell-card {
        width: 100%;
        height: var(--chat-viewport-height, 100dvh);
        min-height: var(--chat-viewport-height, 100dvh);
    }

    .chat-shell-outer {
        place-items: stretch;
    }

    .chat-shell-card {
        display: block;
        position: relative;
        width: 100vw;
        height: var(--chat-viewport-height, 100dvh);
    }

    .chat-sidebar,
    .chat-main {
        position: absolute;
        inset: 0;
        width: 100%;
        height: var(--chat-viewport-height, 100dvh);
        background: rgba(255,255,255,.98);
    }

    .chat-sidebar {
        z-index: 4;
        border-right: 0;
        transform: translateX(-100%);
        transition: transform .18s ease;
    }

    .chat-main {
        z-index: 3;
    }

    .chat-shell-card.is-mobile-list-open .chat-sidebar {
        transform: translateX(0);
    }

    .chat-shell-card.is-mobile-list-open .chat-main {
        visibility: hidden;
    }

    .chat-shell-card.is-mobile-chat-open .chat-sidebar {
        transform: translateX(-100%);
    }

    .chat-bubble {
        max-width: 88%;
    }

    .chat-header {
        padding: 16px 14px 14px;
        align-items: center;
        flex-wrap: wrap;
        gap: 12px;
    }

    .chat-header-profile {
        min-width: 0;
        flex: 1 1 auto;
        gap: 8px;
    }

    .chat-header h1 {
        font-size: 15px;
    }

    .chat-header-consult-copy {
        margin-top: 1px;
        font-size: 11px;
        line-height: 1.15;
    }

    .chat-header-avatar {
        width: 28px;
        height: 28px;
    }

    .chat-sidebar-header {
        padding: 16px 14px 10px;
    }

    .chat-list {
        padding-bottom: 12px;
    }

    .chat-mobile-only {
        display: inline-grid !important;
    }

    #chat-sidebar-close {
        display: inline-grid !important;
    }

    .chat-consult-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .chat-messages {
        padding: 14px;
        padding-bottom: 8px;
    }

    .chat-typing-indicator {
        padding: 0 14px 6px;
    }

    .chat-composer {
        grid-template-columns: 28px minmax(0, 1fr);
        gap: 8px;
        position: sticky;
        bottom: 2px;
        left: 0;
        right: 0;
        margin: 0;
        padding: 8px 8px env(safe-area-inset-bottom, 0px);
        border-top: 0;
        background: rgba(255,255,255,.98);
        z-index: 4;
    }

    .chat-file-button {
        width: 28px;
        height: 28px;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .chat-composer textarea {
        border-radius: 18px;
        padding: 12px 52px 12px 14px;
        min-height: 46px;
        max-height: 190px;
    }

    .chat-send-button {
        right: 12px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
}
