/* Relay — switchboard console
   Graphite field, a single amber signal lamp, engraved rules, monospaced telemetry.
   Type: IBM Plex Serif (wordmark only) / Plex Sans (UI) / Plex Mono (data).
   CSS-first redesign: every class app.js toggles is preserved. */

/* ── Tokens ─────────────────────────────────────────────── */

:root {
  /* Core palette */
  --bg: #0e1319;            /* Graphite — field */
  --panel: #151c25;         /* Panel — raised surface */
  --panel-2: #1b2430;       /* Panel raised — hover / active */
  --panel-inset: #0b0f15;   /* Inset — inputs, screens, output */
  --line: #2a3543;          /* Line — engraved rule */
  --line-soft: #212b38;     /* Hairline — internal dividers */
  --text: #e8e4d8;          /* Paper — warm off-white */
  --muted: #94a1b2;         /* Muted — secondary text */
  --faint: #7b8899;         /* Faint — placeholders, disabled */
  --accent: #f0b429;        /* Signal — brand amber */
  --accent-strong: #ffd257; /* Signal bright — hover / active text */
  --accent-ink: #241a05;    /* Ink on amber */

  /* Semantic status system (used identically in badges, dots, banners) */
  --good: #58c98b;          /* online / ok / active / paid */
  --good-text: #74d6a0;
  --warn: #f0b429;          /* overflow / missing / open / at capacity */
  --warn-text: #ffd257;
  --bad: #e5644e;           /* suspended / expired / revoked / overdue */
  --bad-text: #f0937f;

  /* Shape & elevation */
  --radius: 6px;
  --radius-lg: 8px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);

  /* Spacing scale (4px base) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* Type */
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-display: "IBM Plex Serif", Georgia, serif;
  --font-mono: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;

  --content-max: 1280px;
}

/* ── Base ───────────────────────────────────────────────── */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
}

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

button {
  cursor: pointer;
}

h1, h2, h3, h4, p {
  margin: 0;
}

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

::selection {
  background: rgba(240, 180, 41, 0.28);
}

/* ── Utilities ──────────────────────────────────────────── */

.hidden {
  display: none !important;
}

.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: 12px;
}

.error {
  color: var(--bad-text);
  min-height: 1.2em;
  margin: var(--s1) 0 0;
  font-size: 12.5px;
}

.grow {
  flex: 1;
  min-width: 200px;
}

.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

code {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  color: var(--accent-strong);
}

/* ── Forms ──────────────────────────────────────────────── */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.form-column {
  max-width: 620px;
}

.form-column > button {
  align-self: flex-start;
}

