/* Phone layout (screens up to 600 px): Overview, Alarms, Live, Reports and Analysis.
   Engineering pages stay desktop-first. Hooks come from static/phone.js. Loaded last. */
/* Same specificity as ui-consistency.css's decorated-button rule; this file loads later. */
.phone-page-title, html body button.phone-filter-toggle { display:none; }

@media screen and (max-width:600px) {
  /* !important: navigation.css sets work-page padding with an ID-specific :has() rule. */
  html body main { padding:0 12px 16px !important; }

  /* Sticky top bar: menu button, page name and plant name. */
  #pageHeaderBar {
    position:sticky; top:0; z-index:40; margin:0 -12px 10px; padding:8px 12px;
    background:var(--phone-bar, #f7faff); border-bottom:1px solid var(--phone-bar-border, #d7e2e6);
  }
  html[data-content-theme=dark] #pageHeaderBar { --phone-bar:#152238; --phone-bar-border:#364b68; }
  .phone-page-title { display:flex; flex-direction:column; flex:1; min-width:0; line-height:1.2; }
  .phone-page-title strong { font-size:16px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .phone-page-title span { font-size:11px; color:#5f7481; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .phone-page-title span:empty { display:none; }
  html[data-content-theme=dark] .phone-page-title strong { color:#e2e8f0; }
  html[data-content-theme=dark] .phone-page-title span { color:#a9bbd3; }
  /* The page header (KPI cards, logos) opens on hover on desktop; on phones the chevron is a visible tap target. */
  #pageHeaderToggle { margin-left:0; min-width:40px; }
  #pageHeaderToggle > svg { visibility:visible; width:18px; height:18px; }
  /* Warning banners scroll with the page here: sticky they would slide under the top bar and cover a third of the screen. */
  main :is(#powerGuardBanner,.amc-expired-banner) { position:static; margin:0 0 10px; padding:8px 10px; font-size:12px; }

  /* Overview */
  #dashboard .card { padding:12px; }

  /* Alarms: filters fold away; each alarm is a card. */
  #alarmsPage .phone-filter-toggle { display:inline-flex; align-items:center; gap:6px; width:100%; justify-content:center; margin:6px 0; }
  #alarmsPage:not(.phone-filters-open) > .range-bar { display:none; }
  #alarmsPage .legend { display:none; }
  #alarm-root .range-bar label.alarm-all-tabs { justify-content:flex-start; gap:6px; }
  #alarm-root .alarm-views-row .tabs { flex-wrap:nowrap; overflow-x:auto; scrollbar-width:thin; }
  #alarm-root .alarm-views-row .tabs > button { flex:0 0 auto; }
  #alarm-root .event-table thead tr { display:flex; gap:6px; overflow-x:auto; padding:4px 0; scrollbar-width:thin; }
  #alarm-root .event-table thead th { flex:0 0 auto; }
  #alarm-root .event-table tbody tr {
    grid-template-columns:repeat(6,minmax(0,1fr)); gap:4px 8px; margin:8px 0; padding:8px 4px;
    border:1px solid var(--ae-border); border-radius:10px; background:var(--ae-surface);
  }
  /* Priority and time; device and alarm text; IDs on one line; Acknowledge and Hide side by side. */
  #alarm-root .event-table tbody td { grid-column:span 3; }
  #alarm-root .event-table td[data-cell=priority] { grid-column:1/3; }
  #alarm-root .event-table td[data-cell=date] { grid-column:3/7; }
  #alarm-root .event-table td:is([data-cell=gw],[data-cell=deviceId],[data-cell=code]) { grid-column:span 2; }
  #alarm-root .event-table td[data-cell=ack] { grid-column:1/4; }
  #alarm-root .event-table td[data-cell=hide] { grid-column:4/7; }
  #alarm-root .event-table td:is([data-cell=device],[data-cell=text],[data-cell=resolvedDate]),
  #alarm-root .event-table td.empty { grid-column:1/-1; }
  #alarm-root .event-table td[data-cell]:has(> .cell-line:empty) { display:none; }
  #alarm-root .event-table td:is([data-cell=priority],[data-cell=device],[data-cell=text],[data-cell=ack],[data-cell=hide])::before { display:none; }
  #alarm-root .event-table td[data-cell=device] .cell-line { font-weight:600; }
  #alarm-root .event-table td:is([data-cell=ack],[data-cell=hide]) button { width:100%; min-height:40px; }
  #alarm-root .pagination { flex-wrap:wrap; gap:8px; }

  /* Live: each device is a card with its quick values; no sideways scrolling. */
  #live .live-controls input { flex:1 1 100%; width:auto; }
  #live .live-controls select { flex:1; max-width:none; }
  #live .live-groups-scroll, #live #deviceLiveGroups { max-height:none; overflow:visible; }
  #live .live-summary-table { min-width:0; display:block; }
  #live .live-summary-table thead { display:none; }
  #live .live-summary-table tbody { display:block; }
  #live .live-device-row {
    display:grid; grid-template-columns:auto minmax(0,1fr); align-items:center; gap:2px 10px;
    padding:8px 2px; border-bottom:1px solid var(--live-border, #dfe7ec);
  }
  html[data-content-theme=dark] #live .live-device-row { --live-border:#364b68; }
  #live .live-device-row > td { display:block; border:0; min-width:0; }
  #live .live-device-row > td:first-child { grid-row:span 2; align-self:start; }
  #live .live-device-row .point-expand { height:32px; min-width:32px; }
  #live .live-device-row > td:nth-child(2) { font-size:14px; }
  #live .live-device-row > td:nth-child(3) { font-size:11px; }
  #live .live-device-row > td:nth-child(n+4) { grid-column:2; display:flex; justify-content:space-between; gap:12px; text-align:right; }
  #live .live-device-row > td:nth-child(n+4)::before { content:attr(data-label); text-align:left; opacity:.75; }
  #live .live-device-detail { display:block; }
  #live .live-device-detail[hidden] { display:none; }
  #live .live-device-detail > td { display:block; }

  /* SLD editor stays desktop-first; keep it inside the screen instead of widening the page. */
  #sld .sld-zoom-controls { flex-wrap:wrap; }
  #sld { max-width:100%; overflow-x:auto; }

  /* Reports and Analysis */
  #reports .table-wrap, #reportOutput { overflow-x:auto; }
  #analysis .analysis-filter-actions, #analysis .toolbar { flex-wrap:wrap; }
}
