/* ============================================
   Critical Base Styles - Load First
   ============================================ */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    --primary-color: #667eea;
    --primary-dark: #4c63d2;
    --secondary-color: #764ba2;
    --danger-color: #e74c3c;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --own-message-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --other-message-bg: #ffffff;
    --bg-color: #f8f9fc;
    --header-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --header-height: 70px;
    --input-height: 70px;
    --border-radius: 12px;
    --shadow-light: 0 2px 10px rgba(102, 126, 234, 0.1);
    --shadow-medium: 0 4px 20px rgba(102, 126, 234, 0.15);
    --shadow-heavy: 0 8px 30px rgba(102, 126, 234, 0.2);
    --vh: 1vh;
    --visual-vh: 100%;
    /* Default to 100% for non-iOS */
    --ios-keyboard-offset: 0px;
    --ios-keyboard-gap: 0px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: #666;
    background: rgba(255, 255, 255, 0.9);
    padding: 4px 12px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-right: auto;
    /* Push to the left */
    z-index: 10;
    animation: fadeIn 0.3s ease;
}

.typing-text {
    font-weight: 500;
}

.typing-dots {
    display: flex;
    gap: 2px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background-color: #007bff;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%,
    80%,
    100% {
        transform: scale(0.5);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Adjust header actions to accommodate typing indicator */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    position: relative;
    /* Context for absolute positioning if needed */
}

/* Mobile adjustments - typing indicator stays IN header */
@media (max-width: 600px) {
    .typing-indicator {
        font-size: 0.75rem;
        padding: 4px 10px;
        /* STAY in header, not below it */
        position: relative;
        bottom: auto;
        left: auto;
        background: rgba(255, 255, 255, 0.25);
        box-shadow: none;
        margin: 0;
        max-width: 150px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: white;
        border-radius: 10px;
        gap: 6px;
    }

    /* Make dots white and bigger on mobile */
    .typing-indicator .typing-dots span {
        width: 6px;
        height: 6px;
        background-color: white;
    }

    /* Show short text on mobile */
    .typing-indicator .typing-text {
        display: inline;
        font-size: 0.7rem;
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Force SVG to inherit colors */
svg {
    display: inline-block;
    vertical-align: middle;
    fill: none;
    stroke: currentColor;
}

body,
html {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    width: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* iOS Safari - ensure body fills specific visual viewport height */
.ios-safari body,
.ios-safari html {
    height: var(--visual-vh, 100%) !important;
    position: fixed;
    /* Lock body to avoid scroll */
    width: 100%;
}

/* Loading Styles */
.loading-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    /* Fallback */
    height: var(--visual-vh, 100vh);
    background: white;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ============================================
   PROFESSIONAL PORTAL LOGIN STYLES
   ============================================ */

/* Portal Login Container */
.portal-login-container {
    display: flex;
    min-height: 100vh;
    min-height: var(--visual-vh, 100vh);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    background: #f5f7fa;
}

/* Hero Section (Left Side - Desktop) */
.portal-hero {
    flex: 1;
    background: linear-gradient(135deg, #0052CC 0%, #2C5AA0 50%, #1a365d 100%);
    position: relative;
    overflow: hidden;
    display: none; /* Hidden on mobile by default */
}

.portal-hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.08) 0%, transparent 50%),
        linear-gradient(135deg, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
    animation: gradientShift 20s ease infinite;
}

@keyframes gradientShift {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.hero-overlay {
    position: relative;
    z-index: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
}

.hero-content {
    max-width: 500px;
    color: white;
}

.hero-title {
    font-size: 48px;
    font-weight: 700;
    margin: 0 0 20px 0;
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.hero-subtitle {
    font-size: 20px;
    margin: 0 0 40px 0;
    opacity: 0.95;
    line-height: 1.6;
    font-weight: 300;
}

.hero-features {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.hero-feature {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    opacity: 0.9;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.hero-feature svg {
    flex-shrink: 0;
}

/* Form Section (Right Side) */
.portal-form-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: #f5f7fa;
}

.portal-form-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
    padding: 48px;
    width: 100%;
    max-width: 480px;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Logo */
.portal-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 32px;
}

.portal-logo svg {
    filter: drop-shadow(0 4px 12px rgba(0, 82, 204, 0.2));
}

/* Header */
.portal-header {
    text-align: center;
    margin-bottom: 32px;
}

.portal-header h2 {
    font-size: 28px;
    font-weight: 700;
    color: #1a202c;
    margin: 0 0 8px 0;
    letter-spacing: -0.5px;
}

.portal-header p {
    font-size: 15px;
    color: #718096;
    margin: 0;
}

/* System Status */
.system-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    margin-bottom: 24px;
    font-size: 13px;
    color: #166534;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse 2s ease infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

.status-text {
    font-weight: 500;
}

/* Error Message */
.portal-error-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    margin-bottom: 20px;
    color: #dc2626;
    font-size: 14px;
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.portal-error-message svg {
    flex-shrink: 0;
}

/* Form Groups */
.portal-form-group {
    margin-bottom: 24px;
}

.portal-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.portal-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 16px;
    color: #9ca3af;
    pointer-events: none;
}

.portal-input {
    width: 100%;
    padding: 14px 16px 14px 48px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-size: 16px; /* iOS safe - prevents zoom */
    color: #1f2937;
    transition: all 0.2s ease;
    background: white;
    -webkit-appearance: none; /* iOS safe */
    appearance: none;
}

.portal-input::placeholder {
    color: #9ca3af;
}

.portal-input:focus {
    outline: none;
    border-color: #0052CC;
    box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.1);
}

.portal-input:disabled {
    background: #f9fafb;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Options (Remember Me) */
.portal-options {
    margin-bottom: 24px;
}

.portal-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.portal-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    border: 2px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
}

.checkbox-label {
    font-size: 14px;
    color: #4b5563;
}

/* Portal Button */
.portal-button {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, #0052CC 0%, #2C5AA0 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
    -webkit-tap-highlight-color: transparent;
}

.portal-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 82, 204, 0.4);
}

.portal-button:active:not(:disabled) {
    transform: translateY(0);
}

.portal-button:disabled {
    background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
    cursor: not-allowed;
    box-shadow: none;
}

.button-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Trust Badges */
.portal-trust {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 24px 0;
    border-top: 1px solid #e5e7eb;
    margin-top: 24px;
}

.trust-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #6b7280;
}

