/**
 * Mobile-First Responsive Styles for Knauss Family Office
 * Optimized for tablets and mobile devices
 */

/* ===== MOBILE BREAKPOINTS ===== */
/* Mobile: < 640px */
/* Tablet: 640px - 1024px */
/* Desktop: > 1024px */

/* ===== GLOBAL MOBILE OPTIMIZATIONS ===== */
@media (max-width: 1024px) {
    /* Improve touch targets */
    button, a, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
    }

    /* Prevent text size adjustment */
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    /* Improve scrolling */
    body {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
}

/* ===== NAVIGATION ===== */
@media (max-width: 768px) {
    /* Mobile hamburger menu */
    .mobile-menu-button {
        display: block;
        position: fixed;
        top: 1rem;
        right: 1rem;
        z-index: 50;
        background: #0f172a;
        border: 2px solid #fbbf24;
        border-radius: 0.5rem;
        padding: 0.75rem;
    }

    .mobile-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        background: #0f172a;
        border-left: 2px solid #fbbf24;
        transition: right 0.3s ease;
        z-index: 40;
        overflow-y: auto;
        padding: 5rem 1.5rem 2rem;
    }

    .mobile-menu.open {
        right: 0;
    }

    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 30;
        display: none;
    }

    .mobile-menu-overlay.open {
        display: block;
    }

    /* Mobile navigation links */
    .mobile-menu a {
        display: block;
        padding: 1rem;
        color: #ffffff;
        border-bottom: 1px solid #1e293b;
        font-size: 1.125rem;
    }

    .mobile-menu a:hover {
        background: #1e293b;
        border-left: 4px solid #fbbf24;
    }
}

/* ===== DASHBOARD ===== */
@media (max-width: 1024px) {
    /* Stack dashboard cards */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .dashboard-card {
        padding: 1.5rem 1rem;
    }

    /* Reduce dashboard card heights */
    .dashboard-card {
        min-height: auto;
    }
}

@media (max-width: 640px) {
    .dashboard-card h3 {
        font-size: 1.25rem;
    }

    .dashboard-card p {
        font-size: 0.875rem;
    }
}

/* ===== FAMILY TREE ===== */
@media (max-width: 1024px) {
    /* Mobile tree view toggle */
    .tree-view-toggle {
        display: flex;
        justify-content: center;
        gap: 0.5rem;
        margin-bottom: 1rem;
        padding: 0.5rem;
        background: #1e293b;
        border-radius: 0.5rem;
    }

    .tree-view-toggle button {
        flex: 1;
        padding: 0.75rem;
        background: #0f172a;
        color: #ffffff;
        border: 1px solid #64748b;
        border-radius: 0.375rem;
        font-size: 0.875rem;
    }

    .tree-view-toggle button.active {
        background: #fbbf24;
        color: #0f172a;
        border-color: #fbbf24;
    }

    /* List view for mobile */
    .tree-list-view {
        display: none;
    }

    .tree-list-view.active {
        display: block;
    }

    .tree-list-item {
        background: #1e293b;
        border: 1px solid #64748b;
        border-radius: 0.5rem;
        padding: 1rem;
        margin-bottom: 0.75rem;
    }

    .tree-list-item h4 {
        color: #fbbf24;
        font-size: 1.125rem;
        margin-bottom: 0.5rem;
    }

    .tree-list-item p {
        color: #ffffff;
        font-size: 0.875rem;
        margin-bottom: 0.25rem;
    }

    /* Simplified tree visualization */
    #family-tree {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tree-node {
        width: 280px !important;
        height: 140px !important;
        font-size: 0.875rem;
    }

    .tree-node-name {
        font-size: 1rem;
    }

    .tree-node-dates {
        font-size: 0.75rem;
    }
}

@media (max-width: 640px) {
    .tree-node {
        width: 240px !important;
        height: 120px !important;
    }

    .tree-node-name {
        font-size: 0.875rem;
    }
}

/* ===== ADMIN DASHBOARDS ===== */
@media (max-width: 1024px) {
    /* Stack admin tabs vertically on mobile */
    .admin-tabs {
        flex-direction: column;
        gap: 0.5rem;
    }

    .admin-tab {
        width: 100%;
        text-align: left;
        padding: 1rem;
    }

    /* Admin tables */
    .admin-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .admin-table {
        min-width: 600px;
    }

    /* Admin forms */
    .admin-form-grid {
        grid-template-columns: 1fr !important;
    }

    .admin-form-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .admin-form-actions button {
        width: 100%;
    }
}

/* ===== MEDIA GALLERY ===== */
@media (max-width: 1024px) {
    .media-gallery-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
}

@media (max-width: 640px) {
    .media-gallery-grid {
        grid-template-columns: 1fr !important;
    }

    .media-card {
        max-width: 100%;
    }
}

/* ===== FORMS ===== */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .form-row {
        flex-direction: column;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 0.75rem;
    }

    .form-actions button {
        width: 100%;
    }

    /* Improve form inputs on mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
    }
}

/* ===== MODALS ===== */
@media (max-width: 768px) {
    .modal-container {
        width: 95%;
        max-width: none;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-footer button {
        width: 100%;
    }
}

/* ===== TABLES ===== */
@media (max-width: 768px) {
    /* Responsive table pattern */
    .responsive-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .responsive-table table {
        min-width: 600px;
    }

    /* Card-based table for very small screens */
    .table-card-view {
        display: none;
    }
}

@media (max-width: 640px) {
    .responsive-table {
        display: none;
    }

    .table-card-view {
        display: block;
    }

    .table-card {
        background: #1e293b;
        border: 1px solid #64748b;
        border-radius: 0.5rem;
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .table-card-row {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border-bottom: 1px solid #334155;
    }

    .table-card-row:last-child {
        border-bottom: none;
    }

    .table-card-label {
        font-weight: 600;
        color: #fbbf24;
    }

    .table-card-value {
        color: #ffffff;
        text-align: right;
    }
}

/* ===== CALENDAR ===== */
@media (max-width: 768px) {
    .calendar-grid {
        font-size: 0.875rem;
    }

    .calendar-day {
        min-height: 60px;
        padding: 0.25rem;
    }

    .calendar-event {
        font-size: 0.75rem;
        padding: 0.25rem;
    }
}

/* ===== SEARCH ===== */
@media (max-width: 768px) {
    .search-container {
        width: 100%;
    }

    .search-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .search-results {
        max-height: 60vh;
    }
}

/* ===== GENEALOGY RECORDS ===== */
@media (max-width: 768px) {
    .life-record-header {
        flex-direction: column;
        text-align: center;
    }

    .life-record-portrait {
        margin: 0 auto 1rem;
    }

    .life-record-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== TOUCH OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .hover-effect:hover {
        transform: none;
    }

    /* Increase button padding for touch */
    button, .btn {
        padding: 0.875rem 1.5rem;
    }

    /* Add active states for touch feedback */
    button:active, .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media (max-width: 1024px) and (orientation: landscape) {
    .mobile-menu {
        width: 50%;
        max-width: 400px;
    }

    .modal-container {
        max-height: 85vh;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .mobile-menu-button,
    .mobile-menu,
    .mobile-menu-overlay,
    .tree-view-toggle,
    .admin-tabs,
    button,
    .btn {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .tree-node {
        border: 1px solid black;
        background: white;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .tree-node,
    .dashboard-card,
    .admin-tab {
        border-width: 2px;
    }

    button, .btn {
        border-width: 2px;
    }
}
