body {
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}

body:not(.peer-public-page) {
  background-color: var(--bs-light, #f8f9fa);
}

.table code {
  font-size: 0.85em;
}

.card-header {
  border-bottom: none;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

th.sortable .sort-indicator {
  opacity: 0.85;
  font-size: 0.75em;
}

.btn-rate-limit {
  margin-inline-end: 0.25rem;
}

#rateLimitModal .modal-footer {
  justify-content: space-between;
}

#btn-reapply-all-limits {
  white-space: nowrap;
}

/* Peers list: top chrome fixed height, table fills rest and scrolls inside */
body.peers-list-page {
  background-color: var(--bs-light, #f8f9fa);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  padding-bottom: env(safe-area-inset-bottom, 0);
  font-size: 0.875rem;
}

body.peers-list-page .navbar {
  flex-shrink: 0;
  margin-bottom: 0 !important;
}

body.peers-list-page main.container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-width: 100%;
  overflow: hidden;
  padding-top: 0.35rem;
  padding-bottom: 0 !important;
  margin-bottom: 0;
}

body.peers-list-page main.container > .alert {
  flex-shrink: 0;
  margin-bottom: 0.5rem;
}

.peers-list-layout {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
  row-gap: 0.35rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.peers-list-top {
  min-height: 0;
}

.peers-list-header {
  margin-bottom: 0.25rem;
}

.peers-page-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.peers-list-actions .btn {
  font-size: 0.72rem;
  line-height: 1.35;
  padding: 0.15rem 0.4rem;
}

.peers-count-label {
  font-size: 0.72rem;
}

.peers-filters-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.45rem;
  background: #fff;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 0.375rem;
}

.peers-filters-bar .form-control {
  flex: 1 1 5.5rem;
  min-width: 4.5rem;
  max-width: 9rem;
  font-size: 0.78rem;
  padding: 0.2rem 0.45rem;
  line-height: 1.3;
}

.peers-filters-bar .btn {
  flex: 0 0 auto;
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
}

.peers-table-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
  margin-bottom: 0;
}

.peers-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
}

.peers-table-scroll .table {
  margin-bottom: 0;
}

/* separate borders: sticky cells overlap correctly (collapse breaks layering) */
#peers-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.78rem;
}

#peers-table thead.peers-table-head th {
  font-size: 0.74rem;
  padding: 0.35rem 0.45rem;
  font-weight: 600;
}

#peers-table tbody td {
  padding: 0.3rem 0.45rem;
}

#peers-table .btn-sm {
  font-size: 0.68rem;
  padding: 0.1rem 0.3rem;
  line-height: 1.25;
}

#peers-table .badge {
  font-size: 0.65rem;
  padding: 0.2em 0.45em;
}

#peers-table code {
  font-size: 0.72em;
}

#peers-table thead.peers-table-head th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--bs-dark, #212529);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.15);
}

#peers-table thead.peers-table-head th:not(.peers-col-sticky) {
  z-index: 2;
}

/* Sticky name column: header fixed on vertical + horizontal scroll (corner cell) */
#peers-table thead th.peers-col-sticky {
  position: sticky;
  top: 0;
  inset-inline-start: 0;
  z-index: 6;
  width: 7.5rem;
  min-width: 7.5rem;
  max-width: 7.5rem;
  background-color: var(--bs-dark, #212529) !important;
  border-inline-end: 2px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.175));
  box-shadow: -5px 0 10px -3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(255, 255, 255, 0.15);
  overflow: visible;
  vertical-align: middle;
}

/* Body cells: horizontal scroll only (stay below header) */
#peers-table tbody td.peers-col-sticky {
  position: sticky;
  inset-inline-start: 0;
  z-index: 4;
  width: 7.5rem;
  min-width: 7.5rem;
  max-width: 7.5rem;
  background-color: #fff;
  border-inline-end: 2px solid var(--bs-border-color, #dee2e6);
  box-shadow: -5px 0 10px -3px rgba(0, 0, 0, 0.14);
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

#peers-table tbody td:not(.peers-col-sticky) {
  position: relative;
  z-index: 0;
  background-color: #fff;
}

#peers-table.table-striped > tbody > tr:nth-of-type(odd) > td:not(.peers-col-sticky) {
  background-color: var(--bs-table-striped-bg, #f8f9fa);
}

#peers-table.table-striped > tbody > tr:nth-of-type(odd) > .peers-col-sticky {
  background-color: #f8f9fa;
}

#peers-table.table-striped > tbody > tr:nth-of-type(even) > .peers-col-sticky {
  background-color: #fff;
}

#peers-table.table-hover > tbody > tr:hover > td:not(.peers-col-sticky) {
  background-color: var(--bs-table-hover-bg, #ececec);
}

#peers-table.table-hover > tbody > tr:hover > .peers-col-sticky {
  background-color: #ececec;
}

.peers-filter-empty-msg {
  margin-top: 0.25rem;
}

@media (max-width: 576px) {
  body.peers-list-page main.container {
    padding-top: 0.3rem;
  }

  .peers-filters-bar .form-control {
    max-width: none;
  }

  #peers-table {
    font-size: 0.74rem;
  }

  .peers-table-scroll {
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }
}
