/* Responsive Design and Media Queries */
/* Mobile, tablet, and desktop layout adaptations */

/* Mobile Status Container */
@media (max-width: 768px) {
    .status-container {
        left: 10px;
        right: 10px;
        top: 10px;
        width: auto;
        max-width: 100%;
        transform: none;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .status-message {
        width: auto;
        max-width: 90vw;
        box-sizing: border-box;
        font-size: var(--font-size-sm);
        text-align: center;
    }
}

/* Very Small Screens (under 480px) */
@media (max-width: 480px) {
    .status-container {
        top: 70px;
        max-width: calc(100vw - 20px);
        min-width: 260px;
    }
}

@media (max-width: 360px) {
    .status-container {
        top: 65px;
        max-width: calc(100vw - 15px);
        min-width: auto;
    }
    
    .status-message {
        padding: 10px 12px;
        font-size: var(--font-size-sm);
    }
}

/* Mobile Layout Adaptations */
@media (max-width: 768px) {
    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: flex !important;
    }
    
    /* Sidebar as overlay */
    .admin-sidebar {
        position: fixed !important;
        top: var(--header-height, 60px);
        left: -300px; /* Changed from -100% to fixed value that's larger than width */
        width: 280px !important;
        max-width: 80vw !important;
        min-width: 250px !important;
        height: calc(100vh - var(--header-height, 60px));
        height: calc(var(--app-height, 100vh) - var(--header-height, 60px));
        z-index: 10000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        overflow-y: auto;
        transform: translateX(0); /* Ensure no transform issues */
    }
    
    .admin-sidebar.active {
        left: 0 !important;
        transform: translateX(0); /* Ensure it's fully visible */
    }
    
    /* Show mobile sidebar elements */
    .sidebar-header {
        display: flex !important;
    }
    
    .sidebar-footer {
        display: block !important;
    }
    
    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
    
    /* Admin content takes full width */
    .admin-content {
        width: 100%;
        margin-left: 0;
    }
    
    /* Header adjustments */
    .header {
        padding: 10px 15px;
        display: flex;
        align-items: center;
        gap: 15px;
    }
    
    .header h1 {
        flex: 1;
        text-align: center;
        margin: 0;
        font-size: var(--font-size-xl);
    }
    
    /* Hide desktop elements */
    .desktop-only {
        display: none !important;
    }
    
    .mobile-only {
        display: flex;
    }
    
    /* Admin container becomes full width */
    .admin-container {
        flex-direction: column;
        height: calc(100vh - 50px);
        height: calc(var(--app-height) - 50px);
    }
    
    /* Remove duplicate sidebar styles - keep only the first one above */
    /* DELETE or comment out this duplicate block: */
    /*
    .admin-sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: var(--sidebar-width-mobile);
        height: 100vh;
        height: var(--app-height);
        background: white;
        z-index: var(--z-modal-backdrop);
        transition: left 0.3s ease;
        box-shadow: var(--shadow-md);
        display: flex;
        flex-direction: column;
        padding: var(--padding-base);
    }
    
    .admin-sidebar.active {
        left: 0;
    }
    */
    
    /* Show sidebar header and footer on mobile */
    .sidebar-header {
        display: flex;
    }
    
    .sidebar-footer {
        display: block;
    }
    
    /* Admin nav mobile styling */
    .admin-nav {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 8px;
        margin: var(--padding-base) 0;
    }
    
    .admin-nav a {
        display: flex;
        align-items: center;
        padding: 10px 12px;
        font-size: var(--font-size-base);
        border-radius: var(--border-radius);
        background-color: #f5f5f5;
        border: 1px solid #e0e0e0;
        transition: var(--transition);
    }
    
    .admin-nav a:active {
        background-color: #e0e0e0;
        transform: scale(0.98);
    }
    
    .admin-nav a.active {
        background-color: var(--primary-color);
        color: white;
        border-color: var(--primary-color);
    }
    
    .admin-nav a:hover {
        background-color: #ebebeb;
        border-color: #d0d0d0;
    }
    
    .admin-nav a.active:hover {
        background-color: #0056b3;
        border-color: #0056b3;
    }
    
    /* Navigation icons and text */
    .nav-icon {
        font-size: var(--font-size-lg);
        margin-right: 8px;
        flex-shrink: 0;
    }
    
    .nav-text {
        font-size: var(--font-size-base);
        font-weight: 500;
    }
    
    /* Content adjustments */
    .admin-content {
        padding: 15px;
    }
    
    .admin-section {
        padding: 15px;
    }
    
    .header .header-actions {
        display: flex !important;
        gap: 10px;
        flex-wrap: wrap;
    }
    
    .header .header-actions .btn {
        padding: 6px 10px;
        font-size: var(--font-size-sm);
    }
    
    .admin-info {
        font-size: var(--font-size-xs);
    }
    
    .admin-map-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .admin-map {
        height: 250px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    /* User management mobile */
    .users-admin-container {
        grid-template-columns: 1fr;
        gap: 25px;
    }
    
    .user-form,
    .users-list {
        padding: 25px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .users-list {
        overflow-x: auto;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Data Convert responsive styles */
    .field-mapping-grid {
        grid-template-columns: 1fr;
    }
    
    .csv-example {
        font-size: 10px;
        padding: 10px;
    }
    
    .csv-requirements {
        padding: 15px;
    }
    
    /* NocoDB cards responsive */
    .nocodb-cards {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .nocodb-card {
        padding: var(--padding-base);
    }
    
    .nocodb-card-header h3 {
        font-size: var(--font-size-lg);
    }
    
    .info-box {
        padding: 16px;
    }
    
    /* Shifts admin mobile */
    .shifts-admin-container {
        grid-template-columns: 1fr;
        gap: var(--padding-base);
    }
    
    .shift-admin-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .shift-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    /* Volunteer names mobile styling */
    .volunteer-count {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .volunteer-names {
        font-size: 0.8em;
        line-height: 1.2;
        word-break: break-word;
    }
    
    /* Walk sheet container mobile */
    .walk-sheet-container {
        display: flex !important;
        flex-direction: column !important;
        gap: var(--padding-base);
    }
    
    .walk-sheet-config {
        order: 1 !important;
        margin-bottom: var(--padding-base);
    }
    
    /* Walk sheet mobile */
    .walk-sheet-preview {
        min-width: 0;
        max-width: 100%;
        width: 100%;
        min-height: 500px;
        padding: 10px;
        overflow: hidden;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .walk-sheet-preview #walk-sheet-preview-content {
        transform: scale(0.35);
        transform-origin: top center;
        margin: 0 auto;
        width: 816px;
        max-width: none;
        margin-bottom: -600px;
        position: relative;
        left: 50%;
        margin-left: -408px;
    }
    
    /* Users cards mobile layout */
    .users-cards-container {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .user-card {
        padding: 12px;
    }
    
    .user-card-header {
        /* Keep horizontal layout on mobile to keep user type next to name/email */
        flex-direction: row;
        align-items: flex-start;
        gap: 8px;
    }
    
    .user-role-badge {
        align-items: flex-end;
        flex-shrink: 0;
    }
    
    .user-actions {
        /* Keep all buttons in one row on mobile */
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
    }
    
    .user-communication-actions {
        gap: 4px;
    }
    
    .user-communication-actions .btn {
        min-width: 36px;
        padding: 6px 8px;
        font-size: 14px;
    }
    
    .user-admin-actions {
        /* Keep horizontal layout */
        flex-direction: row;
        gap: 4px;
        margin-left: auto;
    }
    
    .user-admin-actions .btn {
        font-size: var(--font-size-xs);
        padding: 6px 8px;
        white-space: nowrap;
    }
    
    .send-login-btn {
        font-size: 11px !important;
        padding: 6px 6px !important;
    }
    
    /* Mobile user info adjustments */
    .user-info-primary {
        min-width: 0;
        flex: 1;
    }
    
    .user-name {
        font-size: 16px !important;
        margin-bottom: 2px !important;
    }
    
    .user-email {
        font-size: 13px !important;
    }
    
    .user-details-compact {
        font-size: 12px !important;
        margin: 2px 0 !important;
    }
    
    /* Mobile search interface */
    .users-header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .users-search-container {
        min-width: auto;
        width: 100%;
    }
    
    .users-filter-container {
        flex-wrap: wrap;
    }
    
    #email-all-users-btn {
        width: 100%;
        justify-content: center;
    }
    
    .user-form .form-actions {
        flex-direction: column;
    }
    
    /* Modal responsive */
    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .modal-body {
        padding: var(--padding-base);
    }
    
    .form-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .volunteer-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .volunteer-actions {
        align-self: flex-end;
        gap: 6px;
    }
    
    .volunteer-communication-actions {
        justify-content: center;
        gap: 8px;
        margin-bottom: 6px;
    }
    
    .volunteer-communication-actions .btn {
        min-width: 40px;
        padding: 8px 12px;
        font-size: 16px;
    }
    
    .volunteer-admin-actions {
        flex-direction: column;
        gap: 6px;
    }
    
    .processing-actions {
        flex-direction: column;
    }
}

/* Very Small Screens (under 480px) */
@media (max-width: 480px) {
    .admin-sidebar {
        width: 260px !important; /* Added !important to override */
        left: -280px !important; /* Increased to ensure complete hiding */
        padding: 12px;
    }
    
    .admin-sidebar.active {
        left: 0 !important;
    }
    
    .admin-nav {
        gap: 6px;
        margin: 15px 0;
    }
    
    .admin-nav a {
        padding: 8px 10px;
        font-size: var(--font-size-sm);
    }
    
    .nav-icon {
        font-size: var(--font-size-base);
        margin-right: 6px;
    }
    
    .nav-text {
        font-size: var(--font-size-sm);
    }
    
    .admin-content {
        padding: 10px;
    }
    
    .admin-section {
        padding: 10px;
    }
    
    .admin-sidebar {
        padding: 10px;
    }
    
    .admin-nav a {
        padding: 6px 10px;
        font-size: var(--font-size-sm);
    }
    
    .header .header-actions .btn {
        padding: 5px 8px;
        font-size: var(--font-size-xs);
    }
    
    .admin-info {
        display: none;
    }
    
    .admin-map {
        height: 200px;
    }
    
    .walk-sheet-preview .walk-sheet-page {
        transform: scale(0.25);
        transform-origin: center top;
        margin-bottom: -750px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .form-group input,
    .form-group select {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }
    
    .btn-sm {
        min-height: 36px;
        padding: 8px 12px;
    }
}

/* Ultra Small Screens (under 360px) */
@media (max-width: 360px) {
    .admin-sidebar {
        width: 240px !important; /* Added !important */
        left: -260px !important; /* Increased to ensure complete hiding */
    }
    
    .admin-sidebar.active {
        left: 0 !important;
    }
    
    .admin-nav a {
        padding: 8px;
        font-size: var(--font-size-xs);
    }
    
    .nav-icon {
        font-size: var(--font-size-sm);
        margin-right: 5px;
    }
    
    .nav-text {
        font-size: var(--font-size-xs);
    }
}

/* Medium Screen Optimization (900px - 1400px) - Cards layout responsive */
@media (max-width: 1400px) and (min-width: 900px) {
    .users-cards-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 18px;
    }
    
    .user-card {
        padding: 18px;
    }
    
    .user-admin-actions .btn {
        font-size: 11px;
        padding: 6px 10px;
    }
    
    /* Shifts responsive fixes for medium screens */
    .shifts-list {
        overflow-x: auto;
        padding: 20px;
    }
    
    .shift-admin-item {
        min-width: 0;
        overflow: hidden;
        flex-wrap: wrap;
    }
    
    .shift-actions {
        gap: 6px;
        flex-wrap: wrap;
        justify-content: flex-start;
        width: 100%;
        min-width: 250px;
    }
    
    .shift-actions .btn {
        font-size: 11px;
        padding: 5px 8px;
        min-width: 70px;
        flex: 0 0 auto;
        white-space: nowrap;
    }
}

/* Tablet Responsive (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .admin-sidebar {
        width: var(--sidebar-width-tablet);
        min-width: var(--sidebar-width-tablet);
        max-width: var(--sidebar-width-tablet);
        padding: 15px;
    }
    
    .admin-content {
        padding: var(--padding-base);
    }
    
    .admin-section {
        padding: var(--padding-base);
    }
    
    .users-admin-container {
        grid-template-columns: 1fr;
        gap: var(--padding-base);
    }
    
    .shifts-admin-container {
        grid-template-columns: 1fr;
        gap: var(--padding-base);
    }
    
    .user-form,
    .users-list {
        padding: var(--padding-base);
    }
    
    .users-cards-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .user-card {
        padding: 15px;
    }
    
    .user-name {
        font-size: var(--font-size-base);
    }
    
    /* Users search responsive */
    .users-list-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .users-header-actions {
        width: 100%;
        justify-content: space-between;
        flex-direction: row-reverse;
    }
    
    .users-search-container {
        min-width: 200px;
        flex: 1;
    }
    
    /* Shifts responsive for tablet screens */
    .shift-admin-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .shift-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 8px;
    }
    
    .shift-actions .btn {
        font-size: 12px;
        padding: 6px 10px;
        min-width: 85px;
    }
}

/* Medium Desktop (1024px - 1200px) - Ensure table actions are visible */
@media (max-width: 1400px) and (min-width: 1025px) {
    .users-table {
        min-width: 800px;
    }
    
    .user-admin-actions .btn {
        font-size: 10px;
        padding: 5px 6px;
        min-width: 75px;
    }
    
    .users-table th:nth-child(6), 
    .users-table td:nth-child(6) {
        min-width: 200px;
    }
}

/* Small Laptop (1024px - 1200px) */
@media (max-width: 1200px) and (min-width: 1025px) {
    .admin-sidebar {
        width: var(--sidebar-width-tablet);
        min-width: var(--sidebar-width-tablet);
        max-width: var(--sidebar-width-tablet);
    }
    
    .users-admin-container,
    .shifts-admin-container {
        grid-template-columns: 1fr 1.5fr;
        gap: 25px;
    }
    
    .walk-sheet-container {
        display: flex !important;
        flex-direction: column !important;
        gap: var(--padding-base);
    }
    
    .walk-sheet-config {
        order: 1 !important;
        margin-bottom: var(--padding-base);
    }
    
    .walk-sheet-preview {
        order: 2 !important;
        padding: var(--padding-base);
        min-height: auto;
        max-width: 100vw;
        overflow-x: auto;
        display: flex;
        justify-content: center;
        align-items: flex-start;
    }
    
    .walk-sheet-preview .walk-sheet-page {
        transform: scale(0.75);
        transform-origin: center top;
        margin-bottom: -200px;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
}

@media (max-width: 1000px) {
    .walk-sheet-preview .walk-sheet-page {
        transform: scale(0.5);
        transform-origin: center top;
        margin-bottom: -400px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .cuts-map-section {
        height: 400px;
    }
    
    .cuts-filters {
        grid-template-columns: 1fr;
    }
}

/* Header Responsive */
@media (max-width: 1024px) {
    .header {
        padding: 10px 15px;
    }
    
    .header h1 {
        font-size: var(--padding-base);
    }
    
    .header .header-actions {
        gap: 8px;
    }
}

/* Responsive Cards for Very Small Screens */
@media (max-width: 640px) {
    .users-cards-container {
        gap: 12px;
    }
    
    .user-card {
        padding: 12px;
    }
    
    .user-name {
        font-size: var(--font-size-base);
    }
    
    .user-email {
        font-size: 12px;
    }
    
    .user-phone,
    .user-created {
        font-size: 12px;
    }
    
    .user-communication-actions .btn {
        min-width: 38px;
        padding: 8px 10px;
        font-size: 14px;
    }
    
    .user-admin-actions .btn {
        font-size: 12px;
        padding: 8px 12px;
        min-height: 36px;
    }
    
    /* Very small screens search interface */
    .users-search-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .users-filter-select {
        font-size: 14px;
    }
}
