/* ═══════════════════════════════════════════════════════════
   SteelCtrl Responsive CSS — responsive.css
   ───────────────────────────────────────────────────────────
   Load order: last CSS file — overrides all above.
   Depends on: variables.css, layout.css, components.css

   Covers:
     · Touch-target sizing (44px min — WCAG 2.5.5)
     · Mobile bottom navigation bar (site engineer workflow)
     · Tablet-optimised BBS grid (horizontal scroll)
     · Mobile metric cards (stacked)
     · Collapsible panels on mobile
     · PWA standalone mode adjustments
     · Tablet portrait / landscape
     · Print media query
   ═══════════════════════════════════════════════════════════ */


/* ═══════════════════════════════════════════════════════════
   TOUCH TARGETS — minimum 44×44px for all interactive elements
   (applies to all breakpoints — prevents mis-taps on mobile)
   ═══════════════════════════════════════════════════════════ */
@media (pointer: coarse) {
  /* Buttons */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }
  .btn-sm {
    min-height: 36px;
    padding: 7px 12px;
  }

  /* Nav items */
  .nav-item {
    min-height: 44px;
    padding: 10px 14px;
  }

  /* Form inputs */
  .form-input,
  .form-select,
  .form-textarea {
    min-height: 44px;
    font-size: 16px;  /* Prevents iOS zoom on focus */
  }

  /* Table row actions */
  .row-action-btn {
    min-width: 36px;
    min-height: 36px;
  }

  /* Topbar buttons */
  .topbar-btn {
    width: 40px;
    height: 40px;
  }

  /* OTP boxes */
  .otp-box {
    width: 46px;
    height: 54px;
    font-size: 20px;
  }

  /* Cell inputs in BBS */
  .cell-input,
  .cell-select {
    min-height: 38px;
    font-size: 14px;
  }

  /* Profile menu items, context menu items */
  .profile-menu-item,
  .ctx-item {
    min-height: 44px;
  }

  /* Switcher dropdown items */
  .switcher-item {
    min-height: 44px;
  }
}


/* ═══════════════════════════════════════════════════════════
   PWA STANDALONE MODE
   Adjusts for no browser chrome (no URL bar, no back button)
   ═══════════════════════════════════════════════════════════ */
@media (display-mode: standalone) {
  /* Safe area insets for iPhone notch / home indicator */
  body {
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-top:    env(safe-area-inset-top, 0);
    padding-left:   env(safe-area-inset-left, 0);
    padding-right:  env(safe-area-inset-right, 0);
  }

  /* Topbar needs extra top padding on iPhone with Dynamic Island */
  .topbar {
    padding-top: max(0px, env(safe-area-inset-top));
    height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
  }

  /* Bottom mobile nav needs safe area padding */
  #mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
}

/* iOS Safari standalone (legacy check) */
@supports (-webkit-touch-callout: none) {
  @media (display-mode: standalone) {
    .topbar {
      padding-top: max(16px, env(safe-area-inset-top));
    }
  }
}


/* ═══════════════════════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION BAR
   Site engineer primary workflow — thumb-reachable
   Shows only on mobile. Hidden on tablet+.
   ═══════════════════════════════════════════════════════════ */
#mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: calc(var(--z-sidebar, 20) + 5);
  background: var(--sc-base, #0d1220);
  border-top: 1px solid var(--sc-line, rgba(255,255,255,0.06));
  height: 60px;
  flex-direction: row;
  align-items: stretch;
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--sc-text-3, #4b5e78);
  font-size: 9px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  border: none;
  background: transparent;
  font-family: var(--font-sans, sans-serif);
}
.mobile-nav-item i {
  font-size: 22px;
}
.mobile-nav-item.active {
  color: var(--sc-gold, #f59e0b);
}
.mobile-nav-item:active {
  background: rgba(255,255,255,0.04);
}

/* Site engineer shortcuts — show bottom nav on mobile */
@media (max-width: 640px) {
  #mobile-bottom-nav {
    display: flex;
  }

  /* Push page content up to not hide behind bottom nav */
  .content-area {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  /* Hide sidebar entirely on mobile when bottom nav is showing */
  .sidebar {
    display: none;
  }
  .sidebar.mobile-open {
    display: flex;
  }
}


/* ═══════════════════════════════════════════════════════════
   TABLET (641px – 1024px)
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 641px) and (max-width: 1024px) {

  /* Show collapsed sidebar on tablet instead of hiding it */
  .sidebar {
    position: relative;
    transform: none !important;
    width: var(--sidebar-collapsed, 52px);
    min-width: var(--sidebar-collapsed, 52px);
  }
  /* Labels always hidden on tablet — rely on tooltips */
  .sidebar .sidebar-label,
  .sidebar .sidebar-section-title,
  .sidebar .logo-text,
  .sidebar .logo-sub,
  .sidebar .user-badge-info,
  .sidebar .nav-badge {
    display: none;
  }
  .sidebar .nav-item {
    justify-content: center;
    padding: 10px;
  }
  .sidebar .sidebar-logo {
    justify-content: center;
    padding: 14px;
  }

  /* Tablet grid adjustments */
  .mg-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-master-lg { grid-template-columns: 1fr; }
  .admin-stat-grid { grid-template-columns: repeat(3, 1fr); }

  /* Topbar project name shorter */
  .topbar-project-name { max-width: 200px; }

  /* BBS table — enable horizontal scroll */
  .bbs-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Panel body padding reduced */
  .panel-body { padding: 12px; }

  /* Page body padding reduced */
  .page-body { padding: 12px 16px 20px; }

  /* Metric cards — 2 columns on tablet */
  .mg-3 { grid-template-columns: 1fr 1fr; }

  /* Structure tree hidden by default — use tabs */
  .grid-master-lg .panel:first-child {
    display: none;
  }
  .grid-master-lg {
    grid-template-columns: 1fr;
  }
}


/* ═══════════════════════════════════════════════════════════
   MOBILE (≤ 640px) — extended overrides
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  /* Page header compact */
  .page-header {
    padding: 12px 14px 10px;
  }
  .page-title {
    font-size: 15px;
  }
  .page-subtitle {
    font-size: 10px;
  }
  .page-body {
    padding: 10px 14px 80px; /* bottom padding for mobile nav */
  }

  /* All grids → single column */
  .mg-2, .mg-3, .mg-4,
  .grid-2, .grid-3, .grid-4,
  .grid-master-lg,
  .admin-stat-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* Metric cards — compact on mobile */
  .metric-card {
    padding: 12px;
  }
  .metric-value {
    font-size: 20px;
  }
  .metric-label {
    font-size: 8px;
    letter-spacing: 1px;
  }

  /* Panels — no overflow clip (lets tables scroll) */
  .panel {
    overflow: visible;
  }

  /* BBS table — horizontal scroll on mobile */
  .bbs-table-wrap,
  #bbs-tbody,
  .bbs-table {
    min-width: 800px;
  }
  /* Wrapper that actually scrolls */
  .bbs-scroll-host {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 8px 8px;
  }
  /* Freeze first 2 columns (Member + BarMark) */
  .bbs-table th:nth-child(1),
  .bbs-table td:nth-child(1) {
    position: sticky;
    left: 0;
    background: var(--sc-raised, #121929);
    z-index: 1;
  }
  .bbs-table th:nth-child(2),
  .bbs-table td:nth-child(2) {
    position: sticky;
    left: 36px;
    background: var(--sc-raised, #121929);
    z-index: 1;
  }

  /* BBS toolbar wraps on mobile */
  .bbs-toolbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
  }

  /* Modal — full-screen on mobile */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    border-radius: 14px 14px 0 0;
    max-width: 100%;
    max-height: 92vh;
    width: 100%;
    padding: 20px 16px;
  }
  /* Small modals still center on mobile */
  .modal-sm {
    max-height: 70vh;
  }

  /* Form rows → single column */
  .form-row.fr-2,
  .form-row.fr-3,
  .form-row.fr-4 {
    grid-template-columns: 1fr;
  }

  /* Button group wraps */
  .btn-group {
    flex-wrap: wrap;
  }
  .btn {
    font-size: 11px;
    padding: 8px 12px;
  }
  .btn-lg {
    font-size: 13px;
    padding: 11px 20px;
  }

  /* Data tables — horizontal scroll */
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 0 14px;
  }

  /* Hide less-critical table columns on mobile */
  .hide-mobile { display: none !important; }

  /* Portal project grid → 1 col */
  .portal-grid {
    grid-template-columns: 1fr;
  }

  /* Notification panel full width */
  .notif-panel {
    left: 0;
    right: 0;
    width: auto;
    border-radius: 0 0 14px 14px;
    border-left: none;
    border-right: none;
  }

  /* Topbar condensed */
  .topbar {
    padding: 0 10px;
    gap: 6px;
  }
  /* Hide breadcrumb on mobile */
  .topbar-breadcrumb { display: none; }

  /* Project switcher shorter label */
  .topbar-project-name {
    max-width: 100px;
    font-size: 11px;
  }

  /* Subscription plan cards → 1 col */
  .pricing-grid {
    grid-template-columns: 1fr;
  }
  .sub-card {
    max-width: 100%;
  }

  /* Structure tree — full width tabs on mobile */
  .structure-mobile-tabs {
    display: flex;
  }
  .structure-tab-btn {
    flex: 1;
    text-align: center;
    padding: 10px;
    font-size: 11px;
    border-bottom: 2px solid transparent;
    color: var(--sc-text-2);
    cursor: pointer;
  }
  .structure-tab-btn.active {
    border-bottom-color: var(--sc-gold);
    color: var(--sc-gold);
  }

  /* Landing page hero → centered mobile */
  .hero-section {
    padding: 40px 16px 32px;
  }
  .hero-title {
    font-size: 28px;
    line-height: 1.2;
  }
  .hero-subtitle {
    font-size: 14px;
  }
  .hero-cta-row {
    flex-direction: column;
  }
  .hero-cta-row .btn {
    width: 100%;
    justify-content: center;
  }

  /* Feature grid → 1 col on mobile */
  .feature-grid {
    grid-template-columns: 1fr;
  }

  /* Industries strip → scroll */
  .industry-strip {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 8px;
    padding-bottom: 8px;
  }
  .industry-chip {
    flex-shrink: 0;
  }
}


