/* ============================================================
   Design tokens
   ============================================================ */

:root {
  color-scheme: dark;

  --bg: #0a0b0d;
  --bg-alt: #121417;
  --panel: #17191d;
  --panel-2: #1d2024;
  --border: #282c31;
  --border-soft: #202327;

  --text: #edeff2;
  --text-dim: #8b9198;
  --text-faint: #5c6167;

  --brand: #34d399;
  --brand-soft: rgba(52, 211, 153, 0.12);
  --brand-dim: #1c6b4d;

  --up: #45d483;
  --up-soft: rgba(69, 212, 131, 0.12);
  --warn: #f2c14e;
  --warn-soft: rgba(242, 193, 78, 0.12);
  --down: #ef5b5b;
  --down-soft: rgba(239, 91, 91, 0.12);

  --mem: #a78bfa;
  --cpu: #38bdf8;

  --radius: 0.85rem;
  --radius-sm: 0.5rem;
  --shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.6);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

/* ============================================================
   Reset & base
   ============================================================ */

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body.scroll-locked {
  overflow: hidden;
}

a {
  color: var(--brand);
}

svg {
  display: block;
}

.container {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.loading {
  color: var(--text-dim);
  text-align: center;
  grid-column: 1 / -1;
  padding: 2rem 0;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn svg {
  width: 0.95em;
  height: 0.95em;
}

.btn--muted {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--muted:hover {
  border-color: var(--text-faint);
}

.btn--brand {
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--brand-dim);
}

.btn--brand:hover {
  background: var(--brand);
  color: #052e1f;
}

.btn--ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn--ghost:hover {
  color: var(--brand);
  border-color: var(--brand-dim);
}

.btn--done {
  background: var(--up-soft);
  color: var(--up);
}

.btn[disabled] {
  pointer-events: none;
  opacity: 0.5;
}

/* ============================================================
   Status pill + dot
   ============================================================ */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pill--up { color: var(--up); background: var(--up-soft); }
.status-pill--warn { color: var(--warn); background: var(--warn-soft); }
.status-pill--down { color: var(--down); background: var(--down-soft); }

.dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  flex: none;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}

.status-pill--up .dot { animation: pulse 2.2s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ============================================================
   Stat tiles (summary rows on both pages)
   ============================================================ */

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.stat-tile {
  flex: 1 1 9rem;
  background: linear-gradient(160deg, var(--panel), var(--bg-alt));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
}

.stat-tile__label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}

.stat-tile__value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

.stat-tile__value sub {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 0.2rem;
  bottom: 0;
}

/* Public page uses a larger, centered variant of the same component */
.stat-row--hero {
  justify-content: center;
  gap: 2.5rem;
}

.stat-row--hero .stat-tile {
  flex: none;
  background: none;
  border: none;
  padding: 0;
  text-align: center;
}

.stat-row--hero .stat-tile__value {
  font-size: 2rem;
}

/* ============================================================
   Cards (shared between the public grid and the admin grid)
   ============================================================ */

.card {
  background: linear-gradient(160deg, var(--panel), var(--bg-alt));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.card--up { border-color: rgba(69, 212, 131, 0.35); }
.card--warn { border-color: rgba(242, 193, 78, 0.4); box-shadow: 0 0 22px -10px rgba(242, 193, 78, 0.35); }
.card--down { opacity: 0.55; }
.card--occupied { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand), 0 0 22px -10px var(--brand); }

.admin-grid .card {
  cursor: pointer;
}

.admin-grid .card:hover,
.admin-grid .card:focus-visible {
  border-color: var(--brand-dim);
  outline: none;
}

.admin-grid .card--selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
}

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
}

.card__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card__subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.card__body {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.card__offline {
  color: var(--text-faint);
  font-size: 0.85rem;
  padding: 0.2rem 0 0.05rem;
}

/* ============================================================
   Public: hero
   ============================================================ */

.hero {
  padding: 4.5rem 1.5rem 3.5rem;
  text-align: center;
  background:
    radial-gradient(circle at 15% -10%, rgba(52, 211, 153, 0.14), transparent 55%),
    radial-gradient(circle at 85% 0%, rgba(56, 189, 248, 0.08), transparent 50%),
    var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.hero__title {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 4rem);
  letter-spacing: 0.07em;
  font-weight: 800;
}

.hero__title span {
  color: var(--brand);
}

.hero__tagline {
  margin: 0.6rem 0 0;
  color: var(--brand);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.rates {
  margin-top: 1.75rem;
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}

.rate-badge {
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-dim);
}

.rate-badge strong {
  color: var(--text);
}

.cluster-banner {
  text-align: center;
  padding: 0.65rem 1.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.cluster-banner[hidden] {
  display: none;
}

.cluster-banner--warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom-color: rgba(242, 193, 78, 0.35);
}

/* ============================================================
   Public: server grid
   ============================================================ */

main {
  padding: 2.5rem 0 4rem;
}

.summary {
  margin-bottom: 2.25rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18.5rem, 1fr));
  gap: 1rem;
}

