/**
 * 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: 40;
    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);
}

/* Offline/sync status pill (#connection-indicator, assets/js/pwa-register.js). It is
   inline-styled to bottom-right, so these rules need !important. Below 1024px it sits
   above the bottom nav and is hidden while the sidebar drawer is open (the drawer
   footer holds the user card). Desktop placement is unchanged. */
@media (max-width: 1023.98px) {
    #connection-indicator {
        bottom: calc(var(--bottom-nav-height, 64px) + env(safe-area-inset-bottom, 0px) + 8px) !important;
    }

    body:has(.sidebar.open) #connection-indicator {
        display: none !important;
    }

    /* Cookie consent banner (#cookieConsent, includes/footer.php). Where the bottom nav is
       rendered the banner sits above it, so the nav stays tappable on a first visit. Pages
       without the nav (sign-in/register) keep the banner at the bottom edge. */
    body:has(.bottom-nav) #cookieConsent {
        bottom: calc(var(--bottom-nav-height, 64px) + 1px + env(safe-area-inset-bottom, 0px));
    }
}

.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:var(--text-tertiary);
}

.bottom-nav__item--active,
.bottom-nav__item[aria-current="page"] {
    color: var(--color-brand);
}

.bottom-nav__item:active {
    transform: scale(0.95);
    background: hsl(var(--color-brand-h) var(--color-brand-s) var(--color-brand-l) / 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 var(--color-brand);
    background: white;
    color: var(--color-brand);
    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: var(--color-brand);
    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: 1023.98px) {
    .main-content {
        padding-bottom: calc(64px + var(--spacing-6, 1.5rem) + env(safe-area-inset-bottom, 0px));
    }
}

/* ============================================
   MOBILE FORM OPTIMIZATION
   ============================================ */
/* Stat-grid intermediate breakpoint for tablets */
@media (max-width: 1023.98px) {
  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  /* Prevent iOS auto-zoom on input focus (requires font-size >= 16px) */
  .input,
  .select,
  textarea,
  .tf-input,
  .tf-select,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  input[type="date"],
  input[type="time"],
  select {
    font-size: 16px !important;
  }

  /* Minimum touch targets */
  .btn {
    min-height: 44px;
  }
  .btn-xs {
    min-height: 36px;
  }

  /* Stat cards — 2 columns on mobile */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  /* Card headers — compact on mobile */
  .card__header {
    padding: var(--spacing-3) var(--spacing-4);
  }
  .card__title {
    font-size: var(--font-size-base);
  }
  .card__body {
    padding: var(--spacing-4);
  }

  /* Form grid — single column on mobile */
  .tf-grid-2,
  .tf-grid-3 {
    grid-template-columns: 1fr;
  }

  /* Action buttons — full width, stacked */
  .card__footer {
    flex-direction: column;
  }
  .card__footer .btn {
    width: 100%;
  }

  /* Table horizontal scroll indicator */
  .table-wrap {
    position: relative;
  }
  .table-wrap::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg-primary));
    pointer-events: none;
  }
}
