:root {
    --bg: #dde5df;
    --panel: #f7f8f6;
    --panel-strong: #ffffff;
    --line: #d5ddd8;
    --text: #17211c;
    --muted: #66746d;
    --brand: #1f8f6f;
    --brand-dark: #14644e;
    --bubble-in: #ffffff;
    --bubble-out: #d9fdd3;
    --shadow: 0 18px 50px rgba(18, 38, 31, .16);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    background:
        linear-gradient(180deg, #0f6f57 0 128px, transparent 128px),
        var(--bg);
}

button,
input,
textarea {
    font: inherit;
}

.shell {
    width: min(1480px, calc(100vw - 32px));
    height: min(920px, calc(100vh - 32px));
    margin: 16px auto;
    display: grid;
    grid-template-columns: 390px minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.sidebar {
    min-width: 0;
    border-right: 1px solid var(--line);
    background: var(--panel-strong);
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
}

.topbar,
.chat-header {
    min-height: 64px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #eef2ef;
    border-bottom: 1px solid var(--line);
}

.topbar span,
.chat-title span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: white;
    background: var(--brand);
    font-weight: 700;
}

.avatar.muted {
    background: #7d8f87;
}

.search {
    height: 52px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--line);
}

.search input {
    width: 100%;
    height: 36px;
    border: 0;
    outline: 0;
    border-radius: 8px;
    padding: 0 12px;
    background: #f0f3f1;
}

.conversation-list {
    min-height: 0;
    overflow: auto;
}

.conversation-item {
    width: 100%;
    height: 74px;
    border: 0;
    border-bottom: 1px solid #edf0ee;
    padding: 0 14px;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    color: inherit;
    text-align: left;
    background: transparent;
    cursor: pointer;
}

.conversation-item:hover,
.conversation-item.active {
    background: #edf4f0;
}

.conversation-copy {
    min-width: 0;
}

.conversation-copy strong,
.chat-title strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-meta {
    margin-top: 5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

.conversation-meta span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-pane {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

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

.chat-title {
    min-width: 0;
    flex: 1;
}

.icon-button,
.send-button {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    color: var(--muted);
    background: transparent;
    text-decoration: none;
    cursor: pointer;
}

.icon-button:hover {
    background: #dde6e1;
}

.send-button {
    color: white;
    background: var(--brand);
}

.send-button:hover {
    background: var(--brand-dark);
}

.messages {
    position: relative;
    min-height: 0;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 22px clamp(14px, 4vw, 72px) 22px;
    display: flex;
    flex-direction: column;
    background-color: #e7ddd1;
    background-image:
        radial-gradient(rgba(31, 143, 111, .09) 1px, transparent 1px),
        radial-gradient(rgba(23, 33, 28, .05) 1px, transparent 1px);
    background-position: 0 0, 13px 13px;
    background-size: 26px 26px;
}

.empty-state {
    width: min(360px, 100%);
    margin: 22vh auto 0;
    padding: 24px;
    border-radius: 8px;
    text-align: center;
    color: var(--muted);
    background: rgba(255, 255, 255, .72);
}

.empty-state strong {
    display: block;
    margin-bottom: 8px;
    color: var(--text);
}

.message-row {
    width: 100%;
    flex: 0 0 auto;
    display: flex;
    margin: 8px 0;
}

.message-row.outbound {
    justify-content: flex-end;
}

.bubble {
    max-width: min(640px, 78%);
    padding: 8px 10px 6px;
    border-radius: 8px;
    background: var(--bubble-in);
    box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.outbound .bubble {
    background: var(--bubble-out);
}

.bubble-meta {
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    color: #6f7c75;
    font-size: 11px;
}

.composer {
    min-height: 64px;
    padding: 10px 14px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #eef2ef;
    border-top: 1px solid var(--line);
}

.composer textarea {
    min-height: 42px;
    max-height: 120px;
    flex: 1;
    resize: none;
    border: 0;
    outline: 0;
    border-radius: 8px;
    padding: 11px 14px;
    background: white;
}

body[data-mode="client"] .sidebar {
    display: none;
}

body[data-mode="client"] .shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 980px;
}

@media (max-width: 820px) {
    .shell {
        width: 100vw;
        height: 100dvh;
        margin: 0;
        grid-template-columns: 1fr;
    }

    body[data-mode="operator"] .sidebar {
        display: none;
    }

    body[data-mode="operator"].show-list .sidebar {
        display: grid;
    }

    body[data-mode="operator"].show-list .chat-pane {
        display: none;
    }

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