/* Bootstrap table curved scrollbar + desktop/mobile table layout */

.cm-map-table-scroll {
  flex: 1 1 auto;
  min-height: 140px;
  position: relative;
  --card-border-radius: 12px;
  --thumb-color: var(--cm-primary, #007A33);
  --thumb-color-active: var(--cm-accent-end, #764ba2);
}

/* Absolute scroll-content needs an explicit box — never allow 0-height collapse */
body.map-page #table-container .cm-map-table-scroll.scroll-container {
  flex: 1 1 auto !important;
  min-height: 140px !important;
  position: relative !important;
  overflow: hidden !important;
}

.cm-map-table-scroll.has-scrollbar-x .scroll-content,
.cm-map-table-scroll[data-scrollbar="xy"] .scroll-content {
  overflow-x: hidden !important;
}

#table-container {
  flex-direction: column;
}

#table-container .bootstrap-table {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

#table-container .fixed-table-container {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

/* —— Desktop layout: map + optional bottom table —— */
@media (min-width: 769px) {
  html.map-page-root,
  html.map-page-root body.map-page,
  body.map-page {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  body.map-page {
    display: flex !important;
    flex-direction: column;
    box-sizing: border-box;
  }

  body.map-page #map-container {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    position: relative;
  }

  body.map-page #table-container {
    flex: 0 0 auto;
    position: relative;
    width: 100%;
    height: auto !important;
    max-height: min(42vh, calc(100dvh - var(--cm-map-header-h, 66px) - 160px));
    min-height: 0;
    overflow: hidden;
    display: none !important;
    flex-direction: column;
    z-index: 20;
    background: var(--cm-surface, #fff);
    border-top: 1px solid var(--cm-border, rgba(0, 0, 0, 0.08));
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.08);
    padding: 0 !important;
  }

  body.map-page #table-container.is-visible,
  body.map-page.cm-view-split #table-container,
  body.map-page.cm-view-table #table-container {
    display: flex !important;
    min-height: 300px;
    max-height: min(46vh, calc(100dvh - var(--cm-map-header-h, 66px) - 120px));
  }

  body.map-page.cm-view-map #table-container {
    display: none !important;
  }

  body.map-page #table-container.is-table-only,
  body.map-page.cm-view-table #table-container {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
  }

  body.map-page.cm-view-table #map-container {
    display: none !important;
  }

  body.map-page #table-container #toolbar {
    flex-shrink: 0;
  }

  body.map-page #table-container .fixed-table-toolbar {
    flex-shrink: 0;
    display: block !important;
  }

  body.map-page #table-container .bootstrap-table {
    flex: 1 1 auto;
    max-height: none;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  /* The container is the scroll host; bootstrap-table's fixed-header mode is
     unused on desktop (it double-counted the toolbar and squashed the body). */
  body.map-page #table-container .fixed-table-container {
    display: block !important;
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
    max-height: none !important;
    padding-bottom: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    border: 0 !important;
  }

  body.map-page #table-container .fixed-table-header {
    display: none !important;
  }

  body.map-page #table-container .fixed-table-body {
    display: block !important;
    flex: 0 0 auto;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* Real header row stays put while the container scrolls */
  body.map-page #table-container .fixed-table-body > table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 3;
    height: auto !important;
    padding: 0 !important;
    line-height: 1.35 !important;
    overflow: hidden !important;
    border: 0 !important;
    border-bottom: 1px solid var(--cm-border, rgba(0, 0, 0, 0.1)) !important;
    background: var(--cm-surface-2, #f3f7f5) !important;
  }

  body.map-page #table-container .fixed-table-body > table > thead th .th-inner {
    visibility: visible !important;
    height: auto !important;
    padding: 10px 12px !important;
    line-height: 1.35 !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--cm-text-muted, #556);
    white-space: nowrap;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  [data-theme="dark"] body.map-page #table-container .fixed-table-body > table > thead > tr > th {
    background: rgba(255, 255, 255, 0.04) !important;
  }

  [data-theme="dark"] body.map-page #table-container .fixed-table-body > table > thead th .th-inner {
    color: var(--cm-text-muted, #9db0a6);
  }

  /* Legacy curved wrap (if any leftover) — unwrap via JS; keep safe mins */
  body.map-page #table-container .cm-map-table-scroll {
    flex: 1 1 auto !important;
    min-height: 140px !important;
    position: relative !important;
    overflow: hidden !important;
  }

  body.map-page #table-container .cm-map-table-scroll > .fixed-table-body.scroll-content {
    position: relative !important;
    inset: auto !important;
    height: 100% !important;
    overflow-y: auto !important;
  }

  body.map-page #table-container .fixed-table-pagination {
    flex-shrink: 0;
    margin: 0;
    padding: 6px 10px 10px;
    background: var(--cm-surface-2, #f7faf8);
    border-top: 1px solid var(--cm-border, rgba(0, 0, 0, 0.06));
  }

  .mobile-table-handle {
    display: none !important;
  }
}

