/**
 * mobile-saas.css — Mobile SaaS Responsive Layer v1.0
 * Scope: ≤768px (tablet), ≤480px (phone)
 * Strategy: progressive enhancement — desktop unchanged, mobile as extension.
 * All rules behind media queries. Zero specificity wars with desktop styles.
 */

/* ════════════════════════════════════════════════════════
   1. CSS VARIABLES — mobile tokens
   ════════════════════════════════════════════════════════ */
:root {
  --mob-bottom-nav-h: 60px;
  --mob-header-h:     56px;
  --mob-drawer-w:     280px;
  --mob-card-radius:  12px;
  --mob-fab-size:     52px;
  --mob-safe-bottom:  env(safe-area-inset-bottom, 0px);
  --mob-safe-top:     env(safe-area-inset-top, 0px);
}

/* ════════════════════════════════════════════════════════
   2. GLOBAL LAYOUT OVERRIDES — tablet (≤900px)
   ════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  /* Collapse sidebar by default */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 20px rgba(0,0,0,0.18);
    width: var(--mob-drawer-w) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.mob-open {
    transform: translateX(0);
  }

  /* Header adjustments */
  .header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--mob-header-h);
    padding: 0 12px;
    display: flex;
    align-items: center;
  }

  /* Main content takes full width */
  .main-content,
  .dashboard > .content,
  .content {
    margin-left: 0 !important;
    padding: 12px !important;
    padding-bottom: calc(var(--mob-bottom-nav-h) + var(--mob-safe-bottom) + 12px) !important;
  }

  /* Section titles */
  .section-title {
    font-size: 18px !important;
  }

  /* Cards stack properly */
  .stats, .stat-grid, .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
}

/* ════════════════════════════════════════════════════════
   3. PHONE LAYOUT (≤480px)
   ════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .stats, .stat-grid, .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Hide less-critical table columns */
  .table-hide-mobile { display: none !important; }

  /* Full-width forms */
  .form-row {
    flex-direction: column !important;
    gap: 10px !important;
  }
  .form-row input,
  .form-row select,
  .form-row textarea {
    width: 100% !important;
    min-width: unset !important;
  }

  /* Cards full width */
  .card {
    border-radius: var(--mob-card-radius) !important;
  }

  /* Buttons */
  .btn, .ux-btn {
    min-height: 44px;
    font-size: 14px !important;
  }

  /* Section title */
  .section-title {
    font-size: 16px !important;
  }
}

/* ════════════════════════════════════════════════════════
   4. BOTTOM NAVIGATION BAR
   ════════════════════════════════════════════════════════ */
.mob-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--mob-bottom-nav-h) + var(--mob-safe-bottom));
  padding-bottom: var(--mob-safe-bottom);
  background: #fff;
  border-top: 1px solid #E5E7EB;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
  z-index: 200;
  display: none;
  align-items: stretch;
  justify-content: space-around;
}

@media (max-width: 900px) {
  .mob-bottom-nav {
    display: flex !important;
  }
}

