:root {
  --bg: #0b0c0e;
  --bg-soft: #101216;
  --panel: #15171b;
  --panel-strong: #1a1d22;
  --panel-hover: #20242a;
  --line: #292d34;
  --line-bright: #3a4049;
  --text: #f4f5f6;
  --text-soft: #c5c8cd;
  --muted: #99a0ab;
  --text-dim: #99a0ab;
  --red: #e52d34;
  --red-text: #ff6f74;
  --red-soft: rgba(229, 45, 52, .12);
  --green: #71d39a;
  --green-soft: rgba(113, 211, 154, .11);
  --amber: #e6b45b;
  --amber-soft: rgba(230, 180, 91, .11);
  --blue: #7eb7ee;
  --blue-soft: rgba(126, 183, 238, .11);
  --shadow: 0 24px 64px rgba(0, 0, 0, .34);

  --text-xs: .75rem;
  --text-sm: .8125rem;
  --text-base: .875rem;
  --text-md: 1rem;
  --text-lg: 1.1875rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --leading-tight: 1.2;
  --leading-normal: 1.55;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --control-sm: 32px;
  --control-md: 40px;
  --control-lg: 48px;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 6px;

  --sidebar: 246px;
  /* System stack by design. To adopt Inter, self-host a woff2 under
     assets/fonts/ — the CSP (default-src 'self') blocks font CDNs. */
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 82% -20%, rgba(229, 45, 52, .08), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

button,
input,
select,
textarea {
  font: inherit;
}

/* Without this, inputs inherit .field's label typography and users type in
   14px bold. 16px also stops iOS Safari force-zooming on focus. */
input,
select,
textarea {
  font-size: var(--text-md);
  font-weight: 400;
  letter-spacing: normal;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.is-hidden {
  display: none !important;
}

/* boot.js stamps this before first paint so returning users never see the
   login hero flash. */
.tw-authed #auth-view {
  display: none !important;
}

.eyebrow,
.page-context {
  display: block;
  color: var(--red-text);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .12em;
  line-height: 1.4;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand-mark {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #454b54;
  background:
    linear-gradient(135deg, transparent 11px, #23272d 0) top left,
    linear-gradient(225deg, transparent 11px, #23272d 0) top right,
    linear-gradient(315deg, transparent 11px, #23272d 0) bottom right,
    linear-gradient(45deg, transparent 11px, #23272d 0) bottom left;
  background-position: 0 0, 100% 0, 100% 100%, 0 100%;
  background-repeat: no-repeat;
  background-size: 52% 52%;
  color: #eef0f2;
}

.brand-mark::after {
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(229, 45, 52, .72);
  clip-path: polygon(22% 0, 78% 0, 100% 22%, 100% 78%, 78% 100%, 22% 100%, 0 78%, 0 22%);
  content: "";
}

.brand-mark span {
  position: relative;
  z-index: 1;
  font-size: var(--text-xs);
  font-weight: 900;
  letter-spacing: -.08em;
}

.brand-copy {
  display: grid;
  min-width: 0;
}

.brand-copy strong {
  font-size: var(--text-base);
  letter-spacing: .1em;
  line-height: var(--leading-tight);
  white-space: nowrap;
}

.brand-copy small {
  margin-top: var(--space-1);
  color: var(--text-dim);
  font-size: .625rem;
  font-weight: 700;
  letter-spacing: .12em;
  white-space: nowrap;
}

.brand-large {
  gap: var(--space-4);
}

.brand-large .brand-mark {
  width: 52px;
  height: 52px;
  flex-basis: 52px;
}

.brand-large .brand-copy strong {
  font-size: var(--text-md);
}

.auth-view {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr);
}

.auth-brand {
  position: relative;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: clamp(30px, 5vw, 68px);
  border-right: 1px solid var(--line);
  background:
    linear-gradient(140deg, rgba(26, 29, 34, .96), rgba(11, 12, 14, .96)),
    var(--bg);
}

.auth-atmosphere {
  position: fixed;
  z-index: 0;
  top: 20%;
  left: 17%;
  width: 34vw;
  height: 34vw;
  border: 1px solid rgba(229, 45, 52, .12);
  opacity: .7;
  pointer-events: none;
  transform: rotate(45deg);
}

.auth-atmosphere::before,
.auth-atmosphere::after {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, .035);
  content: "";
  inset: 9%;
}

.auth-atmosphere::after {
  inset: 23%;
  border-color: rgba(229, 45, 52, .08);
}

.auth-brand > * {
  position: relative;
  z-index: 1;
}

.auth-message {
  max-width: 600px;
  margin: auto 0;
  padding: 80px 0;
}

.auth-message h1 {
  max-width: 660px;
  margin: var(--space-4) 0 var(--space-4);
  font-size: clamp(2.5rem, 5.3vw, 4.875rem);
  font-weight: 600;
  letter-spacing: -.055em;
  line-height: .98;
}

.auth-message p {
  max-width: 520px;
  margin: 0;
  color: var(--text-soft);
  font-size: clamp(1rem, 1.25vw, 1.25rem);
  line-height: 1.7;
}

.trust-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
  color: var(--text-dim);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.trust-row span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px rgba(113, 211, 154, .55);
}

.auth-panel {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 100vh;
  padding: var(--space-8);
  place-items: center;
}

.auth-card {
  width: min(100%, 410px);
  padding: var(--space-8);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(21, 23, 27, .88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-heading {
  margin-bottom: var(--space-6);
}

.auth-heading h2 {
  margin: var(--space-2) 0 var(--space-2);
  font-size: 1.625rem;
  letter-spacing: -.03em;
  line-height: var(--leading-tight);
}

.auth-heading p,
.modal-header p {
  margin: 0;
  color: var(--text-dim);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
}

.field {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  color: var(--text-soft);
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: .01em;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--bg-soft);
  color: var(--text);
  transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.field input,
.field select {
  height: var(--control-lg);
  padding: 0 var(--space-3);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
  padding: var(--space-3);
}

.field input::placeholder,
.field textarea::placeholder {
  color: #838a95;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: #686f79;
  background: #121419;
  box-shadow: 0 0 0 3px rgba(126, 183, 238, .07);
}

/* .field is a grid, so a checkbox row needs its own display mode — and the
   box must escape the --control-lg height meant for text inputs. */
.field-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.field-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--red);
  cursor: pointer;
}

.field-checkbox span {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 400;
  cursor: pointer;
}

.input-action {
  position: relative;
  display: block;
}

.input-action input {
  padding-right: 72px;
}

.input-action .icon-button {
  position: absolute;
  top: 50%;
  right: var(--space-2);
  transform: translateY(-50%);
}

.icon-button {
  min-width: 40px;
  height: var(--control-sm);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: .04em;
}

.icon-button:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.button {
  display: inline-flex;
  min-height: var(--control-md);
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
  transition: transform .16s ease, border-color .16s ease, background .16s ease, opacity .16s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: .55;
}

.button-block {
  width: 100%;
}

.button-primary {
  border-color: var(--red);
  background: var(--red);
  color: white;
}

.button-primary:hover:not(:disabled) {
  background: #f0373e;
}

.button-ghost {
  border-color: var(--line);
  background: transparent;
  color: var(--text-soft);
}

.button-ghost:hover:not(:disabled) {
  border-color: var(--line-bright);
  background: var(--panel-hover);
  color: var(--text);
}

.button-danger {
  border-color: rgba(229, 45, 52, .4);
  background: var(--red-soft);
  color: #ff7f83;
}

.button-small {
  min-height: var(--control-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.auth-card .button-primary {
  margin-top: var(--space-2);
}

.auth-card .button-ghost {
  margin-top: var(--space-3);
}

.form-note {
  margin: var(--space-4) 0 0;
  color: var(--text-dim);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  text-align: center;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  position: fixed;
  z-index: 20;
  top: 0;
  bottom: 0;
  left: 0;
  display: flex;
  width: var(--sidebar);
  flex-direction: column;
  padding: var(--space-6) var(--space-4) var(--space-4);
  border-right: 1px solid var(--line);
  background: rgba(15, 17, 20, .97);
  backdrop-filter: blur(16px);
}

.sidebar .brand {
  padding: 0 var(--space-2) var(--space-6);
}

.side-nav {
  display: grid;
  gap: var(--space-1);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}

.nav-item {
  position: relative;
  display: flex;
  width: 100%;
  min-height: var(--control-md);
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 600;
  text-align: left;
  transition: color .16s ease, background .16s ease, border-color .16s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, .025);
  color: var(--text-soft);
}

.nav-item.is-active {
  border-color: #343941;
  background: var(--panel-strong);
  color: var(--text);
}

.nav-item.is-active::before {
  position: absolute;
  top: 50%;
  left: 0;
  width: 2px;
  height: 18px;
  border-radius: 2px;
  background: var(--red);
  content: "";
  transform: translateY(-50%);
}

.nav-glyph {
  display: grid;
  width: 18px;
  place-items: center;
  color: currentColor;
  font-size: var(--text-md);
}

.nav-count {
  min-width: 26px;
  margin-left: auto;
  padding: var(--space-1) var(--space-2);
  border-radius: 999px;
  background: #252a31;
  color: var(--text-soft);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  text-align: center;
}

.sidebar-bottom {
  display: grid;
  gap: var(--space-2);
  margin-top: auto;
}

.security-note {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid rgba(113, 211, 154, .14);
  border-radius: var(--radius-sm);
  background: var(--green-soft);
}

.security-icon {
  color: var(--green);
  font-size: var(--text-md);
}

.security-note div {
  display: grid;
  gap: var(--space-1);
}

.security-note strong {
  color: #cbeed9;
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
}

.security-note small {
  color: #8fb69f;
  font-size: var(--text-xs);
  line-height: 1.4;
}

.nav-danger:hover {
  background: var(--red-soft);
  color: #ff777c;
}

.workspace {
  min-width: 0;
  grid-column: 2;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  padding: var(--space-4) clamp(22px, 3vw, 46px);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 12, 14, .88);
  backdrop-filter: blur(16px);
}

.topbar h1 {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xl);
  letter-spacing: -.02em;
  line-height: var(--leading-tight);
}

.account-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.account-chip > span:last-child {
  display: grid;
  gap: var(--space-1);
  text-align: right;
}

.account-chip strong {
  max-width: 260px;
  overflow: hidden;
  font-size: var(--text-base);
  line-height: var(--leading-tight);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-chip small {
  color: var(--text-dim);
  font-size: var(--text-xs);
  line-height: 1.3;
}

.avatar {
  display: grid;
  width: 36px;
  height: 36px;
  order: 2;
  place-items: center;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--text-soft);
  font-size: var(--text-sm);
  font-weight: 700;
}

.avatar-admin {
  border-color: rgba(229, 45, 52, .4);
  background: var(--red-soft);
  color: #ff8b8f;
}

.mobile-nav-button {
  display: none;
  min-height: var(--control-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text-dim);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* Owns the vertical rhythm so sections don't carry their own margin-top —
   that is what made the admin tabs shift 14px against each other. */
.content-area {
  display: grid;
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: clamp(22px, 3vw, 42px);
  gap: var(--space-4);
  align-content: start;
}

.hero-card {
  position: relative;
  display: grid;
  min-height: 212px;
  overflow: hidden;
  grid-template-columns: minmax(0, 1.5fr) minmax(230px, .5fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(112deg, rgba(26, 29, 34, .98), rgba(17, 19, 23, .93)),
    var(--panel);
  box-shadow: 0 18px 45px rgba(0, 0, 0, .18);
}

.hero-card::after {
  position: absolute;
  top: -94px;
  right: -20px;
  width: 310px;
  height: 310px;
  border: 1px solid rgba(229, 45, 52, .13);
  content: "";
  pointer-events: none;
  transform: rotate(45deg);
}

.hero-copy {
  position: relative;
  z-index: 1;
  padding: var(--space-8);
}

.hero-copy h2 {
  max-width: 720px;
  margin: var(--space-3) 0 var(--space-3);
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -.04em;
  line-height: var(--leading-tight);
}

.hero-copy p {
  max-width: 660px;
  margin: 0;
  color: var(--text-soft);
  font-size: var(--text-md);
  line-height: 1.7;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

.hero-side {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: center;
  gap: var(--space-2);
  padding: var(--space-8);
  border-left: 1px solid var(--line);
  background: rgba(8, 9, 11, .28);
}

.hero-side .metric-value {
  font-size: 2.5rem;
}

.hero-side .progress {
  margin-top: var(--space-2);
}

.status-pill,
.meta-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: rgba(255, 255, 255, .025);
  color: var(--text-soft);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .06em;
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pill.active {
  border-color: rgba(113, 211, 154, .22);
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.expired,
.status-pill.revoked,
.status-pill.inactive {
  border-color: rgba(229, 45, 52, .25);
  background: var(--red-soft);
  color: #ff777c;
}

.status-pill.pending {
  border-color: rgba(230, 180, 91, .22);
  background: var(--amber-soft);
  color: var(--amber);
}

/* Informational, not an alarm — a trial is a working state. */
.status-pill.trial,
.status-pill.special,
.meta-pill.trial {
  border-color: rgba(126, 183, 238, .22);
  background: var(--blue-soft);
  color: var(--blue);
}

.metric-trial {
  color: var(--blue);
}

/* The default fill is red; a red bar draining a 7-day trial reads as an
   alarm from the first hour. */
.progress.is-trial span {
  background: linear-gradient(90deg, var(--blue), #a8d0f5);
}

/* auto-fit rather than a fixed 4: the admin overview has five tiles and the
   portal four, and a hardcoded count orphans the last one onto its own row. */
.stats-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
}

.metric-card,
.panel-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(21, 23, 27, .82);
}

.metric-card {
  min-height: 128px;
  padding: var(--space-5);
}

.metric-label {
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.metric-value {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-2xl);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: var(--leading-tight);
}

.metric-caption {
  display: block;
  margin-top: var(--space-1);
  color: var(--text-dim);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.metric-accent {
  color: var(--green);
}

.main-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr);
}

.panel-card {
  min-width: 0;
  overflow: hidden;
}

/* Horizontal padding matches .data-table th/td so the panel title lines up
   with the first column below it. */
.panel-head {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: var(--text-md);
  letter-spacing: -.01em;
  line-height: var(--leading-tight);
}

.panel-head p {
  margin: var(--space-1) 0 0;
  color: var(--text-dim);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.panel-body {
  padding: var(--space-5);
}

.panel-body > .progress,
.panel-body > .manual-banner {
  margin-top: var(--space-4);
}

.detail-list {
  display: grid;
}

.detail-row {
  display: flex;
  min-height: 47px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  border-bottom: 1px solid var(--line);
  font-size: var(--text-base);
}

.detail-row:last-child {
  border-bottom: 0;
}

.detail-row span:first-child {
  min-width: 0;
  color: var(--text-dim);
}

.detail-row strong {
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-base);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress {
  width: 100%;
  height: 5px;
  overflow: hidden;
  border-radius: var(--radius-xs);
  background: #292d33;
}

.progress span {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), #f46b6f);
}

.manual-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid rgba(230, 180, 91, .17);
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  color: #d4b478;
}

.manual-banner > span {
  display: grid;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  place-items: center;
  border: 1px solid rgba(230, 180, 91, .35);
  border-radius: 50%;
  font-size: var(--text-xs);
  font-weight: 700;
}

.manual-banner p {
  margin: 0;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

.feature-list {
  display: grid;
  gap: var(--space-2);
}

.feature-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.feature-item > span:first-child {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--green-soft);
  color: var(--green);
  font-size: var(--text-md);
}

.feature-item div {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.feature-item strong {
  font-size: var(--text-base);
  line-height: var(--leading-tight);
}

.feature-item small {
  color: var(--text-dim);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.section-stack {
  display: grid;
  gap: var(--space-4);
}

.section-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.section-toolbar > * {
  min-width: 0;
}

.section-title {
  flex: 1 1 auto;
  min-width: 0;
}

/* Keeps the filters and the section's primary action on one line, so the
   toolbar is the same height on every tab. */
.toolbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--space-2);
}

.section-title h2 {
  margin: 0;
  font-size: var(--text-lg);
  letter-spacing: -.02em;
  line-height: var(--leading-tight);
}

.section-title p {
  margin: var(--space-1) 0 0;
  color: var(--text-dim);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.filter-row {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  align-items: center;
}

.search-field {
  position: relative;
  width: min(330px, 100%);
}

.search-field input {
  width: 100%;
  height: var(--control-md);
  padding: 0 var(--space-3) 0 var(--space-8);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  background: var(--panel);
  color: var(--text);
}

.search-field input::placeholder {
  color: #838a95;
}

.search-field::before {
  position: absolute;
  top: 50%;
  left: var(--space-3);
  color: var(--text-dim);
  content: "⌕";
  font-size: var(--text-md);
  transform: translateY(-50%);
}

.filter-select {
  height: var(--control-md);
  padding: 0 var(--space-8) 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text-soft);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

/* Wider tables (more columns, or a multi-button action cell) than the
   5-column portal table. */
.data-table-wide {
  min-width: 1080px;
}

.data-table th {
  height: 44px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--line);
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Columns size to their content and the wrapper scrolls, instead of dates and
   action rows wrapping into ragged row heights. */
.data-table td {
  height: 62px;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid rgba(41, 45, 52, .76);
  color: var(--text-soft);
  vertical-align: middle;
  white-space: nowrap;
}

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

.data-table tbody tr {
  transition: background .14s ease;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, .018);
}

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

/* Free-text columns (notes, email) are unbounded in the API — without this a
   single 500-char note stretches the table past any viewport. */
.cell-clip {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.primary-cell {
  display: grid;
  gap: var(--space-1);
}

.primary-cell strong {
  color: var(--text);
  font-size: var(--text-base);
  line-height: var(--leading-tight);
  white-space: nowrap;
}

/* Only the free-text columns (email, device name) clip — dates and counts
   size to their content so they are never cut mid-value. */
.primary-cell-clip strong {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.primary-cell small {
  color: var(--text-dim);
  font-size: var(--text-xs);
  line-height: 1.4;
}

.mono {
  color: #a8aeb6;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

.empty-state {
  display: grid;
  min-height: 230px;
  padding: var(--space-8);
  place-items: center;
  text-align: center;
}

.empty-state > div {
  max-width: 370px;
}

.empty-icon {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto var(--space-4);
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 1.25rem;
}

.empty-state h3 {
  margin: 0;
  font-size: var(--text-md);
  line-height: var(--leading-tight);
}

.empty-state p {
  margin: var(--space-2) 0 0;
  color: var(--text-dim);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

.loading-state {
  display: grid;
  min-height: 60vh;
  align-content: center;
  justify-items: center;
  gap: var(--space-4);
  color: var(--text-dim);
  font-size: var(--text-base);
}

.loading-state p {
  margin: 0;
}

.loader {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.toast-region {
  position: fixed;
  z-index: 100;
  top: var(--space-4);
  right: var(--space-4);
  display: grid;
  width: min(380px, calc(100vw - 32px));
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  background: #1d2025;
  box-shadow: var(--shadow);
  color: var(--text-soft);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  animation: toast-in .2s ease-out;
}

.toast::before {
  color: var(--green);
  content: "◆";
}

.toast.error {
  border-color: rgba(229, 45, 52, .34);
}

.toast.error::before {
  color: #ff6b70;
  content: "!";
  font-weight: 900;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
}

.modal {
  width: min(480px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(3, 4, 5, .72);
  backdrop-filter: blur(6px);
}

.modal-wide {
  width: min(660px, calc(100vw - 28px));
}

.modal-card {
  padding: var(--space-6);
}

.modal-icon {
  display: grid;
  width: 42px;
  height: 42px;
  margin-bottom: var(--space-4);
  place-items: center;
  border-radius: var(--radius);
  font-weight: 900;
}

.modal-icon-danger {
  border: 1px solid rgba(229, 45, 52, .24);
  background: var(--red-soft);
  color: #ff777c;
}

.modal-copy h2,
.modal-header h2 {
  margin: var(--space-2) 0 var(--space-2);
  font-size: var(--text-lg);
  letter-spacing: -.025em;
  line-height: var(--leading-tight);
}

.modal-copy p {
  margin: 0;
  color: var(--text-dim);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.modal-close {
  font-size: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

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

.field-span {
  grid-column: 1 / -1;
}

@media (max-width: 1100px) {
  :root {
    --sidebar: 224px;
  }

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

  .auth-message h1 {
    font-size: clamp(2.5rem, 5vw, 3.875rem);
  }
}

@media (max-width: 860px) {
  .auth-view {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-brand {
    display: none;
  }

  .auth-panel {
    min-height: 100vh;
    padding: var(--space-5);
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    width: min(280px, 84vw);
    transform: translateX(-105%);
    transition: transform .2s ease;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 30px 0 90px rgba(0, 0, 0, .65);
  }

  .workspace {
    grid-column: 1;
  }

  .mobile-nav-button {
    display: inline-flex;
    align-items: center;
  }

  .topbar {
    justify-content: flex-start;
  }

  .topbar .account-chip {
    margin-left: auto;
  }

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

@media (max-width: 660px) {
  .topbar {
    min-height: 68px;
    padding: var(--space-3) var(--space-4);
  }

  .page-context,
  .account-chip small {
    display: none;
  }

  .topbar h1 {
    font-size: var(--text-lg);
  }

  .account-chip > span:last-child {
    display: none;
  }

  .content-area {
    padding: var(--space-4);
  }

  .hero-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-copy {
    padding: var(--space-6);
  }

  .hero-side {
    padding: var(--space-6);
    border-top: 1px solid var(--line);
    border-left: 0;
  }

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

  .metric-card {
    min-height: 116px;
    padding: var(--space-4);
  }

  .metric-value {
    font-size: 1.5rem;
  }

  .hero-side .metric-value {
    font-size: 2rem;
  }

  .section-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    flex-wrap: wrap;
  }

  .toolbar-actions,
  .filter-row {
    flex: 1 1 auto;
  }

  .filter-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 148px;
  }

  .search-field {
    width: 100%;
  }

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

  .field-span {
    grid-column: auto;
  }

  .cell-clip {
    max-width: 180px;
  }
}

@media (max-width: 430px) {
  .auth-card {
    padding: var(--space-6) var(--space-5);
  }

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

  .modal-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .modal-actions .button {
    width: 100%;
  }
}

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