html {
  color-scheme: light;
}

:root {
  --bg: #ffffff;
  --sidebar-bg: #f8f8f8;
  --text: #111111;
  --muted: #666666;
  --line: #e0e0e0;
  --radius: 6px;
  --space: 1.25rem;
  --main-max: 52rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

/* ——— Auth ——— */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: var(--space);
  background: var(--bg);
}

.auth-overlay.hidden,
.hidden {
  display: none !important;
}

.auth-card {
  width: min(22rem, 100%);
  padding: var(--space);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.auth-tabs {
  display: flex;
  margin-bottom: var(--space);
  border-bottom: 1px solid var(--line);
}

.auth-tab {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.auth-tab.is-active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--text);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: var(--space);
}

.brand-row.auth-brand {
  margin-bottom: var(--space);
}

.brand-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.auth-brand .brand-icon {
  width: 44px;
  height: 44px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.brand-wordmark {
  margin-bottom: var(--space);
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-name-small {
  font-size: 1.1rem;
}

.brand-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-message {
  min-height: 1.25rem;
  margin-top: 0.75rem;
  font-size: 0.875rem;
}

.auth-message.error {
  font-weight: 600;
}

.auth-message.success {
  color: var(--muted);
}

.field-hint {
  margin: -0.25rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.label-file .field-hint {
  display: block;
  margin: 0.35rem 0 0;
}

.update-screenshots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.update-thumb {
  max-width: 7rem;
  max-height: 7rem;
  width: auto;
  height: auto;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  vertical-align: top;
}

/* ——— Discord gate ——— */
.discord-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--space);
  background: rgba(255, 255, 255, 0.98);
}

/* Must win over .discord-gate { display: grid } */
.discord-gate.hidden {
  display: none !important;
}

.discord-gate-card {
  width: min(22rem, 100%);
  padding: var(--space);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.discord-gate-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

/* ——— App shell ——— */
.shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 15rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: var(--space);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
}

.sidebar-brand {
  margin-bottom: var(--space);
  padding-bottom: var(--space);
  border-bottom: 1px solid var(--line);
}

.sidebar-brand.brand-row {
  margin-bottom: var(--space);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: auto;
}

.sidebar-link {
  display: block;
  padding: 0.35rem 0;
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 2px;
}

.sidebar-link:hover {
  text-decoration: underline;
}

.sidebar-link.is-active {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sidebar-footer {
  margin-top: var(--space);
  padding-top: var(--space);
  border-top: 1px solid var(--line);
}

.sidebar-meta {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.sidebar-threshold {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.sidebar-hint {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
}

.main-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: calc(var(--space) * 1.25) clamp(var(--space), 4vw, 2rem);
  max-width: calc(var(--main-max) + 4rem);
  overflow-y: auto;
}

/* One route visible at a time (hash routing) */
.main-view.hidden {
  display: none !important;
}

/* Each scroll “page” on the single long view */
.page-pane {
  scroll-margin-top: 1.25rem;
  padding: 2rem 0 2.5rem;
  border-bottom: 1px solid var(--line);
  min-height: min(72vh, 36rem);
}

.page-pane:last-child {
  border-bottom: none;
  min-height: auto;
  padding-bottom: 3rem;
}

.page-overview {
  min-height: min(50vh, 24rem);
  padding-top: 0.5rem;
}

/* Leaderboard: table height only — no extra empty space */
.page-pane--leaderboard {
  min-height: 0;
  padding: 1rem 0 1.5rem;
}

.page-heading {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-intro {
  margin: 0.75rem 0 0;
  max-width: 36rem;
  font-size: 0.9rem;
  line-height: 1.55;
}

.welcome-line {
  margin: 0 0 0.5rem;
  font-size: clamp(1.15rem, 2.5vw, 1.4rem);
  font-weight: 600;
}

/* ——— Sections ——— */
.section {
  scroll-margin-top: 1rem;
}

.section-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.section-lead {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
}

.muted {
  color: var(--muted);
}

/* ——— Stats ——— */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space);
  padding: var(--space) 0 0;
  border-top: 1px solid var(--line);
}

.stat {
  min-width: 0;
}

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

.stat .stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.stat-note {
  display: block;
  font-size: 0.8rem;
  line-height: 1.35;
}

.form-block {
  padding: 0;
  border: none;
  border-radius: 0;
}

.form-block .portal-form {
  margin-top: 0.5rem;
  padding: var(--space);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

/* ——— Logs (two columns) ——— */
.page-logs {
  min-height: min(70vh, 40rem);
}

.logs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space);
  align-items: start;
}

.logs-subheading {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.logs-column .history-list,
.logs-column .empty-state {
  min-height: 8rem;
}

/* ——— Policy page ——— */
.page-policy {
  min-height: auto;
}

.policy-block {
  margin: 0 0 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.policy-block-title {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.policy-block p {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  max-width: 40rem;
  line-height: 1.55;
}

.policy-block p:last-child {
  margin-bottom: 0;
}

.policy-summary {
  margin-top: 1.5rem;
  padding: var(--space);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sidebar-bg);
}

.policy-summary strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
}

.policy-quick {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.policy-quick li {
  margin-bottom: 0.35rem;
}

.simple-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.simple-list li {
  margin-bottom: 0.35rem;
}

/* ——— Leaderboard table ——— */
.leaderboard-body {
  overflow-x: auto;
  margin-top: 0.35rem;
  -webkit-overflow-scrolling: touch;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  table-layout: auto;
}

.leaderboard-table th,
.leaderboard-table td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: top;
}

.leaderboard-table th {
  font-weight: 600;
  background: var(--sidebar-bg);
  white-space: nowrap;
}

.leaderboard-activity {
  max-width: 14rem;
  word-break: break-word;
}

/* ——— Forms ——— */
.portal-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.portal-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.portal-form input,
.portal-form select,
.portal-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  color: var(--text);
}

.portal-form input:focus,
.portal-form select:focus,
.portal-form textarea:focus {
  outline: 2px solid var(--text);
  outline-offset: 0;
}

.button-signin,
.button-primary {
  border: 1px solid var(--text);
  border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--text);
  color: #ffffff;
}

