/* ============================================
   MIRACLES INVITED CHAT - Stylesheet
   Brand Colors: Primary #1a1a1a, Accent #c9a96e
   ============================================ */

/* CSS Variables */
:root {
    --color-primary: #1a1a1a;
    --color-accent: #c9a96e;
    --color-accent-light: #e8d5a3;
    --color-accent-dark: #a0854a;
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-surface-hover: #f0f0f0;
    --color-text: #1a1a1a;
    --color-text-secondary: #666666;
    --color-text-muted: #999999;
    --color-border: #e0e0e0;
    --color-success: #4caf50;
    --color-error: #f44336;
    --color-warning: #ff9800;
    --color-online: #4caf50;
    --color-away: #ff9800;
    --color-offline: #9e9e9e;
    --color-bubble-self: #c9a96e;
    --color-bubble-self-text: #1a1a1a;
    --color-bubble-other: #ffffff;
    --color-bubble-other-text: #1a1a1a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: all 0.2s ease;
    --header-height: 56px;
    --sidebar-width: 280px;
    --input-height: 60px;
}

/* Dark Theme */
[data-theme="dark"] {
    --color-bg: #121212;
    --color-surface: #1e1e1e;
    --color-surface-hover: #2a2a2a;
    --color-text: #e0e0e0;
    --color-text-secondary: #a0a0a0;
    --color-text-muted: #707070;
    --color-border: #333333;
    --color-bubble-other: #2a2a2a;
    --color-bubble-other-text: #e0e0e0;
    --color-bubble-self: #c9a96e;
    --color-bubble-self-text: #1a1a1a;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Utility Classes */
.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    color: var(--color-text);
    white-space: nowrap;
}

.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--color-accent);
    color: var(--color-primary);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-text {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-large {
    padding: 14px 32px;
    font-size: 16px;
    border-radius: var(--radius-lg);
}

.btn-icon {
    padding: 8px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
}

.btn-icon-sm {
    padding: 4px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-danger {
    background: var(--color-error);
    color: #fff;
}

/* ============================================
   ADMIN ROOM LIST
   ============================================ */
.admin-room-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-room-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.admin-room-item:hover {
    background: var(--color-surface-hover);
}

.admin-room-item.current {
    border-color: var(--color-accent);
    background: rgba(201, 169, 110, 0.08);
}

.room-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.room-item-id {
    font-weight: 600;
    font-size: 14px;
    color: var(--color-text);
}

.room-item-meta {
    font-size: 12px;
    color: var(--color-text-muted);
}

.room-item-link {
    font-size: 12px;
    color: var(--color-text-secondary);
    word-break: break-all;
}

.room-item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.room-card-invite-box {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: start;
    padding-top: 8px;
    border-top: 1px dashed var(--color-border);
}

.room-card-invite-names {
    min-height: 42px;
    resize: vertical;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 15px;
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(201, 169, 110, 0.15);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--color-accent);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--color-primary);
    color: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    animation: toastIn 0.3s ease;
}

.toast.hidden { display: none !important; }

.toast-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
}

.toast-close:hover { opacity: 1; }

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

/* ============================================
   PAGES
   ============================================ */
.page {
    display: none;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.page.active { display: flex; }

/* ============================================
   LANDING PAGE
   ============================================ */
.landing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    text-align: center;
    background: linear-gradient(135deg, var(--color-bg) 0%, var(--color-surface) 100%);
}

.landing-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.landing-brand-logo {
    height: 42px;
    width: auto;
    flex: 0 0 auto;
}

.landing-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-accent);
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.landing-subtitle {
    font-size: 16px;
    color: var(--color-text-secondary);
    margin-bottom: 40px;
}

.landing-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 320px;
}

.landing-footer {
    position: absolute;
    bottom: 32px;
    display: flex;
    gap: 20px;
    align-items: center;
}

.theme-toggle {
    display: flex;
    gap: 4px;
    background: var(--color-surface);
    padding: 4px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
}

.theme-btn {
    padding: 6px 10px;
    border: none;
    border-radius: var(--radius-xl);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 12px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-btn.active {
    background: var(--color-accent);
    color: var(--color-primary);
}

.lang-switch {
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    cursor: pointer;
    min-width: 72px;
}

/* ============================================
   AUTH PAGES (Admin Login)
   ============================================ */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    max-width: 400px;
    margin: 0 auto;
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    width: 200px;
    margin-bottom: 16px;
}

