/**
 * Mobile-First CSS for ConcreteInfo Mix Design Calculator
 * Includes bottom navigation, touch optimizations, and responsive utilities
 *
 * Designed by: Amit Haridas, ConcreteInfo
 */

/* ============================================
   BOTTOM NAVIGATION - iOS Style
   ============================================ */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.dark .bottom-nav {
    background: rgba(29, 29, 29, 0.95);
    border-top-color: rgba(255, 255, 255, 0.1);
}

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

.bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    color: #464646;
    text-decoration: none;
    transition: all 0.2s ease;
    min-width: 64px;
    -webkit-tap-highlight-color: transparent;
    border-radius: 12px;
}

.dark .bottom-nav__item {
    color: #9a9696;
}

.bottom-nav__item--active,
.bottom-nav__item[aria-current="page"] {
    color: #e5461f;
}

.bottom-nav__item:active {
    transform: scale(0.95);
    background: rgba(229, 70, 31, 0.1);
}

.bottom-nav__icon {
    font-size: var(--font-size-3xl);
    margin-bottom: 4px;
}

.bottom-nav__label {
    font-size: 10px;
    font-weight: var(--font-weight-medium);
    letter-spacing: 0.01em;
}

/* ============================================
   TOUCH-OPTIMIZED FORM CONTROLS
   ============================================ */

@media (max-width: 768px) {
    /* Minimum 44px touch targets (iOS HIG) */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 12px 16px;
    }

    .btn,
    button {
        min-height: 44px;
        padding: 12px 24px;
        font-size: 16px;
    }

    /* Larger checkbox/radio targets */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
    }

    /* Swipeable cards */
    .card--swipe {
        position: relative;
        touch-action: pan-x;
    }

    /* Full-width mobile buttons */
    .btn-mobile-full {
        width: 100%;
        display: block;
    }
}

/* ============================================
   MOBILE MODAL ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
    /* Full-screen modals on mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
        border-radius: 0;
    }

    .modal-content {
        min-height: 100vh;
        border-radius: 0;
    }

    /* Bottom sheet style modal */
    .modal--bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 90vh;
        border-radius: 16px 16px 0 0;
        min-height: auto;
    }

    .modal--bottom-sheet .modal-content {
        min-height: auto;
        border-radius: 16px 16px 0 0;
    }

    /* Draggable handle for bottom sheets */
    .modal__drag-handle {
        width: 36px;
        height: 4px;
        background: #ccc;
        border-radius: 2px;
        margin: 8px auto;
    }
}

/* ============================================
   MOBILE CARD LISTS
   ============================================ */

@media (max-width: 768px) {
    /* Stack cards vertically */
    .cards-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    /* Compact mobile cards */
    .card--mobile-compact {
        padding: 12px;
        margin: 0 -8px;
        border-radius: 8px;
    }

    /* Swipe actions container */
    .swipe-actions {
        position: relative;
        overflow: hidden;
    }

    .swipe-actions__background {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        display: flex;
        align-items: center;
        padding-right: 20px;
        background: #dc2626;
        color: white;
    }
}

/* ============================================
   SAFE AREA UTILITIES
   ============================================ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .safe-area-top {
        padding-top: env(safe-area-inset-top);
    }

    .safe-area-left {
        padding-left: env(safe-area-inset-left);
    }

    .safe-area-right {
        padding-right: env(safe-area-inset-right);
    }
}

/* ============================================
   MOBILE INPUT STEPPERS
   ============================================ */

.stepper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stepper__btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid #e5461f;
    background: white;
    color: #e5461f;
    font-size: var(--font-size-2xl);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.stepper__btn:active {
    background: #e5461f;
    color: white;
}

.stepper__input {
    width: 80px;
    text-align: center;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
}


/* ============================================
   MOBILE FORM LAYOUT
   ============================================ */

@media (max-width: 768px) {
    /* Stack form groups */
    .form-row {
        flex-direction: column;
        gap: 16px;
    }

    .form-row > * {
        width: 100%;
    }

    /* Compact form labels */
    .form-label {
        margin-bottom: 4px;
        font-weight: var(--font-weight-semibold);
        font-size: var(--font-size-base);
    }

    /* Inline form errors */
    .form-error {
        font-size: var(--font-size-sm);
        margin-top: 4px;
    }
}

/* ============================================
   MOBILE TABLE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    /* Horizontal scroll for tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Or convert to cards */
    .table--mobile-cards thead {
        display: none;
    }

    .table--mobile-cards tbody tr {
        display: block;
        margin-bottom: 16px;
        padding: 12px;
        background: white;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .table--mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid #eee;
    }

    .table--mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: var(--font-weight-semibold);
        color: #464646;
    }
}

/* ============================================
   MOBILE SPACING UTILITIES
   ============================================ */

@media (max-width: 768px) {
    .mobile-p-4 { padding: 1rem; }
    .mobile-p-6 { padding: 1.5rem; }
    .mobile-mb-4 { margin-bottom: 1rem; }
    .mobile-mb-6 { margin-bottom: 1.5rem; }
    .mobile-text-center { text-align: center; }
    .mobile-hidden { display: none !important; }
    .mobile-block { display: block !important; }
    .mobile-flex { display: flex !important; }
}

/* ============================================
   PULL TO REFRESH INDICATOR
   ============================================ */

.ptr-indicator {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.ptr-indicator--loading {
    animation: ptr-spin 0.8s linear infinite;
}

@keyframes ptr-spin {
    from { transform: translateX(-50%) rotate(0deg); }
    to { transform: translateX(-50%) rotate(360deg); }
}

/* ============================================
   SIDEBAR TOUCH TARGETS
   Sidebar links are ~31px tall by default.
   Bump to 44px minimum on mobile per Apple HIG / WCAG 2.5.5.
   ============================================ */
@media (max-width: 1023.98px) {
    .sidebar-link {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        min-height: 44px;
    }
}

/* ============================================
   BOTTOM NAV CONTENT CLEARANCE
   Prevent page content from being hidden behind
   the fixed bottom navigation bar on mobile.
   ============================================ */
@media (max-width: 767.98px) {
    .main-content {
        padding-bottom: calc(64px + var(--spacing-6, 1.5rem) + env(safe-area-inset-bottom, 0px));
    }
}