.stack > span,
label.stack > span {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

.field-help {
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.45;
}

.field-error {
  font-size: 11.5px;
  color: var(--bad-text);
  line-height: 1.4;
}

input,
textarea,
select {
  width: 100%;
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:hover,
textarea:hover,
select:hover {
  border-color: #38465a;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.16);
}

input.field-invalid,
textarea.field-invalid,
select.field-invalid {
  border-color: var(--bad);
}

input.field-invalid:focus,
textarea.field-invalid:focus,
select.field-invalid:focus {
  box-shadow: 0 0 0 3px rgba(229, 100, 78, 0.18);
}

input[type="file"] {
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  margin-right: 10px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 96px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%2394a1b2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

option {
  background: var(--panel-inset);
  color: var(--text);
}

/* ── Buttons ────────────────────────────────────────────── */

button.primary,
a.primary,
button.ghost,
a.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border-radius: var(--radius);
  padding: 8px 15px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  text-decoration: none;
  white-space: nowrap;
  transition: background 130ms ease, border-color 130ms ease, color 130ms ease;
}

button.primary,
a.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

button.primary:hover,
a.primary:hover {
  background: var(--accent-strong);
}

button.primary.danger {
  background: var(--bad);
  color: #fff;
}

button.primary.danger:hover {
  background: #ef7a64;
}

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

button.ghost:hover,
a.ghost:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button.ghost.danger {
  color: var(--bad-text);
  border-color: rgba(229, 100, 78, 0.4);
}

button.ghost.danger:hover {
  border-color: var(--bad);
  color: #fff;
  background: rgba(229, 100, 78, 0.14);
}

button.primary:disabled,
button.ghost:disabled,
a.ghost.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary:disabled:hover {
  background: var(--accent);
}

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

button.wide {
  width: 100%;
  padding: 11px 16px;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent-strong);
  padding: 0;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.link-button:hover {
  text-decoration: underline;
}

/* ── Badges, dots & the status system ───────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel-inset);
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}

/* Status badges carry a lamp + text (never color-only). */
.badge.online::before,
.badge.offline::before,
.badge.active::before,
.badge.suspended::before,
.badge.open::before,
.badge.paid::before,
.badge.overdue::before,
.badge.void::before,
.badge.outstanding::before,
.badge.lic-outstanding::before,
.badge.ok::before,
.badge.none::before,
.badge.missing::before,
.badge.expired::before,
.badge.revoked::before,
.badge.warn::before,
.badge.overflow::before,
.badge.at-capacity::before,
.badge.lic-ok::before,
.badge.lic-none::before,
.badge.lic-missing::before,
.badge.lic-expired::before,
.badge.lic-revoked::before,
.badge.lic-suspended::before,
.badge.lic-open::before,
.badge.lic-paid::before,
.badge.lic-overdue::before,
.badge.lic-void::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* Good — online / ok / active / paid */
.badge.online,
.badge.active,
.badge.paid,
.badge.ok,
.badge.lic-ok,
.badge.lic-paid {
  color: var(--good-text);
  border-color: rgba(88, 201, 139, 0.38);
  background: rgba(88, 201, 139, 0.1);
}

/* Warn — overflow / missing / open / at capacity */
.badge.open,
.badge.outstanding,
.badge.lic-outstanding,
.badge.missing,
.badge.warn,
.badge.overflow,
.badge.at-capacity,
.badge.lic-missing,
.badge.lic-open {
  color: var(--warn-text);
  border-color: rgba(240, 180, 41, 0.38);
  background: rgba(240, 180, 41, 0.09);
}

/* Bad — suspended / expired / revoked / overdue */
.badge.suspended,
.badge.overdue,
.badge.expired,
.badge.revoked,
.badge.lic-expired,
.badge.lic-revoked,
.badge.lic-suspended,
.badge.lic-overdue {
  color: var(--bad-text);
  border-color: rgba(229, 100, 78, 0.4);
  background: rgba(229, 100, 78, 0.1);
}

/* Neutral — offline / none / void */
.badge.offline,
.badge.void,
.badge.none,
.badge.lic-none,
.badge.lic-void {
  color: var(--muted);
}

.badge.bad {
  color: var(--bad-text);
  border-color: rgba(229, 100, 78, 0.4);
  background: rgba(229, 100, 78, 0.1);
}

/* Role badges (no lamp — they are identity, not status) */
.badge.role-badge-admin {
  color: var(--accent-strong);
  border-color: rgba(240, 180, 41, 0.4);
  background: rgba(240, 180, 41, 0.08);
}

.badge.role-badge-org {
  color: var(--text);
  border-color: var(--line);
  background: var(--panel-2);
}

.badge.role-badge-super {
  color: var(--accent-ink);
  border-color: var(--accent);
  background: var(--accent);
}

/* Access control matrix */

.users-tabs {
  margin-bottom: var(--s4);
}

.users-tab-panel > .device-head:first-child {
  margin-top: 0;
}

.rbac-table th:not(:first-child),
.rbac-table td:not(:first-child) {
  width: 130px;
  text-align: center;
}

.rbac-table td:first-child {
  max-width: 520px;
}

.rbac-table td:first-child strong {
  font-size: 13px;
}

.rbac-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.rbac-table input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* Role badge is hidden while there is no role text to show (see app.js). */
.role-badge:empty {
  display: none;
}

.badge.plan-pro,
.badge.plan-enterprise {
  color: var(--accent-strong);
  border-color: rgba(240, 180, 41, 0.4);
  background: rgba(240, 180, 41, 0.08);
}

.overflow-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--warn-text);
  border: 1px solid rgba(240, 180, 41, 0.4);
  background: rgba(240, 180, 41, 0.1);
  border-radius: 999px;
  padding: 2px 9px;
  flex: none;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.dot.online {
  background: var(--good);
  box-shadow: 0 0 7px rgba(88, 201, 139, 0.6);
}

.count-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--accent-strong);
  border: 1px solid var(--line);
  background: var(--panel-inset);
  border-radius: var(--radius);
  padding: 2px 9px;
  min-width: 32px;
  text-align: center;
}

/* ── Brand ──────────────────────────────────────────────── */

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.01em;
  color: var(--text);
}

.brand.large {
  font-size: 38px;
  line-height: 1.1;
}