.trust-item svg {
    color: #0052CC;
    flex-shrink: 0;
}

/* Footer */
.portal-footer {
    text-align: center;
    padding-top: 24px;
    border-top: 1px solid #e5e7eb;
    margin-top: 24px;
}

.portal-footer p {
    font-size: 13px;
    color: #6b7280;
    margin: 0 0 12px 0;
}

.portal-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.portal-links a {
    font-size: 13px;
    color: #0052CC;
    text-decoration: none;
    transition: color 0.2s ease;
}

.portal-links a:hover {
    color: #2C5AA0;
    text-decoration: underline;
}

.portal-links span {
    color: #d1d5db;
}

.portal-version {
    font-size: 12px;
    color: #9ca3af;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Desktop (show hero) */
@media (min-width: 1024px) {
    .portal-hero {
        display: block;
    }

    .portal-login-container {
        flex-direction: row;
    }

    .portal-form-section {
        max-width: 50%;
    }
}

/* Tablet */
@media (max-width: 1023px) and (min-width: 768px) {
    .portal-form-card {
        padding: 40px;
    }

    .hero-title {
        font-size: 36px;
    }
}

/* Mobile */
@media (max-width: 767px) {
    .portal-login-container {
        flex-direction: column;
        background: white;
    }

    .portal-form-section {
        padding: 20px;
    }

    .portal-form-card {
        padding: 32px 24px;
        box-shadow: none;
    }

    .portal-logo {
        margin-bottom: 24px;
    }

    .portal-header h2 {
        font-size: 24px;
    }

    .portal-header p {
        font-size: 14px;
    }

    .portal-trust {
        grid-template-columns: 1fr;
    }

    .hero-features {
        gap: 12px;
    }

    .hero-feature {
        font-size: 14px;
        padding: 10px;
    }

    /* Mobile-safe inputs */
    .portal-input {
        font-size: 16px !important; /* Prevent iOS zoom */
        -webkit-text-size-adjust: 100%;
    }

    .portal-button {
        min-height: 44px; /* iOS touch target */
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .portal-form-card {
        padding: 24px 20px;
    }

    .portal-header h2 {
        font-size: 22px;
    }

    .hero-title {
        font-size: 28px;
    }

    .hero-subtitle {
        font-size: 16px;
    }
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {
    .portal-input {
        font-size: 16px !important;
        -webkit-appearance: none !important;
    }

    .portal-button {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }
}

/* OLD LOGIN STYLES (Fallback/Backup) */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: var(--visual-vh, 100vh);
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.login-box h2 {
    margin-bottom: 10px;
    color: #333;
    font-size: 28px;
    text-align: center;
}

.login-box p {
    margin-bottom: 30px;
    color: #666;
    text-align: center;
}

.error-message {
    background: #fee;
    color: #c33;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    text-align: center;
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-input {
    width: 100%;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.login-button {
    width: 100%;
    padding: 15px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.login-button:hover:not(:disabled) {
    background: #0056b3;
}

.login-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Chat Container */
.chat-container {
    width: 100%;
    height: 100%;
    background: white;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    /* Prevent any parent scroll from affecting layout */
    overscroll-behavior: none;
}

/* iOS Safari - positioning handled entirely by JavaScript */
/* JS uses absolute positioning within a fixed container */

/* Chat Header */
.chat-header {
    background: var(--header-bg);
    color: white;
    padding: 0 20px;
    min-height: var(--header-height);
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-medium);
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    /* CRITICAL: Fixed position keeps header visible when keyboard opens */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    /* DO NOT use transform on fixed elements - it breaks positioning on mobile */
    /* Use will-change for GPU hints without transform */
    will-change: opacity;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.chat-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.header-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.status-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.connection-status {
    font-size: 10px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
}

@media (max-width: 768px) {
    .connection-status {
        font-size: 8px;
    }
}

.connection-status.connected {
    color: #4CAF50;
}

.connection-status.disconnected {
    color: #FF9800;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    background-color: rgba(255, 152, 0, 0.15);
    transition: background-color 0.2s ease;
}

.connection-status.disconnected:hover {
    background-color: rgba(255, 152, 0, 0.25);
}

.connection-status.disconnected:active {
    background-color: rgba(255, 152, 0, 0.35);
}

.retry-icon {
    font-size: 14px;
    font-weight: bold;
}

.reconnecting-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 152, 0, 0.3);
    border-top-color: #FF9800;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.8;
    }

    50% {
        opacity: 0.4;
    }
}

.user-dots {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 10px;
    align-items: center;
}

.user-dot {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 9px;
    font-weight: 500;
    color: white;
    position: relative;
}

.user-dot::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 2px;
}

.user-dot.online::before {
    background-color: #4CAF50;
    box-shadow: 0 0 4px rgba(76, 175, 80, 0.6);
}

.user-dot.offline::before {
    background-color: #f44336;
    box-shadow: 0 0 4px rgba(244, 67, 54, 0.6);
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
}

.desktop-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Logout button always visible */
.logout-btn-always {
    display: flex !important;
}

.mobile-menu-container {
    display: none;
    position: relative;
}

/* Hamburger Button */
.hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    padding: 8px;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    z-index: 100;
    position: relative;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.hamburger-line {
    width: 20px;
    height: 2px;
    background: white;
    margin: 2px 0;
    transition: all 0.3s ease;
    border-radius: 2px;
}

.hamburger-line.active:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.hamburger-line.active:nth-child(2) {
    opacity: 0;
}

.hamburger-line.active:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile Menu Dropdown */
.mobile-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.2);
    border: 1px solid rgba(102, 126, 234, 0.1);
    min-width: 180px;
    z-index: 1000;
    animation: slideDown 0.3s ease;
    overflow: hidden;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.mobile-btn {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.8);
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    color: #333;
    border-bottom: 1px solid rgba(102, 126, 234, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-btn svg {
    flex-shrink: 0;
}

.mobile-btn:last-child {
    border-bottom: none;
}

.mobile-btn:hover {
    background: rgba(102, 126, 234, 0.15);
    color: var(--primary-color);
}

.mobile-btn.delete-btn {
    color: var(--danger-color);
    background: rgba(231, 76, 60, 0.05);
}

.mobile-btn.delete-btn:hover {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger-color);
}

.mobile-btn.stash-view-btn {
    color: var(--primary-color);
    background: rgba(102, 126, 234, 0.05);
}

.mobile-btn.stash-view-btn:hover {
    background: rgba(102, 126, 234, 0.15);
    color: var(--primary-dark);
}

.mobile-btn.logout-btn {
    color: #666;
    background: rgba(108, 117, 125, 0.05);
}

.mobile-btn.logout-btn:hover {
    background: rgba(108, 117, 125, 0.15);
    color: #495057;
}

.mobile-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.mobile-btn:disabled:hover {
    background: rgba(255, 255, 255, 0.8);
    color: #333;
}

.delete-btn,
.stash-view-btn,
.room-start-btn {
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    -webkit-tap-highlight-color: transparent;
}

.room-start-btn {
    background: rgba(76, 175, 80, 0.85);
}

.room-start-btn:hover:not(:disabled) {
    background: rgba(76, 175, 80, 1);
}

.room-start-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.room-start-btn:disabled {
    background: rgba(156, 163, 175, 0.5);
    cursor: not-allowed;
}

.room-start-btn.join-mode {
    background: rgba(33, 150, 243, 0.9);
    animation: pulse-join 2s infinite;
}

.room-start-btn.join-mode:hover {
    background: rgba(33, 150, 243, 1);
}

@keyframes pulse-join {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(33, 150, 243, 0);
    }
}

