html.tables-open {
  overscroll-behavior: none;
}

.tables-modal[hidden] {
  display: none;
}

.tables-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  padding: clamp(1rem, 3vw, 2rem);
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.66);
  animation: tablesBackdropIn 220ms ease both;
}

.tables-modal__panel {
  position: relative;
  width: min(100%, 80rem);
  height: min(90dvh, 54rem);
  min-height: min(42rem, 90dvh);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border: 1px solid rgba(39, 46, 56, 0.14);
  border-radius: 1.5rem;
  background: var(--color-white);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.3);
  animation: tablesPanelIn 360ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.tables-modal__header {
  position: relative;
  padding: clamp(1.5rem, 3vw, 2.25rem) clamp(4.75rem, 7vw, 6.5rem)
    clamp(1.35rem, 2.5vw, 1.9rem) clamp(1.35rem, 3vw, 2.25rem);
  color: var(--color-white);
  background:
    radial-gradient(
      circle at 88% 10%,
      rgba(226, 74, 35, 0.18),
      transparent 34%
    ),
    var(--color-primary);
}

.tables-modal__eyebrow {
  width: fit-content;
  margin: 0 0 0.75rem;
  color: var(--color-secondary);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.tables-modal__title {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(2.6rem, 5vw, 4.8rem);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  transform: skewX(-6deg);
  transform-origin: left center;
}

.tables-modal__intro {
  max-width: 46rem;
  margin: 0.9rem 0 0;
  color: var(--color-text-light-muted);
  font-size: clamp(0.94rem, 1.25vw, 1.06rem);
  font-weight: 500;
  line-height: 1.55;
}

.tables-modal__close {
  position: absolute;
  top: clamp(1.1rem, 2vw, 1.5rem);
  right: clamp(1.1rem, 2vw, 1.5rem);
  width: 3rem;
  height: 3rem;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--color-border-light-soft);
  border-radius: var(--radius-full);
  color: var(--color-white);
  background: rgba(0, 0, 0, 0.18);
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    transform var(--transition-fast),
    border-color var(--transition-fast),
    background-color var(--transition-fast);
}

.tables-modal__close svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.tables-modal__controls {
  padding: 1.15rem clamp(1.35rem, 3vw, 2.25rem);
  display: grid;
  grid-template-columns: minmax(14rem, 20rem) minmax(0, 1fr);
  align-items: end;
  gap: clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--color-border-soft);
  background: var(--color-white);
}

.tables-modal__field {
  display: grid;
  gap: 0.5rem;
}