.mark {
  width: 44px;
  height: 44px;
  color: var(--accent);
  flex: none;
}

.mark.small {
  width: 26px;
  height: 26px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

/* ── Login: the switchboard plate ───────────────────────── */

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
}

.login-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--s5);
  padding: var(--s7);
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}

.login-masthead {
  display: flex;
  align-items: center;
  gap: var(--s4);
}

.login-tag {
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
  max-width: 34ch;
}

.login-pulse {
  position: absolute;
  left: -4%;
  bottom: 8%;
  width: 108%;
  height: auto;
  color: var(--accent);
  opacity: 0.1;
  pointer-events: none;
}

.login-pulse path {
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: pulse-draw 1.6s ease forwards 0.2s;
}

@keyframes pulse-draw {
  to { stroke-dashoffset: 0; }
}

.login-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--s4);
  width: 100%;
  max-width: 400px;
  margin: auto;
  padding: var(--s7) var(--s6);
}

.login-heading {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: calc(var(--s2) * -1);
}

.login-card .stack {
  gap: var(--s2);
}

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: var(--s4);
}

.mfa-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  text-align: center;
}

.mfa-setup img {
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px;
}

.mfa-setup code {
  font-size: 12px;
  overflow-wrap: anywhere;
  color: var(--accent-strong);
}

.mfa-recovery-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.mfa-recovery-list li {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-inset);
  padding: 6px 8px;
  text-align: center;
}

.login-rule {
  display: none;
}

/* ── App shell & topbar ─────────────────────────────────── */

#app-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s4);
  min-height: 56px;
  padding: 0 var(--s5);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
}

.user-chip {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.conn-dot.connecting {
  background: var(--warn);
  animation: conn-pulse 1.4s ease-in-out infinite;
}

.conn-dot.live {
  background: var(--good);
  box-shadow: 0 0 6px rgba(88, 201, 139, 0.6);
}

.conn-dot.down {
  background: var(--bad);
  animation: conn-pulse 1s ease-in-out infinite;
}

@keyframes conn-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Top navigation */
.topnav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.topnav-item {
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  padding: 7px 12px;
  transition: background 120ms ease, color 120ms ease;
}

.topnav-item:hover {
  color: var(--text);
  background: var(--panel);
}

.topnav-item.active {
  color: var(--text);
  background: var(--panel-2);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.nav-toggle {
  display: none;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 12px;
}

.nav-toggle svg {
  width: 15px;
  height: 15px;
}

/* ── Main column & page architecture ────────────────────── */

#main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s6) var(--s5) 72px;
  min-width: 0;
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  min-width: 0;
}

/* Page header (title + purpose + primary action) */
.device-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
}

.device-head h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.device-head p {
  margin-top: var(--s1);
  font-size: 13px;
  color: var(--muted);
  max-width: 72ch;
  line-height: 1.5;
}

.device-head-actions {
  display: flex;
  gap: var(--s2);
  align-items: center;
}

/* ── Tabs ───────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  overflow: visible;
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
  padding: 9px 16px;
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  transition: color 120ms ease, border-color 120ms ease;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
}

.tab-panel {
  animation: panel-in 150ms ease;
}

/* Tools hub */
.tools-intro {
  margin-bottom: var(--s4);
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.tool-group-head {
  grid-column: 1 / -1;
  margin: var(--s3) 0 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.tool-group-head:first-child {
  margin-top: 0;
}

.tool-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  text-align: left;
  padding: 12px 13px;
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.tool-card:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--panel-2);
}

.tool-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tool-card:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.tool-icon {
  grid-row: 1 / span 2;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(240, 180, 41, .07);
  color: var(--accent-strong);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1;
}

.tool-name {
  font-size: 13.5px;
  font-weight: 600;
  min-width: 0;
}

.tool-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  min-width: 0;
}

.tool-workspace-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.tool-workspace-title {
  flex: 1;
  min-width: 0;
}

.tool-workspace-title h3 {
  font-size: 16px;
  font-weight: 600;
}

#tool-back {
  flex: 0 0 auto;
}

.tool-panel {
  animation: panel-in 150ms ease;
}

