/* ════════════════════════════════════════════════════════════
   THRIVE AGRIC — SHARED RESPONSIVE STYLES
   Applied across all pages: index.html, auth.html,
   superadmin.html, admin.html, change-password.html
   ════════════════════════════════════════════════════════════ */

/* ── Touch & Interaction Improvements ────────────────────── */
* { -webkit-tap-highlight-color: transparent; }
button, [role="button"], .nav-btn, .nav-item, .btn, .tab, .tab-btn,
.role-btn, .role-card, .chip, .form-tab {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
input, select, textarea {
  font-size: 16px !important; /* Prevents iOS zoom on focus */
}

/* ── Scrollbar Utilities ──────────────────────────────────── */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-y { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ── Mobile Overlay / Backdrop ────────────────────────────── */
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
}
.mobile-overlay.open { display: block; }

/* ── Mobile Menu Toggle Button ───────────────────────────── */
.mobile-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,.12);
  color: #fff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
}

/* ── Sticky Mobile Header ─────────────────────────────────── */
.mobile-page-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 80;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  padding: 12px 16px;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.mobile-page-header .mph-title {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  color: #1a1a1a;
}

/* ── Responsive Table Wrapper ─────────────────────────────── */
.tbl-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid #e5e5e5;
}
.tbl-responsive table { min-width: 600px; }

/* ── Card Stack (replaces grid on mobile) ──────────────────── */
@media (max-width: 640px) {
  .card-stack > * { margin-bottom: 12px; }
}

/* ── Bottom Navigation Bar (mobile only) ───────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #fff;
  border-top: 1px solid #e5e5e5;
  z-index: 200;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  height: 100%;
  border: none;
  background: transparent;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  color: #888;
  font-size: 10px;
  font-weight: 500;
  transition: color .15s;
  text-decoration: none;
  padding: 0;
}
.bottom-nav-item i, .bottom-nav-item svg { font-size: 18px; }
.bottom-nav-item.active { color: #2D5016; }
.bottom-nav-item.active i { color: #4A7C2E; }

/* ── Safe area padding for notch devices ──────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(60px + env(safe-area-inset-bottom));
  }
  body.has-bottom-nav { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* ════════════════════════════════════════════════════════════
   BREAKPOINTS
   - 1200px: Large tablets / small laptops
   - 900px:  Tablets landscape
   - 768px:  Tablets portrait
   - 600px:  Large phones
   - 480px:  Standard phones
   - 360px:  Small phones
   ════════════════════════════════════════════════════════════ */

/* ── 1200px ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
  .bracket-summary-row { grid-template-columns: repeat(2, 1fr) !important; }
  .kanban-board { grid-template-columns: repeat(2, 1fr) !important; }
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ── 900px ────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* Sidebar: slide in/out */
  #sidebar, .sidebar {
    position: fixed !important;
    top: 0; left: -100% !important;
    height: 100vh;
    z-index: 300 !important;
    transition: left .28s cubic-bezier(.4,0,.2,1) !important;
    width: 260px !important;
    min-width: 260px !important;
    overflow-y: auto;
  }
  #sidebar.open, .sidebar.open {
    left: 0 !important;
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  /* Collapsed override: on mobile never "icon-only" */
  #sidebar.collapsed {
    width: 260px !important;
    min-width: 260px !important;
  }

  /* Main content fills full width */
  #main { margin-left: 0 !important; }
  .main { margin-left: 0 !important; }

  /* Header full width */
  .header { left: 0 !important; }

  /* Show mobile menu toggle */
  .mobile-menu-btn { display: flex !important; }
  .hdr-toggle { display: flex !important; }

  /* Grids */
  .grid-3 { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid.g3 { grid-template-columns: 1fr !important; }
  .form-row { grid-template-columns: 1fr !important; }
  .form-row-3 { grid-template-columns: 1fr !important; }
  .bsc-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-2 { grid-template-columns: 1fr !important; }
}