.auth-header h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--color-text);
}

.auth-form {
    width: 100%;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions .btn {
    flex: 1;
}

/* ============================================
   APP HEADER
   ============================================ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    z-index: 100;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    height: 32px;
    width: auto;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
}

.header-room-info {
    display: flex;
    flex-direction: column;
}

.room-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
}

.room-status {
    font-size: 12px;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online { background: var(--color-online); }
.status-dot.away { background: var(--color-away); }
.status-dot.offline { background: var(--color-offline); }

/* ============================================
   ADMIN CONSOLE
   ============================================ */
.admin-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.admin-panel {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-section {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--color-border);
}

.panel-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--color-text);
}

.room-actions {
    margin-bottom: 16px;
}

.room-info {
    background: var(--color-bg);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.info-label {
    font-size: 13px;
    color: var(--color-text-secondary);
    min-width: 80px;
}

.info-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    font-family: monospace;
    background: var(--color-surface);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    flex: 1;
    word-break: break-all;
}

.info-value.link-value {
    font-size: 12px;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-form .form-group {
    margin-bottom: 0;
}

.settings-form .form-input {
    max-width: 200px;
}

.pending-list, .member-list-compact {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--color-text-muted);
    font-size: 14px;
}

.pending-item, .member-item-compact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--color-bg);
    border-radius: var(--radius-md);
}

.pending-item .user-info, .member-item-compact .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pending-item .user-name, .member-item-compact .user-name {
    font-size: 14px;
    font-weight: 500;
}

.pending-item .user-device {
    font-size: 12px;
    color: var(--color-text-muted);
}

.pending-actions {
    display: flex;
    gap: 8px;
}

.pending-actions .btn {
    padding: 6px 14px;
    font-size: 13px;
}

.member-item-compact .member-role {
    font-size: 12px;
    color: var(--color-accent);
    display: flex;
    align-items: center;
    gap: 4px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h3 {
    margin: 0;
}

.approval-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    padding: 12px;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--color-text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.btn-kick-member {
    margin-left: auto;
    padding: 4px 8px;
    opacity: 0.7;
}

.btn-kick-member:hover {
    opacity: 1;
}

/* ============================================
   CHAT LAYOUT
   ============================================ */
.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.chat-sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.chat-sidebar.closed {
    transform: translateX(-100%);
    width: 0;
    border: none;
}

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

.sidebar-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.sidebar-section-title {
    padding: 10px 16px 6px;
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    border-top: 1px solid var(--color-border);
}

.self-panel {
    padding: 8px 12px 12px;
    border-bottom: 1px solid var(--color-border);
}

.self-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
}

.self-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    position: relative;
}

.self-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--color-surface);
    background: var(--color-online);
}

.self-info {
    flex: 1;
    min-width: 0;
}

.self-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    display: block;
}

.self-status {
    font-size: 12px;
    color: var(--color-online);
}

.member-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.member-item:hover {
    background: var(--color-surface-hover);
}

.member-item.active {
    background: rgba(201, 169, 110, 0.1);
}

.member-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    position: relative;
}

.member-avatar .status-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--color-surface);
}

.member-avatar .status-indicator.online { background: var(--color-online); }
.member-avatar .status-indicator.away { background: var(--color-away); }
.member-avatar .status-indicator.offline { background: var(--color-offline); }

.member-info {
    flex: 1;
    min-width: 0;
}

.member-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 4px;
}

.member-name .admin-badge {
    color: var(--color-accent);
    font-size: 12px;
}