.tool-force {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.tool-force input {
  margin-top: 3px;
}

.tool-note {
  margin: 8px 0 0;
}

.tool-output {
  min-height: 240px;
  max-height: 520px;
  margin-top: var(--s3);
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* ── Devices: fleet groups & rows ───────────────────────── */

.sidebar-search {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 420px;
}

.sidebar-search .search-icon {
  position: absolute;
  left: 11px;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}

.sidebar-search input {
  padding-left: 33px;
  font-size: 13px;
}

.sidebar-search input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

#devices-groups {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
}

.device-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.group-head {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  padding-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s2);
}

.group-head h3 {
  font-size: 14px;
  font-weight: 600;
}

.group-head .muted {
  font-size: 12px;
  font-family: var(--font-mono);
}

.subgroup-head {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  padding: var(--s2) 12px var(--s1);
}

.subgroup-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.subgroup-head .muted {
  font-size: 11.5px;
  font-family: var(--font-mono);
}

.group-rows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s3);
}

.device-item {
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-left: 2px solid transparent;
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 11px;
  transition: background 120ms ease, border-color 120ms ease;
}

.device-item:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

.device-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.device-item.active {
  background: var(--panel-2);
  border-color: var(--line-soft);
  border-left-color: var(--accent);
}

.device-item-text {
  min-width: 0;
  flex: 1;
}

.device-item-name {
  display: block;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
}

.device-item-meta .meta-online {
  color: var(--good-text);
}

.device-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
  flex: none;
}

.device-actions .ghost {
  font-size: 12px;
  padding: 5px 10px;
}

/* ── Empty states ───────────────────────────────────────── */

.empty-note {
  padding: var(--s2) 2px;
  font-size: 13px;
  line-height: 1.55;
}

.empty-state-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s6) var(--s5);
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
}

.empty-state-block p {
  font-size: 13.5px;
  color: var(--muted);
  max-width: 60ch;
  line-height: 1.55;
}

.org-list > .empty-state-block,
.user-list > .empty-state-block,
.file-list > .empty-state-block,
.data-table .empty-state-block {
  padding: var(--s4);
  border: 1px dashed var(--line-soft);
  background: transparent;
}

.data-table .empty-state-block p {
  font-size: 13px;
}

/* ── Device detail ──────────────────────────────────────── */

#device-view {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: var(--s5);
}

#device-view .device-head {
  align-items: center;
}

#device-view .device-head h2 {
  font-size: 18px;
}

#device-meta {
  font-family: var(--font-mono);
  font-size: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.detail-grid > div {
  background: var(--panel-inset);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.label {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
}

.detail-grid > div > span:not(.label),
.detail-grid > div > code {
  font-size: 13px;
  word-break: break-word;
}

.overflow-notice {
  align-self: flex-start;
  font-weight: 500;
  line-height: 1.45;
  border-radius: var(--radius);
  padding: 8px 12px;
}

/* ── Toolbars & output ──────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-row > label.stack {
  flex: 1 1 140px;
}

.output {
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 120px;
  max-height: 460px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: #cfd8c9;
  margin: 0;
}

/* ── Screen tab ─────────────────────────────────────────── */

.screen-select {
  width: auto;
  min-width: 160px;
}

.screen-frame {
  position: relative;
  border: 1px solid var(--line);
  background: var(--panel-inset);
  border-radius: var(--radius-lg);
  min-height: 340px;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.screen-frame img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
}

.screen-frame img.control-enabled {
  cursor: none;
}

/* Camera and microphone tabs */
.camera-frame {
  position: relative;
  border: 1px solid var(--line);
  background: var(--panel-inset);
  border-radius: var(--radius-lg);
  min-height: 340px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.camera-frame img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
}

#audio-player {
  width: 100%;
  margin-top: var(--s4);
}

/* Instant local pointer feedback in fullscreen; the JPEG frames lag behind. */
.local-cursor {
  position: absolute;
  z-index: 3;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: rgba(240, 180, 41, 0.18);
  box-shadow: 0 0 0 2px rgba(4, 7, 11, 0.45);
  pointer-events: none;
  display: none;
}

.local-cursor.visible {
  display: block;
}

/* Unmistakable mouse-control state: amber frame + lamp. */
.screen-frame.control-on {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(240, 180, 41, 0.18);
}

.screen-frame.control-on::after {
  content: "Mouse control on";
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  padding: 3px 9px;
  border-radius: 999px;
  pointer-events: none;
}

#screen-control {
  background: var(--panel-2);
  border: 1px solid #4b5e77;
  color: var(--text);
  padding: 8px 15px;
}

#screen-control:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

#screen-control[aria-pressed="true"],
#screen-control.control-on {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1px rgba(14, 19, 25, 0.25);
}