.button-primary:hover,
.button-signin:hover {
  opacity: 0.88;
}

.button-primary:disabled,
.button-signin:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button-secondary {
  border: 1px solid var(--text);
  border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}

.button-secondary:hover {
  background: #f0f0f0;
}

.btn-block {
  width: 100%;
  margin-top: 0.35rem;
}

/* ——— History ——— */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.history-item strong,
.history-item span {
  display: block;
}

.history-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.empty-state {
  color: var(--muted);
  min-height: 5rem;
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--space);
  font-size: 0.875rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ——— Admin ——— */
.admin-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: var(--space);
}

.summary-chip {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.summary-chip .section-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.summary-chip strong {
  font-size: 1.2rem;
}

.admin-employees {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.employee-card {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.employee-card strong,
.employee-card span {
  display: block;
}

.employee-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.status-good {
  color: var(--text);
}

.status-watch {
  color: var(--muted);
  font-weight: 600;
}

.status-alert {
  font-weight: 700;
}

/* ——— Toast ——— */
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 60;
  max-width: 18rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--text);
  border-radius: var(--radius);
  background: var(--text);
  color: #ffffff;
  font-size: 0.875rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.toast.visible {
  opacity: 1;
}

/* ——— Locked overlay ——— */
body.locked {
  overflow: hidden;
}

body.locked .shell {
  opacity: 0.35;
  pointer-events: none;
  user-select: none;
}

/* ——— Responsive ——— */
@media (max-width: 960px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .sidebar-brand {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
    flex: 0 0 auto;
  }

  .sidebar-nav {
    flex: 1;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
    margin-bottom: 0;
  }

  .sidebar-link {
    display: inline;
    padding: 0;
    font-size: 0.85rem;
  }

  .sidebar-footer {
    width: 100%;
    margin-top: 0;
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
  }

  .stat-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .logs-grid {
    grid-template-columns: 1fr;
  }

  .page-pane {
    min-height: auto;
  }

  .admin-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-employees {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .stat-row {
    grid-template-columns: 1fr;
  }

  .admin-summary {
    grid-template-columns: 1fr;
  }
}