.mobile-btn.room-btn.join-mode {
    background: rgba(33, 150, 243, 0.9) !important;
}

.delete-btn {
    background: rgba(231, 76, 60, 0.85);
}

.stash-view-btn {
    background: rgba(255, 255, 255, 0.15);
}

.delete-btn:hover:not(:disabled) {
    background: rgba(231, 76, 60, 1);
}

.stash-view-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.delete-btn:active:not(:disabled),
.stash-view-btn:active {
    transform: scale(0.95);
}

.delete-btn:disabled {
    background: rgba(156, 163, 175, 0.5);
    cursor: not-allowed;
}

/* Quick Escape button */
.escape-btn {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    border: none;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(139, 92, 246, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

.escape-btn:hover {
    background: rgba(139, 92, 246, 0.5);
    transform: scale(1.1);
}

.escape-btn:active {
    transform: scale(0.95);
    background: rgba(139, 92, 246, 0.4);
}

/* Logout button - always visible, rightmost */
.logout-btn-always {
    /* Reset native appearance */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    border: none;

    /* Sizing & Layout */
    height: 36px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Visuals */
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);

    /* Interaction */
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.logout-btn-always:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.logout-btn-always:active {
    transform: translateY(1px) scale(0.98);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Messages Container */
.messages-container {
    /* Position absolutely between header and input */
    position: absolute;
    top: var(--header-height, 70px);
    left: 0;
    right: 0;
    /* Height will be set by JavaScript */
    height: var(--messages-height, calc(100% - 150px));
    /* Padding inside the scrollable area */
    padding: 10px 15px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
    /* Contain scroll within this element */
    overscroll-behavior: contain;
}

/* Keyboard open state - height handled by JS */
.keyboard-open .messages-container {
    /* Height is dynamically set by JavaScript */
}

.messages-container::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(102, 126, 234, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(118, 75, 162, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* Message Styles */
.message {
    display: flex;
    margin-bottom: 8px;
    animation: fadeInUp 0.4s ease;
    position: relative;
    z-index: 1;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.own {
    justify-content: flex-end;
}

.message.other {
    justify-content: flex-start;
}

.message-content {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
    box-shadow: var(--shadow-light);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message.own .message-content {
    background: var(--own-message-bg);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: var(--shadow-medium);
}

.message.other .message-content {
    background: var(--other-message-bg);
    color: #2c3e50;
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(102, 126, 234, 0.1);
}

.message-content p {
    margin: 0;
    word-break: break-word;
}

.message-text {
    margin: 0;
    word-break: break-word;
    white-space: pre-wrap;
}

.message-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 5px;
    gap: 8px;
}

.timestamp {
    font-size: 11px;
    opacity: 0.7;
    flex-shrink: 0;
}

.read-receipts {
    display: flex;
    align-items: center;
    gap: 2px;
}

.read-indicator {
    font-size: 12px;
    opacity: 0.7;
    cursor: help;
}

.message.own .read-indicator {
    color: rgba(255, 255, 255, 0.8);
}

.message.other .read-indicator {
    color: rgba(0, 0, 0, 0.6);
}

/* Message Action Button Styles */
.action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: inherit;
    min-width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    -webkit-tap-highlight-color: transparent;
}

.action-btn svg {
    width: 14px;
    height: 14px;
    transition: transform 0.15s ease;
}

.action-btn:hover {
    opacity: 1;
}

.action-btn:active {
    transform: scale(0.9);
}

.action-btn:active svg {
    transform: scale(0.9);
}

/* Own message action buttons */
.message.own .action-btn {
    color: rgba(255, 255, 255, 0.85);
}

.message.own .action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.message.own .action-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

/* Other message action buttons */
.message.other .action-btn {
    color: rgba(102, 126, 234, 0.7);
}

.message.other .action-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-color);
}

.message.other .action-btn:active {
    background: rgba(102, 126, 234, 0.18);
}

/* Specific button accent colors */
.message.other .action-btn.reply-btn:hover {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

.message.other .action-btn.stash-btn:hover {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

.message.other .action-btn.edit-btn:hover {
    color: #6b7280;
    background: rgba(107, 114, 128, 0.1);
}

/* Edit Interface Styles */
.edit-container {
    width: 100%;
    margin-top: 10px;
}

.edit-input {
    width: 100%;
    min-height: 56px;
    padding: 10px 14px;
    border: 1.5px solid rgba(102, 126, 234, 0.25);
    border-radius: 12px;
    font-size: 14px;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.95);
    resize: vertical;
    outline: none;
    transition: all 0.2s ease;
    color: #1a1a2e;
}

.edit-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: white;
}

.edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}

.save-edit-btn,
.cancel-edit-btn {
    padding: 0;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.save-edit-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.save-edit-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.save-edit-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.save-edit-btn:disabled {
    background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
    cursor: not-allowed;
    box-shadow: none;
}

.cancel-edit-btn {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.cancel-edit-btn:hover {
    background: rgba(239, 68, 68, 0.18);
}

.cancel-edit-btn:active {
    transform: scale(0.95);
    background: rgba(239, 68, 68, 0.25);
}

.edited-indicator {
    font-size: 11px;
    opacity: 0.7;
    font-style: italic;
    cursor: help;
}

.message.own .edited-indicator {
    color: rgba(255, 255, 255, 0.8);
}

.message.other .edited-indicator {
    color: rgba(0, 0, 0, 0.6);
}

.message-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Time Edit Button */
.action-btn.time-edit-btn:hover {
    color: #8b5cf6;
    background: rgba(139, 92, 246, 0.1);
}

.message.own .action-btn.time-edit-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.95);
}

/* Time Edit Modal */
.time-edit-modal {
    background: white;
    border-radius: 16px;
    padding: 20px;
    width: 90%;
    max-width: 320px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.time-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.time-edit-header h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1a1a2e;
}

.time-edit-header svg {
    color: var(--primary-color);
}

.time-edit-content {
    margin-bottom: 20px;
}

.time-edit-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid rgba(102, 126, 234, 0.25);
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.95);
    outline: none;
    transition: all 0.2s ease;
    color: #1a1a2e;
    box-sizing: border-box;
}

