/* Admin console: dark theme only, mobile first. Colours match style.css. No external fonts. */

:root {
  --bg: #0e1116;
  --panel: #161b24;
  --panel-2: #1d2430;
  --line: #2a3342;
  --text: #e6ebf2;
  --muted: #9aa4b2;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #4f8cff;
  --warn: #f5c542;
  --ctl-h: 44px;
  --row-alt: #151a23;
  color-scheme: dark;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

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

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

h1,
h2,
h3 {
  margin: 0;
}

.mono,
.code,
.detail {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.neg {
  color: var(--down);
}

.pos {
  color: var(--up);
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 56px;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 6px 2px;
  flex: 0 0 auto;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.who {
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--muted);
}

/* ---------- layout ---------- */

.wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  min-width: 0;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.card.narrow {
  max-width: 440px;
  width: 100%;
  margin: 24px auto 0;
}

.card-title {
  font-size: 18px;
  letter-spacing: 0.04em;
}

.section-title {
  font-size: 16px;
  letter-spacing: 0.03em;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.grow {
  flex: 1 1 200px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}

.toolbar > .sub {
  align-self: center;
}

.row2 {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.row2.end {
  justify-content: flex-end;
}

.row2 > .field {
  flex: 1 1 140px;
}

.form {
  min-width: 0;
}

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn.primary {
  border-color: var(--accent);
}

.btn.danger {
  background: var(--down);
  border-color: var(--down);
  color: #1a0505;
}

.btn.sm {
  min-height: 44px;
  padding: 0 10px;
  font-size: 14px;
}

.big-btn {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
  font-weight: 700;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  font-size: 14px;
  color: var(--muted);
}

.input {
  width: 100%;
  min-width: 0;
  min-height: var(--ctl-h);
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 16px; /* at least 16px so iOS does not zoom */
}

.input[aria-invalid="true"] {
  border-color: var(--down);
}

.form .field .input {
  max-width: 100%;
}

button:focus-visible,
a:focus-visible,
.input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field-error,
.form-error {
  margin: 0;
  font-size: 14px;
  color: var(--down);
}

.field-error:empty,
.form-error:empty {
  display: none;
}

.status {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

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

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

.status .btn {
  margin-left: 8px;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab {
  flex: 1 1 96px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.tab[aria-selected="true"] {
  border-color: var(--accent);
  background: var(--panel-2);
}

/* ---------- tables ---------- */

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

table.data {
  width: 100%;
  min-width: 640px;
  border-collapse: separate; /* separate, so sticky cells keep their borders while scrolling */
  border-spacing: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; /* no text wrapping in data tables: the table scrolls inside .table-wrap instead */
}

.users-table {
  min-width: 980px;
}

.audit-table {
  min-width: 720px;
}

table.data th,
table.data td {
  padding: 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

table.data th {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  background: var(--panel-2);
}

/* Row backgrounds. Sticky first-column cells use the same rules, so they always match their row. */
table.data tbody td {
  background: var(--panel);
}

table.data tbody tr:nth-child(even) td {
  background: var(--row-alt);
}

table.data tbody tr:hover td {
  background: var(--panel-2);
}

/* Header stays on top while the table is inside its scrolling container. */
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* First column stays pinned while the table scrolls sideways. The .table-wrap container is the scrolling ancestor. */
table.data th:first-child,
table.data td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  box-shadow: 6px 0 8px -6px rgba(0, 0, 0, 0.7);
}

table.data th:first-child {
  z-index: 3;
}

table.data tbody tr:last-child td {
  border-bottom: 0;
}

table.data .num {
  text-align: right;
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}

/* Audit details: one line, cut with an ellipsis; "Show more" shows the full text (no wrapping, the table scrolls). */
.detail-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
  max-width: 260px;
}

.detail-wrap.open {
  max-width: none;
}

.detail {
  display: block;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail.expanded {
  overflow: visible;
  text-overflow: clip;
  white-space: pre;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
}

/* ---------- pager ---------- */

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.pager:empty {
  display: none;
}

.pager-text {
  flex: 1 1 auto;
}

/* ---------- invites ---------- */

.invite-panel {
  border-color: var(--accent);
}

.code-big {
  margin: 0;
  padding: 12px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 8px;
  overflow-wrap: anywhere;
  user-select: all;
}

.code {
  font-weight: 600;
  white-space: nowrap;
}

.code-cell {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}

/* ---------- stats ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 0;
}

.tile-value {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.tile-label {
  font-size: 13px;
  color: var(--muted);
}

.chart-card {
  min-width: 0;
}

.chart {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.chart-area {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 160px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
}

.chart-labels {
  display: flex;
  gap: 2px;
  height: 16px;
  padding: 0 2px;
  font-size: 11px;
  color: var(--muted);
}

.chart-col {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.chart-label {
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  overflow: visible;
  text-align: left;
}

.bar {
  width: 100%;
  min-height: 0;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
}

.stack {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 3px 3px 0 0;
}

.stack .seg {
  min-height: 0;
}

.seg.compete {
  background: var(--warn);
}

.seg.practice {
  background: var(--accent);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  font-size: 13px;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  border-radius: 3px;
  vertical-align: -1px;
}

.swatch.practice {
  background: var(--accent);
}

.swatch.compete {
  background: var(--warn);
}

.chart-table {
  font-size: 14px;
  color: var(--muted);
}

.chart-table summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 14px;
  min-width: 0;
}

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

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---------- dialogs and toast ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 7, 10, 0.72);
}

.dialog {
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 24px);
  padding: 10px 14px;
  border-radius: 10px;
  background: #242d3b;
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  text-align: center;
  overflow-wrap: anywhere;
}

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