/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile & Tablet  (v2 — comprehensive)
   Breakpoints: mobile < 768px | tablet 768–1023px | desktop ≥ 1024px
   ═══════════════════════════════════════════════════════════════ */

/* ── Hamburger button ─────────────────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border2);
  cursor: pointer;
  z-index: 310;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text2);
  border-radius: 2px;
  transition: all 0.25s ease;
  transform-origin: center;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

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

/* ── Loading spinner ─────────────────────────────────────────── */
.loading-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto 10px;
  display: block;
}

/* ── TABLET (768px – 1023px) ──────────────────────────────────── */
@media (max-width: 1023px) {
  .hamburger { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    width: 220px;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  .main { margin-left: 0 !important; }
  .topbar { padding: 0 16px; }
  .topbar-clock { display: none; }
  .page-content { padding: 16px; }

  .grid-4 { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
  .grid-3 { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
  .grid-12 { grid-template-columns: 1fr !important; }
  .grid-21 { grid-template-columns: 1fr !important; }

  /* Stat strip — 2 col on tablet */
  .stat-strip { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
}

/* ── MOBILE (< 768px) ─────────────────────────────────────────── */
@media (max-width: 767px) {
  :root { --topbar-h: 50px; }

  /* ── Layout ── */
  .main { margin-left: 0 !important; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-title { font-size: 13px; }
  .topbar-breadcrumb, .topbar-clock { display: none; }
  .topbar-right { gap: 6px; }
  .topbar-btn { width: 30px; height: 30px; font-size: 11px; }
  .page-content { padding: 12px; }

  /* ── ALL grids → 1 col ── */
  .grid-2, .grid-3, .grid-4, .grid-12, .grid-21 {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  /* ── Stat strip → 2 col ── */
  .stat-strip { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 22px !important; }
  .stat-icon { width: 30px !important; height: 30px !important; font-size: 14px !important; }

  /* ── Cards ── */
  .card-header { padding: 12px 14px 0; }
  .card-body   { padding: 12px 14px 14px; }
  .card-footer { padding: 8px 14px 12px; }

  /* ── Section header ── */
  .section-header { flex-wrap: wrap; gap: 8px; }
  .section-header .btn { font-size: 11px; padding: 5px 10px; }

  /* ── Buttons ── */
  .btn { padding: 6px 12px; font-size: 11px; }
  .btn-sm { padding: 4px 8px; font-size: 10px; }

  /* ── Forms ── */
  .form-row { grid-template-columns: 1fr !important; gap: 10px; }
  .form-input { font-size: 16px; } /* prevent iOS zoom */

  /* ── Tables → horizontal scroll ── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  .data-table { min-width: 520px; }
  .data-table th { font-size: 9px; padding: 7px 8px; }
  .data-table td { font-size: 11px; padding: 8px 8px; }

  /* Auto-wrap any card-body containing a table */
  .card-body:has(.data-table) { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0; }
  .card-body:has(.data-table) .data-table { min-width: 520px; }

  /* ── Dashboard panels ── */
  /* Inline grid overrides for dashboard panels */
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }


  /* ── Recipes page ── */
  /* Recipe list + detail panel: fixed 340px → stack vertically */
  [style*="grid-template-columns:340px"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  [style*="grid-template-columns: 340px"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* ── Schedules weekly grid ── */
  /* Weekly overview grid → scrollable */
  [style*="grid-template-columns:100px"] {
    min-width: 500px;
  }
  [style*="grid-template-columns: 100px"] {
    min-width: 500px;
  }

  /* ── Alarms ── */
  .alarm-row { flex-wrap: wrap; gap: 6px; }
  .alarm-row .btn { margin-left: auto; }

  /* ── LED sliders ── */
  .ch-row { gap: 6px; }
  .ch-nm { width: 60px; font-size: 9px; }

  /* ── Navigator arrows ── */
  .dev-nav-label { display: none; }

  /* ── Nav items ── */
  .nav-item { padding: 9px 16px; }
  .nav-section { padding: 10px 16px 4px; }
}

/* ── SMALL MOBILE (< 400px) ──────────────────────────────────── */
@media (max-width: 399px) {
  .page-content { padding: 8px; }
  .stat-strip { gap: 6px; }
  .stat-value { font-size: 20px !important; }
  .topbar-btn { width: 28px; height: 28px; }
  .card-header, .card-body { padding-left: 10px; padding-right: 10px; }
}

/* ── Tablet-only tweaks (768–1023) ─────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Recipes: allow side-by-side but narrower */
  [style*="grid-template-columns:340px"] {
    display: grid !important;
    grid-template-columns: 280px 1fr !important;
  }
  [style*="grid-template-columns: 340px"] {
    display: grid !important;
    grid-template-columns: 280px 1fr !important;
  }
}

/* ── mobile-stack utility ───────────────────────────────────────── */
@media (max-width: 767px) {
  .mobile-stack {
    grid-template-columns: 1fr !important;
    display: grid !important;
  }
}
