/* Turnstyle Account Manager. Dark theme (Joseph 2026-11-10), always, whatever
   the device setting, so the panel looks the same for every organizer. */
:root {
  color-scheme: dark;
  --bg: #111317;
  --surface: #1a1d23;
  --surface-2: #23272f;
  --text: #eceef2;
  --muted: #a6adba;
  --border: #343a45;
  --border-strong: #6b7381;
  --accent: #dc2626;        /* white text on this is 4.8:1 */
  --accent-hover: #ef4444;
  --accent-text: #fca5a5;   /* accent used as text on dark surfaces */
  --on-accent: #ffffff;
  --focus: #93c5fd;
  --ok-bg: #12301d;
  --ok-text: #a7e3bc;
  --warn-bg: #3a2c05;
  --warn-text: #f6d98a;
  --err-bg: #3b1414;
  --err-text: #fecaca;
  --info-bg: #17254a;
  --info-text: #c3d4fb;
  --shadow: none;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::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 var(--font);
  overflow-wrap: break-word;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; margin-top: 1.75rem; }
h3 { font-size: 1.05rem; margin-top: 1.25rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent-text); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
h1:focus, h2:focus, h3:focus, main:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.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;
}

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.strong { font-weight: 600; }
.break { overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; }
.boot, .loading { padding: 1.5rem 1rem; color: var(--muted); }
.loading::before {
  content: ""; display: inline-block; width: 0.9em; height: 0.9em; margin-right: 0.5em;
  border: 2px solid var(--border-strong); border-top-color: transparent; border-radius: 50%;
  vertical-align: -0.1em; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading::before { animation: none; } }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0.5rem 1rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--surface); border-color: var(--accent); color: var(--accent-text); }
.btn-danger:hover { background: var(--err-bg); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent-text); }
.btn-quiet:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-busy="true"] { opacity: 0.6; cursor: progress; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.75rem 0; }
td .actions { margin: 0; }