.cm-table-failure {
  margin: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(244, 67, 54, 0.1);
  border: 1px solid rgba(244, 67, 54, 0.35);
  color: #b3261e;
  font-size: 13px;
}

.cm-bootstrap-table-scroll {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

.cm-bootstrap-table-scroll::-webkit-scrollbar {
  display: none !important;
}

/*
 * Curved-scrollbar default padding on .scroll-content misaligns
 * bootstrap-table fixed header vs body columns — keep table flush.
 */
body.map-page #table-container .cm-map-table-scroll > .scroll-content,
body.map-page #table-container .cm-map-table-scroll .fixed-table-body.scroll-content {
  padding: 0 !important;
}

body.map-page #table-container .fixed-table-header {
  margin-right: 0 !important;
  overflow: hidden;
}

body.map-page #table-container .fixed-table-container,
body.map-page #table-container .fixed-table-header,
body.map-page #table-container .fixed-table-body,
body.map-page #table-container .cm-map-table-scroll,
body.map-page #table-container .cm-map-table-scroll > .scroll-content {
  overflow-x: hidden !important;
  max-width: 100%;
}

body.map-page #table-container .fixed-table-header table,
body.map-page #table-container .fixed-table-body table,
body.map-page #table-container .bootstrap-table .table {
  table-layout: fixed !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  border-collapse: collapse !important;
}

body.map-page #table-container .fixed-table-header th,
body.map-page #table-container .fixed-table-body td,
body.map-page #table-container .fixed-table-body th {
  box-sizing: border-box !important;
  min-width: 0 !important;
}

body.map-page #table-container .fixed-table-header thead th .th-inner {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap;
  max-width: 100%;
}

body.map-page #table-container .fixed-table-body tbody td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle !important;
}

/* Shortcuts column: keep icons visible, fixed narrow share */
body.map-page #table-container .fixed-table-header thead th:first-child,
body.map-page #table-container .fixed-table-body thead th:first-child,
body.map-page #table-container .fixed-table-body tbody td:first-child {
  width: 92px !important;
  max-width: 92px !important;
  min-width: 80px !important;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

/* Action column must show both icons — allow wrap, no ellipsis */
body.map-page #table-container .fixed-table-body tbody td:has(a.zoom),
body.map-page #table-container .fixed-table-body tbody td:has(a.identify) {
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

/* Zoom / info actions: larger hit targets, no black focus ring */
body.map-page #table-container a.zoom,
body.map-page #table-container a.identify {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin: 0 2px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: var(--cm-primary, #667eea);
  text-decoration: none !important;
  border: none !important;
  border-radius: 8px;
  outline: none !important;
  box-shadow: none !important;
  -webkit-tap-highlight-color: transparent;
  vertical-align: middle;
}

body.map-page #table-container a.zoom:hover,
body.map-page #table-container a.identify:hover {
  background: rgba(102, 126, 234, 0.12);
  color: var(--cm-primary-dark, #007A33);
}

body.map-page #table-container a.zoom:focus,
body.map-page #table-container a.identify:focus,
body.map-page #table-container a.zoom:active,
body.map-page #table-container a.identify:active,
body.map-page #table-container a.zoom:focus-visible,
body.map-page #table-container a.identify:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}

body.map-page #table-container a.zoom i,
body.map-page #table-container a.identify i {
  font-size: 18px;
  line-height: 1;
  pointer-events: none;
}

[data-theme="dark"] body.map-page #table-container a.zoom,
[data-theme="dark"] body.map-page #table-container a.identify {
  color: #c4b5fd;
}

[data-theme="dark"] body.map-page #table-container a.zoom:hover,
[data-theme="dark"] body.map-page #table-container a.identify:hover {
  background: rgba(118, 75, 162, 0.14);
  color: #a8ffc4;
}

/* Overview pages (no GeoJSON table pipeline) */
body.map-page[data-cm-has-table="0"] #table-container {
  display: none !important;
}

body.map-page[data-cm-has-table="0"].cm-view-split #table-container,
body.map-page[data-cm-has-table="0"].cm-view-table #table-container {
  display: none !important;
}

/* Mobile parcel list — override desktop table rules loaded above */
@media (max-width: 768px) {
  body.map-page #table-container #toolbar,
  body.map-page #table-container .bootstrap-table #toolbar {
    display: none !important;
  }

  body.map-page #table-container .fixed-table-header {
    display: none !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  body.map-page #table-container .fixed-table-toolbar:not(#mobile-table-search .fixed-table-toolbar) {
    display: none !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  body.map-page #table-container .fixed-table-header table,
  body.map-page #table-container .fixed-table-body table,
  body.map-page #table-container .bootstrap-table .table {
    table-layout: auto !important;
  }

  body.map-page #table-container .fixed-table-body tbody td {
    white-space: normal !important;
    text-overflow: clip !important;
    overflow: visible !important;
  }

  body.map-page #table-container .fixed-table-body > table > thead > tr > th {
    height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    line-height: 0 !important;
    overflow: hidden !important;
  }
}