.time-edit-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: white;
}

.time-edit-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.save-time-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.save-time-btn:hover:not(:disabled) {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.save-time-btn:disabled {
    background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
    cursor: not-allowed;
    box-shadow: none;
}

.cancel-time-btn {
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    background: rgba(107, 114, 128, 0.1);
    color: #6b7280;
    transition: all 0.2s ease;
}

.cancel-time-btn:hover {
    background: rgba(107, 114, 128, 0.2);
}

.quoted-message {
    background: rgba(0, 0, 0, 0.1);
    border-left: 3px solid #007bff;
    padding: 8px 10px;
    margin-bottom: 8px;
    border-radius: 4px;
    font-size: 13px;
}

.message.own .quoted-message {
    background: rgba(255, 255, 255, 0.2);
    border-left-color: rgba(255, 255, 255, 0.6);
}

.quote-indicator {
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.8;
}

.quote-content {
    opacity: 0.9;
    font-style: italic;
    white-space: pre-wrap;
    word-break: break-word;
}

.reply-preview {
    background: rgba(102, 126, 234, 0.06);
    border: none;
    border-left: 3px solid var(--primary-color);
    border-radius: 0 12px 12px 0;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.reply-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.reply-header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
}

.reply-header-left svg {
    opacity: 0.8;
}

.cancel-reply-btn {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: #6b7280;
    -webkit-tap-highlight-color: transparent;
}

.cancel-reply-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.cancel-reply-btn:active {
    transform: scale(0.9);
}

.reply-preview-content {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.chat-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 10px;
    cursor: pointer;
    display: block;
}

.hidden-image-placeholder {
    background: rgba(102, 126, 234, 0.06);
    border: 1.5px dashed rgba(102, 126, 234, 0.25);
    border-radius: 14px;
    padding: 32px 20px;
    text-align: center;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 13px;
    font-weight: 500;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    -webkit-tap-highlight-color: transparent;
}

.hidden-image-placeholder svg {
    opacity: 0.7;
    transition: transform 0.2s ease;
}

.hidden-image-placeholder:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: rgba(102, 126, 234, 0.4);
}

.hidden-image-placeholder:hover svg {
    transform: scale(1.1);
}

.hidden-image-placeholder:active {
    transform: scale(0.98);
}

.loading-image-placeholder {
    background: rgba(102, 126, 234, 0.06);
    border: 1.5px solid rgba(102, 126, 234, 0.2);
    border-radius: 14px;
    padding: 32px 20px;
    text-align: center;
    color: var(--primary-color);
    font-size: 13px;
    font-weight: 500;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.loading-spinner-small {
    width: 24px;
    height: 24px;
    border: 2.5px solid rgba(102, 126, 234, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.8;
    }

    50% {
        opacity: 1;
    }
}

.hide-image-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 10px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    -webkit-tap-highlight-color: transparent;
}

.hide-image-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

.hide-image-btn:active {
    transform: scale(0.9);
}

/* Input Container - Unified for all devices */
.input-container-fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 9999;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: rgba(250, 250, 252, 0.96);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: bottom 0.3s ease;
}

/* When keyboard is open, remove safe-area padding */
.keyboard-open .input-container-fixed {
    padding-bottom: 8px !important;
}

/* Android - positioning handled entirely by JavaScript */
/* No CSS position overrides needed */

/* Android - smooth transitions */
.android-device .messages-container {
    transition: height 0.2s ease-out, min-height 0.2s ease-out;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    position: relative;
    flex-wrap: nowrap;
    width: 100%;
}

.message-input {
    flex: 1 1 auto;
    padding: 10px 16px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    font-size: 16px;
    outline: none;
    transition: all 0.2s ease;
    min-width: 100px;
    max-width: calc(100% - 130px);
    resize: none;
    overflow-y: auto;
    line-height: 1.4;
    max-height: 100px;
    min-height: 40px;
    font-family: inherit;
    background: #fff;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
    color: #1a1a2e;
}

.message-input:focus {
    border-color: var(--primary-color);
    background: #fff;
    box-shadow: 0 2px 12px rgba(102, 126, 234, 0.15),
        0 0 0 3px rgba(102, 126, 234, 0.08);
}

.message-input::placeholder {
    color: #9ca3af;
    font-weight: 400;
}

.button-group {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}

.icon-btn,
label.icon-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border: none;
    border-radius: 10px;
    background: rgba(102, 126, 234, 0.08);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    flex-grow: 0;
    position: relative;
    margin-bottom: 0;
    align-self: flex-end;
    color: var(--primary-color);
    -webkit-tap-highlight-color: transparent;
}

.icon-btn svg,
label.icon-btn svg {
    width: 18px;
    height: 18px;
    transition: transform 0.2s ease;
}

.icon-btn:hover,
label.icon-btn:hover {
    background: rgba(102, 126, 234, 0.15);
    transform: scale(1.05);
}

