/* ===== Mobile Responsive Overrides ===== */
/* Primary breakpoint: 768px (phones + small tablets) */

/* ─── Sidebar toggle — hidden on desktop ───────────────────── */
.btn-sidebar-toggle {
  display: none;
}

@media (max-width: 768px) {

  /* ─── Navbar ─────────────────────────────────────────────── */
  .navbar {
    gap: 0.25rem;
    padding: 0 0.75rem;
  }

  /* Hide brand text, keep logo */
  .navbar-brand span {
    display: none;
  }

  /* Smaller nav items in the dropdown on phones */
  .nav-link {
    font-size: 0.82rem;
    padding: 0.6rem 1rem;
  }

  /* Hide user name text on phones — just show the logout button */
  .nav-user-info {
    display: none !important;
  }

  /* ─── Content ─────────────────────────────────────────────── */
  .content {
    padding: 1rem 0.75rem;
  }

  /* ─── Tables — fit on mobile ──────────────────────────────── */
  /* table-layout:fixed forces the table to honour width:100% strictly;
     without it the auto algorithm can still expand the table beyond the viewport */
  .data-table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
    overflow-x: hidden;
  }
  .data-table th,
  .data-table td {
    padding: 0.3rem 0.4rem;
    font-size: 0.72rem;
    white-space: normal;
    word-break: break-word;
    overflow: hidden;
  }
  .th-sort { white-space: normal; }
  .col-date { white-space: normal; font-size: 0.68rem; }
  /* Keep action columns tight so data columns get more room */
  .col-action { width: 2rem; padding-left: 0.15rem !important; padding-right: 0.15rem !important; }

  /* ─── Machine Metrics — horizontal scroll, columns auto-sized ── */
  /* Override grid-table's fixed layout so columns expand to fit their
     content; the wrapper is the scroll container, not the table */
  #tab-machines .machines-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #tab-machines .data-table {
    table-layout: auto;
    min-width: 0;
    overflow-x: visible;
  }
  #tab-machines .data-table th {
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: visible;
  }
  #tab-machines .data-table td {
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: visible;
  }

  /* Filter rows — reduce input min-width so they don't overflow */
  .filter-row input[type="text"] {
    min-width: 100px;
    flex: 1;
  }
  .filter-row select {
    flex: 1;
  }

  /* Section headers stack on mobile */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .header-actions {
    margin-left: 0;
  }

  /* Page header margin */
  .page-header {
    margin-bottom: 1rem;
  }

  /* ─── Operator tab ─────────────────────────────────────────── */
  .op-columns-wrap {
    flex-direction: column;
    height: auto;
    max-height: none;
    overflow-y: auto;
    gap: 0.75rem;
    padding: 0 0.75rem 0.75rem;
  }

  .op-left-col,
  .op-mid-col {
    width: 100%;
    align-items: stretch;
  }

  .op-left-col .op-machine-status,
  .op-mid-col .op-machine-status,
  .op-machine-status,
  .operator-card,
  #op-cycle-widget {
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
  }

  #op-view-active {
    overflow-y: auto;
    align-items: stretch !important;
  }

  #op-cycle-widget {
    max-height: 300px;
  }

  /* Bigger numpad keys for touch */
  .op-key {
    padding: 1rem;
    font-size: 1.2rem;
    min-height: 56px;
  }

  /* ─── Machine Metrics — sidebar overlay ────────────────────── */
  .machines-panel-body {
    position: relative;
  }

  .machines-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    min-width: 240px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 50;
    box-shadow: 2px 0 16px var(--shadow-lg);
  }
  .machines-sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Tap-outside overlay when sidebar is open */
  .sidebar-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 49;
    background: var(--overlay);
  }
  .sidebar-backdrop.active {
    display: block;
  }

  /* Sidebar toggle button — shown on mobile */
  .btn-sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    padding: 0.28rem 0.65rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Dense grid table — bump font size for readability */
  .grid-table {
    font-size: 0.78rem;
  }
  .grid-table th,
  .grid-table td {
    padding: 0.25rem 0.35rem;
  }

  /* ─── Production split panels ──────────────────────────────── */
  .prod-cutting-layout {
    flex-direction: column;
  }
  .prod-file-palette {
    width: 100% !important;
    position: static !important;
    max-height: 220px;
    top: auto !important;
  }
  .pkg-grid-wrap {
    flex-direction: column;
  }
  .pkg-palette {
    width: 100% !important;
    max-height: 220px;
  }

  /* ─── Modals ───────────────────────────────────────────────── */
  .modal-body {
    max-height: 65vh;
  }

}
