/**
 * ═══════════════════════════════════════════════════════════════
 * PRMessenger - Complete Responsive CSS (FIXED)
 * Version: 6.2 Final - All Alignment Issues Fixed
 * ═══════════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════════════════════════
   CSS CUSTOM PROPERTIES (VARIABLES)
   ═══════════════════════════════════════════════════════════════ */

:root {
    /* Colors */
    --primary: #4A90E2;
    --primary-dark: #3a7bc8;
    --primary-light: #5a9eeb;
    --primary-glow: rgba(74, 144, 226, 0.3);
    
    --secondary: #0a0a0a;
    --secondary-light: #1a1a1a;
    --secondary-dark: #000000;
    
    --accent: #4A90E2;
    --accent-ash: #708090;
    --accent-cyan: #5dade2;
    
    --surface-dark: #0a0a0a;
    --surface-card: #1a1a1a;
    --surface-light: #2a2a2a;
    --surface-hover: #353535;
    
    --text-primary: #ffffff;
    --text-secondary: #b0bec5;
    --text-muted: #708090;
    
    --border: rgba(74, 144, 226, 0.2);
    --border-light: rgba(74, 144, 226, 0.1);
    --shadow: rgba(74, 144, 226, 0.3);
    
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --info: #4A90E2;
    
    /* Gradients */
    --gradient: linear-gradient(135deg, #4A90E2 0%, #2c3e50 100%);
    --gradient-reverse: linear-gradient(135deg, #2c3e50 0%, #4A90E2 100%);
    --gradient-subtle: linear-gradient(135deg, rgba(74, 144, 226, 0.1) 0%, rgba(44, 62, 80, 0.1) 100%);
    
    /* Transitions */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 50%;
}

/* ═══════════════════════════════════════════════════════════════
   GLOBAL RESET & BASE STYLES
   ═══════════════════════════════════════════════════════════════ */

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

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--surface-dark);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

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

::-webkit-scrollbar-track {
    background: var(--surface-dark);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Utility Classes */
.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;
}

.h3-style {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

/* ═══════════════════════════════════════════════════════════════
   CONNECTION STATUS
   ═══════════════════════════════════════════════════════════════ */

.connection-status {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px var(--shadow);
    z-index: 10000;
    transition: top 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border: 1px solid var(--primary);
    backdrop-filter: blur(10px);
}

.connection-status.show {
    top: 20px;
}

.connection-status.connected {
    background: var(--success);
    color: #000;
    border-color: var(--success);
}

.connection-status.disconnected {
    background: var(--error);
    color: #fff;
    border-color: var(--error);
}

.connection-status.reconnecting {
    background: var(--warning);
    color: #000;
    border-color: var(--warning);
}

/* ═══════════════════════════════════════════════════════════════
   PWA INSTALL POPUP
   ═══════════════════════════════════════════════════════════════ */

.pwa-install-popup {
    position: fixed;
    bottom: -300px;
    right: 20px;
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 350px;
    box-shadow: 0 12px 48px var(--shadow);
    z-index: 9999;
    transition: bottom 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border: 2px solid var(--primary);
}

.pwa-install-popup.show {
    bottom: 20px;
}

.pwa-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    transition: var(--transition);
}

.pwa-close:hover {
    color: var(--primary);
    transform: rotate(90deg);
}

.pwa-popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.pwa-popup-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.pwa-popup-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
}

.pwa-popup-subtitle {
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.pwa-popup-buttons {
    display: flex;
    gap: 12px;
}

/* ═══════════════════════════════════════════════════════════════
   LANDING PAGE
   ═══════════════════════════════════════════════════════════════ */

.landing-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 20px;
    background: var(--surface-dark);
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(74, 144, 226, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(112, 128, 144, 0.1) 0%, transparent 50%);
    overflow-y: auto;
}

.landing-card {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    max-width: 450px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    border: 2px solid var(--primary);
    position: relative;
    overflow: hidden;
}

