/* The Majestic Network — shared design tokens and primitives.
 *
 * One system, three surfaces: the agency site (web/src/styles/global.css), the
 * premier ops dashboard (static/dashboard/app.css) and the billing site
 * (static/billing/style.css). The token layer below is ported from the agency
 * stylesheet on purpose — a colour or radius change should land in one place,
 * and the dashboard should look like it came from the company that built
 * themajesticnetwork.com.
 *
 * Why hand-authored and not a framework: the whole file is smaller than
 * Bootstrap's reset, it is served from our own origin (one connection, long
 * cache), and every rule here is one we actually use. The pages that load this
 * previously pulled ~700KB from four third-party origins to render tables.
 *
 * Layers, in order: tokens → reset → a11y → primitives → utilities.
 * Components that belong to one surface only live in that surface's file.
 */

/* ── tokens ──────────────────────────────────────────────────────────────── */

:root {
  /* Brand. Matches web/src/styles/global.css --accent, which is itself written
     from site/content.json — keep the three in step. */
  --accent: #7c3aed;
  --accent-soft: color-mix(in oklab, var(--accent) 18%, transparent);
  --accent-line: color-mix(in oklab, var(--accent) 42%, transparent);
  --accent-ink: #ffffff;
  /* --accent is the brand fill; --accent-text is the same hue lightened until
     it clears AA as body text (the brand purple itself is 3.43:1 on dark). Use
     --accent for fills, borders and icons; --accent-text for words. */
  --accent-text: #955ff0;

  /* Dark is the default because this is a dark brand, and because an ops
     dashboard gets stared at all day. The light map below is a real design,
     not an inversion. */
  --bg: #0a0c12;
  --bg-elevated: #11141d;
  --bg-sunken: #070910;
  --panel: color-mix(in oklab, var(--bg-elevated) 92%, var(--accent));
  --text: #eef1f8;
  --text-muted: #99a3b8;
  --text-faint: #757e92;   /* 4.52:1 on --bg-elevated; #6b7488 measured 3.92 */
  --line: #1e2432;
  --line-strong: #2b3346;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 32px -12px rgb(0 0 0 / 0.6);
  --focus: #8ab4ff;

  /* Status. Each has a text-safe ink and a soft fill so a badge never relies on
     colour alone at a contrast the eye can't resolve. */
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;
  --ok-soft: color-mix(in oklab, var(--ok) 16%, transparent);
  --warn-soft: color-mix(in oklab, var(--warn) 16%, transparent);
  --danger-soft: color-mix(in oklab, var(--danger) 16%, transparent);
  --info-soft: color-mix(in oklab, var(--info) 16%, transparent);

  /* Type: system fonts. The fastest webfont is the one already on the device —
     this removes a third-party connection, a render-blocking request and the
     layout shift that came with it. */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* A denser scale than the marketing site's — this one has to fit tables. */
  --step--2: 0.75rem;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.0625rem;
  --step-2: clamp(1.25rem, 1.15rem + 0.4vw, 1.5rem);
  --step-3: clamp(1.5rem, 1.3rem + 0.8vw, 2rem);

  /* Space and shape */
  --gutter: clamp(1rem, 3vw, 2rem);
  --measure: 68ch;
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;
  --btn-radius: var(--radius-pill);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
}

/* The light map is defined twice on purpose: once for viewers on the system
   default (no data-theme attribute at all) and once for an explicit choice, so
   the toggle wins in both directions and neither state falls through to a
   colour that was only ever defined inside a media query. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #fbfbfd;
    --bg-elevated: #ffffff;
    --bg-sunken: #f2f4f9;
    --text: #10141f;
    --text-muted: #4d586d;
    --text-faint: #656f82;
    --line: #e3e7f0;
    --line-strong: #cfd6e4;
    --shadow: 0 1px 2px rgb(16 20 31 / 0.06), 0 14px 34px -18px rgb(16 20 31 / 0.28);
    --accent-text: var(--accent);
    --focus: #2451c7;
    --ok: #047857;
    --warn: #92610a;
    --danger: #b91c1c;
    --info: #1d4ed8;
  }
}

:root[data-theme="light"] {
  --bg: #fbfbfd;
  --bg-elevated: #ffffff;
  --bg-sunken: #f2f4f9;
  --text: #10141f;
  --text-muted: #4d586d;
  --text-faint: #656f82;
  --line: #e3e7f0;
  --line-strong: #cfd6e4;
  --shadow: 0 1px 2px rgb(16 20 31 / 0.06), 0 14px 34px -18px rgb(16 20 31 / 0.28);
  --accent-text: var(--accent);
    --focus: #2451c7;
  --ok: #047857;
  --warn: #92610a;
  --danger: #b91c1c;
  --info: #1d4ed8;
}

/* ── reset / base ────────────────────────────────────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { color-scheme: light; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 0.5em;
  text-wrap: balance;
}
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
h4 { font-size: var(--step-0); }
p { margin: 0 0 1em; text-wrap: pretty; }
p:last-child { margin-bottom: 0; }

a { color: inherit; text-decoration-color: var(--accent-line); text-underline-offset: 0.18em; }
a:hover { text-decoration-color: var(--accent); }

img, svg { max-width: 100%; height: auto; display: block; }

code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }
code {
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.1em 0.38em;
}
pre {
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  overflow-x: auto;   /* long lines scroll here, never widen the page */
  margin: 0 0 var(--space-4);
}
pre code { background: none; border: 0; padding: 0; }

hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-5) 0; }

/* ── accessibility ───────────────────────────────────────────────────────── */

/* One visible, keyboard-only focus ring everywhere. There were no :focus
   styles at all before, which makes a dashboard unusable without a mouse. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -5rem;
  z-index: 200;
  padding: 0.7rem 1rem;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus { top: var(--space-2); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ── icons ───────────────────────────────────────────────────────────────── */

/* Icons are <svg><use href="…#name"> against one cached sprite. Replaces a
   ~160KB webfont that was loaded to draw 63 glyphs. Decorative icons carry
   aria-hidden and inherit currentColor, so they follow the theme for free. */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.16em;
  display: inline-block;
}
.icon-lg { width: 1.5em; height: 1.5em; }
.icon-sm { width: 1em; height: 1em; stroke-width: 2.1; }

/* ── primitives: buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.15rem;
  min-height: 44px;              /* pointer target floor */
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: var(--step--1);
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not([disabled]) { background: color-mix(in oklab, var(--accent) 86%, #fff); }

.btn-ghost { background: transparent; border-color: var(--line-strong); }
.btn-ghost:hover:not([disabled]) { border-color: var(--accent); background: var(--accent-soft); }

.btn-quiet { background: transparent; border-color: transparent; color: var(--text-muted); font-weight: 500; }
.btn-quiet:hover:not([disabled]) { background: var(--bg-sunken); color: var(--text); }

.btn-danger { background: transparent; border-color: color-mix(in oklab, var(--danger) 50%, transparent); color: var(--danger); }
.btn-danger:hover:not([disabled]) { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { min-height: 34px; padding: 0.3rem 0.75rem; font-size: var(--step--2); gap: 0.35rem; }
.btn-block { width: 100%; }

/* A row of buttons that wraps instead of overflowing on a phone. */
.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ── primitives: forms ───────────────────────────────────────────────────── */

.field { display: block; margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }

.field-label, .form-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text);
}
.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: var(--step--2);
  color: var(--text-muted);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--step-0);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.textarea { min-height: 6rem; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  background: var(--bg-elevated);
  outline: none;
}
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-sm, .select-sm { min-height: 34px; padding: 0.25rem 0.55rem; font-size: var(--step--1); }

.select {
  appearance: none;
  padding-right: 2.2rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.05rem) 55%, calc(100% - 0.72rem) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* Checkbox / radio rows: the whole label is the target, not a 13px box. */
.check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 34px;
  cursor: pointer;
  font-size: var(--step--1);
}
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); flex: none; cursor: pointer; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-weight: 600; }

/* ── primitives: panel / card ────────────────────────────────────────────── */

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  font-size: var(--step-0);
  font-weight: 650;
  letter-spacing: -0.01em;
}
.panel-title .icon { color: var(--accent); }
.panel-body { padding: var(--space-5); }
.panel-body > :last-child { margin-bottom: 0; }
.panel-foot {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--line);
  background: var(--bg-sunken);
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: var(--step--1);
  color: var(--text-muted);
}

/* ── primitives: badge / chip ────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.16rem 0.55rem;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: var(--step--2);
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-neutral { background: var(--bg-sunken); border-color: var(--line-strong); color: var(--text-muted); }
.badge-ok { background: var(--ok-soft); border-color: color-mix(in oklab, var(--ok) 40%, transparent); color: var(--ok); }
.badge-warn { background: var(--warn-soft); border-color: color-mix(in oklab, var(--warn) 40%, transparent); color: var(--warn); }
.badge-danger { background: var(--danger-soft); border-color: color-mix(in oklab, var(--danger) 40%, transparent); color: var(--danger); }
.badge-info { background: var(--info-soft); border-color: color-mix(in oklab, var(--info) 40%, transparent); color: var(--info); }
.badge-accent { background: var(--accent-soft); border-color: var(--accent-line); color: color-mix(in oklab, var(--accent) 70%, var(--text)); }

/* A dot that states its meaning to a screen reader through its label, never
   through colour alone. */
.dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; flex: none; background: currentColor; }

/* ── primitives: table ───────────────────────────────────────────────────── */

.table-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}
.table th, .table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--step--2);
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in oklab, var(--accent) 5%, transparent); }
.table tfoot td { background: var(--bg-sunken); font-weight: 650; border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }

.empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--step--1);
}
.empty .icon { width: 1.75rem; height: 1.75rem; margin: 0 auto var(--space-2); color: var(--text-faint); }

/* ── primitives: alert ───────────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.8rem 1rem;
  margin-bottom: var(--space-4);
  border: 1px solid var(--line-strong);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: var(--step--1);
}
.alert-success { border-left-color: var(--ok); background: var(--ok-soft); }
.alert-danger, .alert-error { border-left-color: var(--danger); background: var(--danger-soft); }
.alert-warning { border-left-color: var(--warn); background: var(--warn-soft); }
.alert-info { border-left-color: var(--info); background: var(--info-soft); }
.alert-body { flex: 1; min-width: 0; }
.alert-close {
  border: 0; background: none; color: inherit; cursor: pointer;
  padding: 0.15rem; margin: -0.15rem -0.25rem -0.15rem 0; border-radius: 5px; opacity: 0.65;
}
.alert-close:hover { opacity: 1; background: color-mix(in oklab, currentColor 12%, transparent); }

/* ── primitives: spinner ─────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 0.9em; height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -0.1em;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── utilities ───────────────────────────────────────────────────────────── */

/* Deliberately small: layout primitives plus a spacing scale. Anything that
   needs more than this earns a named component class instead. */

/* .stack puts consistent vertical rhythm between children — the owl selector
   means no first/last-child margin cleanup anywhere. */
.stack > * + * { margin-top: var(--stack-gap, var(--space-4)); }
.stack-2 { --stack-gap: var(--space-2); }
.stack-3 { --stack-gap: var(--space-3); }
.stack-5 { --stack-gap: var(--space-5); }
.stack-6 { --stack-gap: var(--space-6); }

/* .cluster is a wrapping horizontal group — this is what replaces the
   d-flex/gap/flex-wrap trio that was repeated throughout the markup. */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cluster-gap, var(--space-3));
}
.cluster-2 { --cluster-gap: var(--space-2); }
.cluster-4 { --cluster-gap: var(--space-4); }
.cluster-between { justify-content: space-between; }
.cluster-end { justify-content: flex-end; }
.cluster-top { align-items: flex-start; }
.cluster-baseline { align-items: baseline; }

/* One auto-responsive grid instead of col-md-3/col-md-4/col-md-6 breakpoint
   juggling: columns are chosen from available width, so it is correct at every
   size including the ones nobody tested. */
.grid {
  display: grid;
  gap: var(--grid-gap, var(--space-4));
  grid-template-columns: repeat(auto-fit, minmax(min(var(--col, 16rem), 100%), 1fr));
}
.grid-sm { --col: 12rem; }
.grid-lg { --col: 22rem; }
.grid-fixed-2 { grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); }

.flex-fill { flex: 1 1 auto; min-width: 0; }
.full { width: 100%; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.tnum { font-variant-numeric: tabular-nums; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.tone-ok { color: var(--ok); }
.tone-warn { color: var(--warn); }
.tone-danger { color: var(--danger); }
.tone-info { color: var(--info); }
.tone-accent { color: var(--accent-text); }

.t--2 { font-size: var(--step--2); }
.t--1 { font-size: var(--step--1); }
.t-1 { font-size: var(--step-1); }
.weight-600 { font-weight: 600; }

.text-start { text-align: left; }
.text-center { text-align: center; }
.text-end { text-align: right; }

.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: var(--space-2); } .mb-2 { margin-bottom: var(--space-2); }
.mt-3 { margin-top: var(--space-3); } .mb-3 { margin-bottom: var(--space-3); }
.mt-4 { margin-top: var(--space-4); } .mb-4 { margin-bottom: var(--space-4); }
.mt-5 { margin-top: var(--space-5); } .mb-5 { margin-bottom: var(--space-5); }
.mt-6 { margin-top: var(--space-6); } .mb-6 { margin-bottom: var(--space-6); }

.hidden { display: none !important; }

@media print {
  .no-print { display: none !important; }
  .panel { box-shadow: none; border-color: #999; }
}