.poll-status {
  text-align: center;
  color: var(--down);
  font-size: 0.82rem;
  margin: -1.25rem 0 1.5rem;
}

.poll-status[hidden] {
  display: none;
}

.players-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.92rem;
  color: var(--text-dim);
}

.players-line strong {
  color: var(--text);
  font-size: 1.05rem;
}

.players-line--occupied strong {
  color: var(--brand);
}

.players-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex: none;
  background: var(--brand);
  box-shadow: 0 0 6px var(--brand);
  animation: pulse 2.2s infinite;
}

.connect {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.connect-row {
  display: flex;
  gap: 0.5rem;
}

.connect-cmd {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  overflow-x: auto;
  white-space: nowrap;
}

.card--down .btn--steam {
  background: var(--panel-2);
  color: var(--text-faint);
  pointer-events: none;
}

/* ============================================================
   Admin: page chrome
   ============================================================ */

.admin-header {
  padding: 1.35rem 0;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.admin-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.admin-header__title {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.05em;
  font-weight: 800;
}

.admin-header__title span {
  color: var(--brand);
  font-weight: 600;
}

.admin-header__right {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.clock {
  color: var(--text-dim);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

/* ============================================================
   Admin: server grid
   ============================================================ */

.admin-grid {
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
}

.metric-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-bottom: 0.15rem;
}

.metric-label .metric-val {
  font-weight: 700;
}

.metric-val--ok { color: var(--up); }
.metric-val--warn { color: var(--warn); }
.metric-val--crit { color: var(--down); }

.metric-sub {
  font-size: 0.7rem;
  color: var(--text-faint);
}

.sparkline {
  display: block;
  width: 100%;
  height: 28px;
}

.detail {
  margin-top: 0.15rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.76rem;
  font-family: var(--font-mono);
}

.detail-row span:first-child {
  color: var(--text-faint);
  font-family: var(--font);
}

.detail-row--dim {
  color: var(--text-faint);
  font-family: var(--font);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.2rem;
}

.chip {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  background: var(--brand-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.5rem;
}

/* ============================================================
   Admin: detail sidebar
   ============================================================ */

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(26rem, 92vw);
  background: linear-gradient(160deg, var(--panel), var(--bg-alt));
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 50;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.sidebar__head-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: none;
}

.sidebar__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.sidebar__close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 1.9rem;
  height: 1.9rem;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.sidebar__close:hover {
  color: var(--text);
  border-color: var(--text-faint);
}

.sidebar__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sidebar__metrics {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.sidebar__section {
  margin-top: 0.3rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border-soft);
}

.sidebar__section-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.chip--kickable {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.chip__kick {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
}

.chip__kick:hover {
  color: var(--down);
}

.log-view {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.45;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 16rem;
  overflow-y: auto;
}

/* ============================================================
   Admin: fullscreen logs modal
   ============================================================ */

.logs-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 60;
}

.logs-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.logs-modal {
  position: fixed;
  top: 3rem;
  bottom: 3rem;
  left: 3rem;
  right: 3rem;
  background: linear-gradient(160deg, var(--panel), var(--bg-alt));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.25rem;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.logs-modal.open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.logs-modal__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex: none;
}

.logs-modal__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.logs-modal__actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.log-view--full {
  flex: 1;
  min-height: 0;
  max-height: none;
  font-size: 0.8rem;
}

.logs-modal__rcon {
  flex: none;
  border-top: 1px solid var(--border-soft);
  padding-top: 0.8rem;
}

@media (max-width: 40rem) {
  .logs-modal {
    top: 1rem;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    padding: 1rem;
  }
}

.sidebar__rcon-form {
  display: flex;
  gap: 0.5rem;
}

.rcon-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.rcon-input:focus {
  outline: none;
  border-color: var(--brand-dim);
}

.rcon-history {
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 14rem;
  overflow-y: auto;
}

.rcon-entry__cmd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--brand);
}

.rcon-entry__out {
  margin-top: 0.15rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}

.rcon-entry__out--error {
  color: var(--down);
}

@media (max-width: 30rem) {
  .sidebar {
    width: 100vw;
  }
}

/* ============================================================
   Footer
   ============================================================ */

footer {
  text-align: center;
  padding: 2rem 1rem 3rem;
  color: var(--text-faint);
  font-size: 0.85rem;
}

footer.error {
  color: var(--down);
}

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

@media (max-width: 30rem) {
  .stat-row--hero {
    gap: 1.5rem;
  }
}
