/* Mobile Experience Enhancements v2 for Task Platform */

/* ===== Touch-Friendly Button Sizes ===== */
@media (max-width: 767px) {
    button, .btn, a.btn, [role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    .mobile-btn {
        padding: 12px 20px;
        font-size: 16px;
    }
    /* Form inputs - prevent zoom on iOS */
    input, select, textarea {
        font-size: 16px !important;
    }
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    textarea,
    select {
        padding: 12px 16px;
        border-radius: 10px;
    }
    input[type="search"] {
        padding-left: 40px;
        height: 48px;
    }
}

/* ===== Floating Action Button (FAB) ===== */
.fab-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 100;
    display: none;
}
@media (max-width: 767px) {
    .fab-container {
        display: block;
    }
}
.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0170c6 0%, #00a3c4 100%);
    box-shadow: 0 4px 12px rgba(1, 112, 198, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
}
.fab:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(1, 112, 198, 0.6);
}
.fab-menu {
    position: absolute;
    bottom: 70px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(20px);
}
.fab-container.open .fab-menu {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}
.fab-item {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: flex-end;
}
.fab-item-label {
    background: white;
    padding: 8px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 14px;
    color: #374151;
    white-space: nowrap;
}
.fab-item-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0170c6;
    font-size: 18px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}
.fab-item-btn:active {
    transform: scale(0.9);
    background: #f3f4f6;
}