.icon-btn:active,
label.icon-btn:active {
    transform: scale(0.95);
    background: rgba(102, 126, 234, 0.2);
}

/* Media buttons specific styling */
.icon-btn.media-btn,
label.icon-btn.media-btn {
    background: rgba(102, 126, 234, 0.06);
    border: 1.5px solid rgba(102, 126, 234, 0.12);
}

.icon-btn.media-btn:hover,
label.icon-btn.media-btn:hover {
    background: rgba(102, 126, 234, 0.12);
    border-color: rgba(102, 126, 234, 0.25);
}

/* Ensure labels behave like buttons */
label.icon-btn {
    margin: 0;
    padding: 0;
    line-height: 1;
}

.send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    padding: 0;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    flex-grow: 0;
    align-self: flex-end;
    margin-bottom: 0;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.send-btn svg {
    width: 18px;
    height: 18px;
    transition: transform 0.2s ease;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

.send-btn:hover:not(:disabled) svg {
    transform: translateX(2px) translateY(-2px);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.send-btn:disabled {
    background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Sending indicator animation */
.sending-indicator {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    :root {
        --header-height: 50px;
        --input-height: 65px;
    }

    .chat-header {
        padding: 0 10px;
    }

    .chat-header h2 {
        font-size: 16px;
    }

    /* Hide desktop actions (except logout), show mobile menu */
    .desktop-actions {
        display: none;
    }

    /* Logout button always visible on mobile too */
    .logout-btn-always {
        display: flex !important;
        padding: 5px 10px;
        height: 30px;
        border-radius: 6px;
        font-size: 12px;
    }

    /* Escape button on mobile */
    .escape-btn {
        width: 30px;
        height: 30px;
    }

    .escape-btn svg {
        width: 14px;
        height: 14px;
    }

    .mobile-menu-container {
        display: block !important;
        position: relative;
        z-index: 100;
    }

    /* Adjust header title for mobile */
    .header-title {
        flex: 1;
        min-width: 0;
    }

    .status-container {
        gap: 4px;
    }

    .user-dots {
        gap: 6px;
        flex-wrap: wrap;
        max-width: calc(100vw - 80px);
        font-size: 8px;
    }

    .user-dot {
        font-size: 7px;
        white-space: nowrap;
    }

    .user-dot::before {
        width: 6px;
        height: 6px;
    }

    .read-indicator {
        font-size: 10px;
    }

    .timestamp {
        font-size: 10px;
    }

    .reply-btn,
    .edit-btn {
        font-size: 10px;
    }

    .edit-input {
        min-height: 50px;
        font-size: 14px;
        padding: 6px 10px;
    }

    .save-edit-btn,
    .cancel-edit-btn {
        font-size: 12px;
        min-width: 28px;
        height: 28px;
        padding: 4px 8px;
    }

    .quoted-message {
        font-size: 12px;
        padding: 6px 8px;
    }

    .reply-preview {
        padding: 6px;
    }

    .reply-header {
        font-size: 11px;
    }

    .delete-btn,
    .logout-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .message-content {
        max-width: 85%;
        padding: 10px 14px;
    }

    .messages-container {
        padding: 10px;
        padding-bottom: 10px;
        /* Input is handled by flexbox, no extra padding needed */
    }

    .input-container {
        padding: 8px;
        gap: 5px;
    }

    .message-input {
        padding: 10px 15px;
        font-size: 16px;
        /* Prevents zoom on iOS */
        max-height: 100px;
        min-height: 36px;
        min-width: 80px;
        max-width: calc(100% - 120px);
    }

    .icon-btn,
    label.icon-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        border-radius: 8px;
        flex-shrink: 0;
        flex-grow: 0;
        align-self: flex-end;
        margin-bottom: 0;
    }

    .icon-btn svg,
    label.icon-btn svg {
        width: 18px;
        height: 18px;
    }

    .send-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        border-radius: 8px;
        flex-shrink: 0;
        flex-grow: 0;
        align-self: flex-end;
        margin-bottom: 0;
    }

    .send-btn svg {
        width: 18px;
        height: 18px;
    }

    .button-group {
        gap: 6px;
        flex-shrink: 0;
    }
}

/* Small devices */
@media (max-width: 380px) {
    .message-content {
        max-width: 90%;
        font-size: 14px;
    }

    .header-actions {
        gap: 5px;
    }

    .hamburger-btn {
        width: 36px;
        height: 36px;
        padding: 6px;
    }

    .hamburger-line {
        width: 18px;
    }

    .mobile-menu-dropdown {
        min-width: 160px;
        right: -10px;
    }

    .mobile-btn {
        padding: 10px 12px;
        font-size: 13px;
    }

    .user-dots {
        max-width: calc(100vw - 100px);
    }

    .icon-btn,
    label.icon-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        border-radius: 8px;
        flex-shrink: 0;
        flex-grow: 0;
        align-self: flex-end;
        margin-bottom: 0;
    }

    .icon-btn svg,
    label.icon-btn svg {
        width: 18px;
        height: 18px;
    }

    .send-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        border-radius: 8px;
        flex-shrink: 0;
        flex-grow: 0;
        align-self: flex-end;
        margin-bottom: 0;
    }

    .send-btn svg {
        width: 18px;
        height: 18px;
    }

    .delete-btn,
    .logout-btn {
        font-size: 11px;
        padding: 5px 8px;
    }
}

/* Android specific fixes */
@media screen and (max-device-width: 896px) {
    body {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }

    .chat-container {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }
}

/* Android specific optimizations */
.android-device {
    -webkit-tap-highlight-color: transparent;
}

/* Android - positioning handled by JavaScript */
.android-device .chat-header {
    /* JS will set position dynamically */
    left: 0;
    right: 0;
}

/* Consistent button sizing for Android - same as Samsung Internet */
/* Exclude login-button and other full-width buttons */
.android-device button:not(.login-button):not(.save-edit-btn):not(.cancel-edit-btn),
.android-device .icon-btn {
    /* Use exact sizes, not min-sizes to prevent enlargement */
    height: 38px;
    width: 38px;
    min-height: 38px;
    min-width: 38px;
    max-height: 38px;
    max-width: 38px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    /* Prevent Chrome from auto-sizing */
    box-sizing: border-box;
}

