/* Public Chat Styles - Clean & Modern */
:root {
    --bg-primary: #0a0a12;
    --bg-secondary: #12121f;
    --bg-card: #1a1a2e;
    --bg-hover: #242442;
    --text-primary: #ffffff;
    --text-secondary: #8892b0;
    --accent-green: #10b981;
    --accent-emerald: #059669;
    --accent-blue: #4f8cff;
    --border-color: #2a2a45;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --radius: 16px;
    --radius-sm: 10px;
    /* Safe area insets - fallback to 0 */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    /* Fix iOS Safari 100vh issue */
    height: -webkit-fill-available;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    line-height: 1.6;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: contain;
    /* Prevent text selection on UI elements */
    -webkit-user-select: none;
    user-select: none;
}

/* Allow text selection in messages and inputs */
.message-content,
.markdown-content,
input,
textarea {
    -webkit-user-select: text;
    user-select: text;
}

/* Hide mobile hint by default, show desktop hint */
.hint-mobile { display: none; }
.hint-desktop { display: inline; }

/* Full Screen App Container */
.app-container {
    display: grid;
    grid-template-rows: auto minmax(0, auto) 1fr;
    height: 100vh;
    width: 100%;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 32px;
}

.back-button {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-weight: 500;
}

.back-button:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo i {
    font-size: 32px;
    color: var(--accent-green);
}

.logo h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Online Users Container */
.online-users-container {
    position: relative;
}

.online-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--accent-green);
    cursor: pointer;
    transition: all 0.2s;
}

.online-badge:hover,
.online-badge.active {
    background: rgba(16, 185, 129, 0.25);
    border-color: rgba(16, 185, 129, 0.5);
}

.online-badge .fa-users {
    font-size: 14px;
}

.online-count {
    font-weight: 700;
    font-size: 15px;
    min-width: 18px;
    text-align: center;
}

.online-count.updated {
    animation: countPop 0.3s ease;
}

@keyframes countPop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

.online-label {
    font-size: 13px;
    opacity: 0.9;
}

.pulse {
    width: 8px;
    height: 8px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* Online Users Dropdown */
.online-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    width: 240px;
    max-height: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 100;
}

.online-dropdown.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.dropdown-header i {
    color: var(--accent-green);
}

.dropdown-list {
    max-height: 250px;
    overflow-y: auto;
    padding: 8px;
}

.loading-users {
    display: flex;
    justify-content: center;
    padding: 20px;
    color: var(--text-secondary);
}

.no-users {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.online-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    transition: background 0.15s;
}

.online-user:hover {
    background: var(--bg-hover);
}

.online-user.is-you {
    background: rgba(16, 185, 129, 0.1);
}

.user-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-green);
    border-radius: 50%;
    flex-shrink: 0;
    animation: pulse 2s infinite;
}

.user-name {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.you-badge {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--accent-green);
    color: white;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Leaderboard Section */
.leaderboard-section {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    background: transparent;
    border: none;
    color: #fbbf24;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.leaderboard-toggle:hover {
    background: rgba(251, 191, 36, 0.1);
}

.leaderboard-toggle .fa-trophy {
    font-size: 16px;
}

.leaderboard-toggle .toggle-icon {
    font-size: 12px;
    transition: transform 0.3s;
}

.leaderboard-section.expanded .leaderboard-toggle .toggle-icon {
    transform: rotate(180deg);
}

.leaderboard-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.leaderboard-section.expanded .leaderboard-content {
    max-height: 350px;
    overflow-y: auto;
}

.leaderboard-list {
    padding: 12px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-loading {
    display: flex;
    justify-content: center;
    padding: 20px;
    color: var(--text-secondary);
}

.leaderboard-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.leaderboard-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-color);
    transform: translateX(4px);
}

.leaderboard-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}

.leaderboard-rank.rank-1 {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1a1a2e;
}

.leaderboard-rank.rank-2 {
    background: linear-gradient(135deg, #9ca3af, #6b7280);
    color: white;
}

.leaderboard-rank.rank-3 {
    background: linear-gradient(135deg, #d97706, #b45309);
    color: white;
}

.leaderboard-rank.rank-other {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

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

.leaderboard-username {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.leaderboard-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-preview .fa-paperclip {
    margin-right: 4px;
    font-size: 11px;
}

.leaderboard-likes {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(239, 68, 68, 0.15);
    border-radius: 20px;
    color: #ef4444;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.leaderboard-likes i {
    font-size: 13px;
}

/* Username Modal */
.username-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(10px);
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 48px 40px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    animation: modalIn 0.3s ease;
}

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

.modal-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-emerald));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    font-size: 36px;
    color: white;
}

