/* ══════════════════════════════════════════════════════════════
   WFS CI OS — MOBILE-RESPONSIVE STYLESHEET
   Breakpoints:
     ≤ 768px  → mobile  (sidebar hidden, hamburger, stacked layouts)
     ≤ 1024px → tablet  (narrow sidebar, compressed grids)
   All rules are additive — override only what needs changing
══════════════════════════════════════════════════════════════ */

/* ── TABLET (≤ 1024px) ─────────────────────────────────────── */
@media (max-width: 1024px) {

  :root {
    --sidebar-w: 220px;
  }

  /* Compress stat card grids */
  #dash-kpi-cards,
  [id="dash-kpi-cards"] {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
    gap: 12px !important;
  }

  /* Health + Priority row: stack vertically */
  .main-content [style*="grid-template-columns:280px"] {
    grid-template-columns: 1fr !important;
  }

  /* Trend + Ranking row: full-width trend */
  .main-content [style*="grid-template-columns:2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Bottom 3-col row → 2 cols */
  .main-content [style*="grid-template-columns:1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* KPI grid */
  #kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) !important;
  }

  /* Benefits hero */
  .benefits-hero-content {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  /* Reduce modal sizes on tablet */
  .modal-box.modal-xl { max-width: 96vw !important; }
  .modal-box.modal-lg { max-width: 92vw !important; }

  /* Page header: wrap actions below title */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-actions { flex-wrap: wrap; }

  /* Reports template grid */
  #tab-templates > div {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;
  }

  /* Filter bar wrapping */
  .filter-bar {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Two-col form fields → single col */
  .form-row.two-col {
    grid-template-columns: 1fr !important;
  }
}


/* ── MOBILE (≤ 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {

  html { font-size: 13px; }

  /* ── TOP NAV ─────────────────────────── */
  .top-nav {
    padding: 0 10px;
    gap: 8px;
  }

  /* Hide search bar on mobile — accessible via icon */
  .nav-center { display: none; }

  /* Hide brand sub text */
  .brand-sub { display: none; }

  /* Smaller brand name */
  .brand-name { font-size: .88rem; }

  /* Compress nav-left */
  .nav-left { min-width: auto; gap: 8px; }

  /* User chip: hide name on mobile */
  .user-name { display: none; }

  /* ── SIDEBAR → DRAWER ────────────────── */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1), width .22s cubic-bezier(.4,0,.2,1);
    width: 260px !important;
    z-index: 1100;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
  }

  /* When sidebar is toggled open on mobile */
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Sidebar overlay backdrop */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1050;
    backdrop-filter: blur(2px);
  }
  .sidebar-backdrop.visible { display: block; }

  /* Main content: full width on mobile */
  .main-content {
    margin-left: 0 !important;
  }
  .main-content.sidebar-collapsed {
    margin-left: 0 !important;
  }

  /* Module container: reduce padding */
  .module-container {
    padding: 14px;
  }

  /* ── STAT CARDS ───────────────────────── */
  #dash-kpi-cards,
  [id="dash-kpi-cards"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  .stat-card {
    padding: 12px !important;
  }
  .stat-value { font-size: 1.4rem !important; }

  /* ── DASHBOARD ROWS → SINGLE COL ────── */
  .main-content [style*="grid-template-columns:280px"],
  .main-content [style*="grid-template-columns:2fr 1fr"],
  .main-content [style*="grid-template-columns:1fr 1fr 1fr"],
  .main-content [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── CARDS ─────────────────────────── */
  .card { margin-bottom: 12px; }
  .card-header { padding: 12px 14px; }
  .card-body { padding: 12px 14px; }

  /* ── PAGE HEADER ──────────────────── */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 10px;
  }
  .page-title { font-size: 1.15rem !important; }
  .page-actions {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }
  .page-actions .btn-primary,
  .page-actions .btn-secondary,
  .page-actions .btn-ghost {
    font-size: .78rem;
    padding: 7px 10px;
  }

  /* ── TABS ─────────────────────────── */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .tab-btn {
    white-space: nowrap;
    font-size: .78rem;
    padding: 6px 12px;
  }

  /* ── FILTER BAR ───────────────────── */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .filter-bar select,
  .filter-bar input,
  .filter-bar .table-search-wrap {
    width: 100%;
  }
  .table-search-wrap { flex: 1; }

  /* ── TABLES ─────────────────────── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 520px; }

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

  /* ── KPI GRID ─────────────────────── */
  #kpi-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── FORMS ────────────────────────── */
  .form-row.two-col,
  div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── MODALS ─────────────────────── */
  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }
  .modal-box,
  .modal-box.modal-lg,
  .modal-box.modal-xl {
    max-width: 100% !important;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .modal-header { padding: 14px 16px; }
  .modal-body   { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; gap: 8px; flex-wrap: wrap; }
  .modal-footer .btn-primary,
  .modal-footer .btn-secondary,
  .modal-footer .btn-ghost { flex: 1; justify-content: center; }

  /* ── DOC CARDS ─────────────────── */
  .doc-card {
    flex-wrap: wrap;
    gap: 10px;
  }
  .doc-card > div:last-child { width: 100%; justify-content: flex-end; }

  /* ── KANBAN ────────────────────── */
  #capa-kanban,
  #tasks-kanban {
    flex-direction: column !important;
    overflow-x: visible !important;
  }
  .kanban-col {
    min-width: unset !important;
    width: 100% !important;
  }

  /* ── BENEFITS HERO ─────────────── */
  .benefits-hero { padding: 16px !important; }
  .benefits-hero-content { flex-direction: column !important; }
  .benefits-hero-stats {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .benefits-hero-stat { flex: 1; min-width: 100px; }

  /* ── SITE PACK CARDS ──────────── */
  .site-pack-cards-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── GANTT ─────────────────────── */
  .gantt-scroll-area { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── PEOPLE HUB ────────────────── */
  .people-hub-layout {
    flex-direction: column !important;
  }
  .convo-panel {
    width: 100% !important;
    max-height: 220px;
    border-right: none !important;
    border-bottom: 1px solid var(--grey-150);
  }

  /* ── REPORT TEMPLATE CARDS ─────── */
  #tab-templates > div {
    grid-template-columns: 1fr !important;
  }

  /* ── INFO BOXES ─────────────────── */
  .info-box {
    flex-direction: column;
    gap: 4px;
  }

  /* ── TOAST NOTIFICATIONS ─────────── */
  #toast-container {
    left: 10px !important;
    right: 10px !important;
    bottom: 70px !important;
    top: auto !important;
    align-items: stretch;
  }
  .toast { min-width: unset !important; width: 100% !important; }

  /* ── TREND ALERT ROWS ───────────── */
  .trend-alert-row { flex-wrap: wrap; gap: 8px; }

  /* ── WORKLOAD / GANTT TIMELINE ──── */
  .timeline-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── BENCHMARKING PODIUM ─────────── */
  .podium { gap: 8px; }
  .podium-block { width: 54px !important; }

  /* ── CHART WRAP ──────────────────── */
  .chart-wrap canvas { max-width: 100%; }

  /* ── REPORT PREVIEW ──────────────── */
  .report-preview {
    font-size: .84rem !important;
    padding: 12px !important;
  }
  .report-header-section {
    flex-direction: column !important;
    gap: 8px;
  }
  .report-section [style*="grid-template-columns:repeat(4,1fr)"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ── ADMIN PANEL ─────────────────── */
  .admin-content-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── VERY SMALL SCREENS (≤ 400px) ──────────────────────────── */
@media (max-width: 400px) {
  #dash-kpi-cards,
  [id="dash-kpi-cards"] {
    grid-template-columns: 1fr !important;
  }
  .stat-card { flex-direction: column; text-align: center; }
  .brand-name { font-size: .8rem; }
}

/* ── SIDEBAR HAMBURGER TOGGLE FIX ──────────────────────────── */
/* Ensure sidebar-toggle button always visible on mobile */
@media (max-width: 768px) {
  .sidebar-toggle { display: flex !important; }
}
