/* Bipolar - Clean, Modern Chat Interface */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-base: #0f0f0f;
    --bg-elevated: #161616;
    --bg-surface: #1c1c1c;
    --bg-hover: #242424;
    --bg-active: #2a2a2a;
    --text-primary: #e4e4e4;
    --text-secondary: #888;
    --text-muted: #555;
    --accent: #8a8a8a;
    --accent-hover: #9a9a9a;
    --border: #262626;
    --border-light: #333;
    --error: #a04040;
    --success: #408040;
    --warning: #806830;
    --sidebar-width: 280px;
    --sidebar-collapsed: 60px;
    --header-height: 56px;
    --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

html, body {
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

html {
    /* Prevent pull-to-refresh */
    overscroll-behavior-y: contain;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
    overscroll-behavior: none;
}

/* Allow text selection only in specific areas */
.message-content,
input,
textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Custom scrollbars - all browsers */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-light); }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.hidden { display: none !important; }
#app, .view { height: 100%; width: 100%; }

/* Auth */
#auth-view {
    display: flex;
    justify-content: center;
    align-items: center;
}

.auth-container {
    width: 100%;
    max-width: 340px;
    padding: 40px 32px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0;
    animation: fadeSlideUp 0.4s var(--ease-out);
}

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-logo { font-size: 26px; font-weight: 600; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 32px; }
.form-label { font-size: 11px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 16px; }

/* Form Elements */
input, textarea, select {
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s var(--ease-out);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--border-light);
    background: var(--bg-hover);
    box-shadow: 0 0 0 3px rgba(138, 138, 138, 0.1);
}
.password-field { -webkit-text-security: disc; }

/* Buttons */
button {
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s var(--ease-out);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    outline: none !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

button:focus,
button:active,
button:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

* {
    outline: none !important;
    -webkit-tap-highlight-color: transparent;
}

*:focus,
*:active,
*:focus-visible {
    outline: none !important;
}

.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: var(--accent);
    color: var(--bg-base);
    border: 1px solid var(--accent);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
    transition: all 0.2s var(--ease-out);
}
.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(138, 138, 138, 0.2);
}
.btn-primary:active { transform: scale(0.98) translateY(0); opacity: 0.9; }

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0;
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-icon:active { transform: scale(0.92); opacity: 0.8; }

.btn-dashed {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px dashed var(--border-light);
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
}
.btn-dashed:hover { border-color: var(--text-muted); color: var(--text-primary); }

.btn-danger {
    width: 100%;
    padding: 12px 24px;
    background: rgba(196, 80, 80, 0.15);
    color: var(--error);
    border: 1px solid rgba(196, 80, 80, 0.3);
    font-size: 13px;
    margin-top: 12px;
}
.btn-danger:hover { background: rgba(196, 80, 80, 0.25); }

.error-msg { color: var(--error); font-size: 13px; margin-top: 16px; }

/* Main View */
#main-view { display: flex; position: relative; }

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.25s var(--ease-out);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    height: var(--header-height);
    box-sizing: border-box;
}

.sidebar-logo {
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s;
}

.sidebar.collapsed .sidebar-logo { opacity: 0; width: 0; }

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: transform 0.2s;
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

.sidebar-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar.collapsed .sidebar-section-header span { display: none; }
.sidebar.collapsed .sidebar-section-header { justify-content: center; padding: 12px 8px; }

.rooms-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.rooms-list::-webkit-scrollbar {
    display: none;
}



