/* ============================================================================
   CylTrack Pro — Responsive & Mobile Styles
   Breakpoints: desktop >1024px | tablet 768-1024px | mobile <768px
   ============================================================================ */

/* ---- Utility classes ---- */
.mobile-only  { display: none !important; }
.desktop-only { display: block !important; }

/* ---- Mobile bottom navigation (base hidden, shown via media query) ---- */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

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

.mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  padding: 6px 0;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  min-width: 44px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.mobile-tab-icon {
  font-size: 20px;
  line-height: 1;
}

.mobile-tab.active {
  color: var(--accent);
}

/* ---- Mobile hamburger button ---- */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  margin: 0 -8px 0 0;
  flex-shrink: 0;
}

/* ---- Slide-out navigation overlay ---- */
.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-nav-overlay.open {
  display: block;
  opacity: 1;
}

.mobile-nav-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 85vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 1101;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-nav-overlay.open .mobile-nav-panel {
  transform: translateX(0);
}

.mobile-nav-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Mobile sticky bottom action bar ---- */
.mobile-sticky-bottom {
  display: none;
}


/* ============================================================================
   TABLET — 768px to 1024px
   ============================================================================ */
@media (max-width: 1024px) {

  /* Sidebar: collapsible */
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  /* Mobile menu button visible on tablet too */
  .mobile-menu-btn {
    display: flex;
  }

  /* Stat grid: 2 columns */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Two-column grids keep 2 cols but tighter gap */
  .ds-work-area,
  .dlv-work-area,
  .prf-work-area {
    gap: 12px;
  }

  /* Modals: constrained */
  .modal {
    max-width: 600px;
  }

  /* Page padding tighter */
  .page {
    padding: 20px;
  }

  /* Grid-2 stays 2 col */
  .grid-2 {
    gap: 10px;
  }

  /* Filter row wrap better */
  .search-input {
    min-width: 160px;
  }

  /* Cards slightly tighter */
  .card {
    padding: 16px;
  }
}


/* ============================================================================
   MOBILE PHONE — below 768px
   ============================================================================ */
