/* ==========================================================================
   MOBILE-FIRST ENHANCEMENTS FOR TASKMASTER
   Version: 1.0.0
   Based on best practices from 7shifts, Deputy, Connecteam
   ========================================================================== */

/* ==========================================================================
   CSS CUSTOM PROPERTIES (Mobile-First Variables)
   ========================================================================== */
:root {
    /* Touch-friendly sizes */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;

    /* Bottom navigation */
    --bottom-nav-height: 64px;
    --bottom-nav-bg: #1a1a1a;
    --bottom-nav-border: #333333;
    --bottom-nav-active: var(--primary-color, #FF6600);
    --bottom-nav-inactive: #888888;

    /* Skeleton loading */
    --skeleton-bg: #2a2a2a;
    --skeleton-shine: #3a3a3a;

    /* FAB (Floating Action Button) */
    --fab-size: 56px;
    --fab-bg: var(--primary-color, #FF6600);
    --fab-shadow: 0 4px 12px rgba(255, 102, 0, 0.4);

    /* Safe areas for notch phones */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

/* ==========================================================================
   BOTTOM NAVIGATION BAR (Mobile Only)
   ========================================================================== */
.bottom-nav {
    display: none; /* Hidden by default (desktop) */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: var(--bottom-nav-bg);
    border-top: 1px solid var(--bottom-nav-border);
    z-index: 1000;
    padding-bottom: var(--safe-area-inset-bottom);
}

.bottom-nav__container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    min-width: var(--touch-target-min);
    padding: 8px 4px;
    text-decoration: none;
    color: var(--bottom-nav-inactive);
    transition: color 0.2s ease, transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav__item:active {
    transform: scale(0.95);
}

.bottom-nav__item.active,
.bottom-nav__item--active {
    color: var(--bottom-nav-active);
}

.bottom-nav__icon {
    font-size: 1.4rem;
    margin-bottom: 4px;
    transition: transform 0.2s ease;
}

.bottom-nav__item.active .bottom-nav__icon,
.bottom-nav__item--active .bottom-nav__icon {
    transform: scale(1.1);
}

.bottom-nav__label {
    font-size: 0.65rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Badge on bottom nav item */
.bottom-nav__badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 20px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background-color: #F44336;
    border-radius: 9px;
    font-size: 0.65rem;
    font-weight: 600;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Show bottom nav on mobile */
@media (max-width: 768px) {
    .bottom-nav {
        display: block;
    }

    /* Add padding to main content to prevent overlap */
    .main-content,
    .content,
    body {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom)) !important;
    }

    /* Hide sidebar menu toggle when bottom nav is present */
    .sidebar-nav li:last-child {
        /* Keep logout in sidebar for now */
    }
}

/* ==========================================================================
   FLOATING ACTION BUTTON (FAB)
   ========================================================================== */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 16px + var(--safe-area-inset-bottom));
    right: 16px;
    width: var(--fab-size);
    height: var(--fab-size);
    border-radius: 50%;
    background-color: var(--fab-bg);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--fab-shadow);
    z-index: 999;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(255, 102, 0, 0.5);
}

.fab:active {
    transform: scale(0.95);
}

.fab__icon {
    font-size: 1.5rem;
}

/* FAB with extended label */
.fab--extended {
    width: auto;
    border-radius: 28px;
    padding: 0 20px;
}

.fab--extended .fab__label {
    margin-left: 8px;
    font-weight: 500;
}

/* Desktop: position FAB higher (no bottom nav) */
@media (min-width: 769px) {
    .fab {
        bottom: 24px;
    }
}

/* ==========================================================================
   SKELETON LOADING
   ========================================================================== */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--skeleton-bg) 0%,
        var(--skeleton-shine) 50%,
        var(--skeleton-bg) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton variants */
.skeleton--text {
    height: 1em;
    width: 100%;
    margin-bottom: 0.5em;
}

.skeleton--text-sm {
    height: 0.8em;
    width: 60%;
}

.skeleton--title {
    height: 1.5em;
    width: 40%;
    margin-bottom: 1em;
}

.skeleton--avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton--card {
    height: 120px;
    width: 100%;
    margin-bottom: 1rem;
    border-radius: 8px;
}

.skeleton--button {
    height: 44px;
    width: 120px;
    border-radius: 4px;
}

.skeleton--table-row {
    height: 48px;
    width: 100%;
    margin-bottom: 8px;
}

/* Skeleton container for schedule */
.skeleton-schedule {
    display: grid;
    gap: 8px;
}