.modal-content h2 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.modal-content > p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.username-input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.username-input-group input {
    flex: 1;
    padding: 14px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s;
}

.username-input-group input:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.username-input-group input::placeholder {
    color: var(--text-secondary);
}

.random-btn {
    width: 52px;
    height: 52px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--accent-green);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.random-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-green);
    transform: rotate(180deg);
}

.join-btn {
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-emerald));
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.join-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
}

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

/* Chat Container */
.chat-container {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 180px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 40px;
    max-width: 600px;
    margin: auto;
    width: 100%;
}

.welcome-icon {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, var(--accent-green) 0%, var(--accent-emerald) 100%);
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 28px;
    font-size: 44px;
    color: white;
    box-shadow: 0 16px 48px rgba(16, 185, 129, 0.25);
}

.welcome-message h2 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 12px;
}

.welcome-message > p {
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1.6;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    animation: fadeIn 0.3s ease;
}

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

.message.own {
    flex-direction: row-reverse;
    margin-left: auto;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

.message-bubble {
    flex: 1;
    max-width: 70%;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
    padding: 0 4px;
}

.message.own .message-header {
    flex-direction: row-reverse;
}

.message-username {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

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

.message-content {
    border-radius: var(--radius);
    line-height: 1.6;
    font-size: 15px;
    word-wrap: break-word;
    overflow: hidden;
}

.message:not(.own) .message-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-top-left-radius: 4px;
}

.message.own .message-content {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-emerald));
    color: white;
    border-top-right-radius: 4px;
}

/* Message Footer with Like Button */
.message-footer {
    display: flex;
    align-items: center;
    padding: 6px 12px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.message:not(.own) .message-footer {
    border-color: var(--border-color);
}

.like-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 13px;
    transition: all 0.2s;
}

.like-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.like-btn.liked {
    color: #ef4444;
}

.like-btn.liked i {
    animation: heartBeat 0.3s ease;
}

.like-btn.like-animate i {
    animation: heartPop 0.3s ease;
}

@keyframes heartPop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.2); }
    50% { transform: scale(0.95); }
    75% { transform: scale(1.1); }
}

.like-count {
    font-weight: 600;
    min-width: 12px;
}

.message.own .like-btn {
    color: rgba(255, 255, 255, 0.7);
}

.message.own .like-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.message.own .like-btn.liked {
    color: white;
}

/* Text inside message */
.message-text {
    padding: 14px 18px;
}

.message-text:empty {
    display: none;
}

/* Markdown Content Styles */
.markdown-content {
    line-height: 1.6;
}

.markdown-content p {
    margin: 0 0 0.5em 0;
}

.markdown-content p:last-child {
    margin-bottom: 0;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin: 0.8em 0 0.4em 0;
    font-weight: 600;
    line-height: 1.3;
}

.markdown-content h1:first-child,
.markdown-content h2:first-child,
.markdown-content h3:first-child {
    margin-top: 0;
}

.markdown-content h1 { font-size: 1.4em; }
.markdown-content h2 { font-size: 1.25em; }
.markdown-content h3 { font-size: 1.1em; }
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 { font-size: 1em; }

/* Inline code */
.markdown-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9em;
}

.message.own .markdown-content code {
    background: rgba(255, 255, 255, 0.2);
}

/* Code blocks */
.markdown-content pre {
    margin: 0.8em 0;
    padding: 12px 14px;
    background: #1e1e2e;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.9em;
}

.markdown-content pre code {
    background: transparent;
    padding: 0;
    font-size: inherit;
    color: #c9d1d9;
}

.message.own .markdown-content pre {
    background: rgba(0, 0, 0, 0.3);
}

/* Lists */
.markdown-content ul,
.markdown-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.markdown-content li {
    margin: 0.25em 0;
}

.markdown-content ul ul,
.markdown-content ol ol,
.markdown-content ul ol,
.markdown-content ol ul {
    margin: 0.25em 0;
}

/* Blockquotes */
.markdown-content blockquote {
    margin: 0.8em 0;
    padding: 8px 14px;
    border-left: 3px solid var(--accent-green);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 6px 6px 0;
}

.message.own .markdown-content blockquote {
    border-left-color: rgba(255, 255, 255, 0.5);
    background: rgba(0, 0, 0, 0.15);
}

.markdown-content blockquote p {
    margin: 0;
}

/* Links */
.markdown-content a {
    color: var(--accent-blue);
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

.message.own .markdown-content a {
    color: #a8d4ff;
}

/* Horizontal rules */
.markdown-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1em 0;
}

.message.own .markdown-content hr {
    border-top-color: rgba(255, 255, 255, 0.3);
}