/* Action buttons in messages should be smaller */
.android-device .action-btn {
    height: 26px;
    width: 26px;
    min-height: 26px;
    min-width: 26px;
    max-height: 26px;
    max-width: 26px;
    padding: 4px;
}

.android-device .reply-btn {
    height: 26px;
    width: 26px;
    min-height: 26px;
    min-width: 26px;
    padding: 4px;
}

.android-device .cancel-reply-btn {
    height: 28px;
    width: 28px;
    min-height: 28px;
    min-width: 28px;
}

/* Improve text selection on Android */
.android-device .message-text {
    -webkit-user-select: text;
    user-select: text;
}

/* Better scrolling for Android */
.android-device .messages-container {
    scroll-behavior: smooth;
    overscroll-behavior-y: contain;
}

/* Fix input focus on Android */
.android-device .message-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Performance optimizations for Android */
.android-chrome .message {
    transform: translateZ(0);
    will-change: transform;
}

.android-chrome .message-content {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Android Chrome and Samsung Browser - input is fixed at bottom */
.android-chrome .input-container-fixed,
.samsung-browser .input-container-fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
}

/* Ensure both browsers use same button sizing */
.samsung-browser button,
.samsung-browser .icon-btn {
    height: 38px;
    width: 38px;
    min-height: 38px;
    min-width: 38px;
    max-height: 38px;
    max-width: 38px;
    box-sizing: border-box;
}

.samsung-browser .action-btn {
    height: 26px;
    width: 26px;
    min-height: 26px;
    min-width: 26px;
    max-height: 26px;
    max-width: 26px;
    padding: 4px;
}

/* Reduce complex animations on mobile for performance */
@media screen and (max-width: 768px) and (hover: none) and (pointer: coarse) {
    .message {
        animation: none;
    }

    .connection-status.disconnected {
        animation: none;
    }

    /* Simplify transitions */
    *,
    *::before,
    *::after {
        transition-duration: 0.1s !important;
    }

    /* DO NOT use transform on messages-container - it can break fixed header */
    /* Use will-change instead for scroll performance hint */
    .messages-container {
        will-change: scroll-position;
    }

    /* Reduce message rendering complexity */
    .message-content {
        will-change: auto; /* Don't hint will-change on many items */
    }
}

/* iOS Safari specific optimizations */
.ios-safari {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
}

/* iOS Safari - smooth transitions */
.ios-safari .messages-container {
    transition: height 0.2s ease-out, min-height 0.2s ease-out;
}

.ios-safari .chat-container {
    transition: height 0.2s ease-out;
}

/* iOS safe area support */
.ios-device .chat-header {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
}

/* iOS - messages positioning handled by JS */

.ios-device .input-container-fixed {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
}

/* iPhone 14 and similar device fixes */
@media screen and (device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) {
    .chat-header {
        padding-top: max(8px, env(safe-area-inset-top));
        min-height: calc(var(--header-height) + env(safe-area-inset-top));
    }

    .user-dots {
        max-width: calc(100vw - 140px);
        overflow: hidden;
    }

    .user-dot {
        font-size: 8px;
        padding: 1px 3px;
        white-space: nowrap;
    }

    .mobile-menu-dropdown {
        right: max(0px, env(safe-area-inset-right));
    }
}

/* iPhone 14 Pro and Pro Max */
@media screen and (device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3),
screen and (device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) {
    .chat-header {
        padding-top: max(8px, env(safe-area-inset-top));
        min-height: calc(var(--header-height) + env(safe-area-inset-top));
    }

    .user-dots {
        max-width: calc(100vw - 140px);
        overflow: hidden;
    }

    .mobile-menu-dropdown {
        right: max(0px, env(safe-area-inset-right));
    }
}

/* Better touch targets for iOS */
.ios-device button,
.ios-device .icon-btn {
    min-height: 38px;
    min-width: 38px;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    -webkit-appearance: none;
    appearance: none;
    border-radius: 8px;
}

.ios-device .message-input {
    -webkit-appearance: none;
    appearance: none;
    -webkit-border-radius: 25px;
    border-radius: 25px;
    font-size: 16px;
    /* Prevent zoom on focus */
}

/* iOS scroll behavior */
.ios-device .messages-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Prevent iOS elastic scroll */
.ios-device body {
    width: 100%;
    overflow: hidden;
}

/* iOS Safari - let JS control the height */
.ios-safari .chat-container {
    /* Height is set by JavaScript via --viewport-height */
    overflow: hidden;
}

/* iOS keyboard adjustments */
.ios-device .message-input {
    font-size: 16px !important;
    /* Prevent zoom on iOS */
    -webkit-appearance: none !important;
}