/* ===== Pull-to-Refresh Indicator ===== */
.pull-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-100%);
    transition: transform 0.3s;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.pull-refresh.visible {
    transform: translateY(0);
}
.pull-refresh-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top-color: #0170c6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Card Swipe Actions ===== */
.swipe-card {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
}
.swipe-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.swipe-card.swiped .swipe-actions {
    transform: translateX(0);
}
.swipe-action-btn {
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
}
.swipe-action-btn.edit { background: #3b82f6; }
.swipe-action-btn.delete { background: #ef4444; }

/* ===== Mobile Bottom Navigation ===== */
.mobile-bottom-nav a {
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.mobile-bottom-nav a:active {
    transform: scale(0.9);
}
.mobile-bottom-nav a.active svg {
    animation: bounce 0.3s ease;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* ===== Bottom Nav Badge ===== */
.nav-badge {
    position: absolute;
    top: 2px;
    right: 50%;
    transform: translateX(14px);
    min-width: 16px;
    height: 16px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}
.nav-badge.hidden {
    display: none;
}

/* ===== Responsive Typography ===== */
@media (max-width: 640px) {
    h1 { font-size: 1.75rem !important; }
    h2 { font-size: 1.5rem !important; }
    h3 { font-size: 1.25rem !important; }
    .text-5xl { font-size: 2rem !important; }
    .text-4xl { font-size: 1.75rem !important; }
    .text-3xl { font-size: 1.5rem !important; }
    .text-2xl { font-size: 1.25rem !important; }
}

/* ===== Mobile-Optimized Cards ===== */
@media (max-width: 767px) {
    .task-card {
        padding: 16px;
        margin-bottom: 12px;
    }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .card-actions {
        width: 100%;
        display: flex;
        gap: 8px;
        margin-top: 12px;
    }
    .card-actions button {
        flex: 1;
    }
    /* Force single column on mobile task grids */
    .task-grid {
        grid-template-columns: 1fr !important;
    }
    .task-grid .task-card-item {
        animation-delay: 0ms !important;
    }
    /* Better spacing */
    .grid.md\:grid-cols-2,
    .grid.md\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Mobile Search Overlay ===== */
.mobile-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    z-index: 200;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.mobile-search-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.mobile-search-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}
.mobile-search-input {
    flex: 1;
    height: 44px;
    border: 1px solid #d1d5db;
    border-radius: 22px;
    padding: 0 16px 0 40px;
    font-size: 16px;
    background: #f9fafb;
    outline: none;
    transition: border-color 0.2s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 20px;
}
.mobile-search-input:focus {
    border-color: #0170c6;
    background-color: white;
}
.mobile-search-cancel {
    font-size: 15px;
    color: #0170c6;
    font-weight: 500;
    white-space: nowrap;
    padding: 8px;
}
.mobile-search-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}
.mobile-search-suggestions {
    margin-bottom: 24px;
}
.mobile-search-suggestions h4 {
    font-size: 13px;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}
.search-chip {
    display: inline-block;
    padding: 8px 16px;
    background: #f3f4f6;
    border-radius: 20px;
    font-size: 14px;
    color: #374151;
    margin: 0 8px 8px 0;
    cursor: pointer;
    transition: all 0.15s;
}
.search-chip:active {
    background: #e5e7eb;
    transform: scale(0.97);
}

/* ===== Mobile Bottom Sheet ===== */
.bottom-sheet-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.bottom-sheet-backdrop.active {
    opacity: 1;
    pointer-events: all;
}
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 16px 16px 0 0;
    z-index: 151;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-sheet.active {
    transform: translateY(0);
}
.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 12px auto 8px;
}
.bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 20px 12px;
    border-bottom: 1px solid #f3f4f6;
}
.bottom-sheet-header h3 {
    font-size: 16px;
    font-weight: 600;
}
.bottom-sheet-body {
    padding: 16px 20px;
}

/* ===== Mobile Filter Bottom Sheet ===== */
.mobile-filter-trigger {
    display: none;
}
@media (max-width: 767px) {
    .mobile-filter-trigger {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 10px 16px;
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        font-size: 14px;
        color: #374151;
        font-weight: 500;
        white-space: nowrap;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-filter-trigger:active {
        background: #f9fafb;
    }
    .desktop-filters {
        display: none !important;
    }
}
@media (min-width: 768px) {
    .mobile-filter-trigger {
        display: none !important;
    }
}

/* ===== Horizontal Scroll Category Chips ===== */
.category-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 0 0 8px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x mandatory;
}
.category-scroll::-webkit-scrollbar {
    display: none;
}
.category-chip {
    flex-shrink: 0;
    padding: 8px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s;
    scroll-snap-align: start;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}
.category-chip:active {
    transform: scale(0.96);
}
.category-chip.active {
    background: #0170c6;
    color: white;
    border-color: #0170c6;
}

/* ===== Quick Action Chips ===== */
.quick-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.quick-actions::-webkit-scrollbar {
    display: none;
}
.chip {
    flex-shrink: 0;
    padding: 8px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.chip:active {
    background: #f3f4f6;
    transform: scale(0.95);
}
.chip.active {
    background: #0170c6;
    color: white;
    border-color: #0170c6;
}

/* ===== Mobile Toast Notifications ===== */
.toast-mobile {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 9999;
    animation: slideUp 0.3s ease;
    max-width: 80%;
    text-align: center;
}
@keyframes slideUp {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== Safe Area Insets (iOS notch) ===== */
@supports (padding: max(0px)) {
    .mobile-bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    header {
        padding-top: max(0px, env(safe-area-inset-top));
    }
    main {
        padding-bottom: max(72px, calc(64px + env(safe-area-inset-bottom)));
    }
}

/* ===== Haptic Feedback ===== */
.haptic {
    transition: transform 0.1s;
}
.haptic:active {
    transform: scale(0.98);
}

/* ===== Mobile Form Optimizations ===== */
@media (max-width: 767px) {
    .form-group {
        margin-bottom: 20px;
    }
    .form-label {
        font-size: 15px;
        margin-bottom: 8px;
        display: block;
    }
    .form-help {
        font-size: 13px;
        margin-top: 6px;
        color: #6b7280;
    }
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
        margin-right: 12px;
    }
    .file-upload-btn {
        width: 100%;
        padding: 16px;
        text-align: center;
        border: 2px dashed #d1d5db;
        border-radius: 12px;
        background: #f9fafb;
    }
}

/* ===== Mobile Table Alternatives ===== */
@media (max-width: 640px) {
    table.responsive-table {
        display: block;
    }
    table.responsive-table thead {
        display: none;
    }
    table.responsive-table tbody {
        display: block;
    }
    table.responsive-table tr {
        display: block;
        margin-bottom: 16px;
        padding: 16px;
        background: white;
        border-radius: 12px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    table.responsive-table td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border: none;
    }
    table.responsive-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        margin-right: 16px;
    }
}

/* ===== Mobile Loading States ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.loading-spinner-large {
    width: 48px;
    height: 48px;
    border: 4px solid #e5e7eb;
    border-top-color: #0170c6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== Mobile Skeleton Card ===== */
.skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Mobile Enhanced Task Detail ===== */
@media (max-width: 767px) {
    /* Task detail: stack columns */
    .grid.lg\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }
    /* Sticky action bar on mobile */
    .mobile-action-bar {
        position: fixed;
        bottom: 64px;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #e5e7eb;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
        z-index: 49;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    }
    .mobile-action-bar .reward-display {
        font-size: 22px;
        font-weight: 800;
        color: #059669;
    }
    .mobile-action-bar .action-btn {
        flex: 1;
        max-width: 180px;
        padding: 12px 20px;
        background: linear-gradient(135deg, #0170c6, #0d90e8);
        color: white;
        border-radius: 12px;
        font-weight: 600;
        font-size: 15px;
        text-align: center;
        box-shadow: 0 4px 12px rgba(1,112,198,0.3);
    }
    .mobile-action-bar .action-btn:active {
        transform: scale(0.98);
    }
    /* Breadcrumb: hide on mobile */
    .grid.lg\:grid-cols-3 ~ nav,
    nav.mb-6 {
        flex-wrap: wrap;
    }
    nav.mb-6 .flex.items-center.gap-2.text-sm {
        overflow: hidden;
    }
    nav.mb-6 .flex.items-center.gap-2.text-sm span.max-w-xs {
        max-width: 100px;
    }
}

/* ===== Mobile Stats Cards ===== */
@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    .stats-grid .stat-card {
        padding: 14px !important;
    }
    .stats-grid .stat-card .stat-value {
        font-size: 1.25rem !important;
    }
}

