/* ============================================================
   1. Base Layout
   ============================================================ */

html,
body {
  height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
}

calcite-shell {
  height: 100%;
  width: 100%;
  display: flex;
}

#mapContainer {
  position: relative;
  flex: 1;
  height: 100%;
  width: 100%;
  overflow: hidden;
  z-index: 0;
}

#viewDiv {
  flex: 1;
  height: 100%;
  position: relative;
  z-index: 1;
}

#viewDiv:focus {
  outline: none;
  border: none;
}

#mobileLayout {
  display: flex;
  flex-direction: row;
  height: 100%;
  width: 100%;
}

/* ============================================================
   2. Calcite Shell Panel Sizing (using CSS variables)
   ============================================================ */

/* Action bar panel (first panel-start) */
calcite-shell-panel[slot="panel-start"]:nth-of-type(1) {
  --calcite-shell-panel-width: 60px;
  --calcite-shell-panel-min-width: 60px;
  --calcite-shell-panel-max-width: 60px;
  --calcite-shell-panel-height: 100%;
  --calcite-shell-panel-min-height: 100%;
  --calcite-shell-panel-max-height: 100%;
  --calcite-shell-panel-z-index: 1;
}

/* Sidebar panel (second panel-start) */
calcite-shell-panel[slot="panel-start"]:nth-of-type(2) {
  --calcite-shell-panel-width: 350px;
  --calcite-shell-panel-min-width: 0;
  --calcite-shell-panel-max-width: 350px;
  --calcite-shell-panel-height: 100%;
  --calcite-shell-panel-min-height: 100%;
  --calcite-shell-panel-max-height: 100%;
  --calcite-shell-panel-z-index: 1;
}

/* Collapsed states */
calcite-shell-panel[slot="panel-start"]:nth-of-type(2).collapsed {
  --calcite-shell-panel-width: 0px;
  --calcite-shell-panel-min-width: 0px;
  --calcite-shell-panel-max-width: 0px;
}

/* Make internal container full-height flex */
calcite-shell-panel::part(container) {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Allow tooltips to escape the action bar panel */
calcite-shell-panel[slot="panel-start"]:nth-of-type(1)::part(container) {
  overflow: visible !important;
}

/* ============================================================
   3. Action Bar
   ============================================================ */

#actionBar {
  width: 60px;
  min-width: 60px;
  max-width: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;
  background-color: var(--calcite-ui-foreground);
  height: 100%;
  flex: 1 1 auto;
  overflow: visible !important
}

.custom-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 60px;
  height: 52px;
  gap: 4px;
  transition: background-color 0.2s ease;
  font-size: 12px;
  color: var(--calcite-ui-text-2);
}

.custom-action:hover {
  background-color: var(--calcite-ui-foreground-hover, #eaeaea);
}

.custom-label {
  font-size: 0.7em;
  text-align: center;
  line-height: 1;
}

.action-spacer {
  flex: 1 1 auto;
  width: 100%;
}

.action-bg {
  --calcite-action-background-color: transparent;
  background-image: url('../images/logo.png');
  background-size: 44px;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
}

/* ============================================================
   4. Sidebar
   ============================================================ */

.sidebar {
  flex-basis: 350px;
  max-width: 350px;
  min-width: 0;
  flex-shrink: 0;
  height: 100%;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  outline: 1px #e5e5e5 solid;
  transition: flex-basis 0.3s ease;
  z-index: 2;
}

.sidebar.collapsed {
  flex-basis: 0;
  max-width: 0;
  transition: max-width 2s ease;
}

#sideContent {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  border: 1px solid #eadede;
}

/* Sidebar toggle tab */
.tab {
  position: absolute;
  top: 30px;
  right: 0;
  transform: translate(100%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 4px;
  background: #ffffff;
  color: #615c5c;
  border: 1px solid #e5e5e5;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  z-index: 3;
  transition: background 0.2s, transform 0.3s ease;
}

/* Rotate icon when collapsed */
.tab[aria-expanded="false"] calcite-icon {
  transform: rotate(180deg);
  transition: transform 0.3s ease;
}

#count-display {
  margin-top: -8px;
  font-size: 13px;
  font-weight: 700;
  justify-content: center;
  align-items: center;
  display: flex;
}