/* iOS performance optimizations */
.ios-safari .message {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.ios-safari .message-content {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* iOS text selection */
.ios-device .message-text {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* Fix for virtual keyboard */
@supports (-webkit-touch-callout: none) {
    .chat-container {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }

    body {
        min-height: 100vh;
        min-height: calc(var(--vh, 1vh) * 100);
    }
}

/* Ensure input is always visible on Android */
@media screen and (max-height: 600px) {
    .messages-container {
        min-height: 0;
    }

    .input-container {
        position: sticky;
        bottom: 0;
        z-index: 10;
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --header-height: 45px;
        --input-height: 55px;
    }

    .messages-container {
        padding: 8px;
    }

    .message-content {
        padding: 8px 12px;
        font-size: 14px;
    }

    .timestamp {
        font-size: 10px;
    }
}

/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Safe area support for modern phones */
@supports (padding: max(0px)) {
    .chat-header {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }

    .input-container {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
    }

    .mobile-menu-dropdown {
        right: max(0px, env(safe-area-inset-right));
    }
}

/* Blazor specific */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Force proper rendering on Android Chrome */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .chat-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
    }

    .input-container {
        position: relative;
    }
}

/* Handle very small screens */
@media (max-height: 400px) {
    .chat-container {
        display: grid;
        grid-template-rows: 45px 1fr auto;
    }

    .messages-container {
        min-height: 100px;
    }
}

/* Ultra small screens */
@media (max-width: 320px) {
    .chat-header h2 {
        font-size: 14px;
    }

    .message-input {
        font-size: 14px;
        padding: 8px 12px;
    }

    .hamburger-btn {
        width: 32px;
        height: 32px;
        padding: 4px;
    }

    .hamburger-line {
        width: 16px;
        height: 1.5px;
    }

    .mobile-menu-dropdown {
        min-width: 140px;
        right: -15px;
    }

    .mobile-btn {
        padding: 8px 10px;
        font-size: 12px;
    }

    .user-dots {
        max-width: calc(100vw - 80px);
        font-size: 8px;
    }

    .user-dot {
        font-size: 8px;
        padding: 1px 3px;
    }
}

/* Responsive mobile adjustments */
@media screen and (max-width: 768px) {
    .messages-container {
        /* Flexbox handles spacing, no extra padding needed */
        padding-bottom: 10px;
    }
}


/* Stash Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.stash-modal {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 650px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-heavy);
    border: 1px solid rgba(102, 126, 234, 0.1);
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.stash-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(102, 126, 234, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(102, 126, 234, 0.03);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.stash-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--primary-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.stash-header h3 svg {
    opacity: 0.8;
}

.close-btn {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    cursor: pointer;
    padding: 0;
    border-radius: 10px;
    color: #6b7280;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.close-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.close-btn:active {
    transform: scale(0.9);
}

.stash-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stashed-message {
    border: 1px solid rgba(102, 126, 234, 0.15);
    border-radius: var(--border-radius);
    padding: 16px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-light);
    transition: all 0.3s ease;
}

.stashed-message:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
    border-color: rgba(102, 126, 234, 0.25);
}

.stashed-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.original-sender {
    font-weight: 600;
    color: #007bff;
    font-size: 14px;
}

.stash-time {
    font-size: 12px;
    color: #666;
    flex: 1;
    text-align: center;
}

.remove-stash-btn {
    background: rgba(239, 68, 68, 0.08);
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: #ef4444;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.remove-stash-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

.remove-stash-btn:active {
    transform: scale(0.9);
}

.stashed-message-content {
    margin: 8px 0;
}

.stashed-message-content .quoted-message {
    background: rgba(0, 123, 255, 0.1);
    border-left: 3px solid #007bff;
    padding: 6px 8px;
    margin-bottom: 6px;
    border-radius: 4px;
    font-size: 12px;
}

.stashed-message-content .message-text {
    color: #333;
    font-size: 14px;
    line-height: 1.4;
}

.stashed-message-content .chat-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
}

.stashed-message-footer {
    border-top: 1px solid #e0e0e0;
    padding-top: 6px;
    margin-top: 8px;
}

.original-time {
    font-size: 11px;
    color: #666;
    font-style: italic;
}

.empty-stash {
    text-align: center;
    padding: 48px 24px;
    color: #6b7280;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.empty-stash svg {
    color: rgba(102, 126, 234, 0.4);
    margin-bottom: 8px;
}

.empty-stash p {
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    color: #4b5563;
}

.empty-stash small {
    color: #9ca3af;
    font-size: 13px;
}

.empty-stash .expire-note {
    color: #d1d5db;
    font-size: 12px;
}

/* Mobile Stash Modal */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
    }

    .stash-modal {
        max-height: 90vh;
    }

    .stash-header {
        padding: 12px 16px;
    }

    .stash-header h3 {
        font-size: 16px;
    }

    .stash-content {
        padding: 16px;
    }

    .stashed-message {
        padding: 10px;
    }

    .stashed-message-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .stash-time {
        text-align: left;
        flex: none;
    }

    .remove-stash-btn {
        align-self: flex-end;
        margin-top: -20px;
    }
}

/* ============================================
   iOS Safari Specific Optimizations
   ============================================ */

/* iOS button touch feedback */
@supports (-webkit-touch-callout: none) {

    .send-btn,
    .icon-btn,
    label.icon-btn,
    .action-btn,
    .cancel-reply-btn,
    .close-btn,
    .hide-image-btn {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        touch-action: manipulation;
    }

    /* Ensure SVG icons render crisply on iOS */
    svg {
        shape-rendering: geometricPrecision;
        -webkit-font-smoothing: antialiased;
    }

    /* Prevent iOS text size adjustment */
    .message-input,
    .edit-input {
        -webkit-text-size-adjust: 100%;
    }

    /* iOS safe area for input container */
    .input-container-fixed {
        padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
    }
}

/* iOS Safari input focus fixes */
.ios-safari .message-input:focus,
.ios-safari .edit-input:focus {
    font-size: 16px !important;
    /* Prevent zoom on focus */
}

.ios-safari .send-btn,
.ios-safari .icon-btn,
.ios-safari label.icon-btn {
    cursor: pointer;
    -webkit-appearance: none;
}

/* iOS button active states */
.ios-device .send-btn:active,
.ios-device .icon-btn:active,
.ios-device label.icon-btn:active {
    opacity: 0.7;
}

/* ============================================
   Android Chrome Specific Optimizations
   ============================================ */

/* Android ripple-like feedback */
.android-device .send-btn,
.android-device .icon-btn,
.android-device label.icon-btn {
    position: relative;
    overflow: hidden;
}

.android-device .send-btn::after,
.android-device .icon-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
    pointer-events: none;
}

.android-device .send-btn:active::after,
.android-device .icon-btn:active::after {
    width: 150%;
    height: 150%;
}

/* Android SVG rendering */
.android-chrome svg {
    will-change: transform;
}

/* Android action button touch targets */
.android-device .action-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 8px;
}

/* Android input container fixes */
.android-device .input-container-fixed {
    /* JS will set position dynamically */
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ============================================
   Universal Mobile Touch Optimizations
   ============================================ */

@media (hover: none) and (pointer: coarse) {

    /* Increase touch targets on all touch devices */
    .action-btn {
        min-width: 36px;
        min-height: 36px;
    }

    .hide-image-btn {
        width: 36px;
        height: 36px;
    }

    .cancel-reply-btn {
        width: 28px;
        height: 28px;
    }

    /* Disable hover effects on touch devices - use active instead */
    .send-btn:hover,
    .icon-btn:hover,
    label.icon-btn:hover {
        transform: none;
    }

    .send-btn:active {
        transform: scale(0.95);
    }

    .icon-btn:active,
    label.icon-btn:active {
        transform: scale(0.92);
        background: rgba(102, 126, 234, 0.18);
    }

    /* Faster transitions for touch responsiveness */
    .send-btn,
    .icon-btn,
    label.icon-btn,
    .action-btn {
        transition-duration: 0.15s !important;
    }
}

/* ============================================
   High DPI / Retina Display Optimizations
   ============================================ */

@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

    /* Sharper SVG rendering on retina displays */
    svg {
        shape-rendering: geometricPrecision;
    }

    /* Slightly thinner borders for crisp appearance */
    .message-input {
        border-width: 1px;
    }

    .icon-btn.media-btn,
    label.icon-btn.media-btn {
        border-width: 1px;
    }
}