.landing-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: var(--gradient-subtle);
    animation: rotate 20s linear infinite;
    opacity: 0.5;
    z-index: 0;
}

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

.landing-card > * {
    position: relative;
    z-index: 1;
}

.logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    display: block;
    border-radius: var(--radius-full);
    box-shadow: 0 8px 32px var(--primary-glow);
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 8px 32px var(--primary-glow); 
    }
    50% { 
        transform: scale(1.05); 
        box-shadow: 0 12px 48px var(--primary-glow); 
    }
}

.brand-title {
    font-size: 2.5rem;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.brand-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 1rem;
    line-height: 1.5;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.input {
    width: 100%;
    padding: 14px 18px;
    background: var(--surface-light);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
    outline: none;
    font-family: inherit;
}

.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
    background: var(--surface-card);
}

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

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
    z-index: 0;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn > * {
    position: relative;
    z-index: 1;
}

.btn-primary {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--primary-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 10px 18px;
    font-size: 0.9rem;
}

.btn-warning {
    background: var(--warning);
    color: #000;
}

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

.input-group {
    display: flex;
    gap: 12px;
}

.input-group .input {
    flex: 1;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 24px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border);
}

.divider span {
    padding: 0 16px;
}

.features {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.8;
    text-align: center;
}

/* ═══════════════════════════════════════════════════════════════
   CHAT CONTAINER
   ═══════════════════════════════════════════════════════════════ */

.chat-container {
    display: none;
    height: 100vh;
    height: -webkit-fill-available;
    flex-direction: row;
    background: var(--surface-dark);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    overflow: hidden;
}

.chat-container.active {
    display: flex;
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════ */

.sidebar {
    width: 280px;
    background: var(--surface-card);
    border-right: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    height: 100%;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 2px solid var(--border);
    background: var(--gradient-subtle);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.current-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 4px 16px var(--primary-glow);
}

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

.user-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.sidebar-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.sidebar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--surface-light);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 16px;
}

.sidebar-icon-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

.sidebar-search {
    padding: 12px 16px;
    border-bottom: 2px solid var(--border);
    flex-shrink: 0;
}

.sidebar-search-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--surface-light);
    border: 2px solid var(--border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
    font-family: inherit;
    outline: none;
}

.sidebar-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

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

.sidebar-section {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.sidebar-section-header {
    padding: 16px 16px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--surface-card);
    z-index: 10;
}

.sidebar-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.participant-count-badge {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.participants-list {
    padding: 0 8px 16px;
}

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

.participant-item:hover {
    background: var(--surface-light);
}

.participant-item.active {
    background: var(--gradient-subtle);
    border-left: 3px solid var(--primary);
}

.participant-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.participant-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: var(--radius-full);
    background: var(--success);
    border: 2px solid var(--surface-card);
    box-shadow: 0 0 8px var(--success);
}

.participant-status-dot.offline {
    background: var(--text-muted);
    box-shadow: none;
}

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

.participant-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.participant-role {
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.participant-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    background: var(--primary);
    color: white;
}

.participant-badge.admin {
    background: var(--warning);
    color: #000;
}

.participant-badge.you {
    background: var(--success);
    color: #000;
}

/* ═══════════════════════════════════════════════════════════════
   MAIN CHAT AREA
   ═══════════════════════════════════════════════════════════════ */