.member-device {
    font-size: 12px;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.member-summary {
    margin: 4px 0 8px;
    color: var(--color-text-secondary);
    font-size: 13px;
}

.participant-item.offline {
    opacity: 0.72;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ============================================
   CHAT MESSAGES
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

/* ============================================
   CHAT RESIZE HANDLE
   ============================================ */
.chat-resize-handle {
    flex-shrink: 0;
    height: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.resize-handle-bar {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
    transition: background 0.2s;
}

.chat-resize-handle:hover .resize-handle-bar,
.chat-resize-handle:active .resize-handle-bar {
    background: var(--color-accent);
}

.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
    text-align: center;
}

.welcome-icon {
    margin-bottom: 16px;
    opacity: 0.4;
}

.welcome-text {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 4px;
}

.welcome-hint {
    font-size: 13px;
}

.message-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 12px;
    max-width: 70%;
}

.message-group.self {
    align-self: flex-end;
    align-items: flex-end;
}

.message-group.other {
    align-self: flex-start;
    align-items: flex-start;
}

.message-sender {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 2px;
    padding: 0 4px;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.message-group.self .message-bubble {
    background: var(--color-bubble-self);
    color: var(--color-bubble-self-text);
    border-bottom-right-radius: 4px;
}

.message-group.other .message-bubble {
    background: var(--color-bubble-other);
    color: var(--color-bubble-other-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.message-bubble.file-message {
    padding: 12px;
    min-width: 200px;
}

.room-file-area {
    margin: 12px 16px 8px;
    border-radius: 16px;
    border: 2px solid rgba(239, 68, 68, 0.28);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.12), rgba(249, 115, 22, 0.12));
    box-shadow: 0 10px 24px rgba(239, 68, 68, 0.12);
    overflow: hidden;
    flex: 0 0 auto;
}

.room-file-header {
    width: 100%;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    padding: 12px 14px;
    background: linear-gradient(135deg, #ef4444, #f97316);
    color: #fff;
    cursor: pointer;
}

.room-file-toggle-label {
    flex: 0 0 auto;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
    font-size: 13px;
    font-weight: 800;
}

.room-file-panel {
    max-height: min(33vh, 280px);
    overflow-y: auto;
}

.room-file-panel.collapsed {
    display: none;
}

.room-file-title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.03em;
}

.room-file-summary {
    margin-top: 2px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.92);
}

.room-file-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 8px;
    padding: 10px;
}

.room-file-empty {
    grid-column: 1 / -1;
    padding: 12px;
    text-align: center;
    color: var(--color-text-secondary);
    background: rgba(255, 255, 255, 0.55);
    border-radius: 12px;
}

.room-file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 12px;
    background: var(--color-surface);
    border: 1px solid rgba(239, 68, 68, 0.16);
}

.room-file-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    flex: 0 0 auto;
    overflow: hidden;
}

.room-file-image-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    display: block;
}

.room-file-info {
    flex: 1;
    min-width: 0;
}

.room-file-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-file-meta {
    margin-top: 2px;
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-file-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.btn-room-file-download {
    border: 0;
    border-radius: 10px;
    padding: 10px 16px;
    min-height: 42px;
    font-size: 16px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #ef4444, #f97316);
    box-shadow: 0 6px 14px rgba(239, 68, 68, 0.22);
    cursor: pointer;
    white-space: nowrap;
}

.btn-room-file-secondary {
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: 10px;
    padding: 9px 12px;
    min-height: 40px;
    font-size: 14px;
    font-weight: 700;
    color: #ef4444;
    background: var(--color-surface);
    cursor: pointer;
    white-space: nowrap;
}

.btn-room-file-download:hover {
    background: linear-gradient(135deg, #dc2626, #ea580c);
}

.chat-debug-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    white-space: nowrap;
}

.chat-debug-toggle input {
    width: 16px;
    height: 16px;
}

.file-message-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius-md);
    background: var(--color-bg);
}

.file-message-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-message-info {
    flex: 1;
    min-width: 0;
}

.file-message-name {
    font-size: 14px;
    font-weight: 500;
    word-break: break-all;
}

.file-message-size {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

.file-message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    justify-content: flex-end;
}

.btn-file-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 18px;
    min-height: 44px;
    min-width: 44px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-file-action:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.btn-file-primary {
    background: linear-gradient(135deg, #ef4444, #f97316);
    border-color: #ef4444;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 6px 14px rgba(239, 68, 68, 0.22);
}

.btn-file-primary:hover {
    background: linear-gradient(135deg, #dc2626, #ea580c);
    color: #fff;
}

.btn-file-delete:hover {
    border-color: var(--color-error);
    color: var(--color-error);
}

.btn-file-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.message-image {
    max-width: 240px;
    max-height: 240px;
    border-radius: var(--radius-md);
    cursor: pointer;
    object-fit: cover;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding: 0 4px;
}

.message-time {
    font-size: 11px;
    color: var(--color-text-muted);
}

.message-status {
    font-size: 11px;
    color: var(--color-text-muted);
}

.message-status.read {
    color: var(--color-accent);
}

.message-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
    color: var(--color-text-muted);
    font-size: 12px;
}

.message-divider::before,
.message-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
    margin: 0 12px;
}

