/**
 * Nefarious IRC Web Client - Mobile Styles
 * Swipeable sidebars and responsive layout for devices < 1024px
 */

/* ============================================
   Base Styles (prevent race conditions)
   Hide mobile-only elements by default, show in mobile media query
   ============================================ */
.mobile-menu-btn,
.panel-overlay,
.swipe-hint {
    display: none;
}

/* ============================================
   Mobile/Tablet Layout (< 1024px)
   ============================================ */
@media (max-width: 1023px) {
    /* App container adjustments */
    .app-container {
        position: relative;
        overflow: hidden;
    }

    /* Left sidebar (channel list) - off-canvas */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85vw;
        max-width: 320px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 16px var(--shadow-color);
    }

    /* Right panel (user list) - off-canvas */
    .user-list-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 85vw;
        max-width: 320px;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
        box-shadow: none;
    }

    .user-list-panel.open {
        transform: translateX(0);
        box-shadow: -4px 0 16px var(--shadow-color);
    }

    /* Override the collapsed class on mobile */
    .user-list-panel.collapsed {
        width: 85vw;
        max-width: 320px;
        transform: translateX(100%);
    }

    .user-list-panel.collapsed.open {
        transform: translateX(0);
    }

    /* Backdrop overlay */
    .panel-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .panel-overlay.visible {
        opacity: 1;
        visibility: visible;
    }

    /* Chat area takes full width */
    .chat-area {
        width: 100%;
        min-width: 0;
    }

    /* Mobile header adjustments */
    .chat-header {
        display: flex;
        align-items: center;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .chat-header h2 {
        flex: 1;
        text-align: left;
        margin: 0;
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Mobile navigation buttons - static, stay in header */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: var(--text-color);
        font-size: 1.5rem;
        padding: 0.5rem;
        cursor: pointer;
        min-width: 44px;
        min-height: 44px;
        border-radius: 4px;
        transition: background 0.2s;
    }

    .mobile-menu-btn:hover {
        background: var(--hover-dark);
    }

    .mobile-menu-btn:active {
        background: var(--hover-light);
    }

    /* Hide desktop user list toggle and close button */
    #user-list-toggle,
    #user-list-close {
        display: none;
    }

    /* Compact channel/user items on mobile */
    .channel-item,
    .dm-item {
        line-height: 1;
    }

    .user-item {
        padding: 0.5rem;
        min-height: 44px;
    }

    /* Larger touch targets for close buttons */
    .channel-close-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* User controls (Settings, Refresh, Logout) - consistent 44px height */
    .user-controls {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .user-controls .btn {
        min-height: 44px;
        padding: 0 0.75rem;
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        font-size: 0.875rem;
    }

    .user-buttons {
        flex-direction: column;
        gap: 0;
    }

    .user-buttons .btn {
        min-height: 44px;
        padding: 0 0.75rem;
        margin: 0;
    }

    /* Input area adjustments */
    .input-area {
        padding: 0.5rem;
        gap: 0.25rem;
        flex-wrap: nowrap;
        max-width: 100%;
        box-sizing: border-box;
    }

    .input-area input {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 0.75rem 0.5rem;
        min-width: 0; /* Allow flex shrinking below content size */
        flex: 1;
    }

    /* Attach button container compact on mobile */
    .attach-btn-container {
        flex-shrink: 0;
    }

    .attach-btn {
        padding: 0 2px;
        font-size: 20px;
    }

    /* Messages area */
    .messages {
        padding: 0.75rem 1rem;
    }

    /* Allow message text to use full width on mobile - buttons can wrap */
    .message-wrapper .message-text {
        max-width: fit-content;
    }

    /* Smaller app header on mobile */
    .app-header {
        padding: 0.5rem 1rem;
    }

    .app-header h1 {
        font-size: 1rem;
    }

    /* Modal adjustments for mobile */
    .modal-content {
        width: calc(100% - 1rem);
        max-width: 100%;
        max-height: 90vh;
        margin: 0.5rem;
        padding: 1.25rem;
        overflow-y: auto;
        overflow-x: hidden;
        box-sizing: border-box;
    }

    .modal-content h2 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    /* Form group improvements for touch */
    .form-group {
        margin-bottom: 1.25rem;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    .form-group input[type="text"],
    .form-group input[type="password"],
    .form-group input[type="email"],
    .form-group input[type="number"],
    .form-group select {
        width: 100%;
        padding: 0.875rem 1rem;
        font-size: 16px; /* Prevents iOS zoom on focus */
        border-radius: 6px;
        box-sizing: border-box;
        -webkit-appearance: none;
        appearance: none;
    }

    .form-group input[type="checkbox"] {
        width: 20px;
        height: 20px;
        margin-right: 0.75rem;
    }

    /* Stack form action buttons vertically on mobile */
    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 1.25rem;
        width: 100%;
    }

    .form-actions .btn {
        width: 100%;
        padding: 0.875rem 1rem;
        font-size: 1rem;
        min-height: 48px; /* Touch-friendly height */
        justify-content: center;
        box-sizing: border-box;
        white-space: normal; /* Allow text to wrap */
        text-align: center;
    }

    /* Link buttons should be full width and wrap text */
    .form-actions .btn-link {
        text-align: center;
        padding: 0.75rem 0.5rem;
        font-size: 0.875rem;
        white-space: normal;
        line-height: 1.4;
        word-wrap: break-word;
    }

    /* Error and success messages */
    .error-message,
    .success-message {
        padding: 0.75rem;
        font-size: 0.875rem;
        border-radius: 6px;
        margin-bottom: 1rem;
    }

    .channel-browser-content {
        max-height: 85vh;
    }

    /* Swipe hint indicators */
    .swipe-hint {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        width: 4px;
        height: 60px;
        background: var(--primary-color);
        opacity: 0;
        transition: opacity 0.2s ease;
        z-index: 998;
        pointer-events: none;
        border-radius: 2px;
    }

    .swipe-hint-left {
        left: 0;
        border-radius: 0 2px 2px 0;
    }

    .swipe-hint-right {
        right: 0;
        border-radius: 2px 0 0 2px;
    }

    .swipe-hint.visible {
        opacity: 0.6;
    }
}


