/* ===== Metrics on a phone · the views, the filter sidebar as a sheet, charts and tables ===== */

/* every box down the tab runs with the page, so a long table or card list just scrolls the screen */
#tab-metrics .metrics-panel-body,
#tab-metrics .machines-views-area,
#tab-metrics .metrics-main-view,
#tab-metrics .machines-content,
#tab-metrics #view-machines-summary { overflow: visible; min-height: 0; }
#tab-metrics .metrics-panel-body { display: block; }
/* the tab's own inset would leave a strip of page beside the full-width header and tables */
#tab-metrics.tab-panel { padding: 0; }


/* ─── Header · menu, the view you're on, then filters and chart, pinned under the navbar ─── */
#tab-metrics .slim-page-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  position: sticky;
  top: var(--navbar-h);
  z-index: var(--z-popover);
  min-height: 3.25rem;
  padding: 0 0.5rem;
}
#tab-metrics .slim-header-left { flex: none; }
#tab-metrics .slim-page-header h2 { font-size: 1rem; }
/* the bar holds the filter and chart buttons plus the one view you're on, as a label */
#tab-metrics .pill-tab-bar { flex: 1; min-width: 0; justify-content: flex-end; gap: 0.4rem; }
/* the label is the one piece that gives way · it shortens with an ellipsis rather than sliding under the buttons beside it */
#tab-metrics .pill-tab-bar .pill-tab.active { display: block; flex: 0 1 auto; order: -1; margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 0.4rem; border-color: transparent; background: none; color: var(--text); pointer-events: none; }
#tab-metrics .pill-tab-bar .pill-tab.active .icon-slot { display: inline-flex; vertical-align: -2px; margin-right: 0.3rem; }
/* Refresh keeps its icon and gives its word back to the label · the title still names it */
#btn-metrics-refresh { font-size: 0; gap: 0; min-width: var(--touch); min-height: 2.5rem; justify-content: center; padding: 0; }
#btn-metrics-refresh .icon-slot { font-size: 1rem; }
/* the tab's own name keeps just its icon, so the view you're on has the room to be read */
#tab-metrics .slim-page-header h2 [data-label] { display: none; }
.btn-metrics-hamburger,
.btn-sidebar-toggle,
.btn-chart-open { min-width: var(--touch); min-height: 2.5rem; justify-content: center; }

/* the view menu drops from the header at a thumb's width */
.metrics-tab-dropdown { top: 100%; min-width: 14rem; }
.metrics-tab-dropdown .pill-tab { display: flex; min-height: var(--touch); padding: 0 1.1rem; gap: 0.6rem; font-size: 0.9rem; }


/* ─── Filter sidebar · a sheet rising from the tab bar, over the page rather than beside it ─── */
.metrics-sidebar {
  position: fixed;
  top: auto;
  left: 0;
  right: 0;
  bottom: var(--phone-floor);
  width: auto;
  min-width: 0;
  max-height: 75dvh;
  border: 0;
  border-radius: 16px 16px 0 0;
  transform: translateY(calc(100% + var(--phone-floor)));
  /* closed it keeps no shadow, or the edge of it bled along the page */
  box-shadow: none;
  visibility: hidden;
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}
.metrics-sidebar.sidebar-open { transform: none; visibility: visible; box-shadow: 0 -8px 30px var(--shadow-lg); transition: transform 0.22s ease; }
.sidebar-backdrop { position: fixed; inset: 0; }
/* the fold bar is the sheet's head now, and folding it has no column to give back */
.sidebar-collapse-bar { position: sticky; top: 0; z-index: var(--z-raise-1); padding: 0.6rem 1rem; }
#btn-collapse-sidebar { display: none; }
.sidebar-section { padding: 0.6rem 1rem; }
.sidebar-dt-input { min-height: var(--touch); }
.btn-sidebar-apply { width: 100%; min-height: var(--touch); }
.metrics-sidebar label { min-height: 2.25rem; display: flex; align-items: center; gap: 0.5rem; }
.metrics-sidebar input[type="checkbox"] { width: 20px; height: 20px; }


