/* main.css - Legal document viewer theme - RESTORED + KEYBOARD FIX */
* {
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000;
    color: #fff;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Safe area handling for iPhone */
body {
    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);
}

main {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    position: relative;
}

#roomHeader {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    position: relative;
}

#roomTitle {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Floating Top Menu System */
.floating-menu {
    position: fixed;
    top: 0;
    left: 33.33%; /* 1/3 from left */
    transform: translateX(-50%);
    z-index: 1000;
    width: 240px; /* Reduced from 300px */
    max-width: 70vw; /* Reduced from 80vw */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-tab {
    background: rgba(52, 73, 94, 0.85);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0 0 8px 8px;
    border-top: none;
    padding: 6px 16px 8px 16px; /* Increased horizontal padding from 12px to 16px */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
    user-select: none;
    min-height: 20px;
}

.menu-tab:hover {
    background: rgba(52, 73, 94, 1);
}

.menu-connection-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    position: relative;
}

.menu-connection-dot.connecting {
    background: #ffc107;
    box-shadow: 0 0 8px rgba(255, 193, 7, 0.5);
    animation: pulse 2s infinite;
}

.menu-connection-dot.connected {
    background: #28a745;
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.5);
    animation: none;
}

.menu-connection-dot.disconnected {
    background: #dc3545;
    box-shadow: 0 0 8px rgba(220, 53, 69, 0.5);
    animation: pulse-error 1s infinite;
}

.tab-handle {
    width: 16px;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 1px;
    position: relative;
}

.tab-handle::after {
    content: '';
    position: absolute;
    top: -4px;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 1px;
}

.menu-content {
    background: rgba(52, 73, 94, 0.98);
    backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0 0 16px 16px;
    border-top: none;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.floating-menu.expanded .menu-content {
    max-height: 300px;
    opacity: 1;
    transform: translateY(0);
    padding: 16px;
}

.menu-header {
    color: #ecf0f1;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
    text-align: center;
    opacity: 0.9;
}

.menu-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-button {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #ecf0f1;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
}

.menu-button:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
}

.menu-button:active {
    transform: scale(0.98);
}

.menu-icon {
    font-size: 1rem;
    opacity: 0.8;
}

/* Touch interaction improvements */
.floating-menu {
    touch-action: pan-y;
}

.menu-tab {
    min-height: 32px;
    touch-action: manipulation;
}

/* Mobile keyboard handling */
@media screen and (max-width: 768px) {
    .floating-menu {
        width: 200px; /* Reduced from 240px */
        max-width: 65vw; /* Reduced from 75vw */
    }
    
    .menu-tab {
        padding: 4px 14px 6px 14px; /* Increased from 10px to 14px */
        min-height: 18px;
    }
    
    .menu-connection-dot {
        width: 5px;
        height: 5px;
    }
    
    .tab-handle {
        width: 14px;
        height: 2px;
    }
    
    .menu-button {
        padding: 14px 16px;
        font-size: 0.95rem;
    }
    
    /* Keyboard visibility handling */
    main {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
    }
    
    /* When input is focused, adjust layout */
    #messageInput:focus ~ #chatLog,
    #messageInput:focus-within ~ #chatLog {
        max-height: calc(100vh - 200px); /* Reserve space for keyboard */
        max-height: calc(100dvh - 200px);
    }
}

/* iOS specific keyboard handling */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    main {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    @media screen and (max-width: 768px) {
        /* When keyboard appears, completely eliminate gap */
        body.keyboard-visible main {
            height: 100vh;
            height: -webkit-fill-available;
            /* Remove any flex gaps */
            gap: 0;
        }
        
        /* Chat log shrinks to content size, no extra space */
        body.keyboard-visible #chatLog {
            flex: none; /* Don't grow to fill space */
            min-height: auto;
            max-height: none;
            /* Stick messages to bottom */
            justify-content: flex-end;
            /* Remove all padding that creates gap */
            padding: 0.5rem 1rem 0 1rem;
            margin: 0;
            /* Don't take up more space than needed */
            height: auto;
            overflow: visible;
        }
        
        /* Message form directly touches chat */
        body.keyboard-visible #messageForm {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            margin: 0;
            border-radius: 0;
            padding: 0.75rem 1rem;
            /* Remove top border to eliminate visual gap */
            border-top: none;
        }
        
        /* Header takes minimal space */
        body.keyboard-visible #roomHeader {
            flex-shrink: 0;
            padding: 0.5rem 1rem;
        }
        
        /* Force tight layout */
        body.keyboard-visible {
            overflow: hidden;
        }
    }
}

/* MINIMAL KEYBOARD GAP FIX - ADDITION ONLY */
@supports (height: 100dvh) {
    body.keyboard-visible main {
        height: 100dvh !important;
    }
    
    body.keyboard-visible #messageForm {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
        padding-bottom: 0.75rem !important;
        padding-left: calc(1rem + env(safe-area-inset-left, 0)) !important;
        padding-right: calc(1rem + env(safe-area-inset-right, 0)) !important;
        background: rgba(0, 0, 0, 0.95) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
    }
    
    body.keyboard-visible #chatLog {
        height: calc(100dvh - 60px - 80px) !important;
        max-height: calc(100dvh - 60px - 80px) !important;
        flex: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .floating-menu {
        top: env(safe-area-inset-top);
    }
}

#userControls {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

#userButton {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #4fc3f7;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

#userButton:active {
    transform: scale(0.95);
}

#chatLog {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1rem 0.5rem 1rem; /* Reduced bottom padding from 1rem to 0.5rem */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.message {
    margin-bottom: 0.8rem;
    padding: 0.8rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    word-wrap: break-word;
    animation: slideIn 0.3s ease-out;
    max-width: 70%;
    position: relative;
    clear: both;
}

