:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-soft: #fbfbfb;
    --border: #e4e4e4;
    --border-strong: #d5d5d5;
    --text: #4a4a4a;
    --text-muted: #606060;
    --primary: #73216d;
    --primary-dark: #59175e;
    --primary-deep: #59175e;
    --primary-soft: #f5eef5;
    --primary-tint: #f0e4f0;
    --primary-disabled: #c3a3c1;
    --accent: #dda300;
    --accent-dark: #8c6e00;
    --accent-soft: #fdf7e6;
    --neutral: #717171;
    --neutral-dark: #5a5a5a;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    height: 100vh;
    display: flex;
    color: var(--text);
}
.container {
    display: flex;
    width: 100%;
    height: 100%;
}
.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 16px;
}
/* Admin page has two panels side-by-side on desktop */
#adminSidebar {
    width: auto;
    min-width: 540px;
    flex-shrink: 0;
}
#adminSidebar .admin-sidebar-panel {
    flex-shrink: 0;
}
/* Let the chat column yield on a narrow desktop instead of pushing the whole
   page wider than the window, and keep the header tidy when it does. Scoped to
   the admin page, which has two fixed sidebars; the participant page keeps its
   previous behaviour. */
#adminSidebar + .main {
    min-width: 0;
}
#adminSidebar + .main .header {
    flex-wrap: wrap;
    row-gap: 6px;
}
#adminSidebar + .main .header > div {
    min-width: 0;
}
#adminSidebar + .main #chatTitle {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar h3 {
    font-size: 14px;
    color: var(--primary);
    margin-bottom: 8px;
    font-weight: 600;
}
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-soft);
}
.header {
    padding: 16px 24px;
    background: var(--primary);
    border-bottom: 1px solid var(--primary-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
}
.header h3 {
    color: #fff;
    font-weight: 500;
}
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
}
.message.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
}
.message.assistant {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}
.message.has-comment {
    border-left: 3px solid var(--accent);
}
.input-area {
    padding: 16px 24px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
}
input[type="text"], textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}
input[type="text"]:focus, textarea:focus {
    border-color: var(--primary);
}
button {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}
button:hover { background: var(--primary-dark); }
button:disabled {
    background: var(--primary-disabled);
    cursor: not-allowed;
}
button.secondary {
    background: var(--neutral);
}
button.secondary:hover { background: var(--neutral-dark); }
.conversation-list {
    flex: 1;
    overflow-y: auto;
    margin-top: 12px;
}
.conv-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.conv-item:hover { background: var(--primary-soft); }
.conv-item.active { background: var(--primary-tint); }
.conv-item button {
    padding: 2px 6px;
    font-size: 12px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
}
.conv-item button:hover { color: #dc3545; background: transparent; }
.new-chat-btn {
    width: 100%;
    margin-bottom: 8px;
}
.username-section {
    margin-bottom: 16px;
}
.admin-comment {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 8px;
    font-size: 13px;
    color: #8c6e00;
}
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    width: 500px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}
.modal h3 { margin-bottom: 12px; }
.comment-list { margin: 12px 0; }
.comment-item {
    background: var(--surface-soft);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 13px;
}
.comment-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.hidden { display: none !important; }
.user-list-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.user-list-item:hover { background: var(--primary-soft); }
.user-list-item.active { background: var(--primary-tint); }
.badge {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--primary-tint);
    color: var(--text-muted);
}
.powered-by {
    font-size: 11px;
    font-weight: 500;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.16);
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    white-space: nowrap;
}
.message .msg-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}
.comment-actions {
    display: flex;
    gap: 4px;
}
.comment-actions button {
    padding: 2px 6px;
    font-size: 11px;
}
.typing-indicator {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #b0b0b0;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ===== Responsive / Mobile ===== */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    color: #ffffff;
}
.mobile-menu-btn:hover { background: rgba(255, 255, 255, 0.16); border-radius: 6px; }
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 500;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
    .sidebar, #adminSidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 600;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    .sidebar.mobile-open, #adminSidebar.mobile-open {
        transform: translateX(0);
    }
    /* Admin page: stack user list (top) and conversation list (bottom) on mobile */
    #adminSidebar {
        width: 85vw;
        max-width: 320px;
        flex-direction: column !important;
    }
    #adminSidebar .admin-sidebar-panel {
        width: 100% !important;
        flex: 1;
        overflow-y: auto;
        border-right: none !important;
        border-bottom: 1px solid var(--border);
    }
    #adminSidebar .admin-sidebar-panel:last-child {
        border-bottom: none;
    }
    .sidebar-backdrop.show {
        display: block;
    }
    .header {
        padding: 12px 16px;
    }
    .header h3 {
        font-size: 15px;
    }
    .chat-area {
        padding: 16px;
    }
    .message {
        max-width: 90%;
        font-size: 15px;
    }
    .input-area {
        padding: 12px 16px 120px;
    }
    .powered-by {
        display: none;
    }
}