.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-dark);
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.chat-header {
    background: var(--surface-card);
    padding: 16px 20px;
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    min-height: 70px;
    height: 70px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.sidebar-toggle-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: var(--transition);
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-btn:hover {
    background: var(--surface-light);
    color: var(--primary);
}

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

.room-info h1 {
    margin: 0;
    font-size: 1.25rem;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.3;
}

.room-info p {
    margin: 2px 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

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

.participants {
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.menu-btn,
.back-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: var(--transition);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-btn:hover,
.back-btn:hover {
    background: var(--surface-light);
    color: var(--primary);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    padding-bottom: 80px;
    background: var(--surface-dark);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(74, 144, 226, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 90% 80%, rgba(112, 128, 144, 0.05) 0%, transparent 50%);
    min-height: 0;
    scroll-behavior: smooth;
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    max-width: 500px;
    margin: 0 auto;
    min-height: 50vh;
}

.welcome .logo {
    width: 100px;
    height: 100px;
    margin-bottom: 24px;
}

.welcome h2 {
    font-size: 1.75rem;
    margin-bottom: 12px;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.3;
}

.welcome p {
    color: var(--text-secondary);
    line-height: 1.6;
}

.message-group {
    margin-bottom: 24px;
    animation: slideIn 0.3s ease;
}

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

.message-group.own {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

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

.avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 2px 8px var(--primary-glow);
    flex-shrink: 0;
}

.sender-name {
    font-weight: 600;
    color: var(--primary);
}

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

.message-wrapper {
    position: relative;
    max-width: 70%;
    transition: transform 0.2s ease;
}

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

.message-wrapper.swiping {
    transform: translateX(-40px);
}

.swipe-reply-indicator {
    position: absolute;
    right: -35px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message-wrapper.swiping .swipe-reply-indicator {
    opacity: 1;
}

.message {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    word-break: break-word;
    position: relative;
    transition: var(--transition);
    cursor: pointer;
    border: 1px solid transparent;
}

.message.received {
    background: var(--surface-card);
    border-color: var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
}

.message.sent {
    background: var(--gradient);
    color: white;
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
    box-shadow: 0 4px 16px var(--primary-glow);
}

.message:hover {
    transform: scale(1.02);
}

.message.long-pressing {
    animation: vibrate 0.1s linear infinite;
}

@keyframes vibrate {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-1px, 1px); }
    50% { transform: translate(1px, -1px); }
    75% { transform: translate(-1px, -1px); }
}

.message.double-tapped {
    animation: doubleTapPulse 0.3s ease;
}

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

.message-text {
    line-height: 1.5;
}

.reply-indicator {
    background: rgba(255, 255, 255, 0.1);
    border-left: 3px solid var(--primary);
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.reply-to {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 2px;
}

.reply-preview {
    color: var(--text-secondary);
    opacity: 0.8;
}

.message-reactions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.reaction {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.reaction:hover {
    background: var(--surface-hover);
    transform: scale(1.1);
}

.reaction.own-reaction {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.file-message {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    min-width: 200px;
}

.file-icon {
    font-size: 32px;
    flex-shrink: 0;
}

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

.file-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    font-size: 0.8rem;
    opacity: 0.7;
}

.media-message {
    padding: 4px;
    max-width: 300px;
}

.message-media {
    border-radius: var(--radius-md);
    overflow: hidden;
}

.message-image,
.message-video {
    width: 100%;
    max-height: 400px;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: var(--transition);
}

.message-image:hover {
    transform: scale(1.02);
}

.message-audio {
    width: 100%;
}

.voice-message {
    min-width: 200px;
}

.voice-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.play-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: 0 2px 8px var(--primary-glow);
    flex-shrink: 0;
}

.play-btn:hover {
    transform: scale(1.1);
}

.voice-waveform {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
}

.voice-bar {
    width: 3px;
    height: 12px;
    background: currentColor;
    border-radius: 2px;
    animation: wave 1s ease-in-out infinite;
}

.voice-bar:nth-child(1) { animation-delay: 0s; height: 8px; }
.voice-bar:nth-child(2) { animation-delay: 0.1s; height: 16px; }
.voice-bar:nth-child(3) { animation-delay: 0.2s; height: 12px; }
.voice-bar:nth-child(4) { animation-delay: 0.3s; height: 14px; }
.voice-bar:nth-child(5) { animation-delay: 0.4s; height: 10px; }

@keyframes wave {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(1.5); }
}

.voice-duration {
    font-size: 0.85rem;
    flex-shrink: 0;
}

.system-message {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 12px auto;
    padding: 8px 16px;
    background: var(--gradient-subtle);
    border-radius: var(--radius-md);
    max-width: fit-content;
}

.typing-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface-card);
    border-radius: var(--radius-md);
    max-width: fit-content;
    margin: 0 20px 10px;
    opacity: 0;
    transform: translateY(10px);
    transition: var(--transition);
    border: 1px solid var(--border);
}