/* Your messages - right aligned */
.message.own {
    margin-left: auto;
    margin-right: 0;
    background: linear-gradient(135deg, #2196F3, #1976D2);
    border: 1px solid rgba(33, 150, 243, 0.4);
    color: #ffffff;
    text-align: left;
    border-radius: 18px 18px 4px 18px;
}

.message.own strong {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
}

/* Other users' messages - left aligned */
.message.other {
    margin-left: 0;
    margin-right: auto;
    background: rgba(30, 39, 70, 0.8);
    border: 1px solid rgba(55, 71, 133, 0.4);
    color: #ffffff;
    text-align: left;
    border-radius: 18px 18px 18px 4px;
}

.message.other strong {
    color: #4fc3f7;
    font-weight: 600;
}

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

.message strong {
    color: #4fc3f7;
    display: inline;
    margin-right: 0.3rem;
}

.message.own strong {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
}

.message.other strong {
    color: #4fc3f7;
    font-weight: 600;
}

.message.system {
    background: rgba(156, 39, 176, 0.2);
    border-color: rgba(156, 39, 176, 0.3);
    font-style: italic;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    max-width: 80%;
    border-radius: 12px;
}

/* Error/failure message styling */
.message.system:has-text('Failed To Send'),
.message.system:has-text('Message Failed To Send') {
    background: rgba(220, 53, 69, 0.2);
    border-color: rgba(220, 53, 69, 0.3);
    color: #dc3545;
}

.timestamp {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.6);
    margin-left: 0.5rem;
}

#messageForm {
    display: none;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

#inputContainer {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#messageInput {
    flex: 1;
    padding: 0.8rem;
    border: none;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1rem;
    outline: none;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#messageInput::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

#messageInput:focus {
    border-color: #4fc3f7;
    box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.3);
}

.button {
    padding: 0.8rem 1.2rem;
    border: none;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-height: 44px;
}

#sendButton {
    background: linear-gradient(135deg, #4fc3f7, #29b6f6);
    color: #fff;
}

#clearButton {
    background: linear-gradient(135deg, #f44336, #d32f2f);
    color: #fff;
}

.button:active {
    transform: scale(0.95);
}

/* Legal Document Auth Screen - DISGUISED */
#lockScreen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 50%, #2c3e50 100%);
    backdrop-filter: blur(20px);
    z-index: 2000;
    animation: fadeIn 0.3s ease-out;
}

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

#authForm {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(30px);
    padding: 2.5rem 2rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 380px;
    width: 90%;
    text-align: center;
    animation: slideInAuth 0.4s ease-out;
}

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

#documentLogo {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.8;
}

#authForm h3 {
    margin: 0 0 0.5rem 0;
    color: #ecf0f1;
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

#documentSubtitle {
    color: rgba(236, 240, 241, 0.7);
    font-size: 0.9rem;
    margin-bottom: 2rem;
    font-weight: 400;
}

.input-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: rgba(236, 240, 241, 0.9);
    font-size: 0.9rem;
    letter-spacing: 0.3px;
}

.input-group input {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #ecf0f1;
    font-size: 1rem;
    outline: none;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    text-align: center;
    min-height: 44px;
    transition: all 0.2s ease;
}

.input-group input::placeholder {
    color: rgba(236, 240, 241, 0.5);
}

.input-group input:focus {
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
    background: rgba(255, 255, 255, 0.12);
}

#pinInput {
    font-size: 1.3rem !important;
    letter-spacing: 0.5em;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

#welcomeMessage {
    color: rgba(236, 240, 241, 0.8);
    margin: 1.5rem 0;
    font-size: 0.9rem;
    padding: 1rem;
    background: rgba(52, 152, 219, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(52, 152, 219, 0.2);
}

.access-status {
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: #52c41a;
}

.access-subtext {
    font-size: 0.8rem;
    color: rgba(236, 240, 241, 0.6);
}

#unlockButton {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 1rem;
    transition: all 0.2s ease;
    min-height: 44px;
    letter-spacing: 0.5px;
}

#unlockButton:active {
    transform: scale(0.98);
}

#unlockButton:hover {
    background: linear-gradient(135deg, #2980b9, #2471a3);
}

#errorMessage {
    background: rgba(231, 76, 60, 0.2);
    border: 1px solid rgba(231, 76, 60, 0.4);
    color: #e74c3c;
    padding: 0.8rem;
    border-radius: 8px;
    margin-top: 1rem;
    display: none;
    font-size: 0.9rem;
}

#documentFooter {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-text {
    color: rgba(236, 240, 241, 0.6);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
}

.footer-subtext {
    color: rgba(236, 240, 241, 0.4);
    font-size: 0.7rem;
    line-height: 1.3;
}

/* User modal - updated for document theme */
#userModal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2001;
}

#userModalContent {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(30px);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 320px;
    width: 90%;
    text-align: center;
}

/* Loading animation */
.loading {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #3498db;
    animation: spin 1s ease-in-out infinite;
}

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

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

@keyframes pulse-error {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Mobile optimizations */
@media screen and (max-width: 768px) {
    input, textarea, select {
        font-size: 16px !important;
    }
    
    #authForm {
        padding: 2rem 1.5rem;
        margin: 1rem;
    }
    
    #documentLogo {
        font-size: 2.5rem;
    }
}

/* Hide scrollbars but keep functionality */
::-webkit-scrollbar {
    display: none;
}

/* Allow text selection for messages */
.message, #roomHeader, #connectionIndicator {
    -webkit-user-select: text;
    user-select: text;
}