/* ==========================================================================
   STEALIX — shared base + components

   Everything the public site and the admin panel agree on: the reset, the
   type scale, focus and accessibility scaffolding, and the components that
   look the same on both surfaces — buttons, inputs, cards, badges, quota
   bars, modals, toasts, notices, empty states, centred auth cards.

   Requires shared/stealix-tokens.css. Declares no literal colour or size of
   its own: every value is a token.

   A rule belongs here when both surfaces need it. Sidebar, topbar, data
   tables and KPI blocks are admin layout and live in static/admin/admin.css;
   the marketing shell lives in static/site/site.css.
   ========================================================================== */

/* ==========================================================================
   Base
   ========================================================================== */

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

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-weight: var(--fw-regular);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, figure { margin: 0; }
img, svg { max-width: 100%; }

a { color: inherit; }

:focus-visible {
  outline: var(--bw-strong) solid var(--ink);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

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

.skip-link {
  position: absolute; left: var(--s-4); top: -100px; z-index: 100;
  background: var(--ink); color: var(--surface-1);
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  text-decoration: none;
}
.skip-link:focus { top: var(--s-4); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ==========================================================================
   Typography helpers
   ========================================================================== */

.h1    { font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: var(--fw-medium); letter-spacing: -.01em; }
.h2    { font-size: var(--fs-h2); line-height: var(--lh-h2); font-weight: var(--fw-medium); }
.h3    { font-size: var(--fs-h3); line-height: var(--lh-h3); font-weight: var(--fw-medium); }
.label {
  font-size: var(--fs-label); line-height: var(--lh-label); font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--ink-60);
}
.meta  { font-size: var(--fs-small); line-height: var(--lh-small); color: var(--ink-40); }
.mono  { font-family: var(--font-mono); font-size: var(--fs-mono); line-height: var(--lh-mono); }
.num   { font-variant-numeric: tabular-nums; }

/* the reference's signature: lime highlight behind a heading word */
.mark {
  background: var(--lime);
  border-radius: 6px;
  padding: 2px var(--s-2);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* ==========================================================================
   Layout utilities
   ========================================================================== */

.grid { display: grid; gap: var(--s-4); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.wrap { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: var(--surface-1);
  border: var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
}
.card--muted { background: var(--surface-2); border-color: transparent; }
.card--inverted { background: var(--ink); border-color: var(--ink); color: var(--surface-1); }
.card--inverted .card__label { color: var(--on-ink-dim); }
.card--flush { padding: 0; overflow: hidden; }

.card__label { margin-bottom: var(--s-3); }
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); padding: var(--s-6); border-bottom: var(--border-soft);
}
.card__body { padding: var(--s-6); }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 40px; padding: 0 var(--s-4);
  border-radius: var(--r-md);
  border: var(--border);
  background: var(--surface-1); color: var(--ink);
  font-family: inherit; font-size: var(--fs-body); line-height: 1;
  font-weight: var(--fw-medium);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.btn .icon { flex: none; }

.btn--primary {
  background: var(--ink); color: var(--surface-1);
  box-shadow: var(--shadow-hard);
}
.btn--primary:hover { background: var(--lime); color: var(--ink); }

.btn--accent {
  background: var(--lime); color: var(--ink);
  box-shadow: var(--shadow-hard);
}
.btn--accent:hover { background: var(--ink); color: var(--lime); }

.btn--primary:active, .btn--accent:active { transform: translateY(3px); box-shadow: 0 1px 0 0 var(--ink); }

.btn--secondary { background: transparent; }
.btn--secondary:hover { background: var(--surface-2); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-60); font-weight: var(--fw-regular); }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn--danger { background: var(--danger-bg); border-color: var(--danger-fg); color: var(--danger-fg); }
.btn--danger:hover { background: var(--danger-fg); color: var(--surface-1); }

.btn--sm { height: 32px; padding: 0 var(--s-3); font-size: var(--fs-small); }
.btn--lg { height: 48px; padding: 0 var(--s-6); }

.btn[disabled], .btn[aria-disabled="true"] {
  background: var(--surface-2); border-color: var(--line-soft); color: var(--ink-40);
  box-shadow: none; cursor: not-allowed; transform: none;
}