@media (max-width: 767px) {

  /* ---- Show/hide utilities ---- */
  .mobile-only  { display: block !important; }
  .desktop-only { display: none !important; }

  /* ---- Sidebar: completely hidden ---- */
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    margin-bottom: 56px; /* space for bottom nav */
    min-height: calc(100vh - 56px);
  }

  /* ---- Mobile bottom nav: visible ---- */
  .mobile-bottom-nav {
    display: block;
  }

  /* ---- Mobile menu button: visible ---- */
  .mobile-menu-btn {
    display: flex;
  }

  /* ---- Topbar adjustments ---- */
  .topbar {
    padding: 0 14px;
    height: 52px;
  }

  .topbar-title {
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 140px);
  }

  /* ---- Page content ---- */
  .page {
    padding: 14px;
  }

  .page-header {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
  }

  .page-header-title h2 {
    font-size: 17px;
  }

  /* ---- Stat grid: single column ---- */
  .stat-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 14px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-val {
    font-size: 22px;
  }

  /* ---- Cards ---- */
  .card {
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 12px;
  }

  .card-title {
    font-size: 13px;
    margin-bottom: 10px;
  }

  /* ---- Tables: horizontal scroll ---- */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }

  table {
    min-width: 600px;
  }

  /* ---- Modals: full screen ---- */
  .modal-overlay {
    padding: 0;
    align-items: stretch;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
  }

  .modal-close {
    top: 12px;
    right: 12px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .modal-footer {
    margin-top: auto;
    padding-top: 14px;
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
    min-height: 44px;
  }

  /* ---- Grid-2: single column on mobile ---- */
  .grid-2 {
    grid-template-columns: 1fr;
  }

  /* ---- Filter row ---- */
  .filter-row {
    flex-direction: column;
    gap: 8px;
  }

  .search-input {
    min-width: 0;
    width: 100%;
  }

  .filter-select {
    width: 100%;
  }

  /* ---- Tab row: scrollable ---- */
  .tab-row {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tab-row::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    white-space: nowrap;
    padding: 8px 14px;
    min-height: 44px;
  }

  /* ---- Buttons: touch-friendly ---- */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
  }

  .btn-full {
    padding: 14px;
    font-size: 15px;
  }

  .btn-sm {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 13px;
  }

  /* ---- Login screen ---- */
  .login-card {
    width: 100%;
    max-width: 100%;
    margin: 0 16px;
    padding: 28px 20px;
    border-radius: 16px;
  }

  .login-card h2 {
    font-size: 22px;
  }

  .role-row {
    flex-wrap: wrap;
  }

  .role-btn {
    flex: 1 1 calc(50% - 5px);
    min-width: calc(50% - 5px);
    padding: 12px 8px;
    min-height: 44px;
  }

  /* ---- Form fields ---- */
  .fg input,
  .fg select,
  .fg textarea {
    padding: 12px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  /* ---- Notification ---- */
  .notif {
    left: 12px;
    right: 12px;
    bottom: 68px; /* above bottom nav */
    max-width: none;
  }

  /* ==== DISPATCH SCAN — single column ==== */
  .ds-work-area {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .ds-scan-input-row {
    flex-direction: column;
    gap: 8px;
  }

  .ds-scan-input {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
  }

  .ds-scan-input-row .btn {
    width: 100%;
    justify-content: center;
  }

  .ds-info-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
  }

  /* Pool progress: full width compact */
  .ds-pool-row {
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    font-size: 12px;
  }

  /* Scan log: compact scrollable */
  .ds-log-entry {
    font-size: 11px;
    flex-wrap: wrap;
  }

  .card:has(.ds-loaded-list),
  .card:has(.ds-log-entry) {
    max-height: 200px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Warning box: full width */
  .ds-warning-box {
    padding: 12px;
  }

  .ds-override-input {
    font-size: 16px;
    min-height: 60px;
  }

  .ds-override-actions {
    flex-direction: column;
  }

  .ds-override-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Action buttons sticky */
  .ds-action-bar,
  .dlv-action-bar,
  .prf-action-bar {
    position: sticky;
    bottom: 56px; /* above bottom nav */
    background: var(--surface);
    padding: 12px;
    margin: 0 -14px;
    border-top: 1px solid var(--border);
    z-index: 40;
    display: flex;
    gap: 8px;
  }

  .ds-action-bar .btn,
  .dlv-action-bar .btn,
  .prf-action-bar .btn {
    flex: 1;
    justify-content: center;
    min-height: 48px;
  }

  /* ==== DELIVERY SCAN — single column ==== */
  .dlv-work-area {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .dlv-selectors {
    flex-direction: column;
    gap: 8px;
  }

  .dlv-selectors select,
  .dlv-selectors .btn {
    width: 100%;
  }

  .dlv-context-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .dlv-check-item {
    padding: 10px;
    font-size: 14px;
    min-height: 44px;
  }

  /* ==== PROOF OF DELIVERY — single column ==== */
  .prf-work-area {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Signature canvas: responsive */
  .prf-sig-container {
    width: 100%;
  }

  .prf-sig-container canvas {
    width: min(500px, calc(100vw - 32px));
    height: auto;
    aspect-ratio: 500 / 180;
    touch-action: none;
  }

  .prf-sig-actions {
    flex-wrap: wrap;
    justify-content: center;
  }

  .prf-sig-actions .btn {
    flex: 1;
    justify-content: center;
  }

  /* Photo upload */
  .prf-photo-drop {
    padding: 30px 16px;
  }

  .prf-photo-input {
    -webkit-appearance: none;
  }

  /* Mobile sticky bottom utility */
  .mobile-sticky-bottom {
    display: block;
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 14px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
  }

  /* Run cards: tighter */
  .run-card {
    padding: 14px;
    margin-bottom: 10px;
  }

  .run-header {
    flex-direction: column;
    gap: 8px;
  }

  .run-product-strip {
    gap: 4px;
  }

  /* Order line rows */
  .order-line-row {
    grid-template-columns: 1fr auto;
    gap: 6px;
  }

  /* Stage stub */
  .stage-stub {
    padding: 40px 16px;
  }

  .stage-stub-icon {
    font-size: 40px;
  }

  .stage-stub h3 {
    font-size: 16px;
  }

  /* Loaded list rows */
  .ds-loaded-row {
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  .ds-loaded-id {
    min-width: 70px;
  }

  .ds-loaded-product {
    min-width: 0;
  }

  /* Tag rows */
  .ds-tag-row {
    padding: 10px;
    min-height: 44px;
  }

  /* Inline sections */
  .inline-section {
    padding: 12px;
  }

  /* Product tags: allow wrap */
  .product-tag {
    font-size: 10px;
  }
}


/* ============================================================================
   VERY SMALL SCREENS — below 380px
   ============================================================================ */
@media (max-width: 380px) {

  .topbar-title {
    font-size: 13px;
    max-width: calc(100vw - 120px);
  }

  .stat-card {
    padding: 12px;
  }

  .stat-val {
    font-size: 20px;
  }

  .stat-label {
    font-size: 10px;
  }

  .login-card {
    padding: 22px 16px;
  }

  .login-card h2 {
    font-size: 20px;
  }

  .role-btn {
    padding: 10px 6px;
    font-size: 11px;
  }

  .mobile-tab {
    font-size: 9px;
  }

  .mobile-tab-icon {
    font-size: 18px;
  }

  .page {
    padding: 10px;
  }

  .card {
    padding: 10px;
  }
}


/* ============================================================================
   LANDSCAPE PHONE
   ============================================================================ */
@media (max-width: 767px) and (orientation: landscape) {

  .mobile-bottom-nav {
    height: 48px;
  }

  .main-content {
    margin-bottom: 48px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .ds-work-area,
  .dlv-work-area,
  .prf-work-area {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* Signature canvas in landscape can use more width */
  .prf-sig-container canvas {
    width: min(500px, calc(100vw - 32px));
  }
}


/* ============================================================================
   PRINT — hide navigation elements
   ============================================================================ */
@media print {
  .sidebar,
  .mobile-bottom-nav,
  .mobile-menu-btn,
  .topbar,
  .mobile-nav-overlay {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
    margin-bottom: 0 !important;
  }
}
