/**
 * Mobile Responsive Styles for Family Tree PWA
 * Enhances the mobile experience across all devices
 */

/* ==========================================
   Base Mobile Styles
   ========================================== */

/* Improve touch targets */
@media (max-width: 768px) {
    button, 
    a, 
    .clickable,
    input[type="button"],
    input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Improve form inputs on mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        padding: 12px !important;
    }
}

/* ==========================================
   Navigation - Mobile Hamburger Menu
   ========================================== */

@media (max-width: 1024px) {
    /* Hide sidebar by default on mobile */
    .sidebar-nav {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        width: 280px;
        z-index: 9999;
        transition: left 0.3s ease-in-out;
        overflow-y: auto;
    }
    
    .sidebar-nav.mobile-open {
        left: 0;
    }
    
    /* Mobile menu overlay */
    .mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.7);
        z-index: 9998;
    }
    
    .mobile-overlay.active {
        display: block;
    }
    
    /* Show hamburger menu button */
    .mobile-menu-btn {
        display: flex !important;
    }
    
    /* Adjust main content */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

@media (min-width: 1025px) {
    .mobile-menu-btn {
        display: none !important;
    }
    
    .mobile-overlay {
        display: none !important;
    }
}

/* ==========================================
   Header Adjustments
   ========================================== */