#screen-control-hint {
  display: block;
  margin: 0 0 var(--s3);
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 80ch;
}

#screen-control-hint.control-on {
  display: block;
  color: var(--warn-text);
  background: rgba(240, 180, 41, 0.09);
  border: 1px solid rgba(240, 180, 41, 0.4);
  border-radius: var(--radius);
  padding: 7px 10px;
}

.screen-frame:fullscreen {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  border: none;
  border-radius: 0;
  background: #000;
}

.screen-frame:fullscreen img {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  background: #000;
}

/* ── Tables ─────────────────────────────────────────────── */

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: auto;
  max-height: 560px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.data-table td {
  padding: 9px 14px;
  border-top: 1px solid var(--line-soft);
  vertical-align: middle;
}

.data-table tbody tr:first-child td {
  border-top: none;
}

.data-table tr:hover td {
  background: rgba(240, 180, 41, 0.045);
}

.data-table td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.audit-time {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Plans fit their billing card at desktop widths; scroll only on small screens. */
.plans-table-wrap {
  overflow-x: auto;
}

.plans-table-wrap .data-table {
  table-layout: fixed;
  font-size: 12px;
  min-width: 700px;
}

.plans-table-wrap th {
  white-space: normal;
  line-height: 1.3;
}

.plans-table-wrap th,
.plans-table-wrap td {
  padding: 8px 9px;
}

.plans-table-wrap th:nth-child(1) { width: 20%; }
.plans-table-wrap th:nth-child(2) { width: 11%; }
.plans-table-wrap th:nth-child(3) { width: 10%; }
.plans-table-wrap th:nth-child(4) { width: 12%; }
.plans-table-wrap th:nth-child(5) { width: 19%; }
.plans-table-wrap th:nth-child(6) { width: 14%; }
.plans-table-wrap th:nth-child(7) { width: 14%; }

.plans-table-wrap td:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plans-table-wrap .org-row-actions .ghost {
  padding: 5px 8px;
  font-size: 12px;
}

.data-table .org-row-actions {
  justify-content: flex-end;
}

/* ── Cards & row lists ──────────────────────────────────── */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--s5);
  min-width: 0;
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--s3);
}

.card > p {
  line-height: 1.55;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.card-head h3 {
  margin: 0;
}

.org-list,
.user-list,
.group-list,
.file-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-list {
  margin-bottom: var(--s2);
}

.org-row,
.license-row,
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  border: 1px solid var(--line-soft);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 13px;
  flex-wrap: wrap;
}

.org-row > div,
.license-row > div,
.user-row > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.org-row > div:last-child,
.license-row > div:last-child {
  align-items: flex-end;
}

.license-row {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(260px, 320px);
  align-items: start;
}

.license-row > div:last-child {
  align-items: flex-start;
  gap: var(--s2);
}

.license-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.license-row .license-meta .muted {
  font-size: 11.5px;
  font-family: var(--font-mono);
}

.org-row-actions {
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
  align-items: center;
}

.org-row-actions .ghost {
  font-size: 12px;
  padding: 5px 10px;
}

.user-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.org-row .badge,
.license-row .badge {
  align-self: flex-start;
}

.org-row > div:last-child .muted,
.license-row > div:last-child .muted {
  font-size: 11.5px;
  font-family: var(--font-mono);
}

/* ── Installers ─────────────────────────────────────────── */

/* Four compact installer cards per row on laptops, two on small screens. */
#installer-files-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

#installer-files-list > .empty-state-block {
  grid-column: 1 / -1;
}

#installer-files-list > .file-card {
  width: 100%;
  height: 100%;
}

.file-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  min-width: 0;
}

/* Compact installer file cards on the Installers page. */

.installer-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
}

.installer-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.installer-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.installer-name.at-capacity {
  color: var(--warn-text);
}

.installer-meta {
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--muted);
}

.installer-actions {
  display: flex;
  gap: var(--s2);
  align-items: center;
  margin-left: 0;
  flex: none;
  flex-wrap: wrap;
}

.installer-actions .ghost {
  font-size: 12px;
  padding: 5px 10px;
}

.installer-status {
  font-size: 11.5px;
  font-family: var(--font-mono);
}

/* ── Staff & org licence ────────────────────────────────── */

.file-group {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 4px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.file-group-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 10px 0 var(--s2);
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}

.file-group-head h3 {
  font-size: 13.5px;
  font-weight: 600;
}

