:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #4b5565;
  --line: #cfd5df;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --danger-bg: #fde8e8;
  --danger-text: #8a1c1c;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --warn-line: #e4c36a;
  --accent-soft: #e6eefb;
  --up: #12794a;
  --chart-dep: #1f5fbf;
  --chart-wd: #c2570c;
  --down: #b3261e;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --topbar-h: 56px;
  --nav-w: 220px;
  --usd-bg: #e6f6ec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --card: #1b212b;
    --text: #e6e9ef;
    --muted: #aab4c5;
    --line: #333c4b;
    --accent: #5b9bff;
    --accent-text: #0b1220;
    --danger-bg: #3a1c1c;
    --danger-text: #ffb4b4;
    --warn-bg: #3a2f10;
    --warn-text: #f2d48a;
    --warn-line: #6b5518;
    --accent-soft: #1c2a42;
    --up: #5fd39a;
    --chart-dep: #6aa8ff;
    --chart-wd: #f0a05a;
    --down: #ff9a92;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --usd-bg: #15301f;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Sign-in pages: a centred single column, 360-420 px wide on phones and up. */
body.bare {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
}

.card {
  width: 100%;
  max-width: 420px;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 20px;
}

h1 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

h2 {
  margin: 16px 0 8px;
  font-size: 1.1rem;
}

label {
  display: block;
  margin: 16px 0 4px;
  font-weight: 600;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

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

button {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 20px;
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.link {
  margin-top: 8px;
  background: none;
  color: var(--muted);
  font-weight: 400;
  text-decoration: underline;
}

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

.hint {
  margin: 4px 0 0;
  font-size: 0.875rem;
}

.alert {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger-text);
}

.aside {
  margin-top: 8px;
}

.qr {
  margin: 12px auto;
  max-width: 240px;
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.secret code {
  display: block;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
  text-align: center;
  user-select: all;
}

/* --- Admin section (temporary shell; the full app shell replaces it later) --- */
body.admin {
  min-height: 100vh;
}

.admin-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.admin-brand {
  flex: 1 1 auto;
}

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  flex: 1 1 100%;
  order: 3;
}

.admin-nav a {
  color: var(--text);
  padding: 8px 0;
}

.admin-nav a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}

.admin-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
  min-width: 0;
}

.admin-main h1 {
  margin: 8px 0 16px;
}

a.button,
button.small {
  display: inline-block;
  width: auto;
  min-height: 44px;
  margin-top: 0;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.4;
  cursor: pointer;
}

button.small.secondary,
a.button.secondary {
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
}

button.small.danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

form.inline {
  display: inline-block;
  margin: 0 4px 4px 0;
}

.notice {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--accent);
}

select,
input[type="date"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

select:focus-visible,
input[type="date"]:focus-visible,
a.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-narrow {
  max-width: 460px;
}

fieldset {
  margin: 16px 0 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  font-weight: 400;
}

table.grid {
  width: 100%;
  border-collapse: collapse;
}

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

table.grid th {
  font-size: 0.875rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.875rem;
}

.badge-disabled {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 16px;
  align-items: end;
}

.filters > div {
  min-width: 0;
}

.filters-submit button {
  margin-top: 20px;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: 16px 0;
}

.details {
  font-size: 0.875rem;
  color: var(--muted);
}

.temp-password {
  display: block;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
  user-select: all;
}

/* Tables turn into cards on narrow screens: no horizontal scrolling at 375 px. */
@media (max-width: 720px) {
  table.stack,
  table.stack tbody,
  table.stack tr,
  table.stack td {
    display: block;
    width: 100%;
  }

  table.stack thead {
    position: absolute;
    left: -9999px;
  }

  table.stack tr {
    margin: 0 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
  }

  table.stack td {
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr);
    gap: 8px;
    border-bottom: 1px solid var(--line);
  }

  table.stack td:last-child {
    border-bottom: 0;
  }

  table.stack td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.875rem;
  }

  table.stack td.actions {
    display: block;
  }

  table.stack td.actions::before {
    display: block;
    margin-bottom: 4px;
  }
}

