/**
 * GavelSight Mobile PWA — responsive overrides.
 * Loaded only when ENABLE_MOBILE_PWA is on (injected in base.html).
 * All rules scoped to max-width: 768px to avoid touching desktop layout.
 */

/* ── Base mobile resets ──────────────────────────────────────────────────── */

@media (max-width: 768px) {
  html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
  }

  body {
    line-height: 1.5;
    overflow-x: hidden;
  }

  /* Touch targets: min 44×44 px per WCAG 2.5.5 */
  a,
  button,
  [role="button"],
  input[type="submit"],
  input[type="button"],
  input[type="reset"],
  .btn {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Navigation ─────────────────────────────────────────────────────────── */

  .site-header .header-shell {
    flex-wrap: wrap;
    padding: 8px 16px;
  }

  .top-nav {
    display: none;
    flex-direction: column;
    width: 100%;
    padding: 8px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .top-nav.nav-open,
  .header-shell.nav-open .top-nav {
    display: flex;
  }

  .top-nav a {
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    width: 100%;
    justify-content: flex-start;
    min-height: 44px;
  }

  .mobile-menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 32px;
    height: 32px;
    min-height: 44px;
    min-width: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    align-items: center;
  }

  .mobile-menu-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
  }

  .header-actions {
    display: none;
  }

  .header-shell.nav-open .header-actions {
    display: flex;
    width: 100%;
    padding: 8px 0;
    gap: 8px;
  }

  /* ── Collapsible sidebars ────────────────────────────────────────────────── */

  .sidebar,
  .panel-sidebar,
  [class*="sidebar"] {
    position: fixed;
    top: 0;
    left: -100%;
    width: 80vw;
    max-width: 320px;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    transition: left 0.25s ease;
    background: var(--color-bg, #fff);
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.18);
  }

  .sidebar.open,
  [class*="sidebar"].open {
    left: 0;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 999;
  }

  .sidebar.open ~ .sidebar-overlay,
  [class*="sidebar"].open ~ .sidebar-overlay {
    display: block;
  }

  /* ── Tables → stacked cards ─────────────────────────────────────────────── */

  table.responsive-table,
  .data-table {
    display: block;
    width: 100%;
  }

  table.responsive-table thead,
  .data-table thead {
    display: none;
  }

  table.responsive-table tbody,
  .data-table tbody {
    display: block;
  }

  table.responsive-table tr,
  .data-table tr {
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    background: #fff;
  }

  table.responsive-table td,
  .data-table td {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border: none;
    font-size: 0.9rem;
  }

  table.responsive-table td::before,
  .data-table td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    margin-right: 8px;
    flex-shrink: 0;
  }

  /* ── Layout containers ───────────────────────────────────────────────────── */

  .container {
    padding-left: 16px;
    padding-right: 16px;
  }

  .two-col,
  .three-col,
  .grid-cols-2,
  .grid-cols-3 {
    grid-template-columns: 1fr !important;
  }

  /* ── Cards ───────────────────────────────────────────────────────────────── */

  .card,
  .stat-card,
  .judge-card {
    padding: 16px;
    margin-bottom: 12px;
  }

  /* ── Buttons ─────────────────────────────────────────────────────────────── */

  .btn {
    padding: 10px 18px;
    font-size: 1rem;
    border-radius: 6px;
  }

  .btn-group {
    flex-direction: column;
    gap: 8px;
  }

  .btn-group .btn {
    width: 100%;
  }

  /* ── Forms ───────────────────────────────────────────────────────────────── */

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    width: 100%;
    font-size: 16px; /* prevent iOS zoom */
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 6px;
  }

  /* ── Footer ──────────────────────────────────────────────────────────────── */

  .footer-shell {
    flex-direction: column;
    gap: 20px;
    padding: 24px 16px;
  }

  .footer-links {
    flex-wrap: wrap;
    gap: 12px;
  }
}

/* ── PWA install banner ───────────────────────────────────────────────────── */

#pwa-install-banner {
  display: none;
  position: fixed;
  /* Bottom toast — must NOT cover the top nav. (Was top:0 z:10000, which hid
     the entire site header on every page.) */
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, calc(100vw - 32px));
  border-radius: 12px;
  z-index: 900;
  background: #0a2540;
  color: #fff;
  padding: 12px 16px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-size: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

/* PWA install is only meaningful on touch / small screens. On desktop the
   beforeinstallprompt can still fire (Chrome), but the banner just clutters a
   pointer UI — hide it there. */
@media (min-width: 821px) and (pointer: fine) {
  #pwa-install-banner { display: none !important; }
}

#pwa-install-banner .pwa-banner-msg {
  flex: 1;
  font-weight: 500;
}

#pwa-install-banner .pwa-banner-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#pwa-install-banner .btn-install {
  background: #fff;
  color: #0a2540;
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  min-height: 36px;
}

#pwa-install-banner .btn-install:hover {
  background: #e2e8f0;
}

#pwa-install-banner .btn-dismiss {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: none;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
  min-height: 36px;
  min-width: 36px;
}

#pwa-install-banner .btn-dismiss:hover {
  color: #fff;
}