.tables-modal__label {
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.tables-modal__select-wrap {
  position: relative;
}

.tables-modal__select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 1rem;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.tables-modal__select {
  width: 100%;
  min-height: 3.15rem;
  padding: 0.8rem 2.8rem 0.8rem 1rem;
  border: 1px solid var(--color-border-soft);
  border-radius: 0.85rem;
  color: var(--color-primary);
  background: var(--color-gray-light);
  font-family: var(--font-body);
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.2;
  appearance: none;
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    background-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.tables-modal__select:disabled {
  cursor: wait;
  opacity: 0.65;
}

.tables-modal__current {
  min-width: 0;
  display: grid;
  justify-items: end;
  gap: 0.28rem;
  text-align: right;
}

.tables-modal__current strong {
  max-width: 100%;
  overflow: hidden;
  color: var(--color-primary);
  font-size: clamp(1rem, 1.6vw, 1.18rem);
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tables-modal__current span {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
}

.tables-modal__body {
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: grid;
  background: var(--color-gray-light);
}

.tables-modal__status {
  place-self: center;
  width: min(100% - 2rem, 34rem);
  padding: 1.5rem;
  border: 1px solid var(--color-border-soft);
  border-radius: 1rem;
  color: var(--color-text-muted);
  background: var(--color-white);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.06);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.55;
  text-align: center;
}

.tables-modal__status[data-state="loading"]::before {
  content: "";
  width: 1.4rem;
  height: 1.4rem;
  margin: 0 auto 0.8rem;
  display: block;
  border: 2px solid rgba(39, 46, 56, 0.16);
  border-top-color: var(--color-secondary);
  border-radius: 50%;
  animation: tablesSpinner 700ms linear infinite;
}

.tables-modal__status[data-state="error"] {
  border-color: rgba(226, 74, 35, 0.28);
  color: var(--color-primary);
}

.tables-modal__table-wrap {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

.tables-modal__table {
  width: 100%;
  min-width: max(100%, 44rem);
  border-spacing: 0;
  border-collapse: separate;
  color: var(--color-primary);
  background: var(--color-white);
  font-size: 0.88rem;
  line-height: 1.4;
}

.tables-modal__table th,
.tables-modal__table td {
  min-width: 7rem;
  padding: 0.9rem 1rem;
  border-right: 1px solid rgba(39, 46, 56, 0.09);
  border-bottom: 1px solid rgba(39, 46, 56, 0.09);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.tables-modal__table th {
  position: sticky;
  top: 0;
  z-index: 4;
  color: var(--color-white);
  background: var(--color-primary);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.tables-modal__table th:first-child {
  left: 0;
  z-index: 6;
}

.tables-modal__table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--color-white);
  font-weight: 700;
}

.tables-modal__table tbody tr:nth-child(even) td {
  background: rgba(39, 46, 56, 0.025);
}

.tables-modal__table tbody tr:nth-child(even) td:first-child {
  background: #f9f9fa;
}

.tables-modal__table td.is-numeric {
  font-variant-numeric: tabular-nums;
}

@media (hover: hover) and (pointer: fine) {
  .tables-modal__close:hover {
    transform: rotate(4deg) scale(1.03);
    border-color: var(--color-border-light-strong);
    background: rgba(0, 0, 0, 0.3);
  }

  .tables-modal__select:hover {
    border-color: var(--color-border-strong);
  }

  .tables-modal__table tbody tr:hover td {
    background: rgba(226, 74, 35, 0.045);
  }

  .tables-modal__table tbody tr:hover td:first-child {
    background: #fff8f6;
  }
}

.tables-modal__close:active {
  transform: scale(0.98);
}

.tables-modal__select:focus-visible {
  border-color: var(--color-secondary);
  outline: 3px solid rgba(226, 74, 35, 0.2);
  outline-offset: 2px;
}

@keyframes tablesBackdropIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes tablesPanelIn {
  from {
    opacity: 0;
    transform: translate3d(0, 18px, 0) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes tablesSpinner {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  .tables-modal {
    padding: 0;
    place-items: stretch;
  }

  .tables-modal__panel {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .tables-modal__header {
    padding: max(1.25rem, env(safe-area-inset-top)) 4.7rem 1.25rem 1.15rem;
  }

  .tables-modal__close {
    top: max(0.85rem, env(safe-area-inset-top));
    right: 0.9rem;
  }

  .tables-modal__title {
    font-size: clamp(2.45rem, 12vw, 4rem);
  }

  .tables-modal__intro {
    margin-top: 0.7rem;
    font-size: 0.9rem;
  }

  .tables-modal__controls {
    padding: 1rem 1.15rem;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 0.8rem;
  }

  .tables-modal__current {
    justify-items: start;
    text-align: left;
  }

  .tables-modal__current strong {
    white-space: normal;
  }

  .tables-modal__table {
    min-width: max(100%, 40rem);
    font-size: 0.82rem;
  }

  .tables-modal__table th,
  .tables-modal__table td {
    min-width: 6.5rem;
    padding: 0.82rem 0.85rem;
  }

  .tables-modal__table th {
    font-size: 0.71rem;
  }
}

@media (max-width: 420px) {
  .tables-modal__header {
    padding-left: 1rem;
  }

  .tables-modal__controls {
    padding-inline: 1rem;
  }

  .tables-modal__select {
    min-height: 3rem;
    font-size: 0.9rem;
  }

  .tables-modal__status {
    font-size: 0.9rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tables-modal,
  .tables-modal__panel,
  .tables-modal__close,
  .tables-modal__select {
    animation: none;
    transition: none;
  }

  .tables-modal__status[data-state="loading"]::before {
    animation-duration: 1.4s;
  }
}
