/* ═══════════════════════════════════════════════════════════════════════════
   BROKER PORTAL - MOBILE-ONLY STYLES
   ALL styles are scoped within @media queries - NO desktop impact
   Breakpoints: 320px, 375px, 414px (phones), 767px max (mobile cutoff)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ========================================
   MOBILE BREAKPOINT: max-width 767px
   ======================================== */
@media (max-width: 767px) {
  
  /* --- CSS Variables for Mobile --- */
  :root {
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-safe-top: env(safe-area-inset-top, 0px);
    --mobile-safe-left: env(safe-area-inset-left, 0px);
    --mobile-safe-right: env(safe-area-inset-right, 0px);
    --tap-target-min: 44px;
    --mobile-spacing: 16px;
    --mobile-radius: 12px;
  }
  
  /* --- Prevent iOS Zoom on Input Focus --- */
  input, select, textarea {
    font-size: 16px !important;
  }
  
  /* --- Show Mobile Nav Toggle --- */
  .mobile-nav-toggle {
    display: flex !important;
  }
  
  /* --- Mobile Nav Panel --- */
  .mobile-nav {
    display: block !important;
    width: min(280px, 85vw);
    height: 100dvh;
    padding-top: calc(80px + var(--mobile-safe-top));
    padding-bottom: calc(20px + var(--mobile-safe-bottom));
  }
  
  /* --- Mobile Nav Links Touch Targets --- */
  .mobile-nav a {
    min-height: 52px;
    padding: 16px 18px;
  }
  
  /* --- Page Headers --- */
  .page-header,
  .header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 16px !important;
    padding-top: calc(60px + var(--mobile-safe-top)) !important;
    margin-bottom: 24px !important;
  }
  
  .page-header h1,
  .header h1,
  .welcome h1 {
    font-size: 1.5rem !important;
    line-height: 1.2 !important;
  }
  
  /* --- Stats Grid: 2 columns --- */
  .stats-row,
  .stats {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  
  .stat-card,
  .stat {
    padding: 14px !important;
  }
  
  .stat-card .value,
  .stat .value,
  .stat-value {
    font-size: 1.25rem !important;
  }
  
  /* --- Main Grid Layouts: Single Column --- */
  .main-grid,
  .bottom-grid,
  .profile-grid,
  .generator-container,
  .order-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  /* --- Cards Grid: Single Column --- */
  .clients-grid,
  .sheets-grid,
  .presets-grid,
  .recent-list,
  .inventory-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  /* --- Card Styling --- */
  .client-card,
  .sheet-card,
  .preset-card,
  .recent-card,
  .inventory-card,
  .card {
    padding: 16px !important;
    border-radius: 16px !important;
  }
  
  /* --- Quick Actions: Stack Vertically --- */
  .quick-actions-bar {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .quick-action-btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: 52px !important;
    padding: 14px 20px !important;
  }
  
  /* --- Actions Grid: 2x2 --- */
  .actions {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  
  .action {
    padding: 20px 12px !important;
    min-height: 100px !important;
  }
  
  /* --- Buttons: Full Width --- */
  .btn-primary,
  .btn-secondary,
  .submit-btn,
  .checkout-btn,
  .add-client-btn,
  .browse-btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: var(--tap-target-min) !important;
  }
  
  /* --- Button Groups: Stack --- */
  .btn-group,
  .button-group,
  .modal-footer,
  .header-actions,
  .form-actions,
  .order-actions {
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .modal-footer .btn,
  .header-actions .btn {
    width: 100% !important;
    justify-content: center !important;
  }
  
  /* --- Search Box: Full Width --- */
  .search-box,
  .search-container {
    width: 100% !important;
    max-width: none !important;
  }
  
  .search-box input {
    width: 100% !important;
    min-height: 52px !important;
    padding: 14px 14px 14px 48px !important;
    font-size: 16px !important;
    border-radius: 14px !important;
  }
  
  /* --- Filter Tabs: Horizontal Scroll --- */
  .filter-tabs,
  .page-tabs {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
    gap: 8px !important;
    padding-bottom: 8px !important;
    margin: 0 calc(-1 * var(--mobile-spacing)) !important;
    padding-left: var(--mobile-spacing) !important;
    padding-right: var(--mobile-spacing) !important;
  }
  
  .filter-tabs::-webkit-scrollbar,
  .page-tabs::-webkit-scrollbar {
    display: none !important;
  }
  
  .filter-tab,
  .page-tab {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    min-height: 48px !important;
    padding: 12px 20px !important;
  }
  
  /* --- Forms: Full Width Inputs --- */
  .form-input,
  .form-select,
  .form-textarea,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    width: 100% !important;
    min-height: var(--tap-target-min) !important;
    padding: 14px 16px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
  }
  
  .form-row,
  .form-row-3 {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  .form-group {
    margin-bottom: 20px !important;
  }
  
  /* --- Checkbox Touch Target --- */
  .form-checkbox-group,
  .checkbox-group {
    min-height: 52px !important;
    padding: 14px !important;
  }
  
  .form-checkbox,
  input[type="checkbox"] {
    width: 24px !important;
    height: 24px !important;
  }
  
  /* --- Modals: Full Screen Slide-up --- */
  .modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
  }
  
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 95vh !important;
    max-height: 95dvh !important;
    margin: 0 !important;
    border-radius: 24px 24px 0 0 !important;
    animation: modalSlideUp 0.3s ease !important;
  }
  
  @keyframes modalSlideUp {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  .modal-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    border-radius: 24px 24px 0 0 !important;
  }
  
  .modal-body {
    padding: var(--mobile-spacing) !important;
    padding-bottom: calc(var(--mobile-spacing) + var(--mobile-safe-bottom)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  .modal-footer {
    position: sticky !important;
    bottom: 0 !important;
    padding: var(--mobile-spacing) !important;
    padding-bottom: calc(var(--mobile-spacing) + var(--mobile-safe-bottom)) !important;
  }
  
  /* --- Floating Order Bar --- */
  .floating-order-bar {
    padding: 12px var(--mobile-spacing) !important;
    padding-bottom: calc(12px + var(--mobile-safe-bottom)) !important;
  }
  
  .order-bar-inner {
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .order-summary {
    width: 100% !important;
    justify-content: space-between !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }
  
  .order-stat {
    flex: 1 !important;
    min-width: 80px !important;
    text-align: center !important;
  }
  
  .order-stat-value {
    font-size: 1rem !important;
  }
  
  .order-stat-value.highlight {
    font-size: 1.15rem !important;
  }
  
  .order-actions {
    width: 100% !important;
    display: flex !important;
    gap: 12px !important;
  }
  
  .order-actions button,
  .view-order-btn,
  .checkout-btn {
    flex: 1 !important;
    min-height: 48px !important;
  }
  
  /* --- Content Padding for Floating Bar --- */
  .inventory-content-wrapper.has-order {
    padding-bottom: 180px !important;
  }
  
  /* --- Order Items: Card Layout --- */
  .order-item,
  .order-card-main {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    padding: 16px !important;
  }
  
  .order-item .item-info,
  .order-item .item-price {
    width: 100% !important;
  }
  
  .order-item .item-price {
    order: -1 !important;
    font-size: 1.25rem !important;
    text-align: left !important;
  }
  
  .order-item .qty-controls,
  .order-item .remove-btn {
    min-height: 48px !important;
  }
  
  /* --- Order Summary: Sticky on Mobile --- */
  .order-summary {
    position: static !important;
  }
  
  /* --- Inventory Card View --- */
  .card-image {
    height: 140px !important;
  }
  
  .card-body {
    padding: 16px !important;
  }
  
  .card-actions {
    flex-direction: column !important;
    gap: 10px !important;
  }
  
  .qty-selector,
  .card-qty-selector {
    width: 100% !important;
    justify-content: center !important;
  }
  
  .add-to-order-btn,
  .card-add-btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: 48px !important;
  }
  
  /* --- Inventory Table: Hide Some Columns --- */
  .inventory-table th:nth-child(2),
  .inventory-table td:nth-child(2),
  .inventory-table th:nth-child(6),
  .inventory-table td:nth-child(6) {
    display: none !important;
  }
  
  .inventory-table th,
  .inventory-table td {
    padding: 0.75rem 0.5rem !important;
    font-size: 0.8rem !important;
  }
  
  .item-image {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
  }
  
  .item-name {
    font-size: 0.8rem !important;
  }
  
  .item-sku {
    font-size: 0.7rem !important;
  }
  
  /* --- Hide Qty Selector in Table on Mobile --- */
  .inventory-table .qty-selector {
    display: none !important;
  }
  
  .inventory-table .add-to-order-btn {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.7rem !important;
    min-height: 40px !important;
  }
  
  /* --- Pagination --- */
  .pagination {
    flex-direction: column !important;
    gap: 0.75rem !important;
    padding: 0.75rem !important;
  }
  
  .page-numbers {
    display: none !important;
  }
  
  .page-btn {
    min-height: 44px !important;
  }
  
  /* --- Orders List --- */
  .filter-tabs {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
  }
  
  .date-filters {
    width: 100% !important;
    flex-wrap: wrap !important;
  }
  
  .date-input {
    flex: 1 !important;
    min-width: 120px !important;
    min-height: 44px !important;
  }
  
  .controls-row {
    flex-direction: column !important;
    gap: 0.75rem !important;
  }
  
  /* --- Status Timeline --- */
  .status-timeline {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
  }
  
  .timeline-step {
    flex: 0 0 auto !important;
    width: 20% !important;
  }
  
  .timeline-step::after {
    display: none !important;
  }
  
  /* --- Client/Sheet Card Stats --- */
  .client-stats,
  .sheet-actions,
  .recent-card-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  
  /* --- Commission Calculator --- */
  .commission-calculator {
    padding: 20px !important;
  }
  
  .calc-slider {
    height: 8px !important;
  }
  
  .calc-slider::-webkit-slider-thumb {
    width: 28px !important;
    height: 28px !important;
  }
  
  .calc-results {
    padding: 16px !important;
  }
  
  .calc-result-row.highlight .calc-result-value {
    font-size: 1.5rem !important;
  }
  
  /* --- Sheets Generator Preview --- */
  .preview-panel {
    order: -1 !important;
  }
  
  .preview-content {
    min-height: 250px !important;
  }
  
  .column-toggles {
    grid-template-columns: 1fr !important;
  }
  
  .date-range {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  
  .date-divider {
    display: none !important;
  }
  
  .share-options {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* --- Profile Page --- */
  .profile-avatar {
    width: 60px !important;
    height: 60px !important;
    font-size: 28px !important;
  }
  
  .markup-display .value {
    font-size: 36px !important;
  }
  
  .security-item {
    padding: 14px !important;
  }
  
  /* --- Hide Desktop-only Elements --- */
  .desktop-only,
  .top-controls .control-btn {
    display: none !important;
  }
  
  /* --- Badge Adjustments --- */
  .badge {
    padding: 8px 14px !important;
    font-size: 11px !important;
  }
}

/* ========================================
   EXTRA SMALL PHONES: max-width 359px (320px target)
   ======================================== */
@media (max-width: 359px) {
  :root {
    --mobile-spacing: 12px !important;
  }
  
  .page-header h1,
  .header h1,
  .welcome h1 {
    font-size: 1.25rem !important;
  }
  
  .stat-card .value,
  .stat .value,
  .stat-value {
    font-size: 1.1rem !important;
  }
  
  .stats-row,
  .stats {
    grid-template-columns: 1fr !important;
  }
  
  .card-title {
    font-size: 0.9rem !important;
  }
  
  .quick-action-btn {
    padding: 12px 16px !important;
    font-size: 0.85rem !important;
  }
  
  .action {
    padding: 16px 10px !important;
  }
  
  .action .icon {
    font-size: 24px !important;
  }
}

/* ========================================
   SMALL PHONES: 360px - 374px
   ======================================== */
@media (min-width: 360px) and (max-width: 374px) {
  :root {
    --mobile-spacing: 14px !important;
  }
}

/* ========================================
   STANDARD PHONES: 375px - 413px (iPhone SE, etc)
   ======================================== */
@media (min-width: 375px) and (max-width: 413px) {
  :root {
    --mobile-spacing: 16px !important;
  }
}

/* ========================================
   LARGER PHONES: 414px - 767px (iPhone Plus, etc)
   ======================================== */
@media (min-width: 414px) and (max-width: 767px) {
  :root {
    --mobile-spacing: 20px !important;
  }
  
  .page-header h1,
  .header h1,
  .welcome h1 {
    font-size: 1.75rem !important;
  }
}

/* ========================================
   LANDSCAPE PHONES
   ======================================== */
@media (max-width: 767px) and (max-height: 500px) and (orientation: landscape) {
  .mobile-nav {
    padding-top: 60px !important;
  }
  
  .mobile-nav a {
    min-height: 44px !important;
    padding: 10px 14px !important;
    margin-bottom: 4px !important;
  }
  
  .modal {
    max-height: 90vh !important;
  }
  
  .floating-order-bar {
    padding: 8px var(--mobile-spacing) !important;
    padding-bottom: calc(8px + var(--mobile-safe-bottom)) !important;
  }
  
  .order-bar-inner {
    flex-direction: row !important;
    flex-wrap: wrap !important;
  }
}

/* ========================================
   ACCESSIBILITY: Reduced Motion
   ======================================== */
@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .modal {
    animation: none !important;
  }
}

/* ========================================
   PRINT: Hide Mobile Elements
   ======================================== */
@media print {
  .mobile-nav-toggle,
  .mobile-nav,
  .mobile-nav-overlay,
  .floating-order-bar {
    display: none !important;
  }
}
