/**
 * vv3B Mobile CSS
 * Mobile-specific styles and responsive design
 */

/* Mobile First - Base mobile styles */
@media (max-width: 768px) {
    /* App Layout */
    .main-content {
        flex-direction: column;
        height: 100vh;
    }
    
    /* Hide peer panel on mobile */
    .peer-panel {
        display: none;
    }
    
    /* Side panel as overlay on mobile */
    .side-panel {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        background: var(--bg-secondary);
        border-right: 1px solid var(--border);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }
    
    .side-panel.open {
        transform: translateX(0);
    }
    
    /* Chat area takes full space */
    .chat-area {
        flex: 1;
        border: none;
        border-radius: 0;
        min-height: 0;
    }
    
    /* Header adjustments */
    .app-header {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border);
    }
    
    .app-title {
        font-size: 1.2rem;
    }
    
    .menu-toggle {
        display: flex;
    }
    
    /* Chat header */
    .chat-header {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border);
    }
    
    .chat-header h2 {
        font-size: 1.1rem;
    }
    
    /* Messages container adjustments */
    .messages-container {
        flex: 1;
        min-height: 0;
    }
    
    .messages-scroll {
        padding: 16px;
    }
    
    /* Message adjustments for mobile */
    .message {
        margin-bottom: 12px;
    }
    
    .message-content {
        max-width: 85%;
        padding: 10px 14px;
        border-radius: 14px;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
    
    /* Composer adjustments */
    .composer-container {
        padding: 12px 16px;
        border-top: 1px solid var(--border);
        background: var(--bg-primary);
    }
    
    .composer-input {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px; /* iOS touch target */
    }
    
    .composer-actions {
        gap: 8px;
    }
    
    .icon-button, .send-button {
        width: 44px; /* Increased touch target */
        height: 44px;
    }
    
    /* Modal adjustments */
    .modal {
        width: 95%;
        margin: 20px;
        max-height: 90vh;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    /* Form adjustments */
    .form-input, .form-select {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 14px 16px;
        min-height: 44px;
    }
    
    .form-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }
    
    .form-actions .button {
        width: 100%;
        min-height: 44px;
    }
    
    /* Welcome message adjustments */
    .welcome-message {
        padding: 32px 20px;
    }
    
    .welcome-icon {
        font-size: 2.5rem;
        margin-bottom: 12px;
    }
    
    .welcome-message h3 {
        font-size: 1.3rem;
    }
    
    /* Settings modal on mobile */
    .modal-large {
        max-width: 95%;
    }
    
    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .color-picker {
        align-self: stretch;
        justify-content: space-between;
    }
    
    .color-option {
        flex: 1;
        max-width: 40px;
        height: 40px;
    }
    
    /* Identity info in side panel */
    .identity-info {
        padding: 16px;
    }
    
    /* Panel headers */
    .panel-header {
        padding: 16px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .side-panel {
        width: 240px;
    }
    
    .composer-container {
        padding: 8px 16px;
    }
    
    .messages-scroll {
        padding: 12px;
    }
    
    .modal {
        max-height: 85vh;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .main-content {
        gap: 0;
    }
    
    .side-panel {
        min-width: 240px;
        max-width: 280px;
    }
    
    .peer-panel {
        min-width: 200px;
        max-width: 240px;
    }
    
    .message-content {
        max-width: 75%;
    }
    
    .modal {
        width: 80%;
        max-width: 600px;
    }
}

/* Touch device specific styles */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .icon-button, .send-button {
        min-width: 44px;
        min-height: 44px;
    }
    
    .peer-item, .room-item {
        min-height: 44px;
        padding: 12px 16px;
    }
    
    /* Remove hover states on touch devices */
    .icon-button:hover,
    .send-button:hover,
    .button:hover,
    .peer-item:hover,
    .room-item:hover,
    .message:hover {
        background: initial;
        border-color: initial;
        color: initial;
    }
    
    /* Focus states for accessibility */
    .icon-button:focus,
    .send-button:focus,
    .button:focus {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }
}

/* Virtual keyboard handling */
.keyboard-open .messages-container {
    max-height: 50vh;
}

.keyboard-open .composer-container {
    position: relative;
    z-index: 10;
}

/* PWA safe areas */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
    
    .composer-container {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    .side-panel {
        padding-top: env(safe-area-inset-top);
    }
}

/* Small mobile devices (iPhone SE, etc.) */
@media (max-width: 375px) {
    .modal {
        width: 98%;
        margin: 10px;
    }
    
    .form-actions {
        margin-top: 16px;
    }
    
    .composer-input {
        min-height: 40px;
    }
    
    .message-content {
        max-width: 90%;
        padding: 8px 12px;
    }
    
    .welcome-message {
        padding: 24px 16px;
    }
    
    .identity-info {
        padding: 12px;
    }
}

/* Large mobile devices */
@media (min-width: 414px) and (max-width: 768px) {
    .side-panel {
        width: 320px;
    }
    
    .modal {
        width: 90%;
    }
    
    .composer-input {
        min-height: 48px;
    }
    
    .icon-button, .send-button {
        width: 48px;
        height: 48px;
    }
}

/* Foldable devices */
@media (max-width: 768px) and (min-aspect-ratio: 3/2) {
    .main-content {
        flex-direction: row;
    }
    
    .side-panel {
        position: relative;
        transform: none;
        width: 35%;
        max-width: 300px;
    }
    
    .chat-area {
        width: 65%;
    }
    
    .menu-toggle {
        display: none;
    }
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) {
    /* Larger text for better readability */
    .message-text {
        font-size: 1rem;
        line-height: 1.6;
    }
    
    .message-sender {
        font-size: 0.9rem;
    }
    
    .message-time {
        font-size: 0.8rem;
    }
    
    /* Better spacing for touch */
    .message {
        margin-bottom: 16px;
    }
    
    /* Focus indicators */
    .form-input:focus,
    .form-select:focus {
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    }
    
    /* Improved contrast for secondary text */
    .message-time,
    .peer-fingerprint,
    .identity-fingerprint {
        opacity: 0.8;
    }
}