/* --- Agent app shell ------------------------------------------------------------------------------ */
/* Numbers line up in columns everywhere in the app. */
body.app,
body.admin {
  font-variant-numeric: tabular-nums;
}

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

.icon {
  display: block;
  flex: none;
  width: 24px;
  height: 24px;
}

body.app {
  min-height: 100vh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--topbar-h);
  padding: 6px 12px 6px 16px;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  overflow: hidden;
  line-height: 44px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  max-width: 55vw;
  padding: 0 14px 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.chip .icon {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Profile menu (top bar of the app and of the admin pages): a <details>, so it works without JS. */
.profile {
  position: relative;
  flex: none;
}

.profile > summary {
  list-style: none;
}

.profile > summary::-webkit-details-marker {
  display: none;
}

.profile-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.profile[open] > .profile-btn {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.profile-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.profile-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  width: 248px;
  max-width: calc(100vw - 24px);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.18);
}

.profile-who {
  margin: 0 0 4px;
  padding: 4px 10px 10px;
  border-bottom: 1px solid var(--line);
}

.profile-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.profile-login {
  display: block;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.profile-signout {
  margin: 0;
}

.profile-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.profile-item .icon {
  width: 20px;
  height: 20px;
  color: var(--muted);
}

.profile-item[hidden],
.signout-confirm[hidden] {
  display: none;
}

.profile-item:hover {
  background: var(--accent-soft);
}

.profile-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.signout-confirm {
  padding: 4px 10px 8px;
}

.signout-q {
  margin: 4px 0 8px;
  font-weight: 700;
}

.signout-actions {
  display: flex;
  gap: 8px;
}

.signout-actions button.small {
  flex: 1 1 0;
  justify-content: center;
}

.nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--line);
}

.nav-item {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  min-height: 56px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
}

.nav-item[aria-current="page"] {
  color: var(--accent);
}