.file-group-head .muted {
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.staff-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: 9px 2px;
  border-top: 1px solid var(--line-soft);
  flex-wrap: wrap;
}

.staff-row > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.staff-row > div:last-child {
  flex-direction: row;
  align-items: center;
  gap: var(--s2);
}

.staff-row .muted.small {
  font-family: var(--font-mono);
  font-size: 11px;
}

.org-license-info,
#org-license-info {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  align-items: flex-start;
}

#org-license-info .badge,
#org-license-info .muted {
  margin: 0;
}

#org-license-info .table-wrap {
  width: 100%;
}

/* ── Banners ────────────────────────────────────────────── */

.org-banner {
  border: 1px solid rgba(240, 180, 41, 0.45);
  border-left: 3px solid var(--warn);
  background: rgba(240, 180, 41, 0.08);
  color: var(--warn-text);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.org-banner.warning {
  border-color: rgba(229, 100, 78, 0.45);
  border-left-color: var(--bad);
  background: rgba(229, 100, 78, 0.09);
  color: var(--bad-text);
}

/* ── Billing ────────────────────────────────────────────── */

.billing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--s4);
}

#page-billing > .billing-grid-main {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

#page-billing > .billing-grid-main.admin-view {
  grid-template-columns: minmax(0, 1fr);
}

.revenue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.revenue-stat {
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.revenue-stat span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.revenue-stat strong {
  display: block;
  margin-top: var(--s1);
  font-family: var(--font-mono);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.revenue-stat strong.good { color: var(--good-text); }
.revenue-stat strong.warn { color: var(--warn-text); }
.revenue-stat strong.bad { color: var(--bad-text); }
.revenue-stat strong.muted { color: var(--muted); }

.org-billing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.org-billing-card {
  display: flex;
  align-items: center;
  gap: var(--s4);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  min-width: 0;
}

.org-billing-card > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.org-billing-card strong {
  font-family: var(--font-mono);
  font-size: 18px;
}

#org-billing-invoice > div {
  display: flex;
  justify-content: space-between;
  gap: var(--s4);
  padding: 7px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
}

#org-billing-invoice > div:first-child {
  border-top: none;
}

.plan-select {
  width: auto;
  min-width: 140px;
  padding: 7px 30px 7px 10px;
}

.org-billing-payment-note {
  font-size: 12.5px;
  color: var(--muted);
  max-width: 80ch;
  line-height: 1.55;
}

/* Crypto signup payment */

.payment-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: var(--s4);
  align-items: start;
}

.payment-card {
  min-width: 0;
}

.payment-summary {
  display: grid;
  gap: 6px;
  margin: var(--s3) 0 var(--s4);
}

.payment-summary > div {
  display: flex;
  justify-content: space-between;
  gap: var(--s4);
  padding: 6px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
}

.payment-summary > div:first-child {
  border-top: none;
}

.payment-summary strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.payment-coin-field {
  max-width: 380px;
}

.payment-address {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 148px;
  gap: var(--s4);
  align-items: start;
  margin-top: var(--s4);
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-inset);
}

.payment-amount-block,
.payment-address-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.payment-amount-block strong {
  font-family: var(--font-mono);
  font-size: 26px;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

.payment-address-block code {
  overflow-wrap: anywhere;
  font-size: 12.5px;
  color: var(--text);
}

.payment-address-block .ghost {
  align-self: flex-start;
  font-size: 12px;
  padding: 4px 9px;
}

#payment-qr {
  width: 148px;
  height: 148px;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 6px;
  grid-row: 1 / span 2;
  grid-column: 2;
}

.payment-submission {
  margin-top: var(--s4);
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-inset);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.payment-submission code {
  overflow-wrap: anywhere;
  font-size: 12.5px;
  color: var(--accent-strong);
}

.payment-submission p {
  margin: 0;
}

.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  font: inherit;
}

.link-button:hover {
  color: var(--accent-strong);
}

.wallet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s3);
  padding-top: var(--s2);
}

.rates-panel {
  margin-top: var(--s4);
  padding-top: var(--s4);
  border-top: 1px solid var(--line-soft);
}

.billing-warning {
  margin: var(--s2) 0 0;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--warn-text);
}

.rates-panel h4 {
  font-size: 13px;
  font-weight: 600;
}

.rates-line {
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--muted);
  margin-bottom: var(--s2);
  overflow-wrap: anywhere;
}

.rates-line.bad {
  color: var(--bad-text);
}