/* ── Sign in and invite ── */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 1rem 2rem; }
.auth-card {
  width: 100%; max-width: 26rem; padding: 1.5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.auth-card .brand { margin-bottom: 1.25rem; padding-left: 0.6rem; border-left: 4px solid var(--accent); }
.code-input { font-family: var(--mono); font-size: 1.5rem; letter-spacing: 0.3em; text-align: center; }

/* ── Shell ── */
.skip { position: absolute; left: -999px; top: 0; z-index: 20; padding: 0.75rem 1rem; background: var(--surface); }
.skip:focus { left: 0.5rem; top: 0.5rem; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem;
  padding: 0.5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.top .brand { display: inline-flex; align-items: center; min-height: 44px; padding-left: 0.6rem; border-left: 4px solid var(--accent); }
.org-box { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.org-label { font-size: 0.85rem; color: var(--muted); }
.org-name { font-weight: 600; overflow-wrap: anywhere; }
.org-select { max-width: 14rem; }
.user-box { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; min-width: 0; }
.user-id { display: flex; flex-direction: column; min-width: 0; text-align: right; line-height: 1.25; }
.user-name { font-weight: 600; overflow-wrap: anywhere; }
.user-email { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }

.nav { background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.nav ul { display: flex; gap: 0.25rem; margin: 0; padding: 0 0.5rem; list-style: none; }
.nav a {
  display: flex; align-items: center; min-height: 44px; padding: 0 0.85rem;
  color: var(--text); text-decoration: none; white-space: nowrap; font-weight: 500;
  border-bottom: 3px solid transparent;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { border-bottom-color: var(--accent); font-weight: 700; }

.main { padding: 1.25rem 1rem 4rem; max-width: 72rem; width: 100%; min-width: 0; }

@media (min-width: 960px) {
  .body { display: grid; grid-template-columns: 13rem minmax(0, 1fr); align-items: start; min-height: calc(100vh - 61px); }
  .nav { border-bottom: 0; border-right: 1px solid var(--border); align-self: stretch; overflow: visible; padding-top: 0.75rem; }
  .nav ul { flex-direction: column; padding: 0 0.5rem; }
  .nav a { border-bottom: 0; border-left: 3px solid transparent; border-radius: 0 6px 6px 0; }
  .nav a[aria-current="page"] { border-left-color: var(--accent); background: var(--surface-2); }
  .main { padding: 1.75rem 2rem 4rem; }
}

@media (max-width: 520px) {
  .user-email { display: none; }
  .org-box { order: 3; width: 100%; }
  .org-select { max-width: none; flex: 1; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 0.5rem; }
.page-head h1 { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.page-head .actions { margin: 0; }
.event-meta { color: var(--muted); }

/* ── Cards, notices, badges ── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin: 1rem 0; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > h3:first-child, .card-head h2, .card-head h3 { margin-top: 0; }
.card-quiet { background: transparent; box-shadow: none; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.card-head .actions { margin: 0; }
.card-head h2, .card-head h3 { margin-bottom: 0; }

.notice { padding: 0.75rem 1rem; border-radius: var(--radius); margin: 0.75rem 0; border: 1px solid transparent; }
.notice p:last-child { margin-bottom: 0; }
.notice-error { background: var(--err-bg); color: var(--err-text); border-color: var(--err-text); }
.notice-warn { background: var(--warn-bg); color: var(--warn-text); }
.notice-info { background: var(--info-bg); color: var(--info-text); }
.notice-ok { background: var(--ok-bg); color: var(--ok-text); }

.badge {
  display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px;
  font-size: 0.82rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
}
.badge-live { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-text); }
.badge-off { background: var(--surface-2); color: var(--muted); border-style: dashed; }
.badge-note { background: var(--info-bg); color: var(--info-text); border-color: transparent; white-space: normal; }

.empty { padding: 2rem 1rem; text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); margin: 1rem 0; }
.empty h2 { margin-top: 0; }
.empty p:last-child { margin-bottom: 0; }

ul.plain { margin: 0; padding-left: 1.2rem; }

/* ── Details list ── */
.details { display: grid; grid-template-columns: minmax(6rem, 10rem) minmax(0, 1fr); gap: 0.5rem 1rem; margin: 0.75rem 0 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; min-width: 0; }
@media (max-width: 520px) {
  .details { grid-template-columns: 1fr; gap: 0; }
  .details dt { font-size: 0.85rem; margin-top: 0.6rem; }
}

/* ── Stats ── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.75rem; margin: 0.5rem 0 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.85rem 1rem; }
.stat p { margin: 0; }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.stat-value { font-size: clamp(1.2rem, 4.6vw, 1.6rem); font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-sub { color: var(--muted); font-size: 0.9rem; }
.stat-sub a { display: inline-block; padding: 0.6rem 0; }

/* ── Filters and tabs ── */
.filters ul, .tabs ul { display: flex; gap: 0.25rem; margin: 0; padding: 0; list-style: none; }
.filters ul { flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
.filters a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 1rem;
  border: 1px solid var(--border-strong); border-radius: 999px;
  color: var(--text); text-decoration: none; background: var(--surface); font-weight: 500;
}
.filters a:hover { background: var(--surface-2); }
.filters a[aria-current="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.tabs { overflow-x: auto; border-bottom: 1px solid var(--border); margin: 0.75rem 0 1rem; }
.tabs a {
  display: flex; align-items: center; min-height: 44px; padding: 0 0.9rem;
  color: var(--text); text-decoration: none; white-space: nowrap; font-weight: 500;
  border-bottom: 3px solid transparent;
}
.tabs a:hover { background: var(--surface-2); }
.tabs a[aria-current="page"] { border-bottom-color: var(--accent); font-weight: 700; }
.panel > h2:first-child { margin-top: 0.5rem; }

/* ── Forms ── */
.form { max-width: 44rem; }
.field { margin: 0 0 1rem; min-width: 0; }
.field label, .org-box label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.org-box label { margin: 0; font-weight: 400; }
.optional { font-weight: 400; color: var(--muted); }
.hint { margin: 0.3rem 0 0; font-size: 0.9rem; color: var(--muted); }

input, select, textarea {
  width: 100%; min-height: 44px; padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 6rem; resize: vertical; }
input[type="checkbox"] { width: 1.4rem; height: 1.4rem; min-height: 0; padding: 0; accent-color: var(--accent); flex: none; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--accent); border-width: 2px; }
input[readonly] { background: var(--surface-2); }
.check-row { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; }
.check-row label { margin: 0; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0 1rem; }
.form-status { min-height: 1.5rem; margin: 0.25rem 0; color: var(--muted); }
.form-status:empty { min-height: 0; margin: 0; }
.form-status.is-error { color: var(--err-text); background: var(--err-bg); padding: 0.6rem 0.8rem; border-radius: var(--radius); font-weight: 600; }
.form-status.is-ok { color: var(--ok-text); background: var(--ok-bg); padding: 0.6rem 0.8rem; border-radius: var(--radius); }
.fee-note, .pays { padding: 0.6rem 0.8rem; background: var(--surface-2); border-radius: var(--radius); }
.pays:empty { display: none; }
.pays { font-weight: 600; }

.search { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 0.75rem; margin: 0.75rem 0; }
.search .field { flex: 1 1 16rem; margin: 0; }
.search .actions { margin: 0; }

.copy-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 0.5rem 0; }
.copy-row input { flex: 1 1 14rem; }
.copy-row a { min-width: 0; padding: 0.6rem 0; }

.keybox { border: 2px solid var(--accent); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; background: var(--surface); }
.keybox h3 { margin-top: 0; }
.snippet {
  margin: 0.5rem 0; padding: 0.85rem 1rem; overflow-x: auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.9rem; line-height: 1.6; white-space: pre;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin: 0.75rem 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card .table-wrap { border: 0; border-top: 1px solid var(--border); border-radius: 0; margin-bottom: 0; }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data th, .data td { padding: 0.65rem 0.85rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.data th { font-size: 0.85rem; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--surface-2); }
.data tbody tr:last-child td { border-bottom: 0; }
.data .num { text-align: right; white-space: nowrap; }
.data td a:not(.btn) { display: inline-block; padding: 0.55rem 0; margin: -0.55rem 0; }
.bar-track { display: block; width: 100%; min-width: 5rem; height: 0.7rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 0.4rem; }
.bar { display: block; height: 100%; min-width: 2px; background: var(--accent); border-radius: 999px; }

/* Rows become stacked cards on small screens. */
@media (max-width: 720px) {
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .card .table-wrap { border-top: 0; }
  table.data, .data tbody, .data tr, .data td { display: block; width: 100%; }
  .data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .data tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 0.75rem; padding: 0.35rem 0; }
  .card .data tr { background: var(--surface-2); }
  .data td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: 0.35rem 0.85rem; text-align: right; }
  .data td::before { content: attr(data-label); flex: none; max-width: 45%; text-align: left; color: var(--muted); font-size: 0.9rem; }
  .data td .cell { min-width: 0; overflow-wrap: anywhere; }
  .data .num { white-space: normal; }
  .data td:first-child { font-size: 1.05rem; }
  .data td .actions { justify-content: flex-end; }
  .bar-track { min-width: 8rem; }
}

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.pager p { margin: 0; }

/* ── Dialogs ── */
.dialog {
  width: min(40rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem);
  padding: 0; border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); color: var(--text); overflow: auto;
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 0.75rem 0.25rem 1.25rem; }
.dialog-head h2 { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.dialog-body { padding: 0.25rem 1.25rem 1.25rem; }

/* ── Messages ── */
.toasts { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 0.75rem; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 0.75rem;
  max-width: min(36rem, 100%); padding: 0.4rem 0.5rem 0.4rem 1rem;
  background: var(--text); color: var(--bg); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.toast-error { background: var(--err-bg); color: var(--err-text); border: 1px solid var(--err-text); }
.toast-close { min-height: 44px; padding: 0 0.75rem; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
