/* Mobile-first layout for BGVS. Does not change PHP/MySQL behaviour. */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  overflow-x: hidden;
}
img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}
iframe, .survey-dash-map-canvas, #survey-map, .leaflet-container, .gm-style {
  max-width: 100%;
}
.table-wrap,
.card.table-wrap,
.stu-table-card,
.official-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
table {
  max-width: 100%;
}

@media (max-width: 1100px) {
  .chart-grid-8 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-8, .grid-4, .row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .app-header .brand {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
  }
  .nav-toggle {
    display: inline-flex;
    margin-left: auto;
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
  .header-nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    order: 5;
    gap: 6px;
    padding: 4px 0 8px;
    max-height: min(72vh, 560px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .app-shell.nav-open .header-nav {
    display: flex;
  }
  .app-shell.nav-open {
    overflow: hidden;
  }
  .header-nav a.nav-pill,
  .header-nav button.nav-pill,
  .nav-dropdown {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    justify-content: flex-start;
    padding: 0 14px;
  }
  .header-nav a.nav-pill.nav-logout,
  .header-nav a.nav-pill.nav-password {
    margin-left: 0;
    width: 100%;
  }
  .app-shell.is-field-user .nav-toggle { display: none !important; }
  .app-shell.is-field-user .header-nav.is-field-nav {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    width: auto;
    max-height: none;
    overflow: visible;
    order: 3;
    margin-left: auto;
    padding: 0;
  }
  .app-shell.is-field-user .header-nav.is-field-nav a.nav-pill {
    width: auto;
    min-width: 0;
    min-height: 38px;
    justify-content: center;
    padding: 0 12px;
  }
  .nav-dropdown {
    flex-direction: column;
  }
  .nav-dropdown-menu {
    position: static;
    display: none;
    min-width: 0;
    width: 100%;
    max-height: 240px;
    margin-top: 4px;
    box-shadow: none;
  }
  .nav-dropdown.open .nav-dropdown-menu,
  .nav-dropdown:hover .nav-dropdown-menu {
    display: block;
  }
  .nav-dropdown-menu a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

@media (max-width: 960px) {
  html { font-size: 16px; }
  input, select, textarea, button {
    font-size: 16px;
  }
  .id-card-page,
  .print-doc,
  .certificate-canvas,
  .experience-page {
    max-width: 100%;
    overflow-x: auto;
  }
  .more-drop .btn,
  .more-drop a.btn,
  .more-drop button.btn {
    min-height: 44px;
  }

  .content {
    padding: 10px;
  }
  .header-sub {
    padding: 8px 10px;
  }
  .header-sub h1 {
    font-size: 1rem;
  }

  .hub-nav,
  .survey-hub-row,
  .settings-hub-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .hub-nav a,
  .hub-nav-inline a {
    min-height: 44px;
    flex: 0 0 auto;
  }

  .grid-3, .grid-2, .row-3, .row-2, .row-4, .grid-4, .grid-8,
  .kv, .checkgrid, .chart-grid, .chart-grid-8,
  .survey-settings-split, .survey-create-grid,
  .form-section, .form-section-standalone {
    grid-template-columns: 1fr;
  }

  .survey-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters,
  .toolbar,
  .survey-output-filters.toolbar.filters,
  .survey-settings-form,
  .survey-place-title-form,
  .survey-report-filters {
    flex-wrap: wrap;
  }
  .filters input,
  .filters select,
  .toolbar input,
  .toolbar select,
  .survey-output-filters input,
  .survey-output-filters select {
    min-width: 0;
    width: 100%;
    flex: 1 1 140px;
    min-height: 44px;
  }
  .btn,
  .btn-sm,
  td.actions .btn {
    min-height: 44px;
    padding: 0 14px;
  }
  td.actions,
  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .survey-home,
  .survey-home-surveys {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .survey-home .survey-campaign-list {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    width: 100%;
    max-width: none;
    min-width: 0;
    overflow-x: auto;
  }
  .survey-home-surveys {
    flex: 1 1 auto;
  }
  .survey-home .survey-campaign-card {
    flex: 1 1 0;
    width: auto;
    min-width: 140px;
    min-height: 44px;
  }
  .survey-home .survey-report-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: visible;
  }
  .survey-home .survey-report-card {
    width: auto;
    flex: none;
    min-height: 110px;
  }

  .survey-team-add-table,
  .survey-team-title-form,
  .survey-team-form-panel {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .survey-team-form-grid {
    grid-template-columns: 1fr;
    min-width: 280px;
  }
  .survey-team-form-panel .survey-team-guardian-cell,
  .survey-team-form-span-2 { grid-column: 1 / -1; }
  .survey-team-action-group {
    max-width: none;
    flex-wrap: nowrap;
  }
  .survey-team-list-card,
  .survey-team-list {
    overflow-x: auto;
  }
  .survey-team-list td.actions {
    display: table-cell;
    flex-wrap: nowrap;
  }

  .survey-mobile-wrap.is-team-profile {
    padding: 0 0 12px;
  }
  .survey-mobile-wrap.is-team-profile .survey-phone {
    width: 100%;
    max-width: 420px;
    border-radius: 28px;
  }
  .team-profile-photo-wrap {
    width: 108px;
    height: 108px;
  }
  .team-profile-name { font-size: 1.22rem; }

  .modal-box,
  .survey-create-box {
    width: calc(100vw - 20px);
    max-width: 560px;
    margin: 10px auto;
    max-height: calc(100vh - 20px);
    overflow: auto;
  }

  .survey-dash-map,
  .survey-dash-map-canvas,
  #survey-map {
    width: 100%;
    height: 48vh;
    min-height: 240px;
  }

  .post-compose-row,
  .doc-upload-row,
  .doc-upload-row-org,
  .press-upload-row,
  .ebook-form-row,
  .centre-form-row,
  .msg-form-row {
    grid-template-columns: 1fr;
  }

  .login-wrap {
    min-height: 100vh;
  }
}

@media (max-width: 800px) {
  .survey-assign-grid {
    grid-template-columns: 1fr;
  }
  .survey-assign-form select[multiple] {
    min-height: 120px;
  }
  .survey-assign-table th,
  .survey-assign-table td {
    white-space: normal;
  }
}

@media (max-width: 640px) {
  .survey-stats,
  .survey-home .survey-report-grid {
    grid-template-columns: 1fr;
  }
  .chart-card {
    min-height: 220px;
  }
  .survey-hub-actions {
    width: 100%;
    margin-left: 0;
    justify-content: stretch;
  }
  .survey-hub-actions .btn {
    flex: 1 1 auto;
  }
  .login-panel {
    width: 100%;
    padding: 28px 16px 36px;
    padding-top: max(28px, env(safe-area-inset-top));
    align-items: flex-start;
    justify-content: flex-start;
    min-height: 100vh;
    box-shadow: none;
  }
  .login-card {
    max-width: 400px;
    margin: 0 auto;
  }
  .login-logo {
    width: 96px;
    height: 96px;
  }
}