/* ── 768px ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Content padding */
  .content { padding: 16px !important; }
  #content { padding: 16px !important; }

  /* Cards */
  .card { padding: 14px !important; }

  /* KPI Table horizontal scroll */
  .kpi-table-wrap { max-height: 400px; }
  .kpi-table { min-width: 900px; }

  /* Kanban: single column */
  .kanban-board { grid-template-columns: 1fr !important; }

  /* Audit row */
  .audit-row {
    grid-template-columns: 1fr !important;
    gap: 4px !important;
  }
  .audit-row.header { display: none; }

  /* Filter bar wraps tightly */
  .filter-bar { flex-direction: column; align-items: stretch !important; }
  .filter-bar input,
  .filter-bar select { width: 100% !important; min-width: unset !important; }

  /* Stat cards */
  .stat-card { padding: 14px 16px !important; }
  .stat-val { font-size: 20px !important; }

  /* Page header */
  .page-header, .pg-header {
    flex-direction: column;
    gap: 10px;
  }
  .pg-header { align-items: flex-start !important; }

  /* Modals */
  .modal { width: 95vw !important; max-width: unset !important; margin: 16px !important; }
  .modal-xl, .modal-lg { width: 95vw !important; }

  /* Drawers */
  .drawer { width: 100% !important; max-width: 100% !important; right: -100% !important; }
  .drawer.open { right: 0 !important; }

  /* Tables with horizontal scroll */
  .table-wrap, .tbl-responsive { overflow-x: auto !important; }
  table, .tbl { min-width: 600px; }

  /* Bracket summary */
  .bracket-summary-row { grid-template-columns: repeat(2, 1fr) !important; }

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

/* ── 600px ────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Typography */
  .page-header h2, .pg-title { font-size: 18px !important; }
  .stat-val { font-size: 18px !important; }
  .card-title { font-size: 13px !important; }

  /* Grids to single column */
  .grid-2, .grid-3, .grid-4,
  .stat-grid, .bsc-grid,
  .bracket-summary-row,
  .kanban-board,
  .quarter-grid { grid-template-columns: 1fr !important; }

  /* Form layout */
  .form-row, .form-row-3,
  .form-grid, .form-grid.g3 { grid-template-columns: 1fr !important; }

  /* Role select grid */
  .role-select-grid { grid-template-columns: 1fr 1fr !important; }

  /* Action buttons stacking */
  .pg-header { flex-direction: column; align-items: stretch; gap: 8px; }
  .pg-header .btn { justify-content: center; }

  /* Header shrink */
  .hdr-period { display: none; }
  #role-tag { display: none; }
  .hdr-name { display: none; }
  .hdr-role { display: none; }
  .hdr-breadcrumb { display: none; }

  /* Padding */
  .content { padding: 12px !important; }
  #content { padding: 12px !important; }
  .modal-body { padding: 14px 16px !important; }
  .modal-header { padding: 14px 16px !important; }
  .modal-footer { padding: 12px 16px !important; }

  /* Chips wrap */
  .chip-group { gap: 4px; }
  .chip { padding: 4px 10px; font-size: 11px; }

  /* Tabs scroll */
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .tab-strip { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }

  /* Toast */
  #toast-container { bottom: 16px; right: 12px; left: 12px; }
  #toast-container .toast { min-width: unset; width: 100%; }
  #sa-toast { right: 12px; left: 12px; bottom: 16px; max-width: unset; }

  /* Entry screen card */
  .entry-card { width: 95vw !important; padding: 28px 20px !important; }

  /* KPI table touch scroll */
  .kpi-table-wrap { max-height: 350px; }
}

/* ── 480px ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  body { font-size: 13px; }
  .btn { padding: 9px 14px !important; font-size: 12px !important; }
  .btn-sm { padding: 7px 10px !important; font-size: 11px !important; }
  .btn-xs { padding: 4px 8px !important; font-size: 10px !important; }
  .badge { padding: 2px 7px !important; font-size: 10px !important; }
  .stat-grid { gap: 10px !important; }
  .card { padding: 12px !important; }
  .stat-card { padding: 12px !important; }
  .kanban-col { padding: 10px !important; }
  .modal-header h3 { font-size: 15px !important; }
  .form-group { margin-bottom: 12px !important; }
  .field-row { grid-template-columns: 1fr !important; }
  .pager { flex-direction: column; gap: 8px; text-align: center; }
  .filter-bar input,.filter-bar select { font-size: 14px; }
}

/* ── 360px ────────────────────────────────────────────────── */
@media (max-width: 360px) {
  .entry-card { padding: 24px 16px !important; }
  .role-select-grid { grid-template-columns: 1fr !important; }
  .brand-stats { flex-direction: column; gap: 12px !important; }
}

/* ════════════════════════════════════════════════════════════
   UTILITY HELPERS (mobile-first)
   ════════════════════════════════════════════════════════════ */
.flex-mobile { display: flex; flex-wrap: wrap; gap: 8px; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100% !important; }

/* Overflow x on tables for all sizes */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