/* Tables */
.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.8em 0;
    font-size: 0.9em;
}

.markdown-content th,
.markdown-content td {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.markdown-content th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

.message.own .markdown-content th,
.message.own .markdown-content td {
    border-color: rgba(255, 255, 255, 0.2);
}

.message.own .markdown-content th {
    background: rgba(0, 0, 0, 0.15);
}

/* Strong and emphasis */
.markdown-content strong {
    font-weight: 600;
}

.markdown-content em {
    font-style: italic;
}

/* Strikethrough */
.markdown-content del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Images in markdown */
.markdown-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 0.5em 0;
}

/* Task lists */
.markdown-content input[type="checkbox"] {
    margin-right: 6px;
}

/* System Messages */
.system-message {
    text-align: center;
    padding: 12px 20px;
    color: var(--text-secondary);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.system-message i {
    color: var(--accent-green);
}

/* Input Area */
.input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 24px 24px;
    background: transparent;
    z-index: 10;
}

.current-user {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px 14px;
    background: rgba(18, 18, 31, 0.85);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

.current-user i {
    color: var(--accent-green);
}

#displayUsername {
    font-weight: 600;
    color: var(--text-primary);
}

.change-name-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.change-name-btn:hover {
    color: var(--accent-green);
    background: var(--bg-card);
}

/* File Preview */
.file-preview {
    max-width: 700px;
    margin: 0 auto 12px;
    padding: 12px;
    background: rgba(18, 18, 31, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(42, 42, 69, 0.6);
    border-radius: var(--radius-sm);
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
}

.preview-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
}

.preview-content img {
    max-height: 100px;
    max-width: 150px;
    border-radius: 8px;
    object-fit: cover;
}

.preview-content .file-icon {
    width: 48px;
    height: 48px;
    background: var(--bg-card);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--accent-green);
    flex-shrink: 0;
}

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

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

.preview-content .file-size {
    font-size: 12px;
    color: #a0aec0;
}

.remove-file-btn {
    width: 32px;
    height: 32px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.remove-file-btn:hover {
    background: #ff4757;
    border-color: #ff4757;
    color: white;
}

/* Attach Button */
.attach-btn {
    width: 42px;
    height: 42px;
    background: var(--bg-hover);
    border: none;
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: var(--accent-green);
    color: white;
}

.attach-btn.has-file {
    background: var(--accent-green);
    color: white;
}

/* Folder upload button */
.folder-btn {
    background: var(--bg-hover);
}

.folder-btn:hover {
    background: #f59e0b;
    color: white;
}

.folder-btn.compressing {
    background: #f59e0b;
    color: white;
    animation: pulse-folder 1s infinite;
}

@keyframes pulse-folder {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Compression Progress Overlay */
.compression-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(8px);
}

.compression-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 40px 50px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: modalIn 0.3s ease;
}

.compression-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 32px;
    color: white;
    animation: spin-slow 2s linear infinite;
}

@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.compression-modal h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.compression-modal .folder-name {
    color: var(--accent-green);
    font-weight: 500;
    font-size: 16px;
    margin-bottom: 24px;
    word-break: break-all;
}

.compression-progress {
    margin-bottom: 16px;
}

.compression-progress .progress-bar {
    height: 8px;
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}

.compression-progress .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-emerald));
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.compression-progress .progress-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.compression-modal .compression-status {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

/* Message Image */
.message-image {
    display: block;
    max-width: 100%;
    max-height: 300px;
    border-radius: 0 0 12px 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-text + .message-image {
    margin-top: 0;
    border-radius: 0 0 12px 12px;
}

.message-image:only-child {
    border-radius: 12px;
}

.message-image:hover {
    opacity: 0.95;
}

/* Message File Attachment */
.message-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    text-decoration: none;
    transition: all 0.2s;
}

.message:not(.own) .message-file {
    background: var(--bg-card);
}

.message-file:hover {
    background: rgba(0, 0, 0, 0.3);
}

.message:not(.own) .message-file:hover {
    background: var(--bg-hover);
}

.message-file .file-icon {
    width: 40px;
    height: 40px;
    background: var(--bg-hover);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--accent-green);
}