.room-item {
    padding: 14px 16px;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: all 0.15s var(--ease-out);
    position: relative;
}
.room-item:hover { background: var(--bg-surface); }
.room-item:active { background: var(--bg-active); transform: scale(0.98); }
.room-item.active { background: var(--bg-surface); border-left-color: var(--accent); }
.room-item h3 { font-size: 13px; font-weight: 500; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item p { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Collapsed room items */
.sidebar.collapsed .room-item {
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: none;
}
.sidebar.collapsed .room-item h3,
.sidebar.collapsed .room-item p { display: none; }

.room-icon {
    display: none;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    aspect-ratio: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 0;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    flex-shrink: 0;
}
.sidebar.collapsed .room-icon { display: flex; }
.sidebar.collapsed .room-item.active .room-icon { border-color: var(--accent); }

/* Tooltip */
.room-item[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    animation: tooltipIn 0.15s var(--ease-out) forwards;
}
.sidebar:not(.collapsed) .room-item[data-tooltip]:hover::after { display: none; }

@keyframes tooltipIn {
    from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
    to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

.sidebar-bottom {
    border-top: 1px solid var(--border);
    padding: 0;
}

/* User profile button */
.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: background 0.15s;
}

.user-profile-btn:hover {
    background: var(--bg-surface);
}

.user-profile-bg {
    position: absolute;
    left: 0;
    top: 0;
    width: 80px;
    height: 100%;
    background-size: cover;
    background-position: center;
    filter: blur(20px);
    opacity: 0.4;
    pointer-events: none;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 0;
    object-fit: cover;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.user-nickname {
    font-weight: 500;
    position: relative;
    z-index: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar.collapsed .user-profile-btn {
    padding: 10px;
    justify-content: center;
}

.sidebar.collapsed .user-nickname {
    display: none;
}

.sidebar.collapsed .user-profile-bg {
    width: 100%;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
}
.btn-logout:hover { background: var(--bg-surface); color: var(--text-primary); }
.sidebar.collapsed .btn-logout span { display: none; }
.sidebar.collapsed .btn-logout { justify-content: center; padding: 10px; }

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s var(--ease-out);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    height: 100%;
    height: 100dvh;
    background: var(--bg-base);
    transition: margin-left 0.25s var(--ease-out);
    overflow: hidden;
}
.chat-area.collapsed { margin-left: var(--sidebar-collapsed); }

/* Mobile Header */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 8px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: relative;
}
.mobile-room-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 120px);
    text-align: center;
    padding: 0 8px;
}

.mobile-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#mobile-play-btn svg,
#mobile-pause-btn svg { stroke: var(--text-secondary); fill: none; }

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 16px;
}
.empty-icon { opacity: 0.3; }

/* Room Content */
.room-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    animation: fadeIn 0.3s var(--ease-out);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 20px;
    height: var(--header-height);
    box-sizing: border-box;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}
.room-meta { flex: 1; min-width: 0; }
.room-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.room-prompt { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn-icon-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
}
.btn-icon-action:hover { opacity: 0.7; }
.btn-icon-action:active { transform: scale(0.96); }
.btn-icon-action svg { stroke: var(--text-secondary); fill: none; }

/* Participants */
.participants {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}
.participant {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    position: relative;
}
.participant-dot { width: 8px; height: 8px; border-radius: 0; }
.participant .participant-delete {
    display: none;
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: var(--error);
    border: none;
    border-radius: 0;
    color: white;
    font-size: 12px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.participant:hover .participant-delete { display: flex; }

.add-participant-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px dashed var(--border-light);
    border-radius: 0;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    transition: all 0.15s;
}
.add-participant-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* Messages */
.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    padding-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: linear-gradient(180deg, var(--bg-base) 0%, #0c0c0c 100%);
}


.messages.two-participants .message { max-width: 70%; }
.messages.two-participants .message.ai-0 { align-self: flex-start; }
.messages.two-participants .message.ai-1 { align-self: flex-end; }
.messages.two-participants .message.ai-1 .message-header { flex-direction: row-reverse; }
.messages.multi-participants .message { max-width: 80%; align-self: flex-start; }

.message {
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(12px);
    animation: messageIn 0.35s var(--ease-out) forwards;
    position: relative;
}
.message.no-animation { animation: none; opacity: 1; transform: none; }

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

.message-bubble {
    padding: 12px 16px;
    transition: filter 0.15s;
    position: relative;
}
.message-bubble:hover { filter: brightness(1.08); }
.message-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.message-author { font-size: 12px; font-weight: 600; }
.message-time { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }
.message-content { font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; }

/* Message actions (mobile) */
.message-actions {
    display: none;
    position: absolute;
    top: 4px;
    right: 4px;
    gap: 4px;
}
.message-actions button {
    width: 28px;
    height: 28px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.message-actions button:hover { color: var(--text-primary); }
.message-actions .delete-btn:hover { color: var(--error); }

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 18px;
    background: var(--bg-surface);
    align-self: flex-start;
    opacity: 0;
    transform: scale(0.9) translateY(10px);
    transition: all 0.3s var(--ease-out);
}
.typing-indicator.typing-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}
.typing-indicator.typing-collapsing {
    opacity: 0;
    transform: scale(0.7) translateY(-10px);
    filter: blur(4px);
}
.typing-indicator.typing-left {
    align-self: flex-start;
}
.typing-indicator.typing-right {
    align-self: flex-end;
}
.typing-dots {
    display: flex;
    gap: 5px;
    padding: 4px 8px;
}
.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 0;
    background: var(--typing-color, var(--text-secondary));
    opacity: 0.7;
    animation: typingDot 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 80%, 100% { 
        opacity: 0.4; 
        transform: scale(1) translateY(0); 
    }
    40% { 
        opacity: 1; 
        transform: scale(1.3) translateY(-4px); 
    }
}