/* ============================================
   Landscape Mode Mobile Fixes
   ============================================ */

@media (max-height: 450px) and (orientation: landscape) {
    .input-container-fixed {
        padding: 8px 12px !important;
        padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
    }

    .message-input {
        min-height: 36px;
        padding: 8px 14px;
    }

    .send-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }

    .icon-btn,
    label.icon-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }

    .reply-preview {
        padding: 6px 10px;
        margin-bottom: 6px;
    }
}

/* ============================================
   Room Banner Styles (in Chat)
   ============================================ */

.room-banner {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    padding: 12px 16px;
    margin: 0;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.room-banner-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.room-banner-icon {
    font-size: 1.2rem;
}

.room-banner-text {
    color: white;
    font-weight: 500;
    font-size: 0.95rem;
}

.room-banner-join {
    background: white;
    color: #4CAF50;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.room-banner-join:hover {
    background: #f0f0f0;
    transform: scale(1.05);
}

.room-banner-join:active {
    transform: scale(0.98);
}

/* Room button in mobile menu */
.mobile-btn.room-btn {
    color: #4CAF50;
}

.mobile-btn.room-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Room Page Styles
   ============================================ */

.room-page {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 9999;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Room Header */
.room-header {
    display: flex;
    justify-content: space-between;
    padding: 15px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding-top: calc(15px + env(safe-area-inset-top));
}

.room-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.room-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.room-btn:active {
    transform: scale(0.95);
}

.room-btn.primary {
    background: var(--primary-color);
}

.room-btn.primary:hover {
    background: var(--primary-dark);
}

.room-btn.secondary {
    background: rgba(255, 255, 255, 0.2);
    margin-top: 10px;
}

.room-btn.cancel-btn {
    background: rgba(231, 76, 60, 0.8);
}

.room-btn.cancel-btn:hover {
    background: rgba(231, 76, 60, 1);
}

/* Room Loading State */
.room-loading {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.room-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Room Error State */
.room-error {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
    gap: 15px;
}

.room-error .error-icon {
    font-size: 4rem;
    margin-bottom: 10px;
}

.room-error h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.room-error p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95rem;
    max-width: 300px;
}

/* Room Waiting State */
.room-waiting {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 20px;
}

.local-video-container.preview {
    width: 80%;
    max-width: 400px;
    aspect-ratio: 4/3;
    border-radius: 20px;
    overflow: hidden;
    background: #333;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.local-video-container.preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.waiting-text {
    font-size: 1.2rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
}

.waiting-dots {
    display: flex;
    gap: 8px;
}

.waiting-dots span {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: waitingBlink 1.4s infinite ease-in-out both;
}

.waiting-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.waiting-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes waitingBlink {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Room Connecting State */
.room-connecting {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.room-connecting .local-video-container {
    width: 100%;
    height: 100%;
}

.room-connecting .local-video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.connecting-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.7);
    padding: 30px 40px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Room Active State */
.room-active {
    flex: 1;
    position: relative;
}

.remote-video-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.remote-video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #1a1a1a;
}

.local-video-pip {
    position: absolute;
    bottom: 120px;
    right: 20px;
    width: 120px;
    height: 160px;
    border-radius: 15px;
    overflow: hidden;
    border: 3px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    background: #333;
}

.local-video-pip video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.connection-info {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.connection-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffc107;
}

.connection-status-dot.connected {
    background: #4CAF50;
}

.connection-status-dot.connecting {
    background: #ffc107;
    animation: pulse 1.5s infinite;
}

.connection-status-dot.disconnected {
    background: #f44336;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Room Controls */
.room-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 24px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.2s;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.active {
    background: rgba(255, 255, 255, 0.4);
}

.control-btn.end-call {
    background: #ff4444;
}

.control-btn.end-call:hover {
    background: #ff5555;
}

.control-btn.speaker-btn {
    background: rgba(76, 175, 80, 0.6);
}

.control-btn.speaker-btn:hover {
    background: rgba(76, 175, 80, 0.8);
}

.control-btn.speaker-btn:active {
    background: rgba(76, 175, 80, 1);
}

/* Room Ended State */
.room-ended {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
    gap: 15px;
}

.room-ended h2 {
    font-size: 1.8rem;
    font-weight: 600;
}

.room-ended p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.1rem;
}

/* iOS Safe Areas */
@supports (padding-top: env(safe-area-inset-top)) {
    .room-header {
        padding-top: calc(15px + env(safe-area-inset-top));
    }

    .room-controls {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }

    .local-video-pip {
        bottom: calc(120px + env(safe-area-inset-bottom));
    }

    .connection-info {
        top: calc(20px + env(safe-area-inset-top));
    }
}

/* Prevent iOS video controls */
.room-page video::-webkit-media-controls {
    display: none !important;
}

/* Prevent iOS callout on long press */
.room-page video {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Mobile adjustments for room */
@media (max-width: 480px) {
    .local-video-container.preview {
        width: 90%;
    }

    .local-video-pip {
        width: 100px;
        height: 133px;
        right: 15px;
        bottom: 110px;
    }

    .control-btn {
        width: 55px;
        height: 55px;
        font-size: 22px;
    }

    .room-controls {
        gap: 15px;
    }
}

/* Landscape mode for room */
@media (max-height: 450px) and (orientation: landscape) {
    .local-video-pip {
        width: 80px;
        height: 60px;
        bottom: 80px;
        right: 10px;
    }

    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }

    .room-controls {
        padding: 10px;
        gap: 12px;
    }

    .waiting-text {
        font-size: 1rem;
    }

    .local-video-container.preview {
        max-width: 300px;
        aspect-ratio: 16/9;
    }
}