.message.own .message-file .file-icon {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

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

.message-file .file-name {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message:not(.own) .message-file .file-name {
    color: var(--text-primary);
}

.message.own .message-file .file-name {
    color: white;
}

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

.message.own .message-file .file-size {
    color: rgba(255, 255, 255, 0.85);
}

.message-file .download-icon {
    width: 32px;
    height: 32px;
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.4);
    border-radius: 8px;
    color: var(--accent-green);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    transition: all 0.2s;
}

.message:not(.own) .message-file:hover .download-icon {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
}

.message.own .message-file .download-icon {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    color: white;
}

.message.own .message-file:hover .download-icon {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Image Modal for fullscreen view */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    cursor: zoom-out;
}

.image-modal img {
    max-width: 100%;
    max-height: calc(100% - 60px);
    object-fit: contain;
    border-radius: 8px;
}

.modal-download-btn {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--accent-green);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.modal-download-btn:hover {
    background: var(--accent-emerald);
    transform: translateX(-50%) scale(1.05);
}

/* Message Action Buttons */
.message-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    transition: all 0.2s;
    margin-left: auto;
}

.message:hover .message-action-btn {
    opacity: 1;
}

.message-action-btn:hover {
    color: var(--accent-green);
    background: var(--bg-card);
}

.message.own .message-action-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.2);
}

.message-action-btn.copied {
    color: var(--accent-green) !important;
    opacity: 1;
}

.message.own .message-action-btn.copied {
    color: white !important;
}

/* Image Container with Actions */
.message-image-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.image-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-image-container:hover .image-actions {
    opacity: 1;
}

.image-action-btn {
    width: 36px;
    height: 36px;
    background: rgba(16, 185, 129, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.image-action-btn:hover {
    background: var(--accent-emerald);
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.5);
}

/* File Preview Button in Messages */
.file-preview-btn {
    width: 32px;
    height: 32px;
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.4);
    border-radius: 8px;
    color: var(--accent-green);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 14px;
}

.file-preview-btn:hover {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
    transform: scale(1.1);
}

.message.own .file-preview-btn {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    color: white;
}

.message.own .file-preview-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    color: white;
}

/* File Preview Modal */
.file-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.preview-modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.2s ease;
}

.preview-modal-content.pdf-preview {
    max-width: 1000px;
    height: 90vh;
}

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

.preview-filename {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: var(--text-primary);
    min-width: 0;
}

.preview-filename i {
    color: var(--accent-green);
    font-size: 18px;
    flex-shrink: 0;
}

.preview-filename span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.preview-action-btn {
    width: 40px;
    height: 40px;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.4);
    border-radius: 10px;
    color: var(--accent-green);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    text-decoration: none;
    font-size: 16px;
}

.preview-action-btn:hover {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
    transform: scale(1.05);
}

.preview-action-btn.close-btn {
    background: rgba(255, 71, 87, 0.15);
    border-color: rgba(255, 71, 87, 0.4);
    color: #ff4757;
}

.preview-action-btn.close-btn:hover {
    background: #ff4757;
    border-color: #ff4757;
    color: white;
}

.preview-modal-body {
    flex: 1;
    overflow: auto;
    background: #1e1e2e;
}

/* PDF Preview */
.pdf-preview .preview-modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

/* Video Preview */
.video-preview {
    max-width: 1000px;
}

.video-preview .preview-modal-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    min-height: 400px;
}

.video-preview video {
    max-width: 100%;
    max-height: 70vh;
    outline: none;
}

.video-preview video::-webkit-media-controls {
    background: rgba(0, 0, 0, 0.7);
}

/* Audio Preview */
.audio-preview .preview-modal-content {
    max-width: 500px;
}

.audio-preview .preview-modal-body {
    padding: 40px 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.audio-player-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.audio-icon {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-emerald));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: white;
    box-shadow: 0 8px 32px rgba(16, 185, 129, 0.3);
    animation: audioPulse 2s ease-in-out infinite;
}

@keyframes audioPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 32px rgba(16, 185, 129, 0.3); }
    50% { transform: scale(1.05); box-shadow: 0 12px 40px rgba(16, 185, 129, 0.4); }
}

.audio-filename {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audio-player-container audio {
    width: 100%;
    max-width: 400px;
    height: 50px;
    border-radius: 25px;
    outline: none;
}

/* Text Preview */
.text-preview .preview-modal-body {
    padding: 0;
}

.text-preview .preview-modal-body pre {
    margin: 0;
    padding: 20px;
    background: #1e1e2e;
    min-height: 100%;
    overflow-x: auto;
}

.text-preview .preview-modal-body code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.6;
    color: #c9d1d9;
    background: transparent;
    padding: 0;
}

/* Loading state */
.loading-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    gap: 12px;
}

.loading-preview i {
    font-size: 24px;
    color: var(--accent-green);
}

/* Error state */
.preview-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    gap: 12px;
    text-align: center;
}

.preview-error i {
    font-size: 32px;
    color: #ff6b6b;
}