.nav-item:focus-visible,
.chip:focus-visible,
.preset:focus-visible,
.brand:focus-visible,
.sheet-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.main {
  min-width: 0;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

.page-title {
  margin: 8px 0 12px;
  font-size: 1.35rem;
}

.fresh {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.875rem;
}

.banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

.banner-unavailable {
  border-color: transparent;
  background: var(--danger-bg);
  color: var(--danger-text);
}

.empty {
  padding: 32px 16px;
  text-align: center;
}

.empty h2 {
  margin: 0 0 4px;
}

/* Period bottom sheet. Without JS (?sheet=period) it is a plain open dialog in the same place. */
dialog.sheet {
  position: fixed;
  top: auto;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  overflow: auto;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog.sheet::backdrop {
  background: rgba(10, 14, 22, 0.55);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sheet-head h2 {
  margin: 0;
}

.sheet-close {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0 4px;
}

.preset {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.preset[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.range-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 12px;
}

.range-fields > div {
  min-width: 0;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  left: 16px;
  z-index: 40;
  max-width: 280px;
  margin: 0 auto;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.toast.show {
  opacity: 1;
}

/* Tablet and desktop: the navigation moves to a fixed left column under the top bar. */
@media (min-width: 768px) {
  body.app {
    padding-bottom: 0;
    padding-left: var(--nav-w);
  }

  .topbar {
    margin-left: calc(var(--nav-w) * -1);
    padding-left: 20px;
  }

  .nav {
    top: var(--topbar-h);
    right: auto;
    bottom: 0;
    width: var(--nav-w);
    flex-direction: column;
    gap: 4px;
    padding: 12px 8px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .nav-item {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 0.95rem;
  }

  .nav-item[aria-current="page"] {
    background: var(--accent-soft);
  }

  .main {
    padding: 16px 24px 32px;
  }

  .chip {
    max-width: 280px;
  }
}

/* --- Overview ------------------------------------------------------------------------------------- */
.vs {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.875rem;
}

/* Total USD: the one accent block of the screen, Result first and largest. */
.usd-total {
  margin: 0 0 12px;
  padding: 14px 16px 16px;
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--accent-soft);
}

.usd-total h2 {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.875rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.usd-total .vs {
  margin: 0 0 10px;
}

.usd-lead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
}

.usd-lead .metric-head {
  flex-basis: 100%;
}

.usd-lead-value {
  min-width: 0;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.usd-items {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px 0 0;
}

.usd-item {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.usd-item .metric-value {
  font-size: 1.25rem;
}

/* The player counts: smaller than Total USD, still cards. */
.count-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.count-grid .tile {
  padding: 10px 12px;
}

.count-grid .metric-value {
  font-size: 1.125rem;
}

/* By currency: informative only - no cards, muted text, one line per currency. */
.by-currency {
  margin: 16px 0 0;
  color: var(--muted);
}

.by-currency h2 {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.cur-line {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.cur-line:last-child {
  border-bottom: 0;
}

.cur-line h3 {
  margin: 0 0 2px;
  color: var(--text);
  font-size: 0.875rem;
}

dl.kv.kv-quiet {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 16px;
  font-size: 0.8125rem;
}

dl.kv.kv-quiet > div {
  gap: 6px;
  padding: 0;
  border-bottom: 0;
}

dl.kv.kv-quiet dd {
  color: var(--text);
  font-weight: 500;
}

@media (min-width: 768px) {
  .usd-items {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.tile,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.metric-value {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.change {
  font-size: 0.875rem;
  font-weight: 600;
}

.change .arrow {
  font-size: 0.75rem;
}

.change-good {
  color: var(--up);
}

.change-bad {
  color: var(--down);
}

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

.panels {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.panel {
  padding: 12px;
}

.panel h3 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin: 0 0 8px;
  font-size: 1rem;
}

dl.kv {
  margin: 0;
}

/* The account page: one narrow column, also on wide screens. */
.account {
  max-width: 420px;
}

.account .notice {
  margin: 12px 0 0;
}

dl.kv > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}

/* a row with a 44 px copy button centres its text on the button */
dl.kv > div:has(.copy-val) {
  align-items: center;
}

dl.kv > div:last-child {
  border-bottom: 0;
}

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

dl.kv dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

th.num,
td.num {
  text-align: right;
}

.sub-name {
  font-weight: 600;
}

/* Subagents: a table on wide screens, two-line cards on phones. A whole row is one link (the name's link covers it). */
table.sub-table tr.sub-row {
  position: relative;
}

table.sub-table tr.sub-row:hover {
  background: var(--accent-soft);
}

a.sub-link {
  color: var(--accent);
  text-decoration: none;
}

a.sub-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

a.sub-link:hover {
  text-decoration: underline;
}

a.sub-link:focus-visible {
  outline: none;
}

a.sub-link:focus-visible::after {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

@media (min-width: 768px) {
  .count-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .panels {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

/* --- Players ------------------------------------------------------------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: 0 0 8px;
}

.toolbar p {
  margin: 0;
}

/* A wide table scrolls inside this box, never the page itself. */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

table.players,
table.daily {
  font-size: 0.8125rem;
}

table.players td.num,
table.daily td.num {
  white-space: nowrap;
}

/* Totals of the players shown: per currency and in USD, above the list. */
.totals-bar {
  max-width: 34rem;
  margin: 0 0 12px;
}

.totals-bar h3 {
  font-size: 0.9375rem;
}

table.totals {
  font-size: 0.8125rem;
}

table.totals th,
table.totals td {
  padding: 6px 8px;
}

table.totals tbody th {
  color: inherit;
  font-weight: 600;
  white-space: nowrap;
}

table.totals td.num {
  white-space: nowrap;
}

@media (max-width: 767px) {
  table.totals th,
  table.totals td {
    padding: 6px 4px;
  }

  table.totals thead th {
    font-size: 0.75rem;
    white-space: nowrap;
  }

  /* Phones: the currency label sits on its own line above its three amounts, so signed amounts like
     "KSh 12,345,678" keep the whole card width (three columns) instead of sharing it with the label column. */
  table.totals,
  table.totals thead,
  table.totals tbody {
    display: block;
  }

  table.totals tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  table.totals thead th:first-child {
    display: none;
  }

  table.totals tbody th {
    grid-column: 1 / -1;
    padding-bottom: 0;
    border-bottom: 0;
  }
}

table.totals tr.totals-usd th,
table.totals tr.totals-usd td {
  font-weight: 700;
}

table.totals tbody tr:last-child th,
table.totals tbody tr:last-child td {
  border-bottom: 0;
}

/* Login, Client ID: tap or click to copy. */
button.copy {
  display: inline;
  width: auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: underline dotted;
  overflow-wrap: anywhere;
  cursor: copy;
}

button.copy:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a.card-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

a.card-link:hover {
  text-decoration: underline;
}

.badge-blocked {
  border-color: transparent;
  background: var(--danger-bg);
  color: var(--danger-text);
  cursor: help;
}

/* Self-excluded: the danger colour as an outline, apart from the filled Blocked badge. */
.badge-selfex {
  border-color: var(--danger-text);
  background: transparent;
  color: var(--danger-text);
  cursor: help;
}

.badge-former {
  border-color: var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn-text);
}

.labels {
  margin: 0 0 8px;
}

p.back {
  margin: 0 0 8px;
}

p.back a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

input[type="search"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input[type="search"]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Phones: every row of the players and daily tables becomes a card (up to 767 px, like the bottom navigation). */
@media (max-width: 767px) {
  table.cards,
  table.cards tbody,
  table.cards tr,
  table.cards td {
    display: block;
    width: 100%;
  }

  table.cards thead {
    position: absolute;
    left: -9999px;
  }

  table.cards tr {
    display: flex;
    flex-direction: column;
    margin: 0 0 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--shadow);
  }

  table.cards td {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    gap: 8px;
    order: 2;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
  }

  table.cards td:last-child {
    border-bottom: 0;
  }

  table.cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.8125rem;
  }

  table.cards td.num {
    text-align: left;
  }

  /* the card: login, Client ID, name, then deposits and withdrawals, the big Result, the rest below */
  table.cards td.p-id {
    order: 1;
    font-size: 0.9375rem;
  }

  table.cards td.p-login {
    font-size: 1.0625rem;
  }

  table.cards td.p-money {
    order: 2;
  }

  table.cards td.p-result {
    order: 3;
    font-size: 1.25rem;
    font-weight: 700;
  }

  table.cards td.p-more {
    order: 4;
    padding-top: 4px;
    padding-bottom: 4px;
    color: var(--muted);
  }

  table.cards td.p-money,
  table.cards td.p-result {
    font-weight: 600;
  }

  table.cards td.p-result {
    font-weight: 700;
  }

  table.cards td button.copy {
    min-height: 32px;
  }
}

@media (min-width: 768px) {
  table.players th,
  table.players td,
  table.daily th,
  table.daily td {
    padding: 6px 8px;
  }
}

.p-val {
  min-width: 0;
}

.p-val .badge {
  /* the tag keeps its width; a long login shrinks with an ellipsis instead */
  flex: none;
  margin-left: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
}

@media (min-width: 768px) {
  table.players th,
  table.players td,
  table.daily th,
  table.daily td {
    overflow-wrap: normal;
    white-space: nowrap;
  }

  table.players td.p-name {
    min-width: 9rem;
    white-space: normal;
  }
}

/* --- Players: search, Filters chip and sheet, copy icons, phone rows ---------------------------------- */
.searchbar {
  margin: 0 0 8px;
}

.sb-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sb-field {
  flex: 1 1 auto;
  min-width: 0;
}

.sb-submit {
  flex: none;
  width: auto;
  margin: 0;
}

/* With JS the field filters as you type (and Enter works), so the button is only for the plain page. */
.js .sb-submit {
  display: none;
}

.filters-chip {
  min-width: 44px;
}

/* A round icon-only button (Export XLSX next to the player count). */
.icon-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--accent);
}

.icon-button .icon {
  width: 20px;
  height: 20px;
}

.icon-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* USD accounts stand out with a pale green row (table on wide screens, card row on phones). */
table.players-list tr.player-row.usd,
table.players-list tr.player-row.usd td {
  background: var(--usd-bg);
}

/* The list body that a search replaces. */
.pl-region[aria-busy="true"] {
  opacity: 0.55;
}

/* The Filters sheet: the same dialog as the period sheet. */
.sheet-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 12px;
}

.sheet-fields > div {
  min-width: 0;
}

/* the Sort select takes the whole row (its labels are long: "Last activity, newest first") */
.sheet-fields > .sheet-field-wide {
  grid-column: 1 / -1;
}

/* All / New players: two radios drawn as one pill with two halves, 44 px high */
.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
}

.segmented-opt {
  position: relative;
  display: block;
  margin: 0;
}

.segmented-opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented-opt span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
}

.segmented-opt input:checked + span {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.segmented-opt input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.segmented-hint {
  margin: 6px 0 12px;
  font-size: 0.8125rem;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.sheet-actions button {
  flex: 1 1 auto;
  width: auto;
  margin: 0;
}

.sheet-reset {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

/* Login and Client ID: plain text plus a small copy icon button (the tap area is 44 px on a phone). */
table.players-list .p-val,
.copy-val {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

table.players-list .p-text,
.copy-val .p-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.copy-ico {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: copy;
}

button.copy-ico .icon {
  width: 18px;
  height: 18px;
}

button.copy-ico:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

button.copy-ico:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* The "›" link is only for phones; on a wide screen the name opens the card. */
a.row-go {
  display: none;
}

@media (min-width: 768px) {
  button.copy-ico {
    width: 28px;
    height: 28px;
  }

  button.copy-ico .icon {
    width: 16px;
    height: 16px;
  }

  /* a 28 px button keeps the rows low; its tap area is still 44 px (like the tip button) */
  button.copy-ico {
    position: relative;
  }

  button.copy-ico::after {
    content: "";
    position: absolute;
    top: -8px;
    right: -8px;
    bottom: -8px;
    left: -8px;
  }

  .sb-row {
    max-width: 40rem;
  }

  table.players-list td {
    vertical-align: middle;
  }
}

/* Phones: a player is a two-line row. Line 1: login, copy icon, "›". Line 2: Deposits / Withdrawals / Result with small
   labels. The "›" link is stretched over the whole row (its ::after fills the row, which is the positioned box), so a tap
   anywhere on the row opens the card; the copy button sits above it and copies instead. Everything else (Client ID,
   name, balances, GGR, dates) is on the card. */
@media (max-width: 767px) {
  .sheet-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  table.players-list {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--shadow);
  }

  table.players-list tbody {
    border-radius: 12px;
  }

  table.players-list tr.player-row {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) 44px;
    align-items: start;
    margin: 0;
    padding: 0 0 6px 12px;
    overflow: visible;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: none;
    box-shadow: none;
  }

  table.players-list tr.player-row:last-child {
    border-bottom: 0;
  }

  /* the login cell has no box of its own: its text and the link are cells of the row grid */
  table.players-list td.p-login {
    display: contents;
  }

  table.players-list td.p-login::before {
    content: none;
  }

  table.players-list td.p-login .p-val {
    justify-self: start;
    grid-column: 1 / 4;
    grid-row: 1;
    font-size: 1.0625rem;
    font-weight: 600;
  }

  table.players-list a.row-go {
    grid-column: 4;
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    color: var(--accent);
    font-size: 1.75rem;
    line-height: 1;
    text-decoration: none;
  }

  table.players-list a.row-go::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }

  table.players-list a.row-go:focus-visible {
    outline: none;
  }

  table.players-list a.row-go:focus-visible::after {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }

  table.players-list button.copy-ico {
    position: relative;
    z-index: 1;
  }

  table.players-list td.p-cid,
  table.players-list td.p-name,
  table.players-list td.p-more {
    display: none;
  }

  /* line 2 is pulled up under the 44 px icon buttons (their icons sit in the middle of the tap area) */
  table.players-list td.p-money,
  table.players-list td.p-result {
    grid-row: 2;
    display: block;
    min-width: 0;
    margin-top: -8px;
    padding: 0 4px 0 0;
    border: 0;
    overflow-wrap: anywhere;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
  }

  table.players-list td[data-label="Deposits"] {
    grid-column: 1;
  }

  table.players-list td[data-label="Withdrawals"] {
    grid-column: 2;
  }

  table.players-list td.p-result {
    grid-column: 3 / 5;
  }

  table.players-list td.p-money::before,
  table.players-list td.p-result::before {
    display: block;
    font-size: 0.6875rem;
    font-weight: 400;
    line-height: 1.3;
  }
}

/* --- Growth -------------------------------------------------------------------------------------- */

.switch a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* the second line of a segment card: the window, then the hint (they wrap together) */

/* --- The funnel: horizontal bars of decreasing length, "↓ 55.0%" between the steps ------------------ */

.switch {
  display: inline-flex;
  margin: 4px 0 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.switch a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.switch a[aria-current="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

/* Segment list on phones (the rows come from the players-list rules): line 2 is "registered 2 d ago" / "last active 9 d
   ago" on the left and the balance on the right; Top shows Deposits and Result like Players shows its amounts. */

/* --- Links --------------------------------------------------------------------------------------- */

/* Links, wide screens (from 1200 px; below that every subagent is a card): the header cells sit on the bottom edge of a
   header row made tall by long titles; the tips are in the header (the per-cell labels belong to the cards). */

/* Links on phones and tablets (below 1200 px): a subagent is a card, the name over a 3 x 2 grid of the six metrics (label + ⓘ, value, change). */

/* Card rows (phones): a status badge keeps its own width instead of stretching over the value column. */
@media (max-width: 767px) {
  table.cards td > .badge,
  table.stack td > .badge {
    justify-self: start;
  }
}

/* --- The ⓘ tip: a button next to a label; app.js toggles the popover and places it in the viewport ----- */
.metric-head {
  display: flex;
  min-height: 24px;
  align-items: center;
  gap: 2px;
}

button.tip {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
}

/* A 44 px tap target around the 24 px button. */
button.tip::after {
  content: "";
  position: absolute;
  top: -10px;
  right: -10px;
  bottom: -10px;
  left: -10px;
}

button.tip:hover,
button.tip[aria-expanded="true"] {
  background: var(--accent-soft);
}

button.tip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tip-text {
  position: fixed;
  z-index: 40;
  display: none;
  width: min(260px, calc(100vw - 32px));
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.18);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-align: left;
  text-transform: none;
}

.tip[aria-expanded="true"] + .tip-text,
html:not(.js) .tip:focus + .tip-text {
  display: block;
}

/* --- App-style error pages and the offline page (bare layout) ---------------------------------------- */
.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.error-page {
  padding: 16px 0 4px;
  text-align: center;
}

.error-code {
  margin: 0;
  color: var(--accent);
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1.1;
}

.error-code .icon {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  color: var(--muted);
}

.error-page h2 {
  margin: 8px 0 4px;
}

.error-back {
  margin: 20px 0 0;
}

/* --- Admin: edit form, users list, result page, View as agent, usage --------------------------------- */
textarea {
  display: block;
  width: 100%;
  min-height: 96px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.admin-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 24px;
}

.admin-tools > p {
  margin: 0 0 12px;
}

.view-as-picker {
  flex: 0 1 460px;
  min-width: 0;
  margin: 0 0 12px;
}

.view-as-picker label {
  margin-top: 0;
}

.picker-row {
  display: flex;
  gap: 8px;
}

.picker-row select {
  flex: 1 1 auto;
  min-width: 0;
}

.picker-row button {
  flex: none;
  margin-top: 0;
}

table.users-table td.comment-cell {
  color: var(--muted);
  font-size: 0.875rem;
}

table.users-table td.actions a.button,
table.users-table td.actions form.inline {
  margin: 0 4px 4px 0;
}

@media (min-width: 721px) {
  table.usage-table td.num,
  table.usage-table th:nth-child(n + 5) {
    text-align: right;
  }
}

/* The temporary password with its copy button. */
.copy-val.copy-secret {
  display: flex;
  max-width: 100%;
  gap: 8px;
  margin: 0;
}

.copy-secret .temp-password {
  flex: 1 1 auto;
  min-width: 0;
}

.copy-secret button.copy-ico {
  width: 44px;
  height: 44px;
}

/* View as agent: the bar under the top bar on the agent screens (sticky), plain at the top of the admin pages. */
.viewing-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin: 0 0 12px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

.viewing-text {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.viewing-exit {
  margin: 0;
}

.viewing-exit button.small {
  min-height: 44px;
  margin: 0;
  border-color: var(--warn-line);
  color: inherit;
}

.main > .viewing-bar {
  position: sticky;
  top: calc(var(--topbar-h) + 2px);
  z-index: 10;
}

table.users-table td[data-label="Export"],
table.users-table td[data-label="Status"],
table.users-table th:nth-child(6),
table.users-table th:nth-child(7) {
  overflow-wrap: normal;
  white-space: nowrap;
}

table.users-table td[data-label="Login"] {
  min-width: 8rem;
}

/* --- Revision 1 polish ------------------------------------------------------------------------------- */

/* Safety net: every interactive element shows a focus ring, also one that has no rule of its own. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Admin navigation: tabs with a 44 px touch target. */
.admin-nav {
  gap: 4px;
  margin-left: -10px;
}

.admin-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 999px;
  text-decoration: none;
}

.admin-nav a:hover,
.admin-nav a[aria-current="page"] {
  background: var(--accent-soft);
}

/* Table headers keep whole words (the stacked-card rule breaks anywhere). */
table.users-table th,
table.usage-table th {
  overflow-wrap: normal;
}

/* Phones: a stacked card leaves out the fields that are empty (Name, Contact, Comment, audit Details). */
@media (max-width: 720px) {
  table.stack td.empty {
    display: none;
  }
}

/* The Players table (16 columns) cannot fit a 1000 px column with real figures: it scrolls inside its box, with the
   Login column pinned and the header words allowed to wrap (a column is as wide as its figures, not its title). */
@media (min-width: 768px) {
  .table-wrap {
    overflow-y: hidden;
    scrollbar-width: thin;
  }

  table.players-list th {
    line-height: 1.25;
    vertical-align: bottom;
    white-space: normal;
  }

  table.players-list th:first-child,
  table.players-list td.p-login {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg);
    box-shadow: 1px 0 0 var(--line);
  }

  table.players-list th:first-child {
    z-index: 2;
  }
}

@media (max-width: 720px) {
  table.stack td:has(+ td.empty:last-child) {
    border-bottom: 0;
  }
}

/* Links cards on a tablet are wide: two-line labels need no extra height, and from 900 px the six metrics sit in one row. */

/* A multi-part cell of a stacked card (login + role, agent + project) is one grid item. */
.cv {
  min-width: 0;
}

/* Placeholders: the default grey is below 4.5:1 on the field background. */
::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* Revision 2 admin: Agents and Settings */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.codes-list code {
  display: inline-block;
  margin: 0 6px 4px 0;
  overflow-wrap: anywhere;
}

table.agents-table tr.agent-sub td:first-child {
  padding-left: 20px;
}

/* Admin UX pass: agents search, rate groups, danger zone, the row menu */
.agents-search {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
}

.agents-search input[type="search"] {
  flex: 1 1 260px;
  min-width: 0;
  max-width: 420px;
}

.agents-search button,
.agents-search a.button {
  flex: none;
  width: auto;
  margin-top: 0;
}

details.rate-group {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

details.rate-group > summary {
  cursor: pointer;
  padding: 12px;
  min-height: 44px;
  font-weight: 600;
}

details.rate-group > table {
  margin: 0;
}

.danger-zone {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  max-width: 520px;
}

.danger-zone button.danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

details.row-menu {
  position: relative;
  display: inline-block;
  margin: 0 4px 4px 0;
  vertical-align: top;
}

details.row-menu > summary {
  list-style: none;
  cursor: pointer;
}

details.row-menu > summary::-webkit-details-marker {
  display: none;
}

details.row-menu > summary::after {
  content: " ▾";
}

.row-menu-list {
  margin-top: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.row-menu-list form.inline {
  display: block;
  margin: 0 0 6px;
}

.row-menu-list form.inline:last-child {
  margin-bottom: 0;
}

.row-menu-list button {
  width: 100%;
  text-align: left;
}

@media (max-width: 767px) {
  details.row-menu > summary {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
}

@media (min-width: 768px) {
  .row-menu-list {
    position: absolute;
    right: 0;
    z-index: 5;
    min-width: 12rem;
  }
}

/* --- Admin shell: a left sidebar from 960 px, the old top bar below (role-aware navigation) --- */
.admin-role {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

@media (min-width: 960px) {
  body.admin {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    align-items: start;
  }

  body.admin .admin-bar {
    position: sticky;
    top: 0;
    height: 100vh;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 16px;
    padding: 20px 14px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    overflow-y: auto;
  }

  body.admin .admin-brand {
    flex: 0 0 auto;
    padding: 0 10px;
  }

  body.admin .admin-nav {
    flex: 1 1 auto;
    flex-direction: column;
    flex-wrap: nowrap;
    order: 0;
    margin-left: 0;
  }

  body.admin .admin-nav a {
    border-radius: 8px;
  }

  body.admin .admin-main {
    width: 100%;
    margin: 0;
    padding: 28px 32px;
  }
}

/* Roles page and role badges */
.role-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 12px 0 20px;
}

.role-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.role-card.is-me {
  border-color: var(--accent);
}

.role-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.role-yes {
  color: #5fd39a;
}

.roles-table th[scope="row"] {
  text-align: left;
  font-weight: 500;
}

.badge-role-admin { background: #3a2a5e; color: #d9c8ff; }
.badge-role-manager { background: #1d3b63; color: #bcd6ff; }
.badge-role-operator { background: #1f4a3c; color: #b9efd9; }
.badge-role-agent { background: #3d3a2a; color: #efe3b0; }

/* BTag card (generated code, My links) and small helpers */
.btag-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  margin: 12px 0 20px;
  padding: 18px 20px;
  border: 1px solid #2c4670;
  border-radius: 12px;
  background: var(--accent-soft);
}

.btag-card > div:first-child {
  flex: 1 1 auto;
}

.btag-digits {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 30px;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.btag-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btag-input {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 22px;
  letter-spacing: 0.12em;
}

.chip {
  display: inline-block;
  min-width: 36px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-align: center;
  text-decoration: none;
}

.chip.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.copy-mini {
  padding: 0 6px;
  min-height: 24px;
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.link-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.link-card h3 {
  margin: 0;
}

.link-url {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.link-url span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-actions {
  display: flex;
  gap: 8px;
}

.links-empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.admin-brand {
  display: flex;
  flex-direction: column;
}

.badge[class*="badge-role-"] {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* Admin on a phone: the menu opens from a button (no script: a checkbox). */
.admin-menu-toggle:not(:checked) ~ .admin-nav {
  display: none;
}

.admin-hamburger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.admin-menu-toggle:focus-visible + .admin-hamburger {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (min-width: 960px) {
  .admin-hamburger {
    display: none;
  }

  .admin-menu-toggle:not(:checked) ~ .admin-nav {
    display: flex;
  }
}

@media (max-width: 959px) {
  body.admin .admin-nav {
    flex-direction: column;
    gap: 2px;
    margin-left: 0;
  }

  body.admin .admin-nav a {
    border-radius: 8px;
  }

  body.admin .admin-main {
    padding: 14px 16px 28px;
  }
}