/* ─── Status and view bars · a readable line, and the per-view controls wrap instead of floating off the left ─── */
#tab-metrics .machines-status-bar { font-size: 0.78rem; padding: 0.4rem 0.75rem; }
#tab-metrics .subtab-bar { flex-wrap: wrap; gap: 0.4rem; padding: 0.4rem 0.5rem; margin-bottom: 0.75rem; }
#tab-metrics .subtab-bar .filter-row { flex: 1 1 auto; min-width: 0; margin: 0 !important; justify-content: flex-end; }
#tab-metrics .subtab-bar .filter-row input[type="text"] { flex: 1 1 8rem; min-width: 0; min-height: 2.5rem; }
#tab-metrics .subtab-bar .filter-row select { flex: 0 1 auto; min-height: 2.5rem; }
.btn-metrics-subtab-hamburger { min-height: 2.5rem; margin-left: 0; font-size: 0.85rem; }
.metrics-subtab-dropdown { min-width: 12rem; }
.metrics-subtab-dropdown .subtab,
.metrics-subtab-dropdown .metrics-review-tab,
.metrics-subtab-dropdown .metrics-stats-tab { min-height: var(--touch); display: flex; align-items: center; gap: 0.5rem; }
#tab-metrics .btn-icon-action { min-width: 2.5rem; min-height: 2.5rem; }


/* ─── Tables · each scrolls sideways inside itself, the page never does ─── */
#tab-metrics .metrics-table-wrap { overflow-x: auto; overscroll-behavior-x: contain; }
/* the machine or shift name stays put while the figures scroll past it */
#tab-metrics .metrics-table-wrap .data-table td:first-child,
#tab-metrics .metrics-table-wrap .data-table th:first-child { position: sticky; left: 0; z-index: var(--z-raise-1); }
#tab-metrics .metrics-table-wrap .data-table thead th:first-child { z-index: var(--z-raise-2); }
/* a pinned cell needs a ground of its own, or the figures scrolling under it show through · a plain table's row colour lives on the transparent <tr> */
#tab-metrics .metrics-table-wrap .data-table:not(.grid-table) tbody td:first-child { background: var(--table-surface); }
#tab-metrics .metrics-table-wrap .data-table:not(.grid-table) tbody tr:hover td:first-child { background: var(--row-hover); }
#tab-metrics .metrics-table-wrap .data-table:not(.grid-table) tbody tr.is-selected td:first-child { background: var(--row-selected); }
#tab-metrics .metrics-table-wrap .data-table:not(.grid-table) tbody tr.is-flagged td:first-child { background: var(--warning-bg); }
/* the unknown-session tint is see-through, so the pinned cell lays it over the table's surface instead of over the scrolling cells */
#tab-metrics .metrics-table-wrap tr.session-unknown td:first-child { background: linear-gradient(var(--unknown-row-bg), var(--unknown-row-bg)), var(--table-surface) !important; }


/* ─── Dashboard · one column of cards, rearranged from desktop only ─── */
#main-view-dashboard .dashboard-shifts-grid,
#main-view-dashboard .dashboard-grid,
#dashboard-cards { grid-template-columns: minmax(0, 1fr); }
.dashboard-card { padding: 0.9rem 1rem; }
/* dragging cards around is a mouse move, so the grip only takes room */
.dashboard-drag-handle { display: none; }


/* ─── Chart pane · the whole screen between the header and the tab bar, its toggle still in reach above it ─── */
.chart-pane:not(.collapsed) {
  position: fixed;
  top: calc(var(--navbar-h) + 3.25rem);
  bottom: var(--phone-floor);
  left: 0;
  right: 0;
  width: auto;
  z-index: var(--z-popover);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.chart-pane-handle { display: none; }
/* Chart.js sizes to the box it's given, so the box is the width of the phone and a sensible height */
.chart-wrap { overflow: visible; }
.chart-wrap canvas { min-width: 0; }
.chart-float-titlebar { flex-wrap: wrap; gap: 0.4rem; padding: 0.5rem; }
.chart-machine-select { min-height: 2.5rem; }
