:root {
  --tg-bg: #121212;
  --tg-text: #f2f2f2;
  --tg-hint: #9a9a9a;
  --tg-secondary-bg: #1c1d1f;
  --brand-accent: #c1f600;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

#tabs {
  display: flex;
  gap: 6px;
  padding: 10px 8px;
  overflow-x: auto;
  background: var(--tg-secondary-bg);
}

.tab {
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  min-height: 40px;
  display: flex;
  align-items: center;
  background: transparent;
  color: var(--tg-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.tab:active {
  transform: scale(0.96);
}

.tab.active {
  background: var(--brand-accent);
  color: #191919;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

#control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--tg-bg);
  border-bottom: 1px solid var(--tg-secondary-bg);
}

#filter-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.filter-icon {
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--brand-accent);
  color: #191919;
  font-size: 11px;
  font-weight: 700;
  padding: 0 5px;
}

#result-count {
  font-size: 12px;
  color: var(--tg-hint);
  font-weight: 600;
}

#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11px;
  color: var(--tg-hint);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-compact {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--tg-hint);
}

#grid {
  padding: 10px 8px;
  width: 100%;
}

.skeleton-row {
  height: 40px;
  margin-bottom: 6px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--tg-secondary-bg) 25%, #e4e4e4 37%, var(--tg-secondary-bg) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.floor-row {
  display: grid;
  grid-template-columns: 24px repeat(var(--cols), minmax(0, 1fr));
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.floor-label {
  font-size: 14px;
  font-weight: 800;
  color: var(--brand-accent);
  text-align: right;
  padding-right: 2px;
}

.cell {
  min-width: 0;
  width: 100%;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.cell:active {
  transform: scale(0.92);
}

.cell.empty {
  background: transparent;
  cursor: default;
}

.overflow-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 2px 0 8px 28px;
}

.overflow-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px dashed var(--tg-hint);
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.status-free {
  background: var(--brand-accent);
  border: 1px solid var(--brand-accent);
  color: #191919;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.status-sold {
  background: #e0e0e0;
  color: #9a9a9a;
}

.status-reserved {
  background: #c4c4c4;
  color: #5f5f5f;
}

.status-deposit {
  background: #9e9e9e;
  color: #ffffff;
}

.cell.dimmed,
.overflow-chip.dimmed,
.floor-dimmed .cell:not(.empty),
.floor-dimmed .overflow-chip {
  opacity: 0.35;
  filter: grayscale(40%);
  cursor: default;
}

.cell.dimmed:active,
.floor-dimmed .cell:active {
  transform: none;
}

#status-message {
  padding: 32px 16px;
  text-align: center;
  color: var(--tg-hint);
  font-size: 13px;
}

#status-message:empty {
  padding: 0;
}

/* Overlays (detail modal + filter sheet share this scrim) */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  /* Touches on the dim scrim must not scroll the page behind it. */
  touch-action: none;
}

/* Locks the page behind an open sheet/modal so it can't swipe up-down. */
.scroll-locked {
  overflow: hidden;
}

.overlay--bottom {
  align-items: flex-end;
  padding: 0;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes sheetIn {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.sheet {
  background: var(--tg-bg);
  color: var(--tg-text);
  position: relative;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  /* Keep the sheet's own scroll from chaining to the page behind it. */
  overscroll-behavior: contain;
}

.sheet--modal {
  border-radius: 14px;
  padding: 18px;
  max-width: 360px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.18s ease;
}

.sheet--bottom {
  border-radius: 16px 16px 0 0;
  padding: 0 18px 24px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: sheetIn 0.2s ease;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--tg-hint);
  opacity: 0.4;
  /* Visible bar stays 36x4, but padding gives a finger-sized drag target. */
  margin: 0 auto;
  padding: 12px 28px;
  box-sizing: content-box;
  background-clip: content-box;
  touch-action: none;
  cursor: grab;
}

.sheet-title {
  font-size: 16px;
  margin: 4px 28px 8px 0;
}

.sheet-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: none;
  background: var(--brand-accent);
  color: #191919;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

#modal-content h2 {
  font-size: 16px;
  margin: 0 4px 4px 0;
  padding-right: 24px;
}

#modal-content dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 12px 0;
}

#modal-content dt {
  color: var(--tg-hint);
}

#modal-content dd {
  margin: 0;
  font-weight: 600;
}

.floor-plan {
  width: 100%;
  border-radius: 8px;
  margin-top: 8px;
}

/* Filter sheet controls */

.filter-section {
  margin: 18px 0;
}

.filter-section--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.filter-label {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  min-height: 40px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  background: var(--brand-accent);
  color: #191919;
}

.range-values {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--tg-hint);
  margin-bottom: 10px;
}

.range-track {
  position: relative;
  height: 28px;
  touch-action: none;
}

.range-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  border-radius: 2px;
  background: var(--tg-secondary-bg);
  transform: translateY(-50%);
}

.range-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  border-radius: 2px;
  background: var(--brand-accent);
  transform: translateY(-50%);
}

.range-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  border-radius: 50%;
  background: var(--tg-bg);
  border: 2px solid var(--brand-accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transform: translateY(-50%);
  /* Custom-built drag (not a native <input type="range">) so there's no
     WebView-specific widget quirk to fight - this is the one CSS property
     that still matters: without it, a slightly diagonal drag can get
     reinterpreted as a page scroll mid-gesture instead of moving the thumb. */
  touch-action: none;
  transition: transform 0.1s ease;
}

.range-thumb.dragging {
  transform: translateY(-50%) scale(1.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.range-thumb:focus-visible {
  outline: 2px solid var(--brand-accent);
  outline-offset: 2px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--tg-secondary-bg);
  border-radius: 999px;
  transition: background 0.15s ease;
}

.switch-track::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--tg-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
  background: var(--brand-accent);
}

.switch input:checked + .switch-track::before {
  transform: translateX(20px);
}

.switch-label {
  font-size: 14px;
  font-weight: 600;
}

#filter-reset {
  width: 100%;
  border: 1px solid var(--tg-hint);
  background: transparent;
  color: var(--tg-text);
  border-radius: 10px;
  padding: 10px;
  min-height: 40px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

/* Wins the cascade tie against .overlay/.badge's own `display` regardless
   of how many other classes share the element - must stay the last rule. */
.hidden {
  display: none;
}