/* ============================================
   FILE TRANSFER AREA
   ============================================ */
.file-transfer-area {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    max-height: 200px;
    overflow-y: auto;
}

.file-transfer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
}

.file-transfer-list {
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-transfer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: var(--color-bg);
    border-radius: var(--radius-md);
}

.file-transfer-item.completed {
    align-items: flex-start;
}

.file-transfer-item .file-info {
    flex: 1;
    min-width: 0;
}

.file-transfer-item .file-name {
    font-size: 13px;
    font-weight: 500;
    word-break: break-all;
}

.file-transfer-item .file-progress-text {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.file-transfer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.file-transfer-actions .btn,
.file-message-actions .btn-file-action {
    min-height: 30px;
}

.file-transfer-actions .btn {
    padding: 5px 8px;
    font-size: 12px;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}

.progress-fill {
    height: 100%;
    background: var(--color-accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* ============================================
   CHAT INPUT
   ============================================ */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    position: relative;
}

.input-wrapper {
    flex: 1;
    min-width: 0;
}

.chat-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    resize: none;
    max-height: 120px;
    min-height: 44px;
    line-height: 1.4;
    transition: var(--transition);
}

.chat-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.chat-input::placeholder {
    color: var(--color-text-muted);
}

.input-action {
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

.input-action.send {
    background: var(--color-accent);
    color: var(--color-primary);
}

.input-action.send:hover {
    background: var(--color-accent-dark);
}

.drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(201, 169, 110, 0.15);
    border: 2px dashed var(--color-accent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(2px);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--color-accent);
    font-size: 14px;
    font-weight: 500;
}

/* ============================================
   DIALOGS
   ============================================ */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.dialog-overlay.hidden { display: none !important; }

.dialog {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: dialogIn 0.2s ease;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.dialog-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.dialog-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--color-text-secondary);
    cursor: pointer;
    line-height: 1;
}

.dialog-body {
    padding: 20px;
    overflow-y: auto;
    max-height: 60vh;
}

.dialog-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
}

.dialog-footer .btn {
    padding: 8px 20px;
}

.mobile-download-dialog .dialog-body {
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.download-confirm-name {
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 10px;
    background: var(--color-bg);
    color: var(--color-text);
    font-weight: 700;
    word-break: break-word;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.file-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--color-accent);
}

.file-details {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 15px;
    font-weight: 500;
    word-break: break-all;
}

.file-size {
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

.file-sender {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.file-preview {
    margin-top: 16px;
    text-align: center;
}

.file-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-md);
}

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