@media (max-width: 768px) {
    /* Stack header items vertically */
    .header-container {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem;
    }
    
    /* Smaller site title */
    .site-title {
        font-size: 1.25rem !important;
    }
    
    /* Compact header buttons */
    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }
    
    .header-actions button,
    .header-actions a {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* ==========================================
   Cards and Panels
   ========================================== */

@media (max-width: 640px) {
    /* Full-width cards on mobile */
    .card, .panel, .glass-panel {
        margin-left: -1rem;
        margin-right: -1rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    /* Reduce card padding */
    .card-body, .panel-body {
        padding: 1rem !important;
    }
    
    /* Stack card headers */
    .card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }
}

/* ==========================================
   Tables - Responsive Horizontal Scroll
   ========================================== */

@media (max-width: 768px) {
    /* Horizontal scroll for tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    
    /* Minimum column widths */
    .table-responsive table {
        min-width: 600px;
    }
    
    /* Compact table cells */
    .table-responsive th,
    .table-responsive td {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
    
    /* Hide less important columns */
    .table-responsive .hide-mobile {
        display: none;
    }
}

/* Alternative: Card-based table view */
@media (max-width: 640px) {
    .table-cards thead {
        display: none;
    }
    
    .table-cards tbody tr {
        display: block;
        margin-bottom: 1rem;
        padding: 1rem;
        background: rgba(26, 26, 46, 0.5);
        border-radius: 0.5rem;
        border: 1px solid rgba(139, 92, 246, 0.2);
    }
    
    .table-cards tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .table-cards tbody td:last-child {
        border-bottom: none;
    }
    
    .table-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #a78bfa;
    }
}

/* ==========================================
   Modals - Full Screen on Mobile
   ========================================== */

@media (max-width: 640px) {
    .modal-content {
        position: fixed;
        inset: 0;
        max-width: 100% !important;
        max-height: 100% !important;
        width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    
    .modal-body {
        max-height: calc(100vh - 140px);
        overflow-y: auto;
    }
    
    .modal-footer {
        position: sticky;
        bottom: 0;
        background: inherit;
        padding: 1rem;
        border-top: 1px solid rgba(139, 92, 246, 0.2);
    }
}

/* ==========================================
   Individual/Family Profile Pages
   ========================================== */

@media (max-width: 768px) {
    /* Stack profile header */
    .profile-header {
        flex-direction: column;
        text-align: center;
    }
    
    .profile-image {
        margin: 0 auto 1rem;
    }
    
    /* Smaller profile images */
    .profile-image img {
        width: 120px !important;
        height: 120px !important;
    }
    
    /* Stack vital info */
    .vital-info {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .vital-info-item {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Tab navigation - horizontal scroll */
    .profile-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 0.25rem;
    }
    
    .profile-tabs button {
        flex-shrink: 0;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
}

/* ==========================================
   Family Tree Visualization
   ========================================== */

@media (max-width: 768px) {
    /* Allow horizontal scroll for tree */
    .tree-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Smaller tree nodes */
    .tree-node {
        min-width: 100px;
        padding: 0.5rem;
        font-size: 0.75rem;
    }
    
    .tree-node img {
        width: 40px !important;
        height: 40px !important;
    }
}

/* ==========================================
   Media Gallery
   ========================================== */

@media (max-width: 640px) {
    /* 2-column grid on mobile */
    .media-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem;
    }
    
    /* Smaller thumbnails */
    .media-thumbnail {
        aspect-ratio: 1;
    }
}

/* ==========================================
   Forms
   ========================================== */

@media (max-width: 640px) {
    /* Stack form rows */
    .form-row {
        flex-direction: column;
    }
    
    .form-row > * {
        width: 100% !important;
    }
    
    /* Full-width buttons */
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions button {
        width: 100%;
    }
}

/* ==========================================
   Search and Filters
   ========================================== */

@media (max-width: 768px) {
    /* Stack search and filter controls */
    .search-filters {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .search-filters > * {
        width: 100% !important;
    }
    
    /* Collapsible filters */
    .filter-panel {
        display: none;
    }
    
    .filter-panel.show {
        display: block;
    }
    
    .filter-toggle {
        display: flex !important;
    }
}

@media (min-width: 769px) {
    .filter-toggle {
        display: none !important;
    }
    
    .filter-panel {
        display: flex !important;
    }
}

/* ==========================================
   DataTables Overrides
   ========================================== */

@media (max-width: 768px) {
    /* Compact DataTables */
    .dataTables_wrapper {
        padding: 0 !important;
    }
    
    .dataTables_filter,
    .dataTables_length {
        width: 100%;
        text-align: left !important;
        margin-bottom: 0.75rem;
    }
    
    .dataTables_filter input,
    .dataTables_length select {
        width: 100% !important;
        margin-left: 0 !important;
    }
    
    .dataTables_info,
    .dataTables_paginate {
        text-align: center !important;
        width: 100%;
        margin-top: 0.75rem;
    }
    
    .dataTables_paginate .paginate_button {
        padding: 0.5rem 0.75rem !important;
        margin: 0.25rem !important;
    }
}

/* ==========================================
   Utility Classes
   ========================================== */

/* Hide on mobile */
@media (max-width: 640px) {
    .hide-sm { display: none !important; }
}

@media (max-width: 768px) {
    .hide-md { display: none !important; }
}

@media (max-width: 1024px) {
    .hide-lg { display: none !important; }
}

/* Show only on mobile */
@media (min-width: 641px) {
    .show-sm-only { display: none !important; }
}

@media (min-width: 769px) {
    .show-md-only { display: none !important; }
}

/* Mobile-specific spacing */
@media (max-width: 640px) {
    .mobile-p-2 { padding: 0.5rem !important; }
    .mobile-p-4 { padding: 1rem !important; }
    .mobile-mt-4 { margin-top: 1rem !important; }
    .mobile-mb-4 { margin-bottom: 1rem !important; }
    .mobile-text-sm { font-size: 0.875rem !important; }
    .mobile-text-center { text-align: center !important; }
    .mobile-flex-col { flex-direction: column !important; }
    .mobile-w-full { width: 100% !important; }
}

/* ==========================================
   PWA Install Banner
   ========================================== */

.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    z-index: 9999;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.pwa-install-banner.show {
    display: flex;
}

.pwa-install-banner p {
    color: white;
    margin: 0;
    font-size: 0.9rem;
}

.pwa-install-banner button {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all 0.2s;
}

.pwa-install-btn {
    background: white;
    color: #764ba2;
}

.pwa-dismiss-btn {
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

/* ==========================================
   Safe Area Insets (for notched phones)
   ========================================== */

@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .fixed-bottom,
    .modal-footer,
    .pwa-install-banner {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
    
    .fixed-top,
    .header-container {
        padding-top: env(safe-area-inset-top);
    }
}

/* ==========================================
   Print Styles
   ========================================== */

@media print {
    .sidebar-nav,
    .mobile-menu-btn,
    .header-actions,
    .pwa-install-banner,
    button,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
}