.crypto-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.crypto-cell code {
  font-size: 11.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.crypto-cell .badge {
  align-self: flex-start;
}

/* Support tickets */

.ticket-toolbar select {
  width: auto;
  min-width: 190px;
}

.ticket-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.ticket-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 90px 170px;
  align-items: center;
  gap: var(--s4);
  width: 100%;
  padding: 14px 6px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
}

.ticket-row:hover {
  background: rgba(240, 180, 41, 0.045);
}

.ticket-row-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.ticket-row-body strong {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-row-meta {
  font-size: 11.5px;
  color: var(--muted);
}

.ticket-row-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  text-align: right;
}

.ticket-status-open,
.ticket-status-awaiting-customer,
.ticket-status-resolved,
.ticket-status-closed,
.ticket-priority-low,
.ticket-priority-normal,
.ticket-priority-high {
  border-radius: 999px;
}

.ticket-status-open,
.ticket-status-awaiting-customer {
  border-color: rgba(240, 180, 41, 0.45);
  background: rgba(240, 180, 41, 0.12);
  color: var(--warn-text);
}

.ticket-status-resolved {
  border-color: rgba(88, 201, 139, 0.4);
  background: rgba(88, 201, 139, 0.1);
  color: var(--good-text);
}

.ticket-status-closed,
.ticket-priority-normal {
  border-color: var(--line);
  background: var(--panel-inset);
  color: var(--muted);
}

.ticket-priority-high {
  border-color: rgba(229, 100, 78, 0.45);
  background: rgba(229, 100, 78, 0.1);
  color: var(--bad-text);
}

.ticket-priority-low {
  border-color: rgba(88, 201, 139, 0.3);
  background: transparent;
  color: var(--good-text);
}

.ticket-status-open::before,
.ticket-status-awaiting-customer::before,
.ticket-status-resolved::before,
.ticket-status-closed::before,
.ticket-priority-low::before,
.ticket-priority-normal::before,
.ticket-priority-high::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.ticket-new-card {
  width: min(680px, 100%);
}

.ticket-modal-card {
  width: min(900px, 100%);
}

.ticket-admin-controls {
  display: flex;
  align-items: flex-end;
  gap: var(--s3);
  flex-wrap: wrap;
  padding: 14px 16px;
  margin-bottom: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-inset);
}

.ticket-admin-controls .stack {
  min-width: 160px;
  flex: 1 1 160px;
}

.ticket-thread {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  max-height: 48vh;
  overflow-y: auto;
  padding: 2px 2px var(--s4);
}

.ticket-message {
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-inset);
  padding: 12px 15px 14px;
}

.ticket-message.admin {
  border-left-color: var(--accent);
  background: var(--panel);
}

.ticket-message-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ticket-message-head .badge {
  font-size: 9.5px;
  padding: 1px 7px;
}

.ticket-message-head .muted {
  margin-left: auto;
}

.ticket-message-body {
  margin: 9px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13.5px;
  line-height: 1.65;
}

.ticket-reply-form {
  margin-top: var(--s4);
  padding-top: var(--s4);
  border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
  .ticket-row {
    grid-template-columns: 130px minmax(0, 1fr) 80px;
  }

  .ticket-row-time {
    display: none;
  }
}

@media (max-width: 620px) {
  .ticket-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .ticket-row > .badge:first-child {
    grid-row: 1;
    grid-column: 2;
    justify-self: end;
  }

  .ticket-row-body {
    grid-row: 1 / span 2;
    grid-column: 1;
  }

  .ticket-row > .badge:last-of-type {
    grid-row: 2;
    grid-column: 2;
    justify-self: end;
  }
}

.badge.rejected,
.badge.awaiting_payment,
.badge.submitted,
.badge.pending,
.badge.lic-rejected,
.badge.lic-awaiting_payment,
.badge.lic-submitted,
.badge.lic-pending {
  border-color: rgba(240, 180, 41, 0.45);
  background: rgba(240, 180, 41, 0.12);
  color: var(--warn-text);
}

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

@media (max-width: 620px) {
  .payment-address {
    grid-template-columns: minmax(0, 1fr);
  }

  #payment-qr {
    grid-row: auto;
    grid-column: auto;
    width: 132px;
    height: 132px;
  }
}