@keyframes dialogIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 260px;
    }

    .admin-room-item {
        grid-template-columns: 1fr;
    }

    .room-item-actions {
        justify-content: stretch;
    }

    .room-item-actions .btn {
        flex: 1 1 calc(50% - 6px);
    }

    .room-card-invite-box {
        grid-template-columns: 1fr;
    }

    .landing-title {
        font-size: 22px;
    }

    .landing-subtitle {
        font-size: 14px;
    }

    .chat-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 200;
        transform: translateX(-100%);
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    .chat-sidebar.closed {
        transform: translateX(-100%);
    }

    .sidebar-toggle {
        display: flex !important;
    }

    .message-group {
        max-width: 85%;
    }

    .admin-content {
        padding: 12px;
    }

    .panel-section {
        padding: 16px;
    }

    .landing-actions {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .landing-brand {
        gap: 8px;
    }

    .landing-brand-logo {
        height: 34px;
    }

    .landing-title {
        font-size: 20px;
    }

    .btn-large {
        padding: 12px 24px;
        font-size: 15px;
    }

    .app-header {
        padding: 0 12px;
    }

    #btn-open-rejoin-link {
        display: none;
    }

    .header-logo {
        height: 28px;
    }

    .chat-messages {
        padding: 12px;
    }

    .room-file-area {
        margin: 8px 10px 6px;
        border-radius: 14px;
    }

    .room-file-panel {
        max-height: 33vh;
    }

    .room-file-header {
        padding: 10px 12px;
    }

    .room-file-title {
        font-size: 17px;
    }

    .room-file-list {
        grid-template-columns: 1fr;
        padding: 8px;
        gap: 7px;
    }

    .room-file-item {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 8px;
    }

    .room-file-icon {
        width: 34px;
        height: 34px;
    }

    .room-file-item-image .room-file-icon {
        width: 100%;
        height: min(32vh, 180px);
    }

    .room-file-name {
        font-size: 13px;
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .room-file-meta {
        font-size: 11px;
        white-space: normal;
    }

    .btn-room-file-download {
        width: 100%;
        padding: 11px 14px;
        min-height: 42px;
        font-size: 16px;
    }

    .room-file-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        margin-top: 6px;
    }

    .btn-room-file-secondary {
        display: block;
        width: 100%;
    }

    .message-group {
        max-width: 90%;
    }

    .btn-file-action {
        padding: 10px 12px;
        min-height: 40px;
        font-size: 14px;
        white-space: nowrap;
        flex: 0 1 auto;
    }

    .file-message-actions {
        gap: 8px;
        justify-content: flex-start;
    }

    .file-message-actions .btn-file-primary {
        flex: 1 1 110px;
        min-width: 110px;
        font-size: 16px;
        letter-spacing: 0.02em;
    }

    .message-bubble.file-message {
        padding: 10px;
        min-width: 0;
        width: 100%;
    }

    .file-message-content {
        padding: 8px;
        gap: 8px;
    }

    .file-message-icon {
        width: 36px;
        height: 36px;
    }

    .file-message-name {
        font-size: 14px;
        line-height: 1.25;
    }

    .file-message-size {
        font-size: 12px;
    }

    .chat-input-area {
        padding: 8px 12px;
    }

    .dialog {
        max-width: 100%;
        margin: 0 10px;
    }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.pulse {
    animation: pulse 2s infinite;
}

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

.slide-up {
    animation: slideUp 0.3s ease;
}

/* ============================================
   SELECTION
   ============================================ */
::selection {
    background: rgba(201, 169, 110, 0.3);
    color: inherit;
}

/* ============================================
   FOCUS STYLES
   ============================================ */
*:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline-offset: -2px;
}