.preview-fallback-link {
    color: var(--accent-green);
    text-decoration: none;
    padding: 8px 16px;
    border: 1px solid var(--accent-green);
    border-radius: 8px;
    margin-top: 8px;
    transition: all 0.2s;
}

.preview-fallback-link:hover {
    background: var(--accent-green);
    color: white;
}

.input-wrapper {
    max-width: 700px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: rgba(26, 26, 46, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(42, 42, 69, 0.6);
    border-radius: 14px;
    padding: 10px 14px;
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Drag and drop state */
.input-wrapper.drag-over {
    border-color: var(--accent-green);
    border-style: dashed;
    background: rgba(16, 185, 129, 0.1);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

#messageInput {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    line-height: 1.5;
    padding: 6px 4px;
}

#messageInput:focus {
    outline: none;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-emerald));
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.send-btn:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.input-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 10px;
}

/* Scroll to Bottom Button */
.scroll-bottom-btn {
    position: absolute;
    bottom: 180px;
    right: 24px;
    z-index: 20;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    opacity: 0;
    transform: translateY(20px) scale(0.8);
    transition: all 0.2s ease;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.scroll-bottom-btn.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.scroll-bottom-btn:hover {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
    transform: translateY(0) scale(1.05);
}

.scroll-bottom-btn:active {
    transform: scale(0.95);
}

/* New Messages Indicator Button */
.new-messages-btn {
    position: absolute;
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 20px;
    background: var(--accent-green);
    border: none;
    border-radius: 25px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 100;
}

.new-messages-btn.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.new-messages-btn:hover {
    background: var(--accent-emerald);
    box-shadow: 0 6px 24px rgba(16, 185, 129, 0.5);
    transform: translateX(-50%) translateY(-2px);
}

.new-messages-btn i {
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}

/* Error Toast */
.error-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    padding: 14px 24px;
    background: #ff4757;
    border-radius: 12px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(255, 71, 87, 0.4);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 3000;
    max-width: 90%;
}

