/* ===== MOBILE-FIRST RESPONSIVE CSS - COMPLETELY REWRITTEN ===== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* Prevent horizontal scroll */
    overflow-x: hidden;
    width: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    /* Prevent horizontal scroll */
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* ===== MOBILE-FIRST SIDEBAR ===== */
.sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1500;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar.active {
    left: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-header h2 {
    font-size: 1.4rem;
    margin-bottom: 5px;
    font-weight: 700;
}

.sidebar-header p {
    font-size: 0.9rem;
    opacity: 0.9;
}

.sidebar-menu {
    padding: 15px 0;
}

.menu-item {
    padding: 16px 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 16px;
    color: #333;
    border-left: 4px solid transparent;
    font-size: 0.95rem;
    font-weight: 500;
    /* Touch-friendly */
    min-height: 52px;
}

.menu-item:hover,
.menu-item:active {
    background: rgba(102, 126, 234, 0.08);
    border-left-color: #667eea;
}

.menu-item.active {
    background: rgba(102, 126, 234, 0.15);
    border-left-color: #667eea;
    font-weight: 600;
    color: #667eea;
}

.menu-item i {
    font-size: 1.3rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

/* ===== MOBILE-FIRST MAIN CONTAINER ===== */
.main-container {
    width: 100%;
    min-height: 100vh;
    transition: none; /* Remove transition for mobile */
    position: relative;
}

/* ===== MOBILE-FIRST HEADER ===== */
.header {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(15px);
    padding: 12px 16px;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    /* Prevent overflow */
    /* overflow: hidden; */
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0; /* Allow flex shrinking */
}

.menu-toggle {
    background: rgba(102, 126, 234, 0.1);
    border: none;
    font-size: 1.4rem;
    color: #667eea;
    cursor: pointer;
    padding: 10px;
    border-radius: 12px;
    transition: all 0.3s ease;
    /* Touch-friendly */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-toggle:hover,
.menu-toggle:active {
    background: rgba(102, 126, 234, 0.2);
    transform: scale(1.05);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0; /* Allow flex shrinking */
}

.logo i {
    font-size: 1.6rem;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex-shrink: 0;
}

.logo h1 {
    font-size: 1.3rem;
    font-weight: 700;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* ===== MOBILE-FIRST BUTTONS ===== */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.85rem;
    /* Touch-friendly */
    min-height: 44px;
    min-width: 44px;
    box-sizing: border-box;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border: 1px solid rgba(102, 126, 234, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn:hover,
.btn:active {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn:active {
    transform: translateY(0);
}

/* ===== MOBILE-FIRST CONTENT ===== */
.content {
    padding: 16px;
    width: 100%;
    max-width: 100%;
    margin: 0;
    box-sizing: border-box;
}

.section {
    display: none;
    width: 100%;
}

.section.active {
    display: block;
}

.section-header {
    margin-bottom: 24px;
    text-align: center;
    padding: 0 8px;
}

.section-title {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    line-height: 1.2;
}

.section-subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
    line-height: 1.4;
}

/* ===== MOBILE-FIRST CARDS ===== */
.card {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(15px);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
    /* Prevent overflow */
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
    flex-wrap: wrap;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #333;
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.card-title i {
    font-size: 1.4rem;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex-shrink: 0;
}

/* ===== MOBILE-FIRST MEMBER GRID ===== */
.member-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    width: 100%;
}

.member-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
}

.member-card:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.member-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.member-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(45deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 1rem;
    flex-shrink: 0;
}

.member-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.member-info {
    flex: 1;
    min-width: 0;
}

.member-info h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 4px;
    line-height: 1.2;
    word-wrap: break-word;
}

.member-info p {
    color: #667eea;
    font-size: 0.85rem;
    font-weight: 600;
}

.member-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.detail-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: #555;
    padding: 8px 10px;
    background: #f8f9ff;
    border-radius: 8px;
    line-height: 1.3;
}

.detail-item i {
    color: #667eea;
    width: 16px;
    flex-shrink: 0;
    text-align: center;
}

.detail-item span {
    flex: 1;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ===== MOBILE-FIRST MODALS ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 2000;
    padding: 8px;
    box-sizing: border-box;
    /* Prevent scroll issues */
    overflow: hidden;
}

.modal-content {
    position: relative;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* Special sizing for detail modals */
#memberDetailModal .modal-content,
#articleDetailModal .modal-content {
    max-width: 95%;
    max-height: 95vh;
}

.modal-header {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    position: relative;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    flex: 1;
    line-height: 1.3;
    word-wrap: break-word;
    /* Handle long titles */
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    /* Touch-friendly */
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.close-btn:hover,
.close-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.modal-body {
    padding: 20px;
    max-height: 75vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
}

/* ===== MOBILE-FIRST FORMS ===== */
.form-group {
    margin-bottom: 16px;
    width: 100%;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e8e8e8;
    border-radius: 12px;
    font-size: 16px; /* Prevent zoom on iOS */
    transition: all 0.3s ease;
    box-sizing: border-box;
    background: white;
    color: #333;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    transform: translateY(-1px);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

/* ===== MOBILE-FIRST ARTICLES ===== */
.article-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.article-card {
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
}

.article-card:active {
    transform: scale(0.98);
}

.article-image {
    width: 100%;
    height: 180px;
    overflow: hidden;
    flex-shrink: 0;
}

.article-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.article-content {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.article-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.4;
    word-wrap: break-word;
}

.article-excerpt {
    color: #666;
    line-height: 1.5;
    margin-bottom: 12px;
    flex: 1;
    font-size: 0.9rem;
}

.article-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: #888;
}

.article-meta span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.article-meta i {
    color: #667eea;
    width: 14px;
}

/* ===== MOBILE-FIRST PHOTO GALLERY ===== */
.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 16px;
    width: 100%;
}

.photo-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
}

.photo-item:active {
    transform: scale(0.95);
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: white;
    padding: 12px;
    font-size: 0.8rem;
    line-height: 1.3;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.photo-item:hover .photo-overlay,
.photo-item:active .photo-overlay {
    transform: translateY(0);
}

/* ===== MOBILE-FIRST FAMILY TREE ===== */
.family-tree-container {
    position: relative;
    width: 100%;
    height: 300px;
    border: 2px solid #e8e8e8;
    border-radius: 12px;
    overflow: hidden;
    background: linear-gradient(135deg, #f8f9ff 0%, #e8f2ff 100%);
}

.tree-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    display: flex;
    gap: 8px;
}

.tree-control-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    color: #667eea;
}

.tree-control-btn:hover,
.tree-control-btn:active {
    background: #667eea;
    color: white;
    transform: scale(1.1);
}

/* ===== MOBILE-FIRST AUTH ===== */
.auth-container {
    display: none;
    width: calc(100% - 32px);
    max-width: 380px;
    margin: 16px auto;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(15px);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    line-height: 1.2;
}

.auth-header p {
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
}

.auth-tabs {
    display: flex;
    margin-bottom: 24px;
    background: #f5f6fa;
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
}

.auth-tab {
    flex: 1;
    padding: 12px 8px;
    text-align: center;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 0.9rem;
    /* Touch-friendly */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-tab.active {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* ===== MOBILE-FIRST FILE UPLOAD ===== */
.file-upload {
    position: relative;
    display: block;
    cursor: pointer;
    width: 100%;
}

.file-upload input[type=file] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 1;
}

.file-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    border: 2px dashed #d0d0d0;
    border-radius: 12px;
    background: #fafafa;
    transition: all 0.3s ease;
    min-height: 60px;
    text-align: center;
    font-size: 0.9rem;
    color: #666;
}

.file-upload:hover .file-upload-btn,
.file-upload:active .file-upload-btn {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
    color: #667eea;
}

/* ===== MOBILE-FIRST CKEDITOR ===== */
.ckeditor-container {
    margin-bottom: 16px;
    width: 100%;
}

.cke_editable {
    min-height: 150px !important;
    font-size: 14px !important;
}

/* ===== MOBILE-FIRST MESSAGES ===== */
.error-message,
.success-message {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.error-message {
    background: #fee;
    color: #c33;
    border: 1px solid #fcc;
}

.success-message {
    background: #efe;
    color: #393;
    border: 1px solid #cfc;
}

/* ===== MOBILE-FIRST LOADING ===== */
.loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== MOBILE-FIRST EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.empty-state i {
    font-size: 3rem;
    color: #ddd;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: #333;
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 20px;
    line-height: 1.4;
}

/* ===== OVERLAY FOR SIDEBAR ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1400;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
}

/* ===== TABLET RESPONSIVE (min-width: 768px) ===== */
@media screen and (min-width: 768px) {
    .content {
        padding: 24px;
    }
    
    .card {
        padding: 24px;
    }
    
    .section-title {
        font-size: 2.2rem;
    }
    
    .logo h1 {
        font-size: 1.5rem;
    }
    
    .member-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 20px;
    }
    
    .member-details {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .article-card {
        flex-direction: row;
        gap: 16px;
    }
    
    .article-image {
        width: 180px;
        height: 140px;
    }
    
    .photo-gallery {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 16px;
    }
    
    .family-tree-container {
        height: 400px;
    }
    
    .form-row {
        flex-direction: row;
        gap: 20px;
    }
    
    .form-row .form-group {
        flex: 1;
    }
    
    .modal-content {
        max-width: 600px;
    }
    
    .modal-body {
        padding: 24px;
    }
    
    .auth-container {
        padding: 32px;
    }
}

/* ===== DESKTOP RESPONSIVE (min-width: 1024px) ===== */
@media screen and (min-width: 1024px) {
    .main-container.shifted {
        margin-left: 300px;
    }
    
    .sidebar {
        left: -300px;
        width: 300px;
        max-width: none;
    }
    
    .content {
        padding: 32px;
    }
    
    .section-title {
        font-size: 2.5rem;
    }
}   
/* ===== DESKTOP RESPONSIVE (min-width: 1024px) ===== */
@media screen and (min-width: 1024px) {
    .main-container.shifted {
        margin-left: 300px;
    }
    
    .sidebar {
        left: -300px;
        width: 300px;
        max-width: none;
    }
    
    .content {
        padding: 32px;
    }
    
    .section-title {
        font-size: 2.5rem;
    }
    
    .logo h1 {
        font-size: 1.8rem;
    }
    
    .header {
        padding: 16px 32px;
    }
    
    .card {
        padding: 32px;
    }
    
    .card-title {
        font-size: 1.5rem;
    }
    
    .family-tree-container {
        height: 500px;
    }
    
    .member-grid {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 24px;
    }
    
    .photo-gallery {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 20px;
    }
    
    .modal-content {
        max-width: 800px;
    }
    
    .tree-controls {
        top: 16px;
        right: 16px;
    }
    
    .tree-control-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    /* Desktop hover effects */
    .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    }
    
    .member-card:hover {
        transform: translateY(-3px);
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
    }
    
    .article-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
    }
    
    .photo-item:hover {
        transform: scale(1.02);
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    }
    
    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
    }
}