/* ============================================
   Desktop Layout (>= 1024px)
   ============================================ */
@media (min-width: 1024px) {
    /* Hide mobile-only elements */
    .mobile-menu-btn,
    .panel-overlay,
    .swipe-hint {
        display: none !important;
    }

    /* Reset sidebar positioning */
    .sidebar {
        position: relative;
        transform: none;
        width: 250px;
    }

    /* Reset user list panel positioning */
    .user-list-panel {
        position: relative;
        transform: none;
    }

    .user-list-panel:not(.collapsed) {
        width: 250px;
    }
}


/* ============================================
   Emoji Picker - Mobile Fullscreen
   ============================================ */
@media (max-width: 768px) {
    /* Fullscreen emoji picker on mobile */
    .emoji-picker {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
        z-index: 2000;
    }

    /* Larger header on mobile */
    .emoji-picker-header {
        padding: 12px;
        padding-top: calc(12px + env(safe-area-inset-top, 0));
    }

    .emoji-picker-header input {
        padding: 12px 14px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .emoji-picker-close {
        font-size: 1.6em;
        padding: 8px 12px;
    }

    /* Larger tabs */
    .emoji-picker-tabs {
        padding: 8px 12px;
    }

    .emoji-tab {
        padding: 10px;
        font-size: 1.4em;
    }

    /* Larger emoji grid */
    .emoji-category-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 4px;
    }

    .emoji-item {
        font-size: 1.8em;
        padding: 6px;
    }

    .emoji-item.emoji-custom img {
        width: 32px;
        height: 32px;
    }

    /* Category bar scrollable */
    .emoji-categories {
        padding: 8px;
    }

    .emoji-category-btn {
        font-size: 1.3em;
        padding: 8px 10px;
    }

    /* More padding in body */
    .emoji-picker-body {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    }
}


/* ============================================
   Reduced Motion Support
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .user-list-panel,
    .panel-overlay {
        transition: none !important;
    }

    #btn-open-channels.panel-open,
    #btn-open-users.panel-open,
    #btn-open-channels.panel-closing,
    #btn-open-users.panel-closing {
        animation: none !important;
    }
}


/* ============================================
   Pinch-to-Zoom Visual Feedback
   ============================================ */
.pinch-zoomed {
    position: relative;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border-radius: 4px;
}

/* Zoomed images get a subtle border */
img.pinch-zoomed {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Zoomed code blocks */
pre.pinch-zoomed,
code.pinch-zoomed {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    background: var(--bg-secondary);
}

/* Ensure touch-action allows our custom handling */
.messages img,
.media-container img,
.file-attachment img,
pre,
code {
    touch-action: pan-x pan-y;
}

