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

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

/* ─── Operator tab — stack vertically before widgets compress ── */
@media (max-width: 960px) {
  #tab-console.active {
    height: auto;
    min-height: calc(100vh - var(--navbar-h));
    overflow: visible;
  }

  .operator-wrap {
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: calc(100vh - var(--navbar-h));
    align-items: center;
  }

  .op-columns-wrap {
    flex-direction: column;
    width: 100%;
    height: auto;
    max-height: none;
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .op-mid-col {
    width: 90%;
    max-width: 90%;
    margin: 0 auto;
    align-items: stretch;
  }

  /* Widgets inside columns fill their column */
  .op-mid-col .op-machine-status {
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* stacked, the bar has no 80vw dashboard to match, so it fills the column like the widgets do */
  .op-spectate-bar {
    width: 100%;
  }

  /* Standalone stage widget + login/machine-select cards */
  #op-stage-widget,
  .operator-view > .operator-card {
    width: 90% !important;
    max-width: 90%;
    margin: 0 auto;
    box-sizing: border-box;
  }

  #op-view-active {
    align-items: center !important;
  }
}

@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 · tighten the tokens, not a wrapper, so every tab narrows together ─── */
  :root {
    --page-inset-x: 0.75rem;
    --page-inset-y: 0.5rem;
  }

  /* ─── Tables — horizontal scroll on mobile ───────────────────── */
  /* Let table size to content width instead of being clamped to container;
     min-width: 100% prevents a narrower-than-viewport table when content is sparse */
  .data-table:not(.grid-table) {
    width: auto;
    min-width: 100%;
  }
  /* density through the archetype's own properties, not a third copy of the cell rules */
  .data-table:not(.grid-table) {
    --pad-y: 0.3rem;
    --pad-x: 0.5rem;
    --cell-size: 0.75rem;
  }
  .data-table:not(.grid-table) th,
  .data-table:not(.grid-table) td {
    white-space: nowrap;
    min-width: 150px;
  }
  .col-date { font-size: 0.7rem; }
  .col-action { min-width: 2rem !important; width: 2rem; padding-left: 0.15rem !important; padding-right: 0.15rem !important; }

  /* 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;
  }


  /* BOM hierarchy breadcrumb — scroll horizontally rather than overflow */
  .bom-hierarchy {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  /* ─── System tab ────────────────────────────────────────────── */
  #tab-system .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* ─── Server dashboard ──────────────────────────────────────── */
  .srv-header {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  /* Columns already stack at 700px; trim padding on mobile */
  .srv-col {
    padding: 0.65rem 0.75rem;
  }

  /* Scrollable Services / Top Paths tables */
  .srv-services {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.6rem 0.75rem;
  }

  .srv-svc-table {
    min-width: 460px;
  }

  .srv-svc-table th,
  .srv-svc-table td {
    white-space: nowrap;
    padding: 0.28rem 0.5rem 0.28rem 0;
  }

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

  #op-stage-widget {
    max-height: 320px;
  }


  /* ─── Production split panels ──────────────────────────────── */
  .prod-file-palette {
    width: 100% !important;
    position: static !important;
    max-height: 220px;
    top: auto !important;
  }


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

}

/* Metrics' top tabs fold into the hamburger menu well before the rest of its layout compacts · the centered bar needs about 1330px plus the title's width on each side */
@media (max-width: 1600px) {

  /* ─── Machine Metrics — hamburger tab menu ─────────────────── */
  .btn-metrics-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 0.4rem;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
  }
  .btn-metrics-hamburger:hover { color: var(--text); background: var(--row-selected); }

  /* Hide inline tabs — they live in the dropdown instead */
  .pill-tab-bar .pill-tab {
    display: none;
  }

  .metrics-tab-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: var(--z-dropdown);
    flex-direction: column;
    min-width: 150px;
    box-shadow: 0 6px 16px var(--shadow-lg);
  }
  .metrics-tab-dropdown.open {
    display: flex;
  }
  .metrics-tab-dropdown .pill-tab {
    display: block;
    padding: 0.7rem 1.1rem;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-light);
    text-align: left;
    width: 100%;
    margin: 0;
  }
  .metrics-tab-dropdown .pill-tab:first-child {
    border-top: none;
  }
}


@media (max-width: 1024px) {

  /* ─── 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-metrics .metrics-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #tab-metrics .data-table {
    table-layout: auto;
    overflow-x: visible;
  }
  #tab-metrics .data-table th {
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: visible;
  }
  #tab-metrics .data-table td {
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: visible;
  }
  #tab-metrics .data-table .col-truncate {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ─── Metrics sub-subtab dropdowns (Review/Statistics) ─────── */
  .btn-metrics-subtab-hamburger {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.28rem 0.65rem;
    font-size: 0.8rem;
    cursor: pointer;
    margin-left: 0.5rem;
    color: var(--text-muted);
    white-space: nowrap;
  }
  .btn-metrics-subtab-hamburger:hover { color: var(--text); background: var(--row-selected); }

  .metrics-subtab-wrap {
    display: block;
    position: relative;
  }

  /* Hide the inline tab buttons — only visible inside the open dropdown */
  .metrics-subtab-wrap .subtab,
  .metrics-subtab-wrap .metrics-review-tab,
  .metrics-subtab-wrap .metrics-stats-tab {
    display: none;
  }

  .metrics-subtab-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    z-index: var(--z-dropdown);
    flex-direction: column;
    min-width: 140px;
    box-shadow: 0 6px 16px var(--shadow-lg);
  }
  .metrics-subtab-wrap.open .metrics-subtab-dropdown {
    display: flex;
  }
  .metrics-subtab-dropdown .subtab,
  .metrics-subtab-dropdown .metrics-review-tab,
  .metrics-subtab-dropdown .metrics-stats-tab {
    display: block;
    padding: 0.45rem 0.7rem;
    border: none;
    border-radius: 0;
    text-align: left;
    width: 100%;
    margin: 0;
    background: none;
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
  }
  .metrics-subtab-dropdown .subtab:hover,
  .metrics-subtab-dropdown .metrics-review-tab:hover,
  .metrics-subtab-dropdown .metrics-stats-tab:hover {
    background: var(--row-hover);
  }
  .metrics-subtab-dropdown .subtab.active,
  .metrics-subtab-dropdown .metrics-review-tab.active,
  .metrics-subtab-dropdown .metrics-stats-tab.active {
    background: var(--primary);
    color: var(--on-primary);
  }

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

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

  /* Tap-outside overlay when sidebar is open */
  .sidebar-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: var(--z-mobile-backdrop);
    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;
    transition: background 0.15s;
  }
  .btn-sidebar-toggle:hover { background: var(--surface-deep); }

  /* ─── Metrics chart pane — full-width overlay ──────────────── */
  .chart-pane:not(.collapsed) {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    z-index: var(--z-mobile-panel);
  }

  .chart-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .chart-wrap canvas {
    display: block;
    min-width: 360px;
  }

  /* Hide the drag handle — not useful on touch */
  #machines-chart-pane-handle {
    display: none !important;
  }

  /* 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;
  }

}