/* Message expansion animation */
.message.message-expanding {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    max-height: 50px;
    overflow: hidden;
    filter: blur(4px);
}
.message.message-expanded {
    animation: messageExpand 0.5s var(--ease-spring) forwards;
}
@keyframes messageExpand {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
        max-height: 50px;
        filter: blur(4px);
    }
    40% {
        opacity: 1;
        transform: scale(1.02) translateY(-5px);
        filter: blur(0);
    }
    70% {
        transform: scale(0.99) translateY(2px);
        max-height: 500px;
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
        max-height: 3000px;
        filter: blur(0);
    }
}

/* Glow effect on new message */
.message.message-expanded .message-bubble {
    animation: messageBubbleGlow 1.5s ease-out;
}
@keyframes messageBubbleGlow {
    0% {
        box-shadow: 0 0 0 rgba(255,255,255,0);
    }
    15% {
        box-shadow: 0 0 30px rgba(255,255,255,0.08), 0 0 60px rgba(255,255,255,0.04);
    }
    40% {
        box-shadow: 0 0 40px rgba(255,255,255,0.05), 0 0 80px rgba(255,255,255,0.02);
    }
    100% {
        box-shadow: 0 0 0 rgba(255,255,255,0);
    }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}
.modal-content {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.3s var(--ease-spring);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-content.modal-sm { max-width: 360px; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: none;
}
.modal-header h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }
.modal-body { padding: 0 24px 24px; overflow-y: auto; }
.modal-body textarea { min-height: 80px; resize: vertical; }

/* Room creation form */
.form-group {
    margin-bottom: 20px;
}
.form-label-inline {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.modal-section-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 24px 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.modal-section-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

#ai-participants {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.ai-participant-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 16px;
    transition: all 0.2s var(--ease-out);
}
.ai-participant-card:hover {
    border-color: var(--border-light);
}

.ai-participant-header {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ai-participant-color {
    width: 42px;
    height: 42px;
    border-radius: 0;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s var(--ease-out);
    position: relative;
}
.ai-participant-color:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.ai-participant-color::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid rgba(255,255,255,0.1);
    pointer-events: none;
}

.ai-participant-name {
    flex: 1;
    background: var(--bg-hover);
    border: 1px solid transparent;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary);
    margin: 0;
    transition: all 0.15s;
}
.ai-participant-name:focus {
    outline: none;
    border-color: var(--border-light);
    background: var(--bg-active);
}
.ai-participant-name::placeholder {
    color: var(--text-muted);
}