/* ═══════════════════════════════════════════════════════════
   TABLET PORTRAIT (768px – 1024px)
   Optimised for iPad 10" — common on construction sites
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {

  /* Show structure tree + detail as tabs on tablet portrait */
  .grid-master-lg {
    grid-template-columns: 1fr;
  }

  /* BBS editor — slightly larger cells for tablet touch */
  .cell-input,
  .cell-select {
    height: 36px;
  }

  /* Recon log table — hide less-critical columns */
  .recon-table .hide-tablet { display: none; }

  /* Sidebar overlay (same as mobile) */
  .sidebar {
    position: fixed;
  }
}


/* ═══════════════════════════════════════════════════════════
   LARGE DESKTOP (≥ 1440px)
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 1440px) {
  /* Allow 5-column metric grids */
  .mg-5 { grid-template-columns: repeat(5, 1fr); }

  /* Wider admin stat grid */
  .admin-stat-grid { grid-template-columns: repeat(6, 1fr); }

  /* BBS table — slightly wider cells */
  .bbs-table th,
  .bbs-table td {
    padding: 9px 10px;
  }
}


/* ═══════════════════════════════════════════════════════════
   PRINT STYLES
   For printing BBS and reconciliation reports
   ═══════════════════════════════════════════════════════════ */
@media print {
  /* Hide navigation chrome */
  .sidebar,
  .topbar,
  .admin-ribbon,
  .toast-container,
  .modal-overlay,
  .btn,
  .btn-group,
  #mobile-bottom-nav,
  .notif-panel,
  .ctx-menu,
  #pwa-install-banner,
  #pwa-update-banner,
  #pwa-offline-bar {
    display: none !important;
  }

  /* Print from root */
  #root,
  .main,
  .content-area {
    overflow: visible;
    height: auto;
  }
  #app {
    height: auto;
    overflow: visible;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
    overflow: auto;
  }

  /* Tables — full width, borders visible */
  .data-table {
    width: 100%;
    border-collapse: collapse;
  }
  .data-table th,
  .data-table td {
    border: 1px solid #ccc;
    padding: 5pt 8pt;
    color: #000;
    background: #fff;
    font-size: 9pt;
  }
  .data-table th {
    background: #f3f4f6 !important;
    font-weight: bold;
  }

  /* Page break before new section */
  .page-break-before { page-break-before: always; }
  .no-page-break      { page-break-inside: avoid;  }

  /* Print header with project name */
  .print-header {
    display: block !important;
    text-align: center;
    margin-bottom: 12pt;
    font-size: 14pt;
    font-weight: bold;
  }
}