/* === retained additions: prejoin chat, change-name, clear-cache, invite verify === */
.dialog-prejoin { max-width: 480px; }
.prejoin-status { color: var(--text-secondary, #888); margin: 0 0 8px; font-size: 14px; }
.prejoin-messages { max-height: 220px; overflow-y: auto; padding: 8px; border: 1px solid var(--border-color, #ddd); border-radius: 8px; background: var(--bg-secondary, #fafafa); margin-bottom: 8px; }
.prejoin-msg { padding: 4px 6px; border-radius: 6px; font-size: 13px; line-height: 1.4; margin-bottom: 4px; word-break: break-word; }
.prejoin-msg.user { background: rgba(46, 134, 222, 0.08); }
.prejoin-msg.admin { background: rgba(46, 213, 115, 0.10); }
.prejoin-msg-from { font-weight: 600; margin-right: 4px; }
.prejoin-input-row { display: flex; gap: 8px; align-items: center; }
.prejoin-input-row .form-input { flex: 1; }
.prejoin-hint { margin-top: 6px; font-size: 12px; color: var(--text-secondary, #888); }
.prejoin-thread { margin-top: 8px; border-top: 1px dashed var(--border-color, #ddd); padding-top: 8px; }
.prejoin-thread .prejoin-messages-list { max-height: 120px; overflow-y: auto; margin-bottom: 6px; }
.prejoin-reply-row { display: flex; gap: 6px; }
.prejoin-reply-row .form-input { flex: 1; }
.btn-danger { background: #e74c3c; color: #fff; border: 1px solid #c0392b; }
.btn-danger:hover { background: #c0392b; }
.form-error { color: #e74c3c; font-size: 13px; margin-top: 6px; }
.link-value { word-break: break-all; }


/* === v2.4.21 additions: visitor contact, mobile sidebar and rejoin fixes === */
.invite-bulk-box { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-secondary, #666); }
.form-hint { font-size: 12px; color: var(--text-secondary, #888); line-height: 1.4; }
.invitee-textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.invite-results { margin-top: 12px; border: 1px solid var(--border-color, #ddd); border-radius: 10px; overflow: hidden; background: var(--bg-primary, #fff); }
.invite-results-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg-secondary, #f7f7f7); border-bottom: 1px solid var(--border-color, #ddd); }
.invite-results-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.invite-results-body { display: flex; flex-direction: column; }
.invite-result-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(80px, 160px); gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border-color, #eee); }
.invite-result-row:last-child { border-bottom: none; }
.invite-result-link { font-size: 12px; word-break: break-all; color: var(--text-secondary, #555); }
.invite-result-name { font-weight: 600; word-break: break-word; }
.contact-admin-link { align-self: flex-start; margin-top: -4px; padding-left: 0; }
.visitor-contact-item { display: block; }
@media (max-width: 640px) {
    .invite-result-row { grid-template-columns: 1fr; }
    .invite-results-header { align-items: flex-start; flex-direction: column; }
}


/* === v2.4.21 mobile and visitor fixes === */
.sidebar-backdrop {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.18);
    z-index: 190;
}
.visitor-room-detect {
    margin: 8px 0 10px;
    padding: 10px 12px;
    border: 1px solid rgba(183, 143, 76, 0.35);
    border-radius: 10px;
    background: rgba(183, 143, 76, 0.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
@media (max-width: 768px) {
    .chat-sidebar {
        width: min(82vw, 320px) !important;
        max-width: 320px;
        transform: translateX(-110%);
        visibility: hidden;
        pointer-events: none;
        overflow: hidden;
    }
    .chat-sidebar.open {
        transform: translateX(0);
        visibility: visible;
        pointer-events: auto;
    }
    .chat-sidebar.closed {
        transform: translateX(-110%);
        visibility: hidden;
        pointer-events: none;
    }
    .chat-sidebar:not(.open) {
        transform: translateX(-110%) !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}
@media (max-width: 480px) {
    .header-right {
        gap: 6px;
        flex-shrink: 0;
    }
    #btn-sync-room {
        display: inline-flex !important;
    }
    #btn-copy-rejoin-link {
        display: none !important;
    }
    .lang-switch {
        padding: 6px 10px;
    }
}


/* === v2.4.21 admin crash actions === */
.maintenance-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}


/* === v2.4.21 debug console and full sidebar collapse === */
#debug-dot { position: fixed; right: 14px; bottom: 14px; width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); background: #fff; color: #111; z-index: 9999; font-weight: 700; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
#debug-dot.debug-dot-admin { left: 14px; right: auto; bottom: 14px; }
.debug-panel { position: fixed; right: 14px; bottom: 64px; width: min(92vw, 520px); height: min(70vh, 520px); background: #fff; color: #111; border: 1px solid #bbb; border-radius: 10px; z-index: 9999; display: flex; flex-direction: column; box-shadow: 0 8px 28px rgba(0,0,0,.3); }
.debug-head { display: flex; gap: 6px; align-items: center; padding: 8px; border-bottom: 1px solid #ddd; }
.debug-head strong { margin-right: auto; }
.debug-head button { padding: 4px 8px; border: 1px solid #bbb; background: #f7f7f7; color: #111; border-radius: 6px; }
#debug-list { flex: 1; margin: 0; padding: 10px; overflow: auto; white-space: pre-wrap; font-size: 11px; line-height: 1.35; }
.chat-sidebar.closed { display: none !important; width: 0 !important; min-width: 0 !important; max-width: 0 !important; visibility: hidden !important; pointer-events: none !important; }
.chat-sidebar.open { display: flex !important; }

.admin-debug-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 14px;
}
.admin-debug-option input {
    width: 18px;
    height: 18px;
}


/* 聊天室调试入口放回人员面板底部；管理员控制台入口固定在左下角 */
.debug-sidebar-slot {
    margin-top: auto;
    padding: 12px;
}
.debug-sidebar-slot #debug-dot {
    position: static;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.debug-panel .debug-flash {
    position: absolute;
    right: 10px;
    bottom: 10px;
    background: #111;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity .18s ease;
    pointer-events: none;
    font-size: 12px;
}
.debug-panel .debug-flash.show {
    opacity: .92;
}


/* Brand visibility and user-entry mode */
body.brand-hidden .landing-brand,
body.brand-hidden .auth-logo,
body.brand-hidden .header-logo {
    display: none !important;
}

body.user-entry-mode #btn-admin-login {
    display: none !important;
}

.admin-maintenance-options {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    margin-top: 12px;
}
