/* KingsCorner mobile foundation (Step 0a)
   Phone and tablet-portrait rules only. Loaded by base.html after page head_extra. */
@media (max-width: 768px) {
  :root { --kc-container-pad: 14px; }
  html { -webkit-text-size-adjust: 100%; }
  body { overflow-wrap: break-word; }
  img, video { max-width: 100%; height: auto; }

  /* iOS zooms the page when a focused field is under 16px */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select, textarea { font-size: 16px; }

  /* Touch targets */
  .kc-btn, .mm-menu-item, .util-menu-item { min-height: 44px; }
  .kc-btn-icon { min-width: 44px; }

  /* Lighter blur: cheaper on phones. Delete this block if cards look too see-through. */
  .kc-glass-card, .kc-kpi-tile, .kc-panel, .kc-svc-card,
  .card, .kpi, .util-card, .qs-card {
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }

  /* Tables scroll inside their panel instead of stretching the page */
  .kc-panel__scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .kc-panel__scroll .kc-table { min-width: 520px; }

  /* Command Center strip and link grid */
  .kc-svc-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--kc-space-2); }
  .kc-quicklinks { grid-template-columns: 1fr; }
  .kc-section-header { flex-wrap: wrap; }

  /* Popups stay on screen */
  .mm-menu { max-width: calc(100vw - 16px); }
  .kc-toast-host { left: 12px; right: 12px; bottom: 12px; }
}

/* ---- Homepage + megamenu phone layout (Step 0b) ---- */
@media (max-width: 768px) {
  .wrap { padding: 14px 14px 28px; }
  .wrap, .topstrip > *, .kpis > *, .featured > *, .quickstrip-cards > * { min-width: 0; }

  /* Header strip: two columns, first item (logo and title) gets the full row */
  .topstrip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
  .topstrip > :first-child { grid-column: 1 / -1; }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .featured { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .temp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quickstrip { flex-wrap: wrap; }
  .quickstrip-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

  /* Homepage utility menus stay on screen */
  .util-menu, .util-bell-menu { min-width: 0; width: max-content; max-width: calc(100vw - 24px); }

  /* Megamenu: compact two-column pill grid */
  .megamenu { margin: 12px 0; }
  .megamenu-pills { gap: 8px; padding: 6px; }
  .mm-pill { flex: 1 1 calc(50% - 8px); min-width: 0; padding: 12px 8px; font-size: 14px; gap: 6px; }

  /* Megamenu panels: full width under the pills, whatever the desktop alignment */
  .megamenu .mm-panel[data-align] { left: 0; right: 0; width: auto; max-width: none; padding: 14px; transform: translateY(-6px); }
  .megamenu .mm-panel[data-align].is-open { transform: translateY(0); }
  .mm-panel-cards { grid-template-columns: minmax(0, 1fr); }

  /* Holiday countdown pill: smaller, within the screen. The html prefix beats the script's injected style. */
  html #kc-countdown { left: 10px; bottom: 10px; max-width: calc(100vw - 20px); padding: 6px 12px; font-size: 12px; }
}

/* ---- Homepage quick-start strip (Step 0c) ---- */
@media (max-width: 768px) {
  .wrap { padding-bottom: 72px; }  /* room for the fixed holiday countdown pill */
  .quickstrip { flex-wrap: wrap; align-items: stretch; gap: 10px; }
  .quickstrip-cards { flex: 1 1 100%; width: 100%; }
  .quickstrip > .util-card { flex: 1 1 calc(50% - 5px); min-width: 0; min-height: 56px; }
  .qs-card { min-width: 0; padding: 12px; gap: 10px; }
  .qs-card > :last-child { min-width: 0; overflow-wrap: anywhere; }
}

/* ---- Homepage quick-start strip, corrected (Step 0d) ---- */
@media (max-width: 768px) {
  .quickstrip { flex-direction: column; flex-wrap: nowrap; gap: 10px; }
  .quickstrip-cards { flex: 0 0 auto; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .quickstrip-util { flex: 0 0 auto; width: 100%; gap: 10px; }
  .quickstrip-util .util-card { flex: 1 1 0; min-width: 0; min-height: 56px; justify-content: center; }
  .qs-card { min-width: 0; overflow: hidden; padding: 12px; gap: 10px; }
  .qs-card > div:last-child { min-width: 0; overflow-wrap: anywhere; }
}

/* ---- Megamenu panels on phones: beat the homepage inline !important rules (Step 0e) ---- */
@media (max-width: 768px) {
  .megamenu .mm-panel[data-align] {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    width: auto !important;
    max-width: none !important;
    margin-top: 10px !important;
    padding: 14px !important;
    transform: translateY(-6px) !important;
  }
  .megamenu .mm-panel[data-align].is-open { transform: none !important; }
  .megamenu .mm-panel .mm-panel-cards { grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; }
  .megamenu .mm-panel .mm-card { min-width: 0 !important; width: 100% !important; box-sizing: border-box; }
  .megamenu .mm-panel .mm-card-body { min-width: 0; overflow-wrap: anywhere; }
}