/* ===== LARGE DESKTOP (min-width: 1440px) ===== */
@media screen and (min-width: 1440px) {
    .content {
        max-width: 1400px;
        margin: 0 auto;
    }
    
    .member-grid {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    }
    
    .photo-gallery {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
    
    .family-tree-container {
        height: 600px;
    }
}
/* ===== EXTRA SMALL MOBILE (max-width: 767px) ===== */
@media screen and (max-width: 767px) {
    .content {
        padding: 12px;
    }
    
    .header {
        padding: 10px 12px;
        flex-wrap: wrap;
    }
    
    .logo h1 {
        font-size: 1.1rem;
    }
    
    .section-title {
        font-size: 1.6rem;
    }
    
    .section-subtitle {
        font-size: 0.85rem;
    }
    
    .card {
        padding: 16px;
        border-radius: 12px;
        margin-bottom: 16px;
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }
    
    .card-title {
        font-size: 1.1rem;
        gap: 8px;
    }
    
    .btn {
        padding: 8px 14px;
        font-size: 0.8rem;
        min-height: 40px;
        gap: 4px;
    }
    
    .member-avatar {
        width: 45px;
        height: 45px;
        font-size: 0.9rem;
    }
    
    .member-info h3 {
        font-size: 1rem;
    }
    
    .detail-item {
        font-size: 0.8rem;
        padding: 6px 8px;
    }
    
    .photo-gallery {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }
    
    .family-tree-container {
        height: 250px;
    }
    
    .tree-controls {
        top: 8px;
        right: 8px;
        gap: 6px;
    }
    
    .tree-control-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
    
    .modal {
        padding: 4px;
    }
    
    .modal-content {
        width: calc(100% - 8px);
        max-height: 95vh;
        border-radius: 12px;
    }
    
    .modal-header {
        padding: 12px 16px;
    }
    
    .modal-header h3 {
        font-size: 1rem;
    }
    
    .modal-body {
        padding: 16px;
        max-height: 80vh;
    }
    
    .close-btn {
        min-width: 36px;
        min-height: 36px;
        font-size: 1.1rem;
    }
    
    .auth-container {
        width: calc(100% - 16px);
        margin: 8px;
        padding: 20px;
    }
    
    .auth-header h2 {
        font-size: 1.4rem;
    }
    
    .sidebar {
        width: 95%;
        max-width: 280px;
    }
    
    .menu-item {
        padding: 14px 20px;
        font-size: 0.9rem;
    }
    
    .article-image {
        height: 160px;
    }
    
    .article-title {
        font-size: 1rem;
    }
    
    .article-excerpt {
        font-size: 0.85rem;
    }
}

/* ===== VERY SMALL MOBILE (max-width: 480px) ===== */
@media screen and (max-width: 480px) {
    .content {
        padding: 8px;
    }
    
    .header {
        padding: 8px 10px;
    }
    
    .logo h1 {
        font-size: 1rem;
    }
    
    .section-title {
        font-size: 1.4rem;
    }
    
    .card {
        padding: 12px;
    }
    
    .member-avatar {
        width: 40px;
        height: 40px;
        font-size: 0.8rem;
    }
    
    .photo-gallery {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 6px;
    }
    
    .family-tree-container {
        height: 200px;
    }
    
    .modal-content {
        width: calc(100% - 4px);
    }
    
    .modal-header {
        padding: 10px 12px;
    }
    
    .modal-body {
        padding: 12px;
    }
    
    .btn {
        padding: 6px 12px;
        font-size: 0.75rem;
        min-height: 36px;
    }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 90vh;
    }
    
    .modal-body {
        max-height: 60vh;
    }
    
    .family-tree-container {
        height: 250px;
    }
    
    .auth-container {
        margin: 8px auto;
    }
    
    .content {
        padding: 16px;
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .btn:hover,
    .member-card:hover,
    .photo-item:hover,
    .article-card:hover,
    .card:hover {
        transform: none;
        box-shadow: inherit;
    }
    
    /* Add active states for better touch feedback */
    .btn:active {
        transform: scale(0.95);
    }
    
    .member-card:active,
    .article-card:active {
        transform: scale(0.98);
    }
    
    .photo-item:active {
        transform: scale(0.95);
    }
    
    /* Improve touch targets */
    .menu-item {
        min-height: 48px;
    }
    
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .close-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .tree-control-btn {
        min-width: 40px;
        min-height: 40px;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
        color: #e0e0e0;
    }
    
    .sidebar {
        background: rgba(30, 30, 30, 0.98);
        border-right: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .header {
        background: rgba(30, 30, 30, 0.98);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .card {
        background: rgba(40, 40, 40, 0.98);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: #e0e0e0;
    }
    
    .member-card,
    .article-card {
        background: rgba(35, 35, 35, 0.98);
        border: 1px solid rgba(255, 255, 255, 0.05);
    }
    
    .modal-content {
        background: #2a2a2a;
        color: #e0e0e0;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        background: #3a3a3a;
        border-color: #4a4a4a;
        color: #e0e0e0;
    }
    
    .form-group input:focus,
    .form-group select:focus,
    .form-group textarea:focus {
        border-color: #667eea;
        background: #404040;
    }
    
    .detail-item {
        background: rgba(102, 126, 234, 0.1);
        color: #d0d0d0;
    }
    
    .file-upload-btn {
        background: #3a3a3a;
        border-color: #5a5a5a;
        color: #d0d0d0;
    }
    
    .auth-container {
        background: rgba(40, 40, 40, 0.98);
        color: #e0e0e0;
    }
    
    .menu-item {
        color: #d0d0d0;
    }
    
    .menu-item:hover,
    .menu-item.active {
        background: rgba(102, 126, 234, 0.2);
        color: #e0e0e0;
    }
    .card-title{color: #e0e0e0;}
    #memberDetailContent h2,  #memberDetailContent h4{color: #e0e0e0 !important;}
    .member-info h3,.article-title,.empty-state h3,.form-group label{color: #e0e0e0;}
    .article-excerpt,.empty-state p{color: #c5bfbf;}
    #articleDetailContent .items-news span{color: #e0e0e0 !important;}
    #articleDetailContent .info-content{background: #fff;padding: 0 5px;}
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .modal {
        animation: none;
    }
    
    .modal-content {
        animation: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .btn-primary {
        background: #000080;
        border: 2px solid #000080;
    }
    
    .btn-secondary {
        background: white;
        border: 2px solid #000080;
        color: #000080;
    }
    
    .card {
        border: 2px solid #333;
    }
    
    .modal-content {
        border: 3px solid #000080;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .sidebar,
    .header,
    .modal,
    .btn,
    .tree-controls,
    .close-btn {
        display: none !important;
    }
    
    .main-container {
        margin-left: 0 !important;
    }
    
    .content {
        padding: 0;
        max-width: none;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
        margin-bottom: 20px;
    }
    
    .member-card,
    .article-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .photo-gallery {
        display: none;
    }
    
    .family-tree-container {
        height: auto;
        min-height: 300px;
        border: 1px solid #ccc;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .section-title {
        color: black !important;
        -webkit-text-fill-color: black !important;
    }
    
    .card-title {
        color: black !important;
    }
    
    .card-title i {
        color: black !important;
        -webkit-text-fill-color: black !important;
    }
}

/* ===== JAVASCRIPT HELPER CLASSES ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1400;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* No scroll when modal is open */
.modal-open {
    overflow: hidden !important;
    height: 100vh !important;
}

/* Loading states */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(2px);
}

/* Fade animations */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

.fade-out {
    animation: fadeOut 0.3s ease-in-out;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Utility classes */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

.flex {
    display: flex;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.gap-sm {
    gap: 8px;
}

.gap-md {
    gap: 16px;
}

.gap-lg {
    gap: 24px;
}

.mt-sm {
    margin-top: 8px;
}

.mt-md {
    margin-top: 16px;
}

.mt-lg {
    margin-top: 24px;
}

.mb-sm {
    margin-bottom: 8px;
}

.mb-md {
    margin-bottom: 16px;
}

.mb-lg {
    margin-bottom: 24px;
}

.p-sm {
    padding: 8px;
}

.p-md {
    padding: 16px;
}

.p-lg {
    padding: 24px;
}

/* Performance optimizations */
.will-change-transform {
    will-change: transform;
}

.will-change-auto {
    will-change: auto;
}

/* Smooth scrolling for the whole page */
html {
    scroll-behavior: smooth;
}

/* Improve text rendering */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}