.count {
  color: #1d8da2;
  -webkit-text-stroke: 1px #1d8da2;
  letter-spacing: -1px;
  font-size: 18px;
  font-weight: 500;
  margin-left: 2px;
  margin-right: 4px;
}

#intro {
  text-align: left;
}

/* Example highlight style */
.table-row-selected {
  background-color: rgba(255, 0, 0, 0.15) !important;
  border-left: 4px solid red !important;
  transition: background-color 0.3s ease;
}

/* Optional: ensure the transition is smooth */
tr {
  transition: background-color 0.2s ease;
}

/* ============================================================
   5. Map Controls
   ============================================================ */

#viewInfo {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #ffffffa3;
  z-index: 10;
  font-weight: 700;
  font-size: 12px;
  border-radius: 4px;
  text-align: center;
  min-width: 200px;
}

#coordinate-display,
#scale-display {
  display: block;
  font-size: 10px;
}

#loader {
  position: absolute;
  --calcite-loader-size: 20px;
  --calcite-loader-progress-color: #1d8da2;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#loader:not([active]) {
  display: none;
}

/* ============================================================
   6. Dark Mode
   ============================================================ */

.calcite-mode-dark .tab,
.calcite-mode-dark #viewInfo {
  background: #2b2b2b;
  color: #ffffff;
  border-color: #c7c7c7;
}

/* ============================================================
   7. Radio Button Group
   ============================================================ */
.radio-button-group,
.infoBar {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-left: -4px;
}

calcite-radio-button {
  margin-right: -6px;
  margin-top: -2px;
  --calcite-ui-focus-color: none !important;
}

calcite-radio-button-group {
  font-weight: 500;
}

calcite-label {
  margin-right: -4px;
}

.radioFed,
.radioState,
.radioEd {
  margin-left: -12px;
  margin-right: -8px;
  margin-top: -1px;
}

.radioState {
  color: #e5975e;
}

.radioFed {
  color: #9c84a3
}

.radioEd {
  color: #1d8da2
}

/* ============================================================
   8. Checkbox Styles
   ============================================================ */
.checkbox-row {
  display: flex;
  justify-content: center;
  align-items: center;
  --calcite-checkbox-size: 12px;
  --calcite-checkbox-border-color: #888888;
  --calcite-checkbox-border-color-hover: #555555;
  --calcite-checkbox-icon-color: #ffffff;
  font-weight: 500;
  letter-spacing: -0.06em;
  gap: 10px;
  padding-top: 2px;
}

calcite-checkbox {
  margin-right: -5px;
  margin-top: -2px;
  --calcite-ui-focus-color: none !important;
}
.checkbox-icon {
    margin-left: -5px;
    inline-size: 10px;
    block-size: 10px;
    min-inline-size: 10px;
    min-block-size: 10px;
}

/* ============================================================
   9. Sort button Styles
   ============================================================ */
#sort-buttons {
  padding-bottom: 3px;
  text-align: center;
  --calcite-chip-text-color: rgb(0, 0, 0);
  --calcite-chip-corner-radius: 0px;
  --calcite-chip-background-color: transparent;
  font-weight: 700;
}

#sort-buttons calcite-chip {
  --calcite-chip-corner-radius: 2px;
  --calcite-chip-background-color: #b9b8b3;
  opacity: 0.3;
  min-width: 76px;
  background: #b9b8b3;
  justify-content: center;
  cursor: pointer;
}

#sort-buttons .active {
  --calcite-chip-text-color: white;
  --calcite-chip-background-color: #007ac2;
  background: #007ac2;
  opacity: 1;
}

/* ============================================================
   10. Records Table Styles
   ============================================================ */
.custom-list {
  margin: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.map-list-filter {
  padding: 5px 10px 5px 10px;
  font-size: 1em;
}

.map-list-ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid #4c4c4c54;
}

.map-list-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 4px 5px 4px 5px;
  border-bottom: 1px solid #4c4c4c54;
  background: transparent;
  transition: background 0.2s;
  cursor: pointer !important;
}

.no-info {
  font-size: 10px;
  color: #787878;
  white-space: normal;
  line-height: 13px;
  text-align: center;
}

.map-list-item:hover {
  background-color: rgba(53, 86, 127, .25);
}