.error-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.error-toast i {
    font-size: 18px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

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

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

/* Loading dots animation */
.loading-dots {
    display: flex;
    gap: 4px;
    justify-content: center;
    padding: 20px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: loadingDot 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes loadingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Tablet */
@media (max-width: 1024px) {
    .header {
        padding: 14px 20px;
    }

    .header-left {
        gap: 20px;
    }

    .messages-area {
        padding: 20px;
        padding-bottom: 200px;
    }

    .input-area {
        padding: 12px 20px 20px;
    }

    .file-preview {
        margin-bottom: 10px;
    }
}

/* ============================================
   MOBILE OPTIMIZATIONS - Professional Grade
   ============================================ */

/* Mobile First - 600px and below */
@media (max-width: 600px) {
    /* ---- BODY & CONTAINERS ---- */
    body {
        font-size: 15px;
        touch-action: manipulation;
    }

    /* Keep the same grid structure as desktop */
    .app-container {
        display: grid;
        grid-template-rows: auto minmax(0, auto) 1fr;
        height: 100vh;
        height: 100dvh;
        width: 100%;
    }

    /* ---- HEADER - Sticky at top ---- */
    .header {
        position: sticky;
        top: 0;
        z-index: 50;
        padding: 10px 12px;
        padding-top: calc(10px + var(--safe-area-top));
        padding-left: calc(12px + var(--safe-area-left));
        padding-right: calc(12px + var(--safe-area-right));
        min-height: 56px;
    }

    .header-left {
        gap: 8px;
    }

    /* Back button - icon only on mobile */
    .back-button {
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
        border-radius: 10px;
    }

    .back-button span {
        display: none;
    }

    .back-button i {
        font-size: 18px;
    }

    /* Logo - compact */
    .logo {
        gap: 8px;
    }

    .logo i {
        font-size: 22px;
    }

    .logo h1 {
        font-size: 18px;
        letter-spacing: -0.3px;
    }

    /* Online Badge - compact */
    .online-badge {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 44px;
        border-radius: 22px;
    }

    .online-badge .fa-users {
        font-size: 13px;
    }

    .online-count {
        font-size: 14px;
        font-weight: 700;
    }

    .online-label {
        display: none; /* Hide "online" text on mobile */
    }

    .pulse {
        width: 6px;
        height: 6px;
    }

    /* ---- ONLINE DROPDOWN - Full width on mobile ---- */
    .online-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 60vh;
        border-radius: 20px 20px 0 0;
        margin-top: 0;
        padding-bottom: var(--safe-area-bottom);
        transform: translateY(100%);
    }

    .online-dropdown.visible {
        transform: translateY(0);
    }

    .dropdown-header {
        padding: 16px 20px;
        font-size: 16px;
    }

    .dropdown-list {
        padding: 12px 16px;
        max-height: calc(60vh - 60px);
    }

    .online-user {
        padding: 14px 16px;
        border-radius: 12px;
    }

    .user-name {
        font-size: 15px;
    }

    /* ---- LEADERBOARD - Fixed height when expanded ---- */
    .leaderboard-section {
        position: relative;
        z-index: 40;
        flex-shrink: 0;
    }

    .leaderboard-toggle {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 48px;
    }

    .leaderboard-toggle .fa-trophy {
        font-size: 15px;
    }

    .leaderboard-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .leaderboard-section.expanded .leaderboard-content {
        max-height: 280px; /* Smaller on mobile */
        overflow-y: auto;
    }

    .leaderboard-list {
        padding: 10px 12px 14px;
        gap: 8px;
    }

    .leaderboard-item {
        padding: 12px;
        gap: 10px;
        min-height: 56px;
        border-radius: 12px;
    }

    /* Disable hover transform on mobile */
    .leaderboard-item:hover {
        transform: none;
    }

    .leaderboard-item:active {
        background: var(--bg-hover);
        transform: scale(0.98);
    }

    .leaderboard-rank {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }

    .leaderboard-username {
        font-size: 14px;
    }

    .leaderboard-preview {
        font-size: 12px;
        line-height: 1.3;
    }

    .leaderboard-likes {
        padding: 6px 10px;
        font-size: 13px;
    }

    /* ---- USERNAME MODAL ---- */
    .username-modal {
        padding: 16px;
        padding-bottom: calc(16px + var(--safe-area-bottom));
        align-items: flex-end; /* Align to bottom on mobile */
    }

    .modal-content {
        padding: 28px 20px;
        border-radius: 20px 20px 0 0;
        max-width: 100%;
        animation: slideUp 0.3s ease;
    }

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

    .modal-icon {
        width: 60px;
        height: 60px;
        font-size: 26px;
        margin-bottom: 16px;
    }

    .modal-content h2 {
        font-size: 22px;
        margin-bottom: 6px;
    }

    .modal-content > p {
        font-size: 14px;
        margin-bottom: 24px;
    }

    .username-input-group {
        gap: 10px;
        margin-bottom: 16px;
    }

    .username-input-group input {
        padding: 14px 16px;
        /* 16px font prevents iOS zoom on focus */
        font-size: 16px;
        border-radius: 12px;
    }

    .random-btn {
        width: 52px;
        height: 52px;
        min-width: 52px;
        border-radius: 12px;
    }

    .join-btn {
        padding: 16px 24px;
        font-size: 16px;
        border-radius: 12px;
        min-height: 52px;
    }

    .hint {
        font-size: 12px;
        margin-top: 12px;
    }

    /* ---- CHAT CONTAINER - relative for absolute input ---- */
    .chat-container {
        position: relative;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* ---- MESSAGES AREA ---- */
    .messages-area {
        flex: 1;
        overflow-y: auto;
        padding: 12px;
        padding-left: calc(12px + var(--safe-area-left));
        padding-right: calc(12px + var(--safe-area-right));
        padding-bottom: 160px; /* Space for input area */
        gap: 8px;
        -webkit-overflow-scrolling: touch;
    }

    /* Welcome message */
    .welcome-message {
        padding: 32px 16px;
    }

    .welcome-icon {
        width: 64px;
        height: 64px;
        font-size: 28px;
        border-radius: 20px;
        margin-bottom: 20px;
    }

    .welcome-message h2 {
        font-size: 22px;
    }

    .welcome-message > p {
        font-size: 14px;
    }

    /* ---- MESSAGE BUBBLES ---- */
    .message {
        gap: 8px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 11px;
        border-radius: 10px;
    }

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

    .message-header {
        gap: 8px;
        margin-bottom: 3px;
        padding: 0 2px;
    }

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

    .message-time {
        font-size: 10px;
    }

    .message-content {
        font-size: 15px;
        border-radius: 14px;
    }

    .message:not(.own) .message-content {
        border-top-left-radius: 4px;
    }

    .message.own .message-content {
        border-top-right-radius: 4px;
    }

    .message-text {
        padding: 10px 14px;
    }

    /* Like button - larger touch target */
    .message-footer {
        padding: 4px 10px 6px;
    }

    .like-btn {
        padding: 8px 12px;
        min-height: 36px;
        font-size: 14px;
        gap: 6px;
    }

    /* Copy button - always visible on mobile */
    .message-action-btn {
        opacity: 0.8;
        padding: 8px 10px;
        min-width: 36px;
        min-height: 36px;
    }

    /* Image in messages */
    .message-image {
        max-height: 220px;
        border-radius: 0 0 14px 14px;
    }

    .message-image:only-child {
        border-radius: 14px;
    }

    .image-actions {
        opacity: 1; /* Always visible on mobile */
    }

    .image-action-btn {
        width: 40px;
        height: 40px;
        font-size: 15px;
    }

    /* File attachment in messages */
    .message-file {
        margin: 6px;
        padding: 10px;
        gap: 10px;
        border-radius: 10px;
        min-height: 56px;
    }

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

    .message-file .file-name {
        font-size: 13px;
        line-height: 1.3;
    }

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

    .message-file .download-icon,
    .file-preview-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    /* Markdown content */
    .markdown-content pre {
        font-size: 12px;
        padding: 10px 12px;
    }

    .markdown-content code {
        font-size: 13px;
    }

    /* ---- INPUT AREA - Absolute at bottom ---- */
    .input-area {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 10;
        padding: 8px 12px;
        padding-left: calc(12px + var(--safe-area-left));
        padding-right: calc(12px + var(--safe-area-right));
        padding-bottom: calc(12px + var(--safe-area-bottom));
        background: transparent;
    }

    .current-user {
        font-size: 12px;
        padding: 6px 10px;
        margin-bottom: 8px;
        border-radius: 8px;
    }

    .change-name-btn {
        padding: 6px 10px;
        min-width: 36px;
        min-height: 36px;
    }

    /* File preview */
    .file-preview {
        padding: 10px;
        margin-bottom: 8px;
        border-radius: 10px;
    }

    .preview-content img {
        max-height: 50px;
        max-width: 70px;
        border-radius: 6px;
    }

    .preview-content .file-icon {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .preview-content .file-name {
        font-size: 13px;
    }

    .preview-content .file-size {
        font-size: 11px;
    }

    .remove-file-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    /* Input wrapper */
    .input-wrapper {
        padding: 8px 10px;
        gap: 8px;
        border-radius: 16px;
    }

    /* Attach buttons - touch-friendly */
    .attach-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 16px;
        border-radius: 10px;
    }

    /* Hide folder button on mobile (doesn't work well) */
    .folder-btn {
        display: none;
    }

    /* Message input */
    #messageInput {
        /* 16px prevents iOS zoom on focus */
        font-size: 16px;
        min-height: 24px;
        padding: 8px 4px;
    }

    /* Send button */
    .send-btn {
        width: 42px;
        height: 42px;
        min-width: 42px;
        font-size: 16px;
        border-radius: 12px;
    }

    /* Send button active state */
    .send-btn:active {
        transform: scale(0.95);
    }

    /* Input hint */
    .input-hint {
        font-size: 11px;
        margin-top: 6px;
        padding: 0 4px;
    }

    .hint-desktop { display: none; }
    .hint-mobile { display: inline; }

    /* ---- SCROLL TO BOTTOM BUTTON ---- */
    .scroll-bottom-btn {
        bottom: calc(170px + var(--safe-area-bottom));
        right: 16px;
        width: 48px;
        height: 48px;
    }

    .scroll-bottom-btn:hover {
        transform: translateY(0) scale(1);
    }

    .scroll-bottom-btn:active {
        transform: scale(0.9);
        background: var(--accent-green);
        color: white;
    }

    /* ---- NEW MESSAGES INDICATOR ---- */
    .new-messages-btn {
        bottom: calc(170px + var(--safe-area-bottom));
        padding: 10px 18px;
        font-size: 13px;
        border-radius: 20px;
    }

    /* ---- IMAGE MODAL ---- */
    .image-modal {
        padding: 0;
        padding-top: var(--safe-area-top);
        padding-bottom: var(--safe-area-bottom);
    }

    .image-modal img {
        max-height: calc(100vh - 100px);
        border-radius: 0;
    }

    .modal-download-btn {
        bottom: calc(20px + var(--safe-area-bottom));
        padding: 14px 28px;
        font-size: 15px;
        border-radius: 25px;
    }

    /* ---- FILE PREVIEW MODALS ---- */
    .file-preview-modal {
        padding: 0;
    }

    .preview-modal-content {
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }

    .preview-modal-content.pdf-preview {
        height: 100vh;
    }

    .preview-modal-header {
        padding: 12px 16px;
        padding-top: calc(12px + var(--safe-area-top));
        flex-wrap: nowrap;
        gap: 10px;
    }

    .preview-filename {
        font-size: 14px;
        flex: 1;
        min-width: 0;
    }

    .preview-filename span {
        max-width: 150px;
    }

    .preview-modal-actions {
        gap: 6px;
    }

    .preview-action-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }

    .text-preview .preview-modal-body pre {
        padding: 12px;
    }

    .text-preview .preview-modal-body code {
        font-size: 12px;
        line-height: 1.5;
    }

    /* Video preview */
    .video-preview .preview-modal-body {
        min-height: 300px;
    }

    .video-preview video {
        max-height: calc(100vh - 80px);
    }

    /* Audio preview */
    .audio-preview .preview-modal-body {
        padding: 30px 20px;
    }

    .audio-icon {
        width: 80px;
        height: 80px;
        font-size: 32px;
    }

    .audio-filename {
        font-size: 14px;
    }

    .audio-player-container audio {
        max-width: 100%;
        height: 44px;
    }

    /* ---- COMPRESSION MODAL ---- */
    .compression-modal {
        padding: 30px 24px;
        margin: 16px;
        border-radius: 20px;
    }

    .compression-icon {
        width: 64px;
        height: 64px;
        font-size: 28px;
    }

    .compression-modal h3 {
        font-size: 18px;
    }

    .compression-modal .folder-name {
        font-size: 14px;
    }

    /* ---- ERROR TOAST ---- */
    .error-toast {
        top: calc(16px + var(--safe-area-top));
        padding: 12px 20px;
        font-size: 14px;
        border-radius: 16px;
        max-width: calc(100% - 32px);
    }

    /* ---- SCROLLBAR - Hide on mobile ---- */
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
    }

    /* ---- TOUCH FEEDBACK ---- */
    .back-button:active,
    .online-badge:active,
    .random-btn:active,
    .join-btn:active,
    .attach-btn:active,
    .change-name-btn:active,
    .remove-file-btn:active,
    .preview-action-btn:active,
    .image-action-btn:active,
    .file-preview-btn:active,
    .leaderboard-toggle:active {
        opacity: 0.7;
        transform: scale(0.97);
    }

    /* Disable hover effects on touch devices */
    @media (hover: none) {
        .back-button:hover,
        .online-badge:hover,
        .random-btn:hover,
        .join-btn:hover,
        .attach-btn:hover,
        .message-file:hover,
        .leaderboard-item:hover {
            background: inherit;
            transform: none;
        }

        .join-btn:hover {
            background: linear-gradient(135deg, var(--accent-green), var(--accent-emerald));
        }

        .send-btn:hover {
            transform: none;
            box-shadow: none;
        }
    }
}