.skeleton-schedule__header {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.skeleton-schedule__day {
    flex: 1;
    height: 40px;
}

.skeleton-schedule__row {
    display: flex;
    gap: 8px;
}

.skeleton-schedule__name {
    width: 150px;
    height: 60px;
}

.skeleton-schedule__cell {
    flex: 1;
    height: 60px;
}

/* Skeleton container for list */
.skeleton-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.skeleton-list__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--skeleton-bg);
    border-radius: 8px;
}

/* ==========================================================================
   TOUCH-FRIENDLY ELEMENTS
   ========================================================================== */

/* Ensure all interactive elements are at least 44x44px */
@media (max-width: 768px) {
    /* Buttons */
    .btn,
    button,
    [role="button"],
    input[type="button"],
    input[type="submit"],
    input[type="reset"] {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        padding: 12px 16px;
    }

    /* Links that look like buttons */
    a.btn,
    .header-action {
        min-height: var(--touch-target-min);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    textarea,
    select {
        min-height: var(--touch-target-min);
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }

    /* Checkboxes and radios - increase touch area */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
        margin-right: 12px;
    }

    /* Table cells with actions */
    .table td .btn,
    .table td button {
        padding: 8px 12px;
        min-height: 36px;
    }

    /* Navigation links */
    .sidebar-nav li a,
    .menu li a {
        min-height: var(--touch-target-min);
        padding: 14px 20px;
    }

    /* Tabs */
    .tab-button,
    .stats-detail-tab {
        min-height: var(--touch-target-min);
        padding: 12px 16px;
    }

    /* Close buttons */
    .close-modal,
    .modal-close,
    [data-dismiss="modal"] {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ==========================================================================
   PULL TO REFRESH
   ========================================================================== */
.ptr {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    background: var(--background-paper, #242424);
    z-index: 998;
}

.ptr--active {
    transform: translateY(0);
}

.ptr__spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color, #333);
    border-top-color: var(--primary-color, #FF6600);
    border-radius: 50%;
    animation: ptr-spin 0.8s linear infinite;
}

@keyframes ptr-spin {
    to {
        transform: rotate(360deg);
    }
}

.ptr__text {
    margin-left: 12px;
    color: var(--text-secondary, #B3B3B3);
    font-size: 0.9rem;
}

/* ==========================================================================
   SWIPE GESTURES SUPPORT
   ========================================================================== */
.swipeable {
    touch-action: pan-y pinch-zoom;
    overflow-x: hidden;
}

.swipeable-container {
    display: flex;
    transition: transform 0.3s ease;
    will-change: transform;
}

.swipeable-item {
    flex: 0 0 100%;
    min-width: 100%;
}

/* Swipe indicators */
.swipe-indicator {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 12px 0;
}

.swipe-indicator__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--border-color, #333);
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.swipe-indicator__dot--active {
    background-color: var(--primary-color, #FF6600);
    transform: scale(1.2);
}

/* ==========================================================================
   QUICK ACTIONS CARD (Dashboard)
   ========================================================================== */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px;
}

@media (min-width: 768px) {
    .quick-actions {
        grid-template-columns: repeat(4, 1fr);
    }
}

.quick-action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 12px;
    background: var(--background-paper, #242424);
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-primary, #fff);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    min-height: 100px;
    -webkit-tap-highlight-color: transparent;
}

.quick-action-card:hover,
.quick-action-card:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-color: var(--primary-color, #FF6600);
    text-decoration: none;
    color: var(--text-primary, #fff);
}

.quick-action-card:active {
    transform: scale(0.98);
}

.quick-action-card__icon {
    font-size: 1.8rem;
    margin-bottom: 8px;
    color: var(--primary-color, #FF6600);
}

.quick-action-card__title {
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
}

.quick-action-card__badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #F44336;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Quick action variants */
.quick-action-card--primary {
    border-color: var(--primary-color, #FF6600);
    background: rgba(255, 102, 0, 0.1);
}

.quick-action-card--success {
    border-color: var(--success-color, #4CAF50);
}

.quick-action-card--success .quick-action-card__icon {
    color: var(--success-color, #4CAF50);
}

.quick-action-card--warning {
    border-color: var(--warning-color, #FFC107);
}

.quick-action-card--warning .quick-action-card__icon {
    color: var(--warning-color, #FFC107);
}

.quick-action-card--danger {
    border-color: var(--error-color, #F44336);
}

.quick-action-card--danger .quick-action-card__icon {
    color: var(--error-color, #F44336);
}

/* ==========================================================================
   MOBILE-OPTIMIZED CARDS
   ========================================================================== */
@media (max-width: 768px) {
    .card {
        margin-bottom: 12px;
        border-radius: 12px;
    }

    .card-header {
        padding: 14px 16px;
        font-size: 1rem;
    }

    .card-body {
        padding: 16px;
    }

    /* Horizontal scrollable cards container */
    .cards-scroll {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 12px;
        padding: 4px;
        margin: 0 -16px;
        padding-left: 16px;
        padding-right: 16px;
    }

    .cards-scroll::-webkit-scrollbar {
        display: none;
    }

    .cards-scroll .card {
        flex: 0 0 280px;
        scroll-snap-align: start;
        margin-bottom: 0;
    }
}

/* ==========================================================================
   MOBILE-OPTIMIZED TABLES
   ========================================================================== */
@media (max-width: 768px) {
    /* Card-based table for mobile */
    .table-mobile-cards {
        display: block;
    }

    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .table-mobile-cards tr {
        display: block;
        background: var(--background-paper, #242424);
        border: 1px solid var(--border-color, #333);
        border-radius: 12px;
        padding: 16px;
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid var(--border-color, #333);
    }

    .table-mobile-cards td:last-child {
        border-bottom: none;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary, #B3B3B3);
        flex: 0 0 40%;
    }
}

/* ==========================================================================
   NOTIFICATION TOAST (Mobile Optimized)
   ========================================================================== */
.toast-container {
    position: fixed;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

@media (min-width: 769px) {
    .toast-container {
        left: auto;
        right: 24px;
        width: 360px;
    }
}

.toast {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--background-paper, #242424);
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    animation: toast-slide-in 0.3s ease;
}

@keyframes toast-slide-in {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.toast--success {
    border-left: 4px solid var(--success-color, #4CAF50);
}

.toast--warning {
    border-left: 4px solid var(--warning-color, #FFC107);
}

.toast--error {
    border-left: 4px solid var(--error-color, #F44336);
}

.toast--info {
    border-left: 4px solid var(--primary-color, #FF6600);
}

.toast__icon {
    font-size: 1.2rem;
    margin-right: 12px;
}

.toast__content {
    flex: 1;
}

.toast__title {
    font-weight: 600;
    margin-bottom: 2px;
}

.toast__message {
    font-size: 0.9rem;
    color: var(--text-secondary, #B3B3B3);
}

.toast__close {
    background: none;
    border: none;
    color: var(--text-secondary, #B3B3B3);
    padding: 8px;
    margin: -8px -8px -8px 8px;
    cursor: pointer;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   PROGRESS INDICATORS
   ========================================================================== */
.progress-ring {
    transform: rotate(-90deg);
}

.progress-ring__circle {
    transition: stroke-dashoffset 0.5s ease;
    stroke-linecap: round;
}

.progress-ring__text {
    transform: rotate(90deg);
    transform-origin: center;
    font-weight: 600;
}

/* Linear progress */
.progress-bar {
    height: 8px;
    background: var(--skeleton-bg, #2a2a2a);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar__fill {
    height: 100%;
    background: var(--primary-color, #FF6600);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* ==========================================================================
   STREAK COUNTER (Gamification)
   ========================================================================== */
.streak-counter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #FF6600, #FF8533);
    border-radius: 20px;
    color: white;
    font-weight: 600;
}

.streak-counter__icon {
    font-size: 1.2rem;
}

.streak-counter__value {
    font-size: 1.1rem;
}

.streak-counter__label {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* ==========================================================================
   BADGE COMPONENT (Gamification)
   ========================================================================== */
.badge-earned {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid #FFC107;
    border-radius: 16px;
    color: #FFC107;
    font-size: 0.85rem;
    font-weight: 500;
}

.badge-earned__icon {
    font-size: 1rem;
}

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.empty-state__icon {
    font-size: 4rem;
    color: var(--text-secondary, #B3B3B3);
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state__title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary, #fff);
}

.empty-state__description {
    font-size: 0.95rem;
    color: var(--text-secondary, #B3B3B3);
    margin-bottom: 24px;
    max-width: 300px;
}

.empty-state__action {
    min-height: var(--touch-target-min);
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

/* Confetti animation for achievements */
@keyframes confetti-fall {
    0% {
        transform: translateY(-100%) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.confetti {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

.confetti__piece {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-color, #FF6600);
    animation: confetti-fall 3s ease-out forwards;
}

/* Pulse animation for notifications */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* Bounce animation for FAB */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

.bounce {
    animation: bounce 2s ease-in-out infinite;
}

/* ==========================================================================
   UTILITIES
   ========================================================================== */

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

/* Hide on desktop */
@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}

/* Touch-friendly spacing */
.touch-spacing {
    padding: 12px;
}

/* No text selection for interactive elements */
.no-select {
    -webkit-user-select: none;
    user-select: none;
}

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

/* Safe area padding */
.safe-area-top {
    padding-top: var(--safe-area-inset-top);
}

.safe-area-bottom {
    padding-bottom: var(--safe-area-inset-bottom);
}

/* Haptic feedback class (used with JS) */
.haptic {
    /* Applied via JavaScript for haptic feedback */
}
