/* Phone/tablet corrections verified with the portal's existing navigation. */
@media (max-width: 1200px) {
  html body .local-condition-invite { grid-template-columns: minmax(0,1fr) !important; min-width: 0; margin: 16px !important; padding: 18px !important; }
  html body .local-condition-primary { grid-column: 1 / -1; min-width: 0; max-width: 100%; white-space: normal; }
  html body .pagasa-andrr-grid { grid-template-columns: minmax(0,1fr) !important; }
  html body .pagasa-himawari-panel,
  html body .pagasa-context-panel { min-width: 0; max-width: 100%; box-sizing: border-box; }
  html body #incident-report .public-tools-grid { grid-template-columns: minmax(0,1fr) !important; padding: 18px !important; gap: 18px !important; }
  html body #incident-report .public-tool-panel { min-width: 0; max-width: 100%; box-sizing: border-box; }
}
@media (max-width: 980px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  html body .page { min-width: 0; box-sizing: border-box; }
  html body .page :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    min-width: 0;
    max-width: 100%;
    font-size: 16px !important;
    box-sizing: border-box;
  }
  html body .page :is(button, summary),
  html body #utilityPanel button,
  html body .officer-login-dialog button { min-height: 44px; touch-action: manipulation; }
  html body .page :is(h1,h2,h3,h4,p,label,button,summary) { overflow-wrap: break-word; }
  html body .hotline-action-bar,
  html body .messenger-float-btn {
    position: static !important;
    inset: auto !important;
    transform: none !important;
    z-index: auto !important;
    box-sizing: border-box;
  }
  html body .hotline-action-bar { width: auto !important; margin: 20px 12px !important; }
  html body .messenger-float-btn { width: calc(100% - 24px) !important; max-width: 360px !important; margin: 16px auto 90px !important; }

  /* Body mounting avoids the transformed navigation becoming a fixed ancestor. */
  html body > #utilityPanel:not([hidden]) {
    position: fixed !important;
    inset: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    transform: none !important;
    overflow: hidden !important;
    background: #f5f9fc !important;
    color: #102d43 !important;
    border: 1px solid #a8c7d8 !important;
    border-radius: 16px !important;
    z-index: 30000 !important;
  }
  html body #utilityPanel .utility-panel-header {
    flex: 0 0 auto;
    padding: 16px !important;
    gap: 12px;
    grid-auto-rows: max-content;
    align-content: start;
    grid-template-columns: minmax(0,1fr) 44px;
  }
  html body #utilityPanel .utility-panel-header h2 { font-size: 23px; line-height: 1.15; }
  html body #utilityPanel .utility-panel-header p { font-size: 13px; line-height: 1.4; }
  html body #utilityPanel .utility-panel-kicker { color: #fde68a !important; font-size: 10px; }
  html body #utilityPanel .utility-panel-grid {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none !important;
    overflow-y: auto !important;
    padding: 14px;
    gap: 12px;
    grid-auto-rows: max-content;
    align-content: start;
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  html body #utilityPanel .utility-panel-grid > .control-card {
    min-width: 0;
    min-height: max-content !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 16px !important;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid #d3e1eb;
    border-radius: 12px;
    background: #fff !important;
    color: #102d43 !important;
  }
  html body #utilityPanel .control-card > * { flex-shrink: 0; }
  html body #utilityPanel .utility-panel-grid > .control-card:has(#notifyBtn) { overflow-y: visible !important; }
  html body #utilityPanel .control-card-label { color: #334155 !important; font-size: 12px; font-weight: 800; }
  html body #utilityPanel .control-status { color: #475569 !important; font-size: 13px; line-height: 1.45; }
  html body #utilityPanel .control-btn { width: 100%; white-space: normal; }
  html body #utilityPanel [hidden] { display: none !important; }
  html body #utilityPanel .utility-panel-close { width: 44px; height: 44px; }
  html body #utilityPanel .utility-panel-close::before,
  html body .officer-login-header > button::before { display: none !important; }
  html body #utilityPanel .utility-panel-close .portal-menu-symbol { display: none !important; }
  html body.utility-dock-open { overflow: hidden; }
  html body.utility-dock-open .mobile-eoc-dock,
  html body:has(#officerLoginModal:not([hidden])) .mobile-eoc-dock { visibility: hidden !important; pointer-events: none !important; }

  html body #officerLoginModal { z-index: 31000; padding: 8px; }
  html body #officerLoginModal .officer-login-dialog {
    box-sizing: border-box !important;
    width: min(620px, calc(100vw - 16px)) !important;
    max-width: 100% !important;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
  }
  html body .officer-login-header { padding: 16px; gap: 12px; flex: 0 0 auto; }
  html body .officer-login-header h2 { font-size: 23px; line-height: 1.15; }
  html body .officer-login-header p { font-size: 13px; line-height: 1.4; }
  html body .officer-login-form { padding: 16px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  html body .officer-login-code-row input { min-width: 0; width: 100%; font-size: 16px; box-sizing: border-box; }
  html body #mobilePrimaryNav .eoc-nav-messenger { display: flex !important; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
  html body #mobilePrimaryNav .eoc-nav-messenger .eoc-nav-group-title { flex: 1 1 140px; min-width: 0; white-space: normal !important; word-break: normal !important; overflow-wrap: normal !important; }

  /* These tables already become labelled record cards on phones. */
  html body .mobile-card-table > thead { clip-path: inset(50%); }
  html body #incident-log .incident-log-shell { padding: 12px !important; }
  html body #incident-log .portal-table-region { padding: 4px; }
  html body #incident-log .incident-table.mobile-card-table td { overflow-wrap: anywhere !important; }
  html body #incident-log .portal-table-filter { flex-wrap: wrap; }
  html body #incident-log .portal-table-filter input { width: 100%; }

  /* Export controls must fit even at 320px, without clipping the last action. */
  body .summary-panel .export-grid { display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)); }
  body .summary-panel .export-grid button { min-width: 0; min-height: 44px; white-space: normal; }
  body:has(#operationalMap) .topbar { display: grid !important; grid-template-columns: minmax(0,1fr) auto; height: auto !important; min-height: 72px; padding: 12px; gap: 10px; }
  body:has(#operationalMap) .brand { min-width: 0; grid-column: 1 / -1; grid-row: 2; }
  body:has(#operationalMap) .brand h1 { font-size: 20px; line-height: 1.25; overflow-wrap: normal; word-break: normal; }
  body:has(#operationalMap) .back-link { grid-column: 1; grid-row: 1; justify-self: start; }
  body:has(#operationalMap) .access-badge { grid-column: 2; grid-row: 1; }
  body:has(#operationalMap) .back-link,
  body:has(#operationalMap) .access-badge { flex: 0 0 auto; }
}
@media (max-width: 480px) {
  html body #utilityPanel .utility-panel-grid { grid-template-columns: minmax(0,1fr); }
  html body .officer-login-code-row { grid-template-columns: minmax(0,1fr); }
  html body .officer-login-code-row button { justify-self: start; min-height: 44px; padding: 8px 16px; }
  html body #incident-log .incident-log-shell { padding: 10px !important; }
  body .summary-panel .export-grid { grid-template-columns: minmax(0,1fr); }
}
@media (max-height: 480px) and (max-width: 980px) {
  html body #utilityPanel .utility-panel-header p,
  html body #utilityPanel .utility-panel-kicker,
  html body .officer-login-header p { display: none; }
  html body #utilityPanel .utility-panel-header,
  html body .officer-login-header { padding: 10px 14px !important; }
}