/* ── Modals ─────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 7, 11, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: modal-fade 140ms ease;
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: min(460px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: var(--s5);
  box-shadow: var(--shadow);
  animation: modal-rise 160ms ease;
}

@keyframes modal-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.modal-card .device-head {
  margin-bottom: var(--s3);
  align-items: center;
}

.modal-card h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-card.device-modal-card {
  width: min(1120px, 100%);
  padding: 0;
  overflow: auto;
}

.modal-card.device-modal-card #device-view {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: var(--s5);
}

.modal-card .stack {
  margin-top: var(--s3);
}

.modal-card .toolbar {
  margin-top: var(--s4);
}

.modal-actions {
  justify-content: flex-end;
}

.confirm-message {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
  margin-top: var(--s2);
}

/* ── Toast ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-width: min(420px, calc(100vw - 40px));
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
  animation: toast-in 180ms ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.toast::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
  margin-top: 5px;
}

.toast.bad {
  border-left-color: var(--bad);
}

.toast.bad::before {
  background: var(--bad);
}

.toast.good {
  border-left-color: var(--good);
}

.toast.good::before {
  background: var(--good);
}

/* ── Loading: skeletons & spinner ───────────────────────── */

.skeleton {
  display: block;
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--panel-2) 25%, #232e3d 37%, var(--panel-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.skeleton-row td {
  padding: 12px 14px;
}

.skeleton-list-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: 15px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
}

.skeleton-card {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.output .skeleton {
  height: 10px;
  margin-bottom: 6px;
}

.skeleton-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: var(--s2) 0;
}

.skeleton-device {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
}

.skeleton-device .skeleton.dot-sk {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.skeleton-device .skeleton.lines {
  flex: 1;
  height: 26px;
}

.busy {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.busy::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
  flex: none;
}

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

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 960px) {
  .login-shell {
    grid-template-columns: 1fr;
  }

  .login-brand {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: var(--s6) var(--s5);
    gap: var(--s3);
  }

  .login-pulse {
    display: none;
  }

  .brand.large {
    font-size: 30px;
  }

  .login-card {
    padding: var(--s6) var(--s5);
    max-width: 460px;
  }
}

@media (max-width: 1100px) {
  #page-billing > .billing-grid-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: var(--s2);
    padding: 10px var(--s4);
    min-height: 0;
  }

  .nav-toggle {
    display: inline-flex;
    order: 2;
  }

  .topbar-brand {
    order: 1;
  }

  .topbar-right {
    order: 3;
    margin-left: auto;
  }

  .topnav {
    order: 10;
    flex-basis: 100%;
    flex-direction: column;
    gap: 2px;
    display: none;
    padding-top: var(--s2);
    border-top: 1px solid var(--line-soft);
    margin-top: var(--s2);
  }

  .topbar.nav-open .topnav {
    display: flex;
  }

  .topnav-item {
    text-align: left;
    padding: 9px 12px;
  }

  .topnav-item.active {
    box-shadow: inset 2px 0 0 var(--accent);
  }

  .user-chip {
    display: none;
  }

  .conn-status .conn-text {
    display: none;
  }

  #main {
    padding: var(--s5) var(--s4) 64px;
  }

  #installer-files-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .group-rows {
    grid-template-columns: minmax(0, 1fr);
  }

  .plans-table-wrap {
    overflow-x: auto;
  }

  .plans-table-wrap .data-table {
    min-width: 520px;
  }
}

@media (max-width: 620px) {
  .device-head {
    flex-direction: column;
    align-items: stretch;
  }

  .device-head-actions {
    justify-content: flex-start;
  }

  .org-row,
  .license-row,
  .user-row,
  .staff-row {
    flex-direction: column;
    align-items: stretch;
  }

  .license-row {
    grid-template-columns: 1fr;
  }

  .org-row > div:last-child,
  .license-row > div:last-child {
    align-items: flex-start;
  }

  .org-row-actions {
    justify-content: flex-start;
  }

  .sidebar-search {
    max-width: none;
  }

  .toast {
    right: 12px;
    left: 12px;
    bottom: 12px;
    max-width: none;
  }

  #installer-files-list {
    gap: 8px;
  }

  #installer-files-list .file-card {
    padding: 10px 12px;
  }

  #installer-files-list .installer-name {
    font-size: 13px;
  }

  #installer-files-list .installer-actions {
    gap: 6px;
  }
}

/* ── Reduced motion ─────────────────────────────────────── */

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

  .login-pulse path {
    stroke-dashoffset: 0;
  }

  .skeleton {
    background: var(--panel-2);
  }
}
