/* Passage / courseloop.app -- shared styles.
   Design tokens first; components below use only these.
   Monospace is reserved for real technical values (links, figures), not labels. */

:root {
  --bg: #0b0d10;
  --surface: #12161b;
  --line: #232932;
  --text: #e6e9ed;
  --muted: #8993a0;
  --accent: #14b8a6;
  --accent-strong: #0f9488;
  --warn: #e5a03b;
  --danger: #e5484d;

  --font-ui: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --radius: 6px;
  --column: 44rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }

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

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: #5eead4; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

/* ---------- layout ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: var(--column); margin: 0 auto; padding: 1.5rem 1.25rem;
}
.brand { font-weight: 700; font-size: 1.25rem; letter-spacing: -0.01em; color: var(--text); text-decoration: none; }
.site-nav { display: flex; align-items: center; gap: 1.25rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--text); }

main { max-width: var(--column); margin: 0 auto; padding: 1rem 1.25rem 4rem; }

h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 0.75rem; }
h2 { font-size: 1.125rem; margin: 0 0 0.75rem; letter-spacing: -0.01em; }
p { margin: 0 0 1rem; }
.lede { color: var(--muted); font-size: 1.125rem; max-width: 36rem; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.65rem 1.1rem; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--accent); color: #04110f;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #04110f; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--line); }
.btn-quiet:hover { background: var(--surface); border-color: var(--muted); color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }

/* ---------- auth pages ---------- */
.auth-wrap { display: flex; justify-content: center; padding-top: 1rem; }
#clerk-mount { min-height: 26rem; display: flex; justify-content: center; width: 100%; }

/* ---------- dashboard ---------- */
.status-line { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); margin-bottom: 2rem; }
.dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--accent); }
.dot.bad { background: var(--danger); }

.setup {
  display: grid; grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); gap: 2rem; align-items: start;
  padding: 1.5rem 0 2rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  margin-bottom: 2rem;
}
.qr-box { background: #fff; border-radius: var(--radius); padding: 0.75rem; line-height: 0; }
.qr-box svg { width: 100%; height: auto; display: block; }
.qr-box.empty {
  background: var(--surface); color: var(--muted); line-height: 1.4;
  padding: 1.25rem; font-size: 0.9rem; min-height: 9rem;
}
.link-field {
  font-family: var(--font-data); font-size: 0.8125rem; line-height: 1.5;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.75rem 0.85rem; word-break: break-all; margin: 0.5rem 0 0.75rem;
  max-height: 8.5rem; overflow: auto;
}
.setup-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.facts { margin: 0 0 2rem; }
.facts > div { display: flex; justify-content: space-between; gap: 1.5rem; padding: 0.85rem 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.facts .figure { font-family: var(--font-data); font-variant-numeric: tabular-nums; }

.meter { height: 0.35rem; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 0.5rem; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter.low > span { background: var(--warn); }
.meter.critical > span { background: var(--danger); }

.contact textarea {
  width: 100%; min-height: 6rem; resize: vertical; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; font: inherit;
}
.contact textarea:focus { border-color: var(--accent); outline: none; }
.contact .row { display: flex; align-items: center; gap: 1rem; margin-top: 0.75rem; }

.note { color: var(--muted); font-size: 0.9rem; }
.error-text { color: var(--danger); }
.fatal { padding: 1rem 0; }
.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;
}

@media (max-width: 40rem) {
  .setup { grid-template-columns: 1fr; }
  .qr-box { max-width: 15rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- small shared bits ---------- */
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.badge {
  display: inline-block; font-size: 0.75rem; line-height: 1; padding: 0.2rem 0.45rem;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  vertical-align: middle;
}
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--danger); border-color: var(--danger); }
.badge.good { color: var(--accent); border-color: var(--accent); }
.apps { margin: 0 0 2rem; }
.apps ul { margin: 0.25rem 0 0; padding-left: 1.1rem; color: var(--muted); }
.apps li { margin: 0.25rem 0; }
.apps strong { color: var(--text); font-weight: 500; }

/* ---------- admin ---------- */
body:has(.admin) main, body:has(.admin) .site-header { max-width: 72rem; }
.stats { display: flex; flex-wrap: wrap; gap: 0.75rem 2.5rem; margin: 0 0 1.5rem; }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { color: var(--muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-family: var(--font-data); font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  font: inherit; padding: 0.6rem 0.9rem; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.toolbar input { flex: 1 1 14rem; }
.admin input, .admin select, .sheet input, .sheet select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.5rem 0.65rem; font: inherit; min-width: 0;
}
.admin input:focus, .admin select:focus, .sheet input:focus, .sheet select:focus { border-color: var(--accent); outline: none; }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.grid th { text-align: left; color: var(--muted); font-weight: 500; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 0.75rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid .figure { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.conn { padding: 0.5rem 0; }
.conn + .conn { border-top: 1px dashed var(--line); }
.conn .meter { max-width: 14rem; }
.conn-head { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem; }
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-start;
  justify-content: center; padding: 4vh 1rem; z-index: 50; overflow-y: auto;
}
.sheet-backdrop[hidden] { display: none; }
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); width: min(34rem, 100%); padding: 1.25rem 1.25rem 1.5rem; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.sheet-head h2 { margin: 0; }
.form { display: grid; gap: 0.85rem; }
.form label { display: grid; gap: 0.3rem; color: var(--muted); font-size: 0.9rem; }
.form .inline { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; margin: 0; display: grid; gap: 0.75rem; }
.form legend { color: var(--muted); font-size: 0.85rem; padding: 0 0.3rem; }
.form .actions { margin-top: 0.25rem; }
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 1rem; max-width: calc(100vw - 2rem);
}
.toast.bad { border-color: var(--danger); color: var(--danger); }
.msg { padding: 0.9rem 0; border-bottom: 1px solid var(--line); }
.msg p { white-space: pre-wrap; margin: 0.4rem 0; }
.msg-meta { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; color: var(--muted); font-size: 0.85rem; }
.empty-state { color: var(--muted); padding: 1.5rem 0; }

/* Elements with the hidden attribute stay hidden even when a class sets display. */
[hidden] { display: none !important; }
.facts dd .meter { width: 10rem; margin-left: auto; }

/* Admin table becomes stacked cards on phones. */
@media (max-width: 760px) {
  table.grid thead { display: none; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr { border-bottom: 1px solid var(--line); padding: 0.75rem 0; }
  table.grid td { border: 0; padding: 0.3rem 0; }
  .conn .meter { max-width: none; }
}