.typing-indicator.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: var(--radius-full);
    animation: typingDot 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

.reply-mode {
    padding: 12px 20px;
    background: var(--surface-card);
    border-top: 2px solid var(--border);
    display: none;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.reply-mode.active {
    display: flex;
}

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

.reply-cancel {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-md);
    transition: var(--transition);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.reply-cancel:hover {
    color: var(--primary);
    background: var(--surface-light);
}

.message-input-container {
    padding: 16px 20px;
    background: var(--surface-card);
    border-top: 2px solid var(--border);
    flex-shrink: 0;
    min-height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.message-input-wrapper {
    background: var(--surface-light);
    border: 2px solid var(--border);
    border-radius: 24px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
    min-height: 48px;
}

.message-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.input-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-full);
    transition: var(--transition);
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-btn:hover {
    background: var(--surface-hover);
    color: var(--primary);
}

.message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    padding: 8px 0;
    line-height: 1.5;
    min-height: 24px;
}

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

.send-btn {
    background: var(--gradient);
    color: white;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.send-btn:hover {
    transform: scale(1.05);
}

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

.recording-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    color: var(--error);
    font-size: 0.9rem;
}

.recording-indicator.active {
    display: flex;
}

.recording-dot {
    width: 12px;
    height: 12px;
    background: var(--error);
    border-radius: var(--radius-full);
    animation: recordingPulse 1s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes recordingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.context-menu {
    position: fixed;
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8);
    border: 2px solid var(--border);
    padding: 8px 0;
    min-width: 160px;
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95);
    transition: var(--transition);
}

.context-menu.show {
    opacity: 1;
    pointer-events: all;
    transform: scale(1);
}

.context-menu-item {
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
    text-align: left;
    font-family: inherit;
}

.context-menu-item:hover {
    background: var(--surface-light);
}

.context-menu-item.danger {
    color: var(--error);
}

.reaction-picker {
    position: fixed;
    background: var(--surface-card);
    border-radius: 40px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8);
    border: 2px solid var(--border);
    padding: 8px 12px;
    display: flex;
    gap: 8px;
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
    transition: var(--transition);
}

.reaction-picker.show {
    opacity: 1;
    pointer-events: all;
    transform: scale(1);
}