/* Small phones (iPhone SE, etc.) */
@media (max-width: 375px) {
    .header {
        padding: 8px 10px;
        padding-top: calc(8px + var(--safe-area-top));
    }

    .logo h1 {
        font-size: 16px;
    }

    .logo i {
        font-size: 20px;
    }

    .online-badge {
        padding: 6px 10px;
    }

    .messages-area {
        padding: 10px;
        padding-bottom: 150px;
    }

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

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 10px;
    }

    .attach-btn,
    .send-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }
}

/* Landscape mode on phones */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 6px 16px;
        padding-left: calc(16px + var(--safe-area-left));
        padding-right: calc(16px + var(--safe-area-right));
    }

    .logo h1 {
        font-size: 16px;
    }

    .messages-area {
        padding: 8px 16px;
        padding-left: calc(16px + var(--safe-area-left));
        padding-right: calc(16px + var(--safe-area-right));
        padding-bottom: 100px;
    }

    .input-area {
        padding: 6px 16px;
        padding-left: calc(16px + var(--safe-area-left));
        padding-right: calc(16px + var(--safe-area-right));
        padding-bottom: calc(6px + var(--safe-area-bottom));
    }

    .current-user {
        display: none;
    }

    .input-hint {
        display: none;
    }

    .leaderboard-section {
        display: none;
    }

    .new-messages-btn {
        bottom: calc(80px + var(--safe-area-bottom));
    }

    /* Modal takes full screen in landscape */
    .username-modal {
        align-items: center;
    }

    .modal-content {
        border-radius: 16px;
        max-width: 400px;
    }

    .modal-icon {
        width: 50px;
        height: 50px;
        font-size: 22px;
        margin-bottom: 12px;
    }

    .modal-content h2 {
        font-size: 18px;
    }
}

/* Dropdown backdrop for mobile */
.dropdown-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.dropdown-backdrop.visible {
    opacity: 1;
}

/* Keyboard visible state (detected by JS) */
body.keyboard-visible .input-hint {
    display: none;
}

body.keyboard-visible .current-user {
    display: none;
}

body.keyboard-visible .new-messages-btn {
    bottom: 80px;
}

body.keyboard-visible .leaderboard-section {
    display: none;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .pulse {
        animation: none;
    }

    .messagesArea {
        scroll-behavior: auto;
    }
}