.btn-row { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }

/* ==========================================================================
   Forms
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: var(--fw-medium); color: var(--ink-60); }

.input {
  height: 40px;
  padding: 0 14px;
  border: var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1); color: var(--ink);
  font-family: inherit; font-size: var(--fs-body); line-height: var(--lh-body);
  width: 100%;
}
.input::placeholder { color: var(--ink-40); }
.input:focus-visible { outline: 0; border-width: var(--bw-strong); box-shadow: var(--focus-ring); }
.input[disabled] { background: var(--surface-2); border-color: var(--line-soft); color: var(--ink-40); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--danger-fg); }

select.input { appearance: none; padding-right: var(--s-8); cursor: pointer; }

.select-wrap { position: relative; }
.select-wrap .icon {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--ink-60);
}

.field__error { font-size: var(--fs-small); line-height: var(--lh-small); color: var(--danger-fg); }

/* search */
.search { position: relative; width: 360px; max-width: 100%; }
.search .icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--ink-40); pointer-events: none;
}
.search .input { height: 44px; padding-left: 42px; border-radius: var(--r-pill); }

/* segmented control */
.segmented {
  display: inline-flex; gap: var(--s-1);
  padding: var(--s-1);
  background: var(--surface-2);
  border-radius: var(--r-pill);
}
.segmented__item {
  min-height: 32px; padding: 0 var(--s-4);
  display: inline-flex; align-items: center;
  border: var(--bw) solid transparent; border-radius: var(--r-pill);
  background: none; color: var(--ink-60);
  font: inherit; font-size: var(--fs-small); cursor: pointer;
}
.segmented__item[aria-pressed="true"] {
  background: var(--surface-1); border-color: var(--line); color: var(--ink);
  font-weight: var(--fw-medium);
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-small); line-height: var(--lh-small); font-weight: var(--fw-medium);
  white-space: nowrap;
  background: var(--info-bg); color: var(--info-fg);
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: var(--r-pill);
  background: currentColor; flex: none;
}
.badge--ok      { background: var(--ok-bg);     color: var(--ok-fg); }
.badge--warn    { background: var(--warn-bg);   color: var(--warn-fg); }
.badge--danger  { background: var(--danger-bg); color: var(--danger-fg); }
.badge--neutral { background: var(--info-bg);   color: var(--ink-60); }
.badge--accent  { background: var(--lime); color: var(--ink); border: var(--bw) solid var(--ink); }
.badge--accent::before { background: var(--ink); }

/* ==========================================================================
   Quota bar
   The same component reports a device quota to an operator in /admin and to
   the owner of the subscription in /account.
   ========================================================================== */

.quota { display: flex; flex-direction: column; gap: 6px; min-width: 132px; }
.quota__track {
  height: 6px; border-radius: var(--r-pill);
  background: var(--surface-2); overflow: hidden;
}
.quota__fill { height: 100%; border-radius: var(--r-pill); background: var(--ok-fg); }
.quota--warn   .quota__fill { background: var(--warn-fill); }
.quota--danger .quota__fill { background: var(--danger-fg); }
.quota__text { font-size: var(--fs-small); line-height: var(--lh-small); color: var(--ink-60); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Empty & loading
   ========================================================================== */

.empty { text-align: center; padding: var(--s-12) var(--s-6); }
.empty__icon {
  width: 48px; height: 48px; margin: 0 auto var(--s-4);
  display: grid; place-items: center;
  border-radius: var(--r-md); background: var(--surface-1);
  border: var(--border); color: var(--ink-40);
}
.empty__title { font-weight: var(--fw-medium); margin-bottom: var(--s-2); }
.empty__text { color: var(--ink-60); margin-bottom: var(--s-6); }

.skeleton {
  background: var(--surface-2);
  border-radius: var(--r-sm);
  height: 12px;
  animation: sk 1.4s ease-in-out infinite;
}
.skeleton--text  { width: 60%; }
.skeleton--wide  { width: 85%; }
.skeleton--pill  { height: 24px; width: 84px; border-radius: var(--r-pill); }
@keyframes sk { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ==========================================================================
   Modal
   ========================================================================== */

.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: var(--s-6);
  background: var(--overlay);
}
.modal__panel {
  width: 100%; max-width: 520px;
  background: var(--surface-1);
  border: var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.modal__stripe { height: 4px; background: var(--danger-fg); }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); padding: var(--s-6); border-bottom: var(--border-soft);
}
.modal__body { padding: var(--s-6); display: flex; flex-direction: column; gap: var(--s-4); }
.modal__body p { color: var(--ink-60); }
.modal__foot {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  padding: var(--s-6); border-top: var(--border-soft);
}