.reaction-option {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.reaction-option:hover {
    background: var(--surface-light);
    transform: scale(1.2);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    padding: 32px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 80px rgba(0, 0, 0, 0.9);
    border: 2px solid var(--border);
    position: relative;
    animation: modalSlideIn 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-content h3 {
    color: var(--primary);
    margin-bottom: 24px;
    text-align: center;
    font-size: 1.5rem;
    line-height: 1.3;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.admin-controls {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.media-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(12px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.media-viewer.active {
    display: flex;
}

.media-viewer-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--surface-card);
    border: none;
    color: var(--text-primary);
    font-size: 32px;
    width: 50px;
    height: 50px;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.media-viewer-close:hover {
    background: var(--primary);
    transform: rotate(90deg);
}

.media-viewer-content {
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 80px rgba(0, 0, 0, 0.9);
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-card);
    color: var(--text-primary);
    padding: 14px 24px;
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
    border: 2px solid var(--border);
    z-index: 10001;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    min-width: 300px;
    text-align: center;
}

.toast.show {
    opacity: 1;
    pointer-events: all;
}

.toast.success {
    border-color: var(--success);
    background: var(--success);
    color: #000;
}

.toast.error {
    border-color: var(--error);
    background: var(--error);
    color: #fff;
}

.toast.info {
    border-color: var(--info);
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR OVERLAY (MOBILE)
   ═══════════════════════════════════════════════════════════════ */

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    display: none;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
    pointer-events: all;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVENESS - TABLET (1024px)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .sidebar {
        width: 260px;
    }
    
    .participants {
        font-size: 0.85rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVENESS - MOBILE (768px)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Landing Page */
    .landing-page {
        padding: 16px;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    .landing-card {
        padding: 40px 24px;
        max-width: 100%;
    }
    
    .logo {
        width: 90px;
        height: 90px;
    }
    
    .brand-title {
        font-size: 2rem;
    }
    
    .brand-subtitle {
        font-size: 0.95rem;
    }
    
    .input {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 14px 16px;
    }
    
    .btn {
        min-height: 48px;
        padding: 14px 20px;
    }
    
    /* Chat Header */
    .chat-header {
        padding: 12px 16px;
        min-height: 64px;
        height: 64px;
    }
    
    .sidebar-toggle-btn {
        display: flex !important;
    }
    
    .room-info h1 {
        font-size: 1.1rem;
    }
    
    .room-info p {
        font-size: 0.75rem;
    }
    
    .participants {
        display: none !important;
    }
    
    .menu-btn,
    .back-btn {
        font-size: 20px;
    }
    
    /* Sidebar */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 250;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.7);
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    /* Messages */
    .messages-container {
        padding: 16px 12px;
        padding-bottom: 100px;
        -webkit-overflow-scrolling: touch;
    }
    
    .welcome {
        padding: 40px 20px;
        min-height: 40vh;
    }
    
    .welcome .logo {
        width: 120px;
        height: 120px;
    }
    
    .welcome h2 {
        font-size: 1.5rem;
    }
    
    .welcome p {
        font-size: 0.95rem;
    }
    
    .message-wrapper {
        max-width: 85%;
    }
    
    .message {
        padding: 12px 14px;
        font-size: 15px;
    }
    
    .message-info {
        font-size: 0.8rem;
    }
    
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    /* Input Area - FIXED FOR MOBILE */
    .message-input-container {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        position: relative;
        background: var(--surface-card);
        min-height: 68px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .message-input-wrapper {
        padding: 8px 12px;
        border-radius: 24px;
        min-height: 48px;
        display: flex;
        align-items: center;
    }
    
    .message-input {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 8px 6px;
        min-height: 32px;
        line-height: 1.5;
        display: flex;
        align-items: center;
    }
    
    .input-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        font-size: 20px;
        flex-shrink: 0;
    }
    
    .send-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        flex-shrink: 0;
    }
    
    /* Reply Mode */
    .reply-mode {
        padding: 10px 12px;
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    .reply-to {
        font-size: 0.85rem;
    }
    
    .reply-preview {
        font-size: 0.8rem;
    }
    
    /* Context Menu */
    .context-menu {
        min-width: 180px;
    }
    
    .context-menu-item {
        padding: 14px 18px;
        min-height: 48px;
        font-size: 1rem;
    }
    
    /* Reaction Picker */
    .reaction-picker {
        padding: 10px 14px;
        gap: 10px;
    }
    
    .reaction-option {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 26px;
    }
    
    /* Media */
    .media-message {
        max-width: 250px;
    }
    
    .message-image,
    .message-video {
        max-height: 300px;
    }
    
    /* Modal */
    .modal {
        padding: 16px;
    }
    
    .modal-content {
        padding: 24px 20px;
        max-width: 90%;
        margin: auto;
    }
    
    /* Toast */
    .toast {
        left: 16px;
        right: 16px;
        transform: none;
        min-width: auto;
        width: auto;
        text-align: center;
    }
    
    /* PWA Popup */
    .pwa-install-popup {
        left: 12px;
        right: 12px;
        max-width: none;
    }
}

/* ═══════════════════════════════════════════════════════════════
   SMALL MOBILE (480px)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .brand-title {
        font-size: 1.75rem;
    }
    
    .landing-card {
        padding: 32px 20px;
    }
    
    .sidebar {
        width: 90%;
        max-width: 300px;
    }
    
    .message-wrapper {
        max-width: 90%;
    }
    
    .message {
        font-size: 14px;
        padding: 10px 12px;
    }
    
    .chat-header {
        padding: 10px 12px;
    }
    
    .room-info h1 {
        font-size: 1rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   EXTRA SMALL MOBILE (360px)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 360px) {
    .brand-title {
        font-size: 1.5rem;
    }
    
    .logo {
        width: 70px;
        height: 70px;
    }
    
    .message-input-wrapper {
        padding: 6px 10px;
        display: flex;
        align-items: center;
        min-height: 44px;
    }
    
    .input-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        font-size: 16px;
    }
    
    .send-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   iOS SPECIFIC FIXES
   ═══════════════════════════════════════════════════════════════ */

@supports (-webkit-touch-callout: none) {
    body {
        min-height: -webkit-fill-available;
    }
    
    .chat-container {
        height: -webkit-fill-available;
    }
    
    .messages-container {
        padding-bottom: calc(100px + env(safe-area-inset-bottom));
    }
    
    /* Prevent iOS zoom on input focus */
    .input,
    .message-input,
    .sidebar-search-input {
        font-size: 16px !important;
    }
    
    /* iOS safe area handling */
    .chat-header {
        padding-top: calc(12px + env(safe-area-inset-top));
        height: auto;
        min-height: calc(64px + env(safe-area-inset-top));
    }
    
    .message-input-container {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    /* iOS smooth scrolling */
    .messages-container,
    .sidebar-section {
        -webkit-overflow-scrolling: touch;
    }
}

/* ═══════════════════════════════════════════════════════════════
   TOUCH DEVICE OPTIMIZATIONS
   ═══════════════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .input-btn,
    .menu-btn,
    .back-btn,
    .sidebar-icon-btn,
    .sidebar-toggle-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Better touch feedback */
    .btn:active {
        transform: scale(0.97);
    }
    
    .message:active {
        transform: scale(0.98);
    }
    
    /* Remove hover states on touch devices */
    .message:hover,
    .participant-item:hover,
    .context-menu-item:hover {
        transform: none;
    }
    
    /* Touch-specific tap highlight */
    button,
    .message,
    .participant-item {
        -webkit-tap-highlight-color: rgba(74, 144, 226, 0.15);
    }
}

/* ═══════════════════════════════════════════════════════════════
   LANDSCAPE MODE (MOBILE)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 896px) and (orientation: landscape) {
    .landing-page {
        padding: 12px;
    }
    
    .landing-card {
        padding: 24px 28px;
        max-height: 90vh;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .logo {
        width: 60px;
        height: 60px;
        margin-bottom: 12px;
    }
    
    .brand-title {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }
    
    .brand-subtitle {
        font-size: 0.85rem;
        margin-bottom: 20px;
    }
    
    .messages-container {
        padding: 12px;
    }
    
    .welcome {
        padding: 30px 20px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   HIGH CONTRAST MODE
   ═══════════════════════════════════════════════════════════════ */

@media (prefers-contrast: high) {
    .border,
    .message,
    .input,
    .btn-outline {
        border-width: 3px;
    }
    
    .text-muted {
        opacity: 1;
        color: var(--text-secondary);
    }
}

/* ═══════════════════════════════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════════════════════════════ */

@media print {
    .sidebar,
    .chat-header,
    .message-input-container,
    .context-menu,
    .reaction-picker,
    .modal,
    .toast,
    .sidebar-overlay {
        display: none !important;
    }
    
    .messages-container {
        overflow: visible !important;
        height: auto !important;
        padding: 20px !important;
    }
    
    .message-group {
        page-break-inside: avoid;
    }
    
    .chat-container {
        position: static;
        height: auto;
    }
}

/* ═══════════════════════════════════════════════════════════════
   END OF CSS - ALL ALIGNMENT ISSUES FIXED
   ═══════════════════════════════════════════════════════════════ */