.header {
  color: #5e5858;
}

.map-list-avatar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 94px;
  height: 94px;
}

.map-list-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  width: 100%;
}

.map-list-info {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 16px;
}

.map-list-desc {
  font-size: 11px;
  color: #232323;
  white-space: normal;
  font-weight: 700;
}

/* Right column: full height + centered icons */
.map-list-actions-vertical {
  flex: 0 0 30px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.custom-action.btn-locate,
.custom-action.btn-fix {
  width: 30px;
  height: 42px;
  color: #585858;
}

.custom-action.btn-locate:hover,
.custom-action.btn-fix:hover {
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 5px
}

/* =========================
   Esri Overrides
   ========================= */

calcite-tooltip {
  pointer-events: none;
}

calcite-action-bar,
calcite-shell-panel,
calcite-link,
calcite-action,
calcite-button,
calcite-panel {
  outline: none !important;
  --calcite-ui-focus-color: none !important;
}

calcite-button:focus,
calcite-input:focus {
  outline: none !important;
}

arcgis-zoom {
  margin-top: 50px;
}

/* =========================
   Selection Prevention
   ========================= */
#intro,
#actionBar,
.count-display,
.map-list-item,
.themeInfo,
.map-list-info,
.map-list-desc {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  cursor: default;
}

.map-list-item, 
.map-list-item *,
.custom-action,
.btn-locate,
.btn-fix {
  cursor: pointer !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

/* Allow selection for the email */
.map-list-item calcite-link {
  user-select: text;
  -webkit-user-select: text;
}

/* Prevent selection of map UI elements */
#viewDiv,
.esri-ui,
.esri-scale-bar,
.esri-attribution {
  user-select: none;
  -webkit-user-select: none;
}

/* =========================
   Responsive Layout
   ========================= */

/* Desktop action bar visible by default */
.desktop-action-bar {
  display: flex;
}

/* =========================
   Mobile Layout
   ========================= */
@media (max-width: 700px) {

  /* Hide desktop-only UI */
  .desktop-action-bar,
  .desktop-element {
    display: none !important;
  }

  #intro {
    text-align: center;
  }

  .mobile-map-widgets {
    display: block !important;
  }

  /* Mobile layout container */
  #mobileLayout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  /* Map takes top half by default */
  #mapContainer {
    flex: 1 1 50vh;
    height: 50vh;
    min-height: 50vh;
    order: 1;
    z-index: 0;
    transition: height 0.5s ease;
  }

  /* Map when sidebar collapsed*/
  #mapContainer.fullscreen {
    height: 100vh !important;
    min-height: 100vh !important;
    flex: 0 0 100vh !important;
  }

  /* Sidebar mobile*/
  #sidebarPanel,
  .sidebar {
    max-width: 100%;
    flex: 1 1 50vh;
    height: 50vh;
    min-height: 50vh;
    order: 2;
    z-index: 1;
  }

  /* Calcite shell panel full width */
  calcite-shell-panel[slot="panel-start"]:nth-of-type(2) {
    --calcite-shell-panel-width: 100%;
    --calcite-shell-panel-max-width: 100%;
  }

  /* Disable desktop collapse */
  .sidebar {
    max-width: 100% !important;
    flex-basis: auto !important;
    transition: none !important;
  }

  .sidebar.collapsed {
    max-width: 100% !important;
    flex-basis: auto !important;
    transition: none !important;
  }

  /* Mobile collapse */
  .sidebar {
    max-height: 50vh;
    transition: max-height 0.7s ease !important;
    overflow: hidden;
  }

  .sidebar.collapsed {
    max-height: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
  }

  /* Default mobile tab position */
  .tab {
    position: absolute !important;
    top: -37px !important;
    right: 28px !important;
    left: auto !important;
    transform: rotate(270deg);
    border-radius: 0;
    z-index: 9999;
    margin: 0;
    border-radius: 0px 4px 4px 0px;
  }

  .sidebar.collapsed .tab,
  .tab[aria-expanded="false"] {
    position: fixed !important;
    top: auto !important;
    bottom: -12px !important;
    right: 28px !important;
    transform: rotate(270deg);
    z-index: 9999;
  }

  /* Zoom widget spacing */
  arcgis-zoom {
    margin-top: 0px;
  }
}