/* ==========================================================================
   Toast
   ========================================================================== */

.toasts {
  position: fixed; right: var(--s-6); bottom: var(--s-6); z-index: 70;
  display: flex; flex-direction: column; gap: var(--s-3);
  width: 340px; max-width: calc(100vw - var(--s-8));
}
.toast {
  display: flex; align-items: flex-start; gap: var(--s-3);
  background: var(--surface-1);
  border: var(--border);
  border-left-width: 4px;
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-pop);
}
.toast--ok     { border-left-color: var(--ok-fg); }
.toast--warn   { border-left-color: var(--warn-fg); }
.toast--danger { border-left-color: var(--danger-fg); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-weight: var(--fw-medium); }
.toast__text { color: var(--ink-60); font-size: var(--fs-small); line-height: var(--lh-small); margin-top: 2px; }

/* ==========================================================================
   Notice banner — states a page-wide caveat (e.g. placeholder data)
   ========================================================================== */

.notice {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-4);
  border: var(--border);
  border-left-width: 4px;
  border-radius: var(--r-lg);
  background: var(--warn-bg);
  border-left-color: var(--warn-fg);
  color: var(--warn-fg);
  margin-bottom: var(--s-6);
}
.notice .icon { flex: none; margin-top: 2px; }
.notice__title { font-weight: var(--fw-medium); }
/* block, so a notice with both a title and a text reads as two lines --
   the margin-top above always assumed it and nothing supplied it */
.notice__text { display: block; font-size: var(--fs-small); line-height: var(--lh-small); margin-top: 2px; }

/* Every notice carries an icon and words as well as a colour, so the state is
   never conveyed by hue alone. */
.notice--ok {
  background: var(--ok-bg);
  border-left-color: var(--ok-fg);
  color: var(--ok-fg);
}
.notice--danger {
  background: var(--danger-bg);
  border-left-color: var(--danger-fg);
  color: var(--danger-fg);
}

/* ==========================================================================
   Centred single-card pages (sign-in, verification, 403)
   ========================================================================== */

.centered {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: var(--s-6);
  background: var(--canvas);
}
.centered__card {
  width: 100%; max-width: 420px;
  background: var(--surface-1);
  border: var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-8);
  text-align: center;
}
.centered__brand {
  display: inline-flex; align-items: center; gap: var(--s-3);
  margin-bottom: var(--s-6);
}
.centered__title { margin-bottom: var(--s-2); }
.centered__text { color: var(--ink-60); margin-bottom: var(--s-6); }
.centered__slot { display: flex; justify-content: center; min-height: 48px; }
.centered__foot { margin-top: var(--s-6); }

/* ==========================================================================
   Touch input
   Desktop density (40px / 32px controls) is deliberate for a pointer. On a
   touch device every control grows to the 44px target instead.
   ========================================================================== */

@media (pointer: coarse) {
  .btn,
  .btn--sm,
  .btn--lg,
  .input,
  .segmented__item { min-height: var(--tap-min); }
  .search .input { min-height: var(--tap-min); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* 1280–1439 */
@media (max-width: 1439px) {
  .grid--4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 1024–1279 */
@media (max-width: 1279px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ≤767 — single column */
@media (max-width: 767px) {
  .h1 { font-size: 28px; line-height: 34px; }

  .grid--4, .grid--3, .grid--2 { grid-template-columns: minmax(0, 1fr); }

  .search { width: 100%; }

  .modal { padding: var(--s-4); align-items: end; }
  .toasts { right: var(--s-4); left: var(--s-4); bottom: var(--s-4); width: auto; }
}