.ai-participant-remove {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.ai-participant-remove:hover {
    color: var(--error);
    background: rgba(160, 64, 64, 0.1);
    border-color: rgba(160, 64, 64, 0.2);
}

.ai-participant-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.ai-participant-palette.hidden { display: none; }
.ai-participant-palette .color-option {
    aspect-ratio: 1;
    border-radius: 0;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
}
.ai-participant-palette .color-option:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.ai-participant-palette .color-option.selected {
    border-color: white;
    transform: scale(1.05);
}

.ai-participant-add {
    width: 100%;
    padding: 14px;
    background: transparent;
    border: 1px dashed var(--border-light);
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.ai-participant-add:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
    background: var(--bg-surface);
}
.ai-participant-add::before {
    content: '+';
    font-size: 18px;
    font-weight: 300;
}

/* Color palette picker */
.color-picker-btn {
    width: 42px; height: 42px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.color-picker-btn .color-preview {
    width: 28px; height: 28px;
    border-radius: 0;
}
.color-palette {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.color-palette.hidden { display: none; }
.color-option {
    width: 24px; height: 24px;
    border-radius: 0;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, border-color 0.1s;
}
.color-option:hover { transform: scale(1.15); }
.color-option.selected { border-color: white; }

.color-palette-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.color-palette-inline .color-option {
    width: 28px; height: 28px;
    border-radius: 0;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, border-color 0.1s;
}
.color-palette-inline .color-option:hover { transform: scale(1.1); }
.color-palette-inline .color-option.selected { border-color: white; }

.ai-participant .remove-ai-btn {
    width: 42px; height: 42px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(196, 80, 80, 0.1); border: 1px solid rgba(196, 80, 80, 0.2);
    color: #c45050; font-size: 18px;
}
.ai-participant .remove-ai-btn:hover { background: rgba(196, 80, 80, 0.2); color: #d66; }

/* Custom Dialog */
.modal-dialog {
    max-width: 320px;
    text-align: center;
    padding: 24px;
}
.dialog-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}
.dialog-icon.warning { color: var(--warning); }
.dialog-icon.error { color: var(--error); }
.dialog-icon.info { color: var(--accent); }
.dialog-icon.success { color: var(--success); }
.modal-dialog h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}
.modal-dialog p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}
#dialog-input-wrap {
    margin-bottom: 20px;
}
#dialog-input {
    text-align: center;
}
.dialog-buttons {
    display: flex;
    gap: 12px;
}
.dialog-buttons button {
    flex: 1;
    padding: 12px 16px;
}
.btn-secondary {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
}
.btn-secondary:hover {
    background: var(--bg-hover);
}
.btn-dialog-danger {
    background: rgba(160, 64, 64, 0.2);
    border: 1px solid rgba(160, 64, 64, 0.4);
    color: #c06060;
}
.btn-dialog-danger:hover {
    background: rgba(160, 64, 64, 0.3);
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0;
    min-width: 140px;
    z-index: 300;
    opacity: 0;
    transform: scale(0.92) translateY(-4px);
    transition: opacity 0.18s var(--ease-out), transform 0.18s var(--ease-out);
    pointer-events: none;
}

.context-menu.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item:active { background: var(--bg-active); transform: scale(0.98); }
.context-menu-item.danger { color: var(--error); }
.context-menu-item.danger:hover { background: rgba(196, 80, 80, 0.1); }
.context-menu-item.danger:active { background: rgba(196, 80, 80, 0.2); }

/* Mobile */
@media (max-width: 768px) {
    :root { --sidebar-width: 280px; }
    
    /* Safe area support */
    .mobile-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--header-height) + env(safe-area-inset-top));
    }
    
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        transition: transform 0.3s var(--ease-out);
        padding-top: env(safe-area-inset-top);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.collapsed { transform: translateX(-100%); width: var(--sidebar-width); }
    .sidebar-toggle { display: none; }
    .sidebar-overlay { display: block; }
    
    .chat-area {
        margin-left: 0;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }
    .chat-area.collapsed { margin-left: 0; }
    
    .mobile-header {
        display: flex;
        flex-shrink: 0;
    }
    
    .room-header { display: none; }
    
    .participants { padding-top: 12px; }
    .room-title { font-size: 14px; }
    .room-prompt { display: none; }
    
    /* Larger participant chips on mobile */
    .participants {
        padding: 12px 16px;
        gap: 8px;
        flex-wrap: wrap;
    }
    .participant {
        padding: 8px 12px;
        font-size: 13px;
        position: relative;
    }
    .participant-dot {
        width: 10px;
        height: 10px;
    }
    /* Always show delete button on mobile */
    .participant .participant-delete {
        display: flex;
        position: relative;
        top: auto;
        right: auto;
        width: 20px;
        height: 20px;
        margin-left: 6px;
        background: rgba(160, 64, 64, 0.3);
        font-size: 14px;
    }
    .add-participant-btn {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }
    
    .messages {
        padding: 16px;
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 16px));
        gap: 12px;
        flex: 1;
        min-height: 0;
    }
    
    .participants {
        flex-shrink: 0;
    }
    .messages.two-participants .message,
    .messages.multi-participants .message { max-width: 85%; }
    .message-bubble { padding: 10px 14px; }
    .message-content { font-size: 13px; }
    
    /* Hide message actions on mobile - use context menu instead */
    .message-actions {
        display: none !important;
    }
    
    .modal { padding: 16px; }
    .modal-content { max-height: 90vh; }
    
    .auth-container { margin: 16px; padding: 32px 24px; }
}

@media (max-width: 400px) {
    .room-actions { flex-direction: column; gap: 6px; }
    .btn-action { padding: 6px 10px; font-size: 11px; }
}

/* Modal closing animation */
.modal.closing .modal-content {
    animation: modalOut 0.2s var(--ease-out) forwards;
}

.modal.closing .modal-backdrop {
    animation: fadeOut 0.2s var(--ease-out) forwards;
}