.mob-bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 2px;
  padding: 6px 4px;
  cursor: pointer;
  border: none;
  background: none;
  color: #9CA3AF;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.mob-bottom-nav__item .mob-nav-icon {
  font-size: 20px;
  line-height: 1;
  transition: transform 0.15s;
}
.mob-bottom-nav__item:active .mob-nav-icon {
  transform: scale(0.88);
}
.mob-bottom-nav__item.active {
  color: var(--primary, #8e44ad);
}
.mob-bottom-nav__item.active::before {
  content: '';
  position: absolute;
  top: 0; left: 25%; right: 25%;
  height: 3px;
  background: var(--primary, #8e44ad);
  border-radius: 0 0 4px 4px;
}
.mob-bottom-nav__badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  background: #EF4444;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  min-width: 16px;
  height: 16px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 1.5px solid #fff;
}

/* ════════════════════════════════════════════════════════
   5. MOBILE HEADER (hamburger + search)
   ════════════════════════════════════════════════════════ */
.mob-header-controls {
  display: none;
  align-items: center;
  gap: 8px;
}
@media (max-width: 900px) {
  .mob-header-controls { display: flex; }
}

.mob-hamburger {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary, #8e44ad);
  font-size: 22px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.mob-hamburger:active { background: #F3F4F6; }

/* Drawer overlay backdrop */
.mob-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  z-index: 299;
  animation: fadeIn 0.2s ease;
}
.mob-drawer-backdrop.active { display: block; }

/* ════════════════════════════════════════════════════════
   6. MOBILE SEARCH BAR (full-width, top of content)
   ════════════════════════════════════════════════════════ */
.mob-search-bar {
  display: none;
}
@media (max-width: 900px) {
  .mob-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #F9FAFB;
    border: 1.5px solid #E5E7EB;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 14px;
    color: #6B7280;
    cursor: text;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .mob-search-bar:focus-within {
    border-color: var(--primary, #8e44ad);
    box-shadow: 0 0 0 3px rgba(142,68,173,0.1);
    background: #fff;
  }
  .mob-search-bar input {
    border: none;
    background: none;
    outline: none;
    flex: 1;
    font-size: 14px;
    color: #1F2937;
  }
  .mob-search-bar input::placeholder { color: #9CA3AF; }
}

/* ════════════════════════════════════════════════════════
   7. MOBILE QUICK ACTIONS STRIP
   ════════════════════════════════════════════════════════ */
.mob-quick-strip {
  display: none;
}
@media (max-width: 900px) {
  .mob-quick-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0 10px;
    margin-bottom: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .mob-quick-strip::-webkit-scrollbar { display: none; }
}

.mob-quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 99px;
  background: #fff;
  border: 1.5px solid #E5E7EB;
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  scroll-snap-align: start;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.mob-quick-chip:active {
  transform: scale(0.96);
  background: #F3F4F6;
}
.mob-quick-chip.active,
.mob-quick-chip:focus {
  background: var(--primary, #8e44ad);
  color: #fff;
  border-color: var(--primary, #8e44ad);
}

/* ════════════════════════════════════════════════════════
   8. FLOATING ACTION BUTTON (FAB)
   ════════════════════════════════════════════════════════ */
.mob-fab {
  display: none;
  position: fixed;
  right: 18px;
  bottom: calc(var(--mob-bottom-nav-h) + var(--mob-safe-bottom) + 14px);
  width: var(--mob-fab-size);
  height: var(--mob-fab-size);
  border-radius: 50%;
  background: var(--primary, #8e44ad);
  color: #fff;
  font-size: 22px;
  border: none;
  cursor: pointer;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 16px rgba(142,68,173,0.4);
  z-index: 150;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
@media (max-width: 900px) {
  .mob-fab { display: flex; }
}
.mob-fab:active {
  transform: scale(0.93);
  box-shadow: 0 2px 8px rgba(142,68,173,0.3);
}
/* FAB label */
.mob-fab[data-label]::after {
  content: attr(data-label);
  position: absolute;
  right: calc(100% + 10px);
  background: #1F2937;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.mob-fab:focus[data-label]::after { opacity: 1; }

/* ════════════════════════════════════════════════════════
   9. MOBILE TABLE → CARD-LIST TRANSFORM
   ════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* The table itself becomes invisible; rows become cards via JS */
  .mob-card-table table  { display: block; }
  .mob-card-table thead  { display: none; }
  .mob-card-table tbody  { display: flex; flex-direction: column; gap: 10px; }
  .mob-card-table tr {
    display: block;
    background: #fff;
    border-radius: var(--mob-card-radius);
    border: 1px solid #E5E7EB;
    padding: 12px 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  }
  .mob-card-table td {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
    border: none;
  }
  .mob-card-table td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    color: #9CA3AF;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    min-width: 80px;
    flex-shrink: 0;
  }
}

/* ════════════════════════════════════════════════════════
   10. MOBILE SUMMARY DASHBOARD
   ════════════════════════════════════════════════════════ */
.mob-dashboard-summary {
  display: none;
}
@media (max-width: 900px) {
  .mob-dashboard-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
}
.mob-metric-card {
  background: #fff;
  border: 1px solid #E5E7EB;
  border-radius: var(--mob-card-radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.mob-metric-card__icon  { font-size: 20px; }
.mob-metric-card__value {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary, #8e44ad);
  line-height: 1;
}
.mob-metric-card__label {
  font-size: 11px;
  color: #9CA3AF;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.mob-metric-card__delta {
  font-size: 11px;
  font-weight: 700;
}
.mob-metric-card__delta.up   { color: #059669; }
.mob-metric-card__delta.down { color: #EF4444; }

/* ════════════════════════════════════════════════════════
   11. MOBILE NOTIFICATION DRAWER
   ════════════════════════════════════════════════════════ */
.mob-notif-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(320px, 92vw);
  background: #fff;
  z-index: 400;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  box-shadow: -4px 0 20px rgba(0,0,0,0.14);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mob-notif-panel.open { transform: translateX(0); }
.mob-notif-panel__header {
  display: flex; align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid #F3F4F6;
  font-weight: 800;
  font-size: 15px;
  color: #1F2937;
  gap: 10px;
}
.mob-notif-panel__close {
  margin-left: auto;
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: #F9FAFB;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.mob-notif-panel__body { flex: 1; overflow-y: auto; padding: 12px; }
.mob-notif-item {
  display: flex; gap: 10px;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid #F9FAFB;
}
.mob-notif-item:hover { background: #F9FAFB; }
.mob-notif-item__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary, #8e44ad);
  margin-top: 5px;
  flex-shrink: 0;
}
.mob-notif-item__dot.read { background: #E5E7EB; }
.mob-notif-item__title { font-weight: 600; font-size: 13px; color: #1F2937; }
.mob-notif-item__body  { font-size: 12px; color: #6B7280; margin-top: 2px; }
.mob-notif-item__time  { font-size: 10px; color: #9CA3AF; margin-top: 4px; }

/* ════════════════════════════════════════════════════════
   12. MOBILE OS ORDER CARD (for list view)
   ════════════════════════════════════════════════════════ */
.mob-os-card {
  background: #fff;
  border: 1px solid #E5E7EB;
  border-radius: var(--mob-card-radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.mob-os-card:active {
  transform: scale(0.99);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.mob-os-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mob-os-card__num  { font-size: 11px; color: #9CA3AF; font-weight: 700; }
.mob-os-card__equip { font-size: 14px; font-weight: 700; color: #1F2937; margin-top: 1px; }
.mob-os-card__client { font-size: 12px; color: #6B7280; }
.mob-os-card__footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.mob-os-card__date { font-size: 11px; color: #9CA3AF; margin-left: auto; }

/* ════════════════════════════════════════════════════════
   13. SKELETON LOADING (mobile list)
   ════════════════════════════════════════════════════════ */
.mob-skeleton {
  background: linear-gradient(90deg, #F3F4F6 25%, #E9EAED 50%, #F3F4F6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.mob-skeleton-card {
  border-radius: var(--mob-card-radius);
  padding: 16px;
  background: #fff;
  border: 1px solid #F3F4F6;
  display: flex; flex-direction: column; gap: 10px;
}
.mob-skeleton-line { height: 12px; border-radius: 4px; }

/* ════════════════════════════════════════════════════════
   14. PULL-TO-REFRESH INDICATOR
   ════════════════════════════════════════════════════════ */
.mob-ptr-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 0;
  overflow: hidden;
  transition: height 0.2s ease;
  font-size: 12px;
  color: #9CA3AF;
  font-weight: 600;
}
.mob-ptr-indicator.active { height: 48px; }
.mob-ptr-spinner {
  width: 18px; height: 18px;
  border: 2px solid #E5E7EB;
  border-top-color: var(--primary, #8e44ad);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════════════════════════
   15. MOBILE FILTER SHEET (bottom drawer)
   ════════════════════════════════════════════════════════ */
.mob-filter-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-radius: 18px 18px 0 0;
  z-index: 350;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 -8px 30px rgba(0,0,0,0.14);
  padding-bottom: calc(20px + var(--mob-safe-bottom));
  max-height: 80vh;
  overflow-y: auto;
}
.mob-filter-sheet.open { transform: translateY(0); }
.mob-filter-sheet__handle {
  width: 36px; height: 4px;
  background: #E5E7EB;
  border-radius: 2px;
  margin: 12px auto 16px;
}
.mob-filter-sheet__title {
  font-size: 16px;
  font-weight: 800;
  color: #1F2937;
  padding: 0 20px 12px;
  border-bottom: 1px solid #F3F4F6;
}
.mob-filter-sheet__body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mob-filter-sheet__actions {
  padding: 0 20px;
  display: flex;
  gap: 10px;
}

/* ════════════════════════════════════════════════════════
   16. OFFLINE BANNER
   ════════════════════════════════════════════════════════ */
.mob-offline-banner {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  background: #F59E0B;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  padding: 8px;
  z-index: 500;
  animation: slideDown 0.3s ease;
}
.mob-offline-banner.visible { display: block; }
@keyframes slideDown {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

/* ════════════════════════════════════════════════════════
   17. TOUCH TARGETS — minimum 44×44px
   ════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  button, a, select,
  .btn, .ux-btn, .mob-quick-chip {
    min-height: 44px;
  }
  input[type="text"],
  input[type="email"],
  input[type="number"],
  input[type="password"],
  select, textarea {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    min-height: 44px;
  }
}