/* ===== Mobile Hero Section ===== */
@media (max-width: 640px) {
    .gradient-hero {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }
    .gradient-hero h1 {
        font-size: 1.75rem !important;
        line-height: 1.3 !important;
    }
    .gradient-hero p {
        font-size: 0.95rem !important;
    }
    .gradient-hero .btn-micro {
        padding: 12px 20px !important;
        font-size: 15px !important;
    }
}

/* ===== Mobile Personal Center ===== */
@media (max-width: 640px) {
    .profile-hero {
        padding: 20px !important;
    }
    .profile-hero .avatar {
        width: 56px !important;
        height: 56px !important;
    }
    .chart-container {
        height: 200px !important;
    }
    /* Achievement grid: 3 cols */
    .achievement-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }
}

/* ===== Mobile Task Create Form ===== */
@media (max-width: 767px) {
    .create-task-form textarea {
        min-height: 120px;
    }
    .step-indicator {
        padding: 8px 12px !important;
        font-size: 12px !important;
    }
}

/* ===== Swipe Hint Animation ===== */
@keyframes swipeHint {
    0% { transform: translateX(0); }
    50% { transform: translateX(-16px); }
    100% { transform: translateX(0); }
}
.swipe-hint {
    animation: swipeHint 2s ease-in-out 1;
}

/* ===== Mobile Share Sheet ===== */
.share-sheet-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 16px 0;
}
.share-sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.share-sheet-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}
.share-sheet-label {
    font-size: 12px;
    color: #6b7280;
    text-align: center;
}

/* ===== Mobile Notification Items ===== */
@media (max-width: 767px) {
    .notification-item {
        padding: 14px 16px !important;
    }
    .notification-item .notif-icon {
        width: 36px !important;
        height: 36px !important;
    }
}

/* ===== Smooth Momentum Scrolling ===== */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ===== Prevent horizontal overflow on mobile ===== */
@media (max-width: 767px) {
    body {
        overflow-x: hidden;
    }
    .max-w-7xl {
        max-width: 100%;
    }
    section > .max-w-7xl {
        padding-left: 16px;
        padding-right: 16px;
    }
}