@keyframes modalOut {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to { opacity: 0; transform: scale(0.95) translateY(10px); }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Message deletion animation */
.message.deleting {
    animation: messageDelete 0.3s var(--ease-out) forwards;
}

@keyframes messageDelete {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.9); height: 0; margin: 0; padding: 0; }
}



/* Participant clickable */
.participant {
    cursor: pointer;
    transition: all 0.15s;
}

.participant:hover {
    filter: brightness(1.2);
}
.participant:active {
    transform: scale(0.95);
    opacity: 0.8;
}

/* Edit AI modal styles */
.color-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.color-row label {
    font-size: 13px;
    color: var(--text-secondary);
}

.color-row input[type="color"] {
    width: 48px;
    height: 36px;
    padding: 2px;
    margin: 0;
}

.field-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

/* Auto-resize textarea */
#edit-message-content,
#edit-ai-prompt {
    resize: none;
    overflow-y: auto;
    min-height: 80px;
}

/* Mobile menu button - larger touch target */
#mobile-menu-btn {
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255,255,255,0.1);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    position: relative;
    z-index: 10;
}

/* Make SVG inside button not capture events */
#mobile-menu-btn svg,
#mobile-menu-btn * {
    pointer-events: none;
}

#mobile-menu-btn:active {
    background: var(--bg-hover);
}

/* Ensure mobile header doesn't block touches */
.mobile-header {
    position: relative;
    z-index: 5;
}



/* Auth switch */
.auth-switch {
    margin-top: 20px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}
.auth-switch span {
    margin-right: 6px;
}
.btn-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}
.btn-link:hover {
    color: var(--text-primary);
}

/* Captcha container */
.captcha-container {
    margin-bottom: 16px;
}

/* Cap.js widget customization */
cap-widget {
    --cap-background: var(--bg-surface);
    --cap-border-color: var(--border);
    --cap-border-radius: 0;
    --cap-widget-height: 48px;
    --cap-widget-width: 100%;
    --cap-widget-padding: 12px 16px;
    --cap-gap: 12px;
    --cap-color: var(--text-primary);
    --cap-checkbox-size: 22px;
    --cap-checkbox-border: 1px solid var(--border-light);
    --cap-checkbox-border-radius: 0;
    --cap-checkbox-background: var(--bg-hover);
    --cap-checkbox-margin: 0;
    --cap-font: inherit;
    --cap-spinner-color: var(--text-secondary);
    --cap-spinner-background-color: var(--bg-active);
    --cap-spinner-thickness: 3px;
    /* Gray checkmark instead of green */
    --cap-checkmark: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cstyle%3E%40keyframes%20anim%7B0%25%7Bstroke-dashoffset%3A23.21320343017578px%7Dto%7Bstroke-dashoffset%3A0%7D%7D%3C%2Fstyle%3E%3Cpath%20fill%3D%22none%22%20stroke%3D%22%23888888%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%20stroke-width%3D%222%22%20d%3D%22m5%2012%205%205L20%207%22%20style%3D%22stroke-dashoffset%3A0%3Bstroke-dasharray%3A23.21320343017578px%3Banimation%3Aanim%20.5s%20ease%22%2F%3E%3C%2Fsvg%3E");
    display: block;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
    outline: none !important;
}

cap-widget:focus,
cap-widget:focus-visible,
cap-widget *:focus,
cap-widget *:focus-visible {
    outline: none !important;
}

cap-widget::part(attribution) {
    display: none !important;
}


/* Settings modal */
.settings-section {
    margin-bottom: 24px;
}
.settings-section:last-child {
    margin-bottom: 0;
}

.avatar-upload-container {
    display: flex;
    align-items: center;
    gap: 16px;
}

.settings-avatar {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 0;
}

.avatar-upload-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.avatar-upload-btn {
    cursor: pointer;
}

.invite-code-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    margin-bottom: 6px;
}
.invite-code-display code {
    flex: 1;
    font-family: monospace;
    font-size: 14px;
    color: var(--text-primary);
    letter-spacing: 1px;
    word-break: break-all;
}

.btn-icon-small {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
}
.btn-icon-small:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

.field-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0;
}

.btn-danger-outline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1px solid rgba(196, 80, 80, 0.4);
    color: var(--error);
    font-size: 13px;
    cursor: pointer;
}
.btn-danger-outline:hover {
    background: rgba(196, 80, 80, 0.1);
    border-color: rgba(196, 80, 80, 0.6);
}

.settings-logout {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
