/* Mobile layout: up to 767px. */
@media (max-width: 767px) {
  .map-shell {
    height: 100vh;
    height: 100svh;
    min-height: 100vh;
    min-height: 100svh;
    overflow: hidden;
  }

  .app-header {
    border-top-width: 3px;
  }

  .app-header.topbar-parent {
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
  }

  .title-bar {
    display: flex;
    align-items: center;
    padding: 8px 10px;
  }

  .title-bar h1 {
    font-size: 16px;
  }

  .topbar {
    min-height: 58px;
    gap: 8px;
    padding: 6px 10px;
  }

  .brand-block {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 8px;
  }

  .brand-logo {
    width: 58px;
    height: 34px;
  }

  .topbar h1 {
    font-size: 16px;
    line-height: 1.12;
  }

  .brand-subtitle {
    display: none;
  }

  .header-actions {
    gap: 4px;
  }

  .about-data-button {
    width: 32px;
    min-height: 32px;
    padding: 0;
  }

  .about-data-button > span:last-child {
    display: none;
  }

  .view-switch {
    padding: 2px;
  }

  .view-switch label {
    min-width: 58px;
    height: 30px;
    padding: 0 8px;
    font-size: 12px;
  }

  .filter-disclosure-summary {
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    color: var(--funasa-blue-dark);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
  }

  .filter-disclosure-summary::after {
    content: "+";
    color: var(--funasa-red);
    font-size: 19px;
    font-weight: 400;
  }

  .filter-disclosure.filter-open .filter-disclosure-summary::after {
    transform: rotate(45deg);
  }

  .filter-disclosure > .toolbar,
  .filter-disclosure > .table-controls {
    display: none !important;
  }

  .filter-disclosure.filter-open > .toolbar,
  .filter-disclosure.filter-open > .table-controls {
    display: grid !important;
  }

  .toolbar {
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
    grid-template-columns: 1fr;
    grid-template-areas:
      "municipality"
      "search"
      "source"
      "region"
      "uf"
      "year"
      "status"
      "program"
      "transfergov"
      "action"
      "pmsb"
      "clear";
    gap: 9px;
    padding: 8px 12px 12px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    border-top: 1px solid var(--border);
  }

  .filter-field .dash-dropdown,
  .Select-control,
  .search-field input,
  .reset-filters {
    min-height: 40px;
  }

  .filter-actions,
  .reset-filters {
    width: 100%;
  }

  .reset-filters {
    justify-content: center;
  }

  .metric-grid {
    min-height: 88px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    min-height: 44px;
    gap: 1px;
    padding: 6px 10px;
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(n + 3) {
    border-top: 1px solid var(--border);
  }

  .metric:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    border-right: 0;
  }

  .metric span {
    font-size: 9px;
  }

  .metric strong {
    font-size: 17px;
  }

  .map-workspace {
    grid-template-columns: 1fr;
    position: relative;
  }

  .map-context-bar {
    min-height: 58px;
    gap: 4px;
    padding: 6px 10px;
  }

  .map-context-main {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .map-result-label {
    font-size: 12px;
  }

  .map-legend {
    width: 100%;
    justify-content: flex-start;
    gap: 11px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .map-legend-item {
    font-size: 10px;
  }

  .map-marker-note {
    font-size: 9px;
  }

  .about-data-layer {
    place-items: end stretch;
  }

  .about-data-dialog {
    width: 100%;
    max-height: 86vh;
    max-height: 86svh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
    transform: translateY(24px);
  }

  .about-data-header {
    min-height: 62px;
    padding: 11px 14px;
  }

  .about-data-content {
    padding: 14px 15px 22px;
  }

  .about-definition-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .detail-panel {
    width: 100%;
    height: auto;
    max-height: 72%;
    position: absolute;
    inset: auto 0 0;
    z-index: 25;
    border-top: 1px solid var(--border-strong);
    border-left: 0;
    box-shadow: 0 -12px 34px rgba(23, 43, 58, 0.2);
  }

  .detail-sheet-handle {
    width: 100%;
    min-height: 48px;
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: var(--surface);
    border: 0;
    color: var(--funasa-blue-dark);
    cursor: pointer;
  }

  .detail-sheet-handle strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sheet-grip {
    width: 30px;
    height: 4px;
    display: block;
    border-radius: 2px;
    background: var(--border-strong);
  }

  .detail-panel > .detail-panel-body {
    display: none;
  }

  .detail-panel.sheet-open > .detail-panel-body {
    display: block;
    height: auto;
    max-height: calc(72vh - 48px);
    overflow: auto;
    padding: 16px 14px 22px;
  }

  .detail-content h2 {
    font-size: 20px;
  }

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

  .table-workspace {
    gap: 7px;
    padding: 8px 9px 10px;
  }

  .table-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "municipality municipality"
      "search search"
      "source source"
      "region uf"
      "year pmsb"
      "status status"
      "program program"
      "transfergov transfergov"
      "action action"
      "clear clear";
    gap: 8px;
    padding: 8px;
    max-height: none;
    overflow: visible;
  }

  .table-filter-actions,
  .table-reset-filters {
    width: 100%;
  }

  .table-reset-filters {
    min-height: 40px;
    justify-content: center;
  }

  .table-view-bar {
    margin-inline: 0;
  }

  .table-view-switch label {
    min-height: 36px;
    padding-inline: 12px;
    font-size: 11px;
  }

  .table-result-toolbar {
    min-height: 72px;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 6px;
    padding: 1px 0;
  }

  .table-summary {
    width: 100%;
    font-size: 12px;
  }

  .table-result-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .table-page-size-control label {
    display: none;
  }

  .table-export-button {
    min-height: 36px;
  }

  .desktop-table-shell {
    display: none;
  }

  .table-results {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .table-results.is-hidden {
    display: none;
  }

  .table-mobile-list {
    min-height: 0;
    display: grid;
    align-content: start;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
  }

  .table-mobile-row {
    width: 100%;
    min-width: 0;
    display: grid;
    gap: 7px;
    padding: 11px 12px;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: var(--surface);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
  }

  .table-mobile-row:last-child {
    border-bottom: 0;
  }

  .table-mobile-row:active,
  .table-mobile-row:focus-visible {
    background: var(--funasa-blue-soft);
  }

  .table-mobile-row-heading {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .table-mobile-name {
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 7px;
  }

  .table-mobile-name strong {
    min-width: 0;
    overflow: hidden;
    color: var(--funasa-blue-dark);
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table-mobile-name small {
    flex: 0 0 auto;
    color: var(--funasa-blue-dark);
    font-size: 11px;
    font-weight: 800;
  }

  .table-mobile-chevron {
    flex: 0 0 auto;
    color: var(--funasa-red);
    font-size: 23px;
    line-height: 1;
  }

  .table-mobile-actions {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    overflow: hidden;
  }

  .table-mobile-action {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 650;
    white-space: nowrap;
  }

  .table-mobile-action-dot {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    border-radius: 50%;
  }

  .table-mobile-metrics {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .table-mobile-metric {
    min-width: 0;
    display: grid;
    gap: 1px;
  }

  .table-mobile-metric span {
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table-mobile-metric strong {
    overflow: hidden;
    color: var(--text-primary);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table-mobile-pagination {
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 13px;
    padding-top: 7px;
  }

  .table-mobile-pagination button {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--funasa-blue);
    border-radius: 5px;
    background: var(--funasa-blue);
    color: #fff;
    font-size: 21px;
    cursor: pointer;
  }

  .table-mobile-pagination button:disabled {
    opacity: 0.38;
    cursor: default;
  }

  .table-mobile-pagination span {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
  }

  .table-empty-state.is-visible {
    min-height: 220px;
    padding: 24px 16px;
  }

  .table-detail-drawer {
    width: 100%;
    height: min(76vh, 640px);
    inset: auto 0 0;
    border-top: 1px solid var(--border-strong);
    border-left: 0;
    box-shadow: 0 -16px 36px rgba(23, 43, 58, 0.22);
    transform: translateY(102%);
  }

  .table-detail-layer.is-open .table-detail-drawer {
    transform: translateY(0);
  }

  .table-detail-content {
    padding: 15px 14px 22px;
  }
}

@media (max-width: 420px) {
  .topbar {
    gap: 6px;
  }

  .brand-block {
    grid-template-columns: 50px minmax(0, 1fr);
  }

  .brand-logo {
    width: 50px;
  }

  .topbar h1 {
    font-size: 15px;
  }

  .view-switch label {
    min-width: 52px;
    padding-inline: 6px;
  }
}
