/* ==========================================================================
 * DocuTrack portal — the TextBot design system (v2), shared so the products read as one family.
 *
 * Built to the Secureza/GPS Track portal system so the products read as one family:
 * Inter for everything that is interface, small radii (six to eight pixels on controls,
 * twelve to sixteen on surfaces), solid surfaces with one-pixel borders and a barely-there
 * shadow, sentence-case labels at ordinary weight, and teal spent sparingly — on the
 * primary action and on what is selected — so that it means something when it appears.
 *
 * Rules for new markup: no capsules on anything with text in it, no uppercase, no letter
 * tracking, no gradients on controls. Colours only through the tokens below, so the dark
 * theme (html[data-theme="dark"]) follows without extra rules.
 * ======================================================================== */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;450;500;600;700&display=swap");

:root {
  color-scheme: light;

  --ds-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ds-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --ds-r-xs: 4px;
  --ds-r-sm: 6px;
  --ds-r-md: 8px;
  --ds-r-lg: 12px;
  --ds-r-xl: 14px;

  --ds-surface: #ffffff;
  --ds-surface-2: #f6f7f9;
  --ds-surface-3: #eef0f3;
  --ds-border: rgba(15, 23, 42, 0.08);
  --ds-border-strong: rgba(15, 23, 42, 0.14);
  --ds-text: #0f172a;
  --ds-text-2: #475569;
  --ds-text-3: #64748b;

  --ds-accent: #0f766e;
  --ds-accent-hover: #115e59;
  --ds-accent-soft: rgba(15, 118, 110, 0.09);
  --ds-accent-line: rgba(15, 118, 110, 0.32);
  --ds-accent-text: #0f766e;

  --ds-ok-bg: rgba(5, 150, 105, 0.1);
  --ds-ok-text: #047857;
  --ds-warn-bg: rgba(217, 119, 6, 0.12);
  --ds-warn-text: #b45309;
  --ds-danger-bg: rgba(225, 29, 72, 0.1);
  --ds-danger-text: #be123c;
  --ds-danger-line: rgba(225, 29, 72, 0.3);

  --ds-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --ds-shadow-md: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px -8px rgba(15, 23, 42, 0.1);
  --ds-shadow-lg: 0 20px 48px -16px rgba(15, 23, 42, 0.28);
  --ds-ring: 0 0 0 3px rgba(20, 184, 166, 0.2);

  --ds-bg-0: #f7faf8;
  --ds-bg-1: #eff6f2;
  --ds-bg-2: #e6f0eb;
  --ds-glow-1: rgba(15, 118, 110, 0.1);
  --ds-glow-2: rgba(20, 184, 166, 0.08);
  --ds-rail-bg: var(--ds-surface);
  --ds-menu-bg: var(--ds-surface);
  --ds-backdrop: rgba(2, 6, 23, 0.55);
  --ds-toast-bg: #0f172a;
  --ds-toast-text: #f8fafc;

  --rail-w: 296px;
  --rail-w-collapsed: 76px;
  --shell-pad: 20px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --ds-surface: #16191e;
  --ds-surface-2: rgba(255, 255, 255, 0.03);
  --ds-surface-3: rgba(255, 255, 255, 0.06);
  --ds-border: rgba(255, 255, 255, 0.07);
  --ds-border-strong: rgba(255, 255, 255, 0.12);
  --ds-text: #e8ebef;
  --ds-text-2: #a6afbb;
  --ds-text-3: #7f8995;

  --ds-accent: #0d9488;
  --ds-accent-hover: #0fa396;
  --ds-accent-soft: rgba(45, 212, 191, 0.1);
  --ds-accent-line: rgba(45, 212, 191, 0.3);
  --ds-accent-text: #5eead4;

  --ds-ok-bg: rgba(16, 185, 129, 0.14);
  --ds-ok-text: #34d399;
  --ds-warn-bg: rgba(245, 158, 11, 0.14);
  --ds-warn-text: #fbbf24;
  --ds-danger-bg: rgba(244, 63, 94, 0.14);
  --ds-danger-text: #fb7185;
  --ds-danger-line: rgba(251, 113, 133, 0.3);

  --ds-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --ds-shadow-md: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px -12px rgba(0, 0, 0, 0.45);
  --ds-shadow-lg: 0 24px 60px -18px rgba(0, 0, 0, 0.65);
  --ds-ring: 0 0 0 3px rgba(45, 212, 191, 0.22);

  --ds-bg-0: #0e1114;
  --ds-bg-1: #15191e;
  --ds-bg-2: #1d2329;
  --ds-glow-1: rgba(112, 128, 144, 0.14);
  --ds-glow-2: rgba(52, 63, 73, 0.18);
  /* The rail keeps a slate of its own: the near-black of a surface was hard on the eyes there. */
  --ds-rail-bg: linear-gradient(180deg, rgba(27, 32, 38, 0.97), rgba(20, 24, 29, 0.95));
  --ds-menu-bg: #1a1e23;
  --ds-backdrop: rgba(0, 0, 0, 0.62);
  --ds-toast-bg: #262b32;
  --ds-toast-text: #e8ebef;
}

/* ---- base -------------------------------------------------------------------------- */

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

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ds-text);
  font-family: var(--ds-font);
  font-size: 13.5px;
  line-height: 1.5;
  letter-spacing: -0.003em;
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background:
    radial-gradient(1200px 680px at 12% -5%, var(--ds-glow-1), transparent 58%),
    radial-gradient(860px 580px at 90% 0%, var(--ds-glow-2), transparent 58%),
    linear-gradient(165deg, var(--ds-bg-0), var(--ds-bg-1) 46%, var(--ds-bg-2));
  background-attachment: fixed;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: -0.003em;
}

button {
  border: 0;
  cursor: pointer;
  color: inherit;
  background: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

a {
  color: var(--ds-accent-text);
}

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

h1,
h2,
h3 {
  color: var(--ds-text);
  font-weight: 600;
  letter-spacing: -0.012em;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.022em;
}

h2 {
  font-size: 15px;
  line-height: 1.35;
}

h3 {
  font-size: 14px;
  line-height: 1.4;
}

p {
  color: var(--ds-text-3);
  line-height: 1.55;
}

strong {
  font-weight: 600;
}

code,
pre {
  font-family: var(--ds-mono);
}

td,
.stat strong,
.price,
.tabular {
  font-variant-numeric: tabular-nums;
}

::selection {
  background: rgba(15, 118, 110, 0.22);
}

:root[data-theme="dark"] ::selection {
  background: rgba(15, 118, 110, 0.4);
}

::-webkit-scrollbar {
  width: 10px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(100, 116, 139, 0.3) padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.5) padding-box;
}

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--ds-text-3);
  font-weight: 500;
}

.muted {
  color: var(--ds-text-3);
}

/* ---- buttons ----------------------------------------------------------------------- */

.primary,
.secondary,
.ghost,
.danger,
.tiny {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--ds-r-md);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 20px;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: var(--ds-shadow-sm);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.primary svg,
.secondary svg,
.ghost svg,
.danger svg,
.tiny svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.primary {
  color: #ffffff;
  background: var(--ds-accent);
  box-shadow: var(--ds-shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

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

.secondary,
.ghost,
.tiny {
  border-color: var(--ds-border-strong);
  color: var(--ds-text);
  background: var(--ds-surface);
}

:root[data-theme="dark"] .secondary,
:root[data-theme="dark"] .ghost,
:root[data-theme="dark"] .tiny {
  background: rgba(255, 255, 255, 0.04);
}

.secondary:hover:not(:disabled),
.ghost:hover:not(:disabled),
.tiny:hover:not(:disabled) {
  background: var(--ds-surface-3);
}

.danger {
  border-color: var(--ds-danger-line);
  color: var(--ds-danger-text);
  background: transparent;
  box-shadow: none;
}

.danger:hover:not(:disabled) {
  background: var(--ds-danger-bg);
}

.tiny {
  padding: 4px 10px;
  border-radius: var(--ds-r-sm);
  font-size: 12.5px;
  line-height: 18px;
}

.tiny.danger,
.danger-text {
  border-color: var(--ds-danger-line);
  color: var(--ds-danger-text);
  background: transparent;
}

.tiny.danger:hover:not(:disabled),
.danger-text:hover:not(:disabled) {
  background: var(--ds-danger-bg);
}

.linkish {
  display: inline-flex;
  width: fit-content;
  padding: 0;
  color: var(--ds-accent-text);
  font-size: 13.5px;
  font-weight: 500;
  background: transparent;
}

.linkish:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: var(--ds-r-md);
  color: var(--ds-text-3);
  background: transparent;
  transition: background-color 120ms ease, color 120ms ease;
}

.icon-button:hover {
  color: var(--ds-text);
  background: var(--ds-surface-3);
}

.icon-button svg {
  width: 16px;
  height: 16px;
}

:is(.primary, .secondary, .ghost, .danger, .tiny, .icon-button, .linkish, .nav-row, .nav-section-title):focus-visible {
  outline: none;
  box-shadow: var(--ds-ring);
}

/* ---- fields ------------------------------------------------------------------------ */

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  min-width: 0;
}

.form-grid .field,
.log-composer .field {
  margin-bottom: 0;
}

.field > label,
label {
  color: var(--ds-text-2);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--ds-r-md);
  color: var(--ds-text);
  background: var(--ds-surface);
  font-size: 13.5px;
  line-height: 20px;
  outline: none;
  box-shadow: var(--ds-shadow-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

/* background-color, not the shorthand: the search magnifier and select chevron are images. */
:root[data-theme="dark"] :is(input, select, textarea) {
  background-color: rgba(255, 255, 255, 0.03);
}

select {
  padding-right: 28px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px 14px;
}

select option,
select optgroup {
  color: #0f172a;
  background-color: #ffffff;
}

:root[data-theme="dark"] select option,
:root[data-theme="dark"] select optgroup {
  color: #e8ebef;
  background-color: #1a1e23;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--ds-text-3);
  opacity: 0.8;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--ds-accent-line);
  box-shadow: var(--ds-ring);
}

input[readonly] {
  color: var(--ds-text-2);
  background: var(--ds-surface-2);
  box-shadow: none;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--ds-accent);
  box-shadow: none;
}

.form-grid,
.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.full {
  grid-column: 1 / -1;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 2px 0 14px;
}

.form-grid .check-grid {
  margin-bottom: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ds-text);
  font-size: 13.5px;
  font-weight: 450;
}

/* A search field names itself with its placeholder and a magnifier; its label is for readers. */
.search-field > label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.search-field input,
.conversation-search input {
  padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 11px center;
  background-size: 15px 15px;
}

/* ---- badges and chips -------------------------------------------------------------- */

/* A status or category mark. Four pixels: a label, never a capsule. */
.badge {
  display: inline-block;
  width: fit-content;
  padding: 1px 7px;
  border-radius: var(--ds-r-xs);
  color: var(--ds-text-2);
  background: var(--ds-surface-3);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 18px;
  white-space: nowrap;
}

/* Statuses arrive in lower case ("connected", "2 active"): sentence case, not Title Case. */
.badge::first-letter {
  text-transform: uppercase;
}

.badge.connected {
  color: var(--ds-ok-text);
  background: var(--ds-ok-bg);
}

.badge.connecting,
.badge.qr {
  color: var(--ds-accent-text);
  background: var(--ds-accent-soft);
}

.badge.disabled,
.badge.error,
.badge.failed {
  color: var(--ds-danger-text);
  background: var(--ds-danger-bg);
}

.badge.warning {
  color: var(--ds-warn-text);
  background: var(--ds-warn-bg);
}

/* ---- the app shell ----------------------------------------------------------------- */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: var(--shell-pad);
  padding: var(--shell-pad);
  transition: grid-template-columns 240ms ease;
}

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

/* The side menu: a solid panel with a hairline edge, not frosted glass on a long shadow. */
.rail {
  position: sticky;
  top: var(--shell-pad);
  z-index: 30;
  height: calc(100vh - 2 * var(--shell-pad));
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-xl);
  color: var(--ds-text);
  background: var(--ds-rail-bg);
  box-shadow: var(--ds-shadow-md);
}

.rail-collapse {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
}

.rail-brand {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 26px 52px 18px 24px;
  border-bottom: 1px solid var(--ds-border);
}

.rail-brand img {
  display: block;
  width: auto;
  max-width: 100%;
  height: 42px;
  object-fit: contain;
  user-select: none;
}

/* One lockup at a time: the light one, the reversed one in dark mode, the mark when collapsed. */
.rail-brand .logo-dark,
.rail-brand .logo-mark,
.auth-mobile-logo .logo-dark {
  display: none;
}

:root[data-theme="dark"] .rail-brand .logo-light,
:root[data-theme="dark"] .auth-mobile-logo .logo-light {
  display: none;
}

:root[data-theme="dark"] .rail-brand .logo-dark,
:root[data-theme="dark"] .auth-mobile-logo .logo-dark {
  display: block;
}

.rail-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--ds-border-strong) transparent;
}

.nav-section {
  display: block;
  margin-bottom: 1px;
}

/* A section header reads like a row of the menu: its icon, its name, a chevron. The section
   holding the page you are on is shown by its name brightening and its icon taking the accent. */
.nav-section-title {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 10px;
  border-radius: var(--ds-r-md);
  color: var(--ds-text-2);
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: -0.003em;
  line-height: 1.2;
  text-align: left;
  white-space: nowrap;
  transition: background-color 100ms ease, color 100ms ease;
}

.nav-section-title:hover {
  color: var(--ds-text);
  background: var(--ds-surface-3);
}

.nav-section.has-active .nav-section-title {
  color: var(--ds-text);
}

.nav-section-title .section-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--ds-text-3);
}

.nav-section-title:hover .nav-section-icon {
  color: var(--ds-text-2);
}

.nav-section.has-active .nav-section-icon {
  color: var(--ds-accent-text);
}

.nav-chevron {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--ds-text-3);
  transition: transform 150ms ease;
}

.nav-section.open .nav-chevron {
  transform: rotate(180deg);
}

/* A section's pages, hung off a guide line rather than floating in an indent. */
.nav-section-body {
  display: none;
  gap: 1px;
  margin: 2px 0 6px 18px;
  padding-left: 9px;
  border-left: 1px solid var(--ds-border);
}

.nav-section.open .nav-section-body {
  display: grid;
}

/* One page of the menu. Six-pixel corners, sentence case. The page you are on is a quiet
   fill and a two-pixel accent mark on the guide line, not a filled green block. */
.nav-row {
  position: relative;
  width: 100%;
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-radius: var(--ds-r-sm);
  color: var(--ds-text-2);
  font-size: 13px;
  font-weight: 450;
  letter-spacing: -0.003em;
  line-height: 1.2;
  text-align: left;
  white-space: nowrap;
  transition: background-color 100ms ease, color 100ms ease;
}

.nav-row > span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-row:hover {
  color: var(--ds-text);
  background: var(--ds-surface-3);
}

.nav-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--ds-text-3);
  transition: color 100ms ease;
}

.nav-row:hover .nav-icon {
  color: var(--ds-text-2);
}

.nav-row.active,
.nav-row.active:hover {
  color: var(--ds-text);
  background: var(--ds-surface-3);
  font-weight: 500;
}

.nav-row.active .nav-icon {
  color: var(--ds-accent-text);
}

.nav-row.active::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: -10px;
  width: 2px;
  border-radius: 2px;
  background: var(--ds-accent-text);
}

.nav-row b {
  flex-shrink: 0;
  padding: 0 6px;
  border-radius: var(--ds-r-xs);
  color: var(--ds-text-3);
  background: var(--ds-surface-3);
  font-size: 11px;
  font-weight: 500;
  line-height: 18px;
}

.nav-row.active b {
  color: var(--ds-text-2);
  background: var(--ds-surface);
}

/* The foot of the menu: rows the size of the section headers above them. */
.nav-row.rail-action {
  min-height: 38px;
  gap: 11px;
  border-radius: var(--ds-r-md);
  font-size: 14.5px;
  font-weight: 500;
}

.rail-action .nav-icon {
  width: 18px;
  height: 18px;
}

.rail-foot {
  flex-shrink: 0;
  padding: 6px 12px 12px;
  border-top: 1px solid var(--ds-border);
}

.rail-account {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-top: 6px;
  padding: 10px 10px 2px;
  border-top: 1px solid var(--ds-border);
}

.rail-account > span:last-child {
  min-width: 0;
}

.rail-account strong,
.rail-account small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-account strong {
  color: var(--ds-text);
  font-size: 13px;
  font-weight: 500;
}

.rail-account small {
  color: var(--ds-text-3);
  font-size: 12px;
}

.avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--ds-accent-text);
  background: var(--ds-accent-soft);
  font-size: 12px;
  font-weight: 600;
}

/* Collapsed: icons only, centred; names come back as tooltips. */
.rail-collapsed .rail-brand {
  justify-content: center;
  padding: 52px 8px 14px;
}

.rail-collapsed .rail-brand img {
  height: 32px;
}

:root .rail-collapsed .rail-brand .logo-light,
:root .rail-collapsed .rail-brand .logo-dark,
:root[data-theme="dark"] .rail-collapsed .rail-brand .logo-dark {
  display: none;
}

:root .rail-collapsed .rail-brand .logo-mark {
  display: block;
}

.rail-collapsed .rail-collapse {
  right: 50%;
  transform: translateX(50%);
}

.rail-collapsed .rail-nav,
.rail-collapsed .rail-foot {
  padding-left: 10px;
  padding-right: 10px;
}

@media (min-width: 1024px) {
  .rail-collapsed .nav-section-title {
    min-height: 0;
    height: 9px;
    margin: 4px 6px;
    padding: 0;
    pointer-events: none;
  }

  .rail-collapsed .nav-section-title::before {
    content: "";
    width: 100%;
    height: 1px;
    background: var(--ds-border);
  }

  .rail-collapsed .nav-section:first-child .nav-section-title,
  .rail-collapsed .nav-section-icon,
  .rail-collapsed .nav-chevron,
  .rail-collapsed .section-label,
  .rail-collapsed .nav-row b {
    display: none;
  }

  .rail-collapsed .nav-section-body {
    display: grid;
    gap: 2px;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .rail-collapsed .nav-row {
    justify-content: center;
    height: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: var(--ds-r-md);
  }

  .rail-collapsed .nav-row.active::before {
    left: 0;
    top: 8px;
    bottom: 8px;
  }

  .rail-collapsed .nav-icon {
    width: 17px;
    height: 17px;
  }
}

.rail-collapsed .nav-row > span,
.rail-collapsed .rail-account > span:last-child {
  display: none;
}

.rail-collapsed .rail-account {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.mobile-nav-button,
.rail-backdrop {
  display: none;
}

.content {
  min-width: 0;
  padding: 16px;
}

.content > * + * {
  margin-top: 20px;
}

/* ---- page header ------------------------------------------------------------------- */

/* Every page opens on one header card: an eyebrow naming the area, the title, a line of
   description, its actions, and — on the right — a summary card. */
.dashboard-hero,
.hero-panel,
.settings-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 340px);
  gap: 24px;
  align-items: center;
  padding: 24px;
  border: 1px solid var(--ds-border);
  border-radius: 16px;
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-md);
}

.hero-panel > :only-child,
.settings-hero > :only-child {
  grid-column: 1 / -1;
}

.hero-panel > .download-button {
  justify-self: end;
}

.dashboard-copy {
  min-width: 0;
}

.dashboard-copy h2,
.hero-panel h2,
.settings-hero h2 {
  max-width: 820px;
  color: var(--ds-text);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.022em;
}

.dashboard-copy p,
.hero-panel p,
.settings-hero p {
  max-width: 760px;
  margin-top: 6px;
  color: var(--ds-text-3);
  font-size: 14px;
}

/* Small words above a heading: the page's area, quietly, in the accent. */
.eyebrow {
  display: block;
  margin-bottom: 6px;
  color: var(--ds-accent-text);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
}

.hero-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.hero-actions {
  margin-top: 18px;
}

.signal-card,
.payfast-chip,
.stat {
  min-width: 0;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface);
}

:root[data-theme="dark"] :is(.signal-card, .payfast-chip, .stat) {
  background: rgba(255, 255, 255, 0.025);
}

.signal-card {
  display: grid;
  gap: 8px;
  align-content: center;
  padding: 16px;
}

.signal-card > strong {
  color: var(--ds-text);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.signal-card > p {
  font-size: 13px;
}

.signal-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 4px;
}

.signal-metrics span {
  display: grid;
  gap: 1px;
  padding: 8px 10px;
  border-radius: var(--ds-r-md);
  color: var(--ds-text-3);
  background: var(--ds-surface-2);
  font-size: 12px;
}

.signal-metrics strong {
  color: var(--ds-text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

.payfast-chip {
  justify-self: end;
  min-width: 200px;
  padding: 14px 16px;
}

.payfast-chip span,
.payfast-chip strong {
  display: block;
}

.payfast-chip span {
  color: var(--ds-text-3);
  font-size: 12px;
  font-weight: 500;
}

.payfast-chip strong {
  margin-top: 2px;
  color: var(--ds-accent-text);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.settings-health {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

/* ---- stat cards -------------------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.stat small {
  color: var(--ds-text-2);
  font-size: 12.5px;
  font-weight: 500;
}

.stat strong {
  color: var(--ds-text);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

/* ---- panels ------------------------------------------------------------------------ */

/* Solid, bordered, barely raised. A panel's title sits on the panel, over a hairline. */
.panel,
.plan-card,
.ticket-card,
.key-card,
.selected-billing-key {
  min-width: 0;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-xl);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-md);
}

.panel {
  padding: 20px;
}

.panel > h2:first-child {
  margin-bottom: 4px;
}

.panel > h2 + p {
  margin-bottom: 12px;
  font-size: 13.5px;
}

.panel > p + p {
  margin-top: 10px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  margin-bottom: 16px;
}

.toolbar p {
  margin-top: 2px;
  font-size: 13px;
}

.panel > .toolbar:first-child {
  min-height: 56px;
  margin: -20px -20px 20px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--ds-border);
}

.panel > .toolbar:first-child h2 {
  font-size: 14.8px;
  font-weight: 600;
}

.flat-panel {
  box-shadow: none;
}

/* A list page: the title band, a filter band, then the table running edge to edge. */
.panel > .toolbar:first-child + .search-field {
  margin: -20px -20px 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--ds-border);
  background: var(--ds-surface-2);
}

.panel > .search-field + :is(.key-table-wrap, .ticket-table-wrap, .user-table-wrap) {
  margin: 0 -20px -20px;
  border: 0;
  border-radius: 0 0 var(--ds-r-xl) var(--ds-r-xl);
}

.grid {
  display: grid;
  gap: 20px;
}

.grid.two {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  align-items: start;
}

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

.control-stack,
.detail-stack,
.ticket-list,
.settings-content,
.modal-grid,
.modal-stack,
.key-list,
.package-list,
.user-list {
  display: grid;
  gap: 16px;
}

.empty,
.dashboard-empty {
  padding: 28px 20px;
  border: 1px dashed var(--ds-border-strong);
  border-radius: var(--ds-r-lg);
  color: var(--ds-text-3);
  background: transparent;
  font-size: 13.5px;
  text-align: center;
}

.dashboard-empty {
  min-height: 300px;
  display: grid;
  place-items: center;
}

td > .empty {
  border: 0;
}

/* ---- tables ------------------------------------------------------------------------ */

.user-table-wrap,
.key-table-wrap,
.ticket-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
}

.logs,
.admin-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--ds-text-2);
  font-size: 13.5px;
}

.user-table {
  min-width: 860px;
}

.key-table {
  min-width: 980px;
}

.ticket-table {
  min-width: 900px;
}

.modal-body .logs {
  min-width: 760px;
}

/* Column heads are labels, not a banner: the muted text colour on the faintest of tints. */
.logs th,
.admin-table th {
  padding: 10px 16px;
  border-bottom: 1px solid var(--ds-border);
  color: var(--ds-text-3);
  background: var(--ds-surface-2);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.logs td,
.admin-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--ds-border);
  text-align: left;
  vertical-align: middle;
}

.logs tbody tr:last-child td,
.admin-table tbody tr:last-child td {
  border-bottom: 0;
}

.logs tbody tr,
.admin-table tbody tr {
  transition: background-color 120ms ease;
}

.logs tbody tr:hover,
.admin-table tbody tr:hover {
  background: var(--ds-surface-2);
}

.admin-table td strong,
.logs td strong {
  color: var(--ds-text);
  font-weight: 600;
}

.panel > .logs {
  margin: 0 -20px -20px;
  width: calc(100% + 40px);
}

/* A table straight under the title band hangs from it, with no gap. */
.panel > .toolbar:first-child + .logs {
  margin-top: -20px;
}

.table-link {
  display: grid;
  gap: 2px;
  padding: 0;
  color: inherit;
  text-align: left;
}

.table-link strong {
  color: var(--ds-text);
  font-size: 13.5px;
  font-weight: 600;
  transition: color 120ms ease;
}

.table-link:hover strong {
  color: var(--ds-accent-text);
}

.table-link span,
.usage-mini,
.usage-mini span {
  color: var(--ds-text-3);
  font-size: 12px;
}

.usage-mini {
  display: block;
  line-height: 1.35;
  white-space: nowrap;
}

.usage-mini strong {
  color: var(--ds-text);
  font-size: 13.5px;
}

.usage-mini span {
  display: block;
}

.row-actions {
  text-align: right;
  white-space: nowrap;
}

.row-actions > * + * {
  margin-left: 6px;
}

/* ---- API keys ---------------------------------------------------------------------- */

.code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  color: var(--ds-text);
  background: var(--ds-surface-2);
  word-break: break-all;
}

.code code {
  font-size: 12.5px;
}

.panel > .code + *,
.panel > * + .code {
  margin-top: 10px;
}

p.code {
  color: var(--ds-text);
}

pre {
  max-width: 100%;
  margin: 12px 0 0;
  padding: 12px 14px;
  overflow: auto;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  color: var(--ds-text);
  background: var(--ds-surface-2);
  font-size: 12.5px;
  line-height: 1.6;
}

.panel code:not(.code code) {
  padding: 1px 5px;
  border-radius: var(--ds-r-xs);
  color: var(--ds-text);
  background: var(--ds-surface-3);
  font-size: 12.5px;
}

.usage-strip,
.key-card-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.usage-strip span,
.key-card-metrics span {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  color: var(--ds-text-3);
  background: var(--ds-surface-2);
  font-size: 12.5px;
}

.usage-strip strong,
.key-card-metrics strong {
  color: var(--ds-text);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
}

.qr-wrap {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 260px;
  padding: 20px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
  text-align: center;
}

.qr-wrap img {
  width: min(280px, 100%);
  padding: 10px;
  border-radius: var(--ds-r-md);
  background: #ffffff;
}

.qr-wrap h1 {
  font-family: var(--ds-mono);
  font-size: 30px;
  letter-spacing: 0.08em;
}

.qr-wrap + p {
  margin-top: 10px;
  font-size: 13px;
}

.key-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface);
  text-align: left;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.key-row:hover,
.key-row.active {
  border-color: var(--ds-border-strong);
  background: var(--ds-surface-2);
}

.key-row strong {
  display: block;
  color: var(--ds-text);
}

.key-row small {
  font-size: 12px;
}

.key-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.key-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.key-card-main {
  display: grid;
  gap: 6px;
  padding: 0;
  color: inherit;
  text-align: left;
}

.key-card-main strong {
  color: var(--ds-text);
  font-size: 15px;
}

.key-card-main small {
  color: var(--ds-text-3);
  font-size: 12.5px;
}

.key-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---- message logs ------------------------------------------------------------------ */

.conversation-search {
  margin-bottom: 12px;
}

.conversation-logs {
  height: clamp(480px, 66vh, 760px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 0.36fr) minmax(0, 0.64fr);
  overflow: hidden;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface);
}

.conversation-list {
  height: 100%;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border-right: 1px solid var(--ds-border);
  background: var(--ds-surface-2);
}

.conversation-list button {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--ds-r-md);
  color: var(--ds-text-2);
  text-align: left;
  transition: background-color 100ms ease;
}

.conversation-list button + button {
  margin-top: 2px;
}

.conversation-list button:hover {
  background: var(--ds-surface-3);
}

.conversation-list button.active {
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-sm), 0 0 0 1px var(--ds-border);
}

.conversation-list button.active::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--ds-accent-text);
}

.conversation-list button > span {
  min-width: 0;
}

.conversation-list strong,
.conversation-list small,
.conversation-list em {
  display: block;
}

.conversation-list strong {
  color: var(--ds-text);
  font-size: 13.5px;
  font-weight: 600;
}

.conversation-list small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--ds-text-3);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-list em {
  flex: 0 0 80px;
  color: var(--ds-text-3);
  font-size: 11.5px;
  font-style: normal;
  line-height: 1.35;
  text-align: right;
}

.conversation-thread {
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.conversation-thread-head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--ds-border);
}

.conversation-thread-head h3 {
  font-size: 14.5px;
}

.conversation-thread-head p {
  margin-top: 1px;
  font-size: 12.5px;
}

.message-thread {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px;
}

.message-thread-end {
  flex: 0 0 1px;
}

.message-bubble {
  max-width: min(640px, 84%);
  padding: 10px 12px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
}

.message-bubble.inbound {
  align-self: flex-start;
  border-bottom-left-radius: var(--ds-r-xs);
}

.message-bubble.outbound {
  align-self: flex-end;
  border-color: var(--ds-accent-line);
  border-bottom-right-radius: var(--ds-r-xs);
  background: var(--ds-accent-soft);
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  color: var(--ds-text-3);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: capitalize;
}

.message-meta .danger {
  margin-left: auto;
}

.message-bubble p {
  color: var(--ds-text);
  font-size: 13.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-bubble time {
  display: block;
  margin-top: 6px;
  color: var(--ds-text-3);
  font-size: 11.5px;
}

.log-composer {
  display: grid;
  grid-template-columns: 150px 150px 130px minmax(200px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border-top: 1px solid var(--ds-border);
  background: var(--ds-surface-2);
}

.log-composer .composer-text textarea {
  min-height: 36px;
  height: 36px;
}

/* ---- billing ----------------------------------------------------------------------- */

.selected-billing-key {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
}

.selected-billing-key strong,
.selected-billing-key small {
  display: block;
}

.selected-billing-key strong {
  color: var(--ds-text);
}

.selected-billing-key small {
  color: var(--ds-text-3);
  font-size: 12.5px;
}

.plans-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.plan-card {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 20px;
}

.plan-card.featured {
  border-color: var(--ds-accent-line);
  box-shadow: var(--ds-shadow-md), 0 0 0 3px var(--ds-accent-soft);
}

.plan-card h3 {
  font-size: 16px;
}

.plan-card p {
  font-size: 13px;
}

.plan-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.price {
  display: flex;
  align-items: baseline;
  gap: 2px;
  color: var(--ds-text);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.price span,
.price small {
  color: var(--ds-text-3);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
}

.plan-included {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--ds-r-md);
  background: var(--ds-accent-soft);
}

.plan-included strong {
  color: var(--ds-accent-text);
  font-size: 18px;
  font-weight: 700;
}

.plan-included span {
  color: var(--ds-text-2);
  font-size: 12.5px;
  font-weight: 500;
}

.plan-card ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  color: var(--ds-text-2);
  font-size: 13.5px;
  list-style: none;
}

.plan-card li {
  position: relative;
  padding-left: 22px;
}

.plan-card li::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 0;
  width: 14px;
  height: 14px;
  background: var(--ds-accent-text);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.plan-card > button {
  width: 100%;
  margin-top: 4px;
}

.admin-payment-link-result {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--ds-border);
}

.admin-payment-link-result > div:first-child {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.admin-payment-link-result small {
  color: var(--ds-text-3);
  font-size: 12.5px;
}

.payment-link-code {
  align-items: flex-start;
}

.payment-link-code code {
  white-space: normal;
}

/* ---- settings ---------------------------------------------------------------------- */

.settings-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.settings-menu {
  position: sticky;
  top: calc(var(--shell-pad) + 16px);
  display: grid;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-xl);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-md);
}

.settings-menu button {
  position: relative;
  display: grid;
  gap: 1px;
  padding: 8px 12px;
  border-radius: var(--ds-r-md);
  color: var(--ds-text-2);
  text-align: left;
  transition: background-color 100ms ease, color 100ms ease;
}

.settings-menu button:hover {
  color: var(--ds-text);
  background: var(--ds-surface-3);
}

.settings-menu button.active {
  color: var(--ds-text);
  background: var(--ds-surface-3);
}

.settings-menu button.active::before {
  content: "";
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--ds-accent-text);
}

.settings-menu span {
  color: inherit;
  font-size: 13.5px;
  font-weight: 500;
}

.settings-menu small {
  color: var(--ds-text-3);
  font-size: 12px;
}

.settings-content > * + * {
  margin-top: 0;
}

.package-list {
  margin-top: 20px;
}

.package-edit {
  padding: 18px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
}

/* ---- users ------------------------------------------------------------------------- */

.user-modal {
  width: min(760px, 100%);
}

.modal-form-actions,
.modal-check-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.modal-check-row {
  justify-content: space-between;
  gap: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--ds-border);
  color: var(--ds-text-3);
  font-size: 13px;
}

.modal-form-actions {
  padding-top: 4px;
}

.user-card {
  padding: 16px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
}

/* ---- tickets ----------------------------------------------------------------------- */

.ticket-modal {
  width: min(900px, calc(100vw - 32px));
}

.ticket-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.ticket-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.ticket-head h3 {
  margin-top: 6px;
}

.ticket-head p {
  margin-top: 2px;
  font-size: 13px;
}

.ticket-message,
.ticket-note {
  padding: 12px 14px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  color: var(--ds-text);
  background: var(--ds-surface-2);
  white-space: pre-wrap;
}

.ticket-note {
  border-color: var(--ds-accent-line);
  background: var(--ds-accent-soft);
}

.ticket-note strong {
  display: block;
  margin-bottom: 4px;
}

.ticket-update {
  padding-top: 16px;
  border-top: 1px solid var(--ds-border);
}

.ticket-thread {
  display: grid;
  gap: 10px;
}

.thread-item {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
}

.thread-item.support {
  border-color: var(--ds-accent-line);
  background: var(--ds-accent-soft);
}

.thread-item > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--ds-text-3);
  font-size: 12px;
}

.thread-item strong {
  color: var(--ds-text);
  font-size: 13px;
}

.thread-item p {
  color: var(--ds-text);
  font-size: 13.5px;
  white-space: pre-wrap;
}

/* ---- guides: plugin, AgentDesk, docs ----------------------------------------------- */

.plugin-card {
  display: grid;
  align-content: start;
  gap: 12px;
}

.plugin-card > .toolbar:first-child {
  margin-bottom: 4px;
}

.download-button {
  flex: 0 0 auto;
}

/* The section index is a row of quiet toggles, not capsules. */
.plugin-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.plugin-toc a {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-sm);
  color: var(--ds-text-2);
  background: var(--ds-surface);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.plugin-toc a:hover {
  border-color: var(--ds-accent-line);
  color: var(--ds-accent-text);
  background: var(--ds-accent-soft);
}

.guide-copy {
  max-width: 980px;
  color: var(--ds-text-2);
  font-size: 13.5px;
  line-height: 1.6;
}

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

.guide-steps div,
.guide-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
}

.guide-card {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.guide-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ds-text-2);
  font-size: 13.5px;
}

.guide-steps strong {
  display: block;
  color: var(--ds-text);
  font-size: 13.5px;
}

.guide-steps p {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.5;
}

.module-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.module-list span {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-sm);
  color: var(--ds-text-2);
  background: var(--ds-surface-2);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 20px;
}

.module-list.compact span {
  font-family: var(--ds-mono);
  font-size: 12px;
}

.shortcode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.feature-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  color: var(--ds-text-2);
  font-size: 13.5px;
  line-height: 1.55;
  list-style: none;
}

.feature-list li {
  position: relative;
  padding-left: 18px;
}

.feature-list li::before {
  content: "";
  position: absolute;
  top: 0.62em;
  left: 2px;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--ds-accent-text);
  opacity: 0.8;
}

.feature-list strong {
  color: var(--ds-text);
}

/* ---- modals ------------------------------------------------------------------------ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--ds-backdrop);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.key-modal {
  width: min(980px, 100%);
  max-height: min(840px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-xl);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-lg);
  animation: ds-modal-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--ds-border);
}

.modal-head h2 {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.modal-head .badge + h2 {
  margin-top: 8px;
}

.modal-head p {
  margin-top: 2px;
  font-size: 13px;
}

/* Tabs inside a dialog: a strip as wide as its tabs; the one you are on is lifted. */
.modal-actions {
  display: flex;
  gap: 2px;
  width: fit-content;
  max-width: calc(100% - 40px);
  margin: 14px 20px 0;
  padding: 3px;
  overflow-x: auto;
  border: 1px solid var(--ds-border);
  border-radius: 10px;
  background: var(--ds-surface-2);
}

.modal-actions button {
  padding: 5px 12px;
  border-radius: 7px;
  color: var(--ds-text-2);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 20px;
  white-space: nowrap;
  transition: background-color 100ms ease, color 100ms ease;
}

.modal-actions button:hover {
  color: var(--ds-text);
  background: var(--ds-surface-3);
}

.modal-actions button.active {
  color: var(--ds-text);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-sm), 0 0 0 1px var(--ds-border);
}

:root[data-theme="dark"] .modal-actions button.active {
  background: rgba(255, 255, 255, 0.09);
}

.modal-body {
  min-height: 0;
  overflow: auto;
  padding: 20px;
}

.logs-modal .modal-body {
  display: grid;
  overflow: hidden;
}

.logs-modal .modal-stack {
  height: 100%;
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.logs-modal .modal-stack > .toolbar {
  margin-bottom: 0;
}

.logs-modal .conversation-search {
  margin-bottom: 0;
}

.logs-modal .conversation-logs {
  height: auto;
}

.create-key-modal {
  width: min(720px, calc(100vw - 32px));
}

.terms-backdrop {
  z-index: 120;
}

.terms-modal {
  width: min(820px, calc(100vw - 32px));
  grid-template-rows: auto minmax(0, 1fr);
}

.terms-document {
  max-height: 420px;
  overflow: auto;
  padding: 16px 18px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  color: var(--ds-text-2);
  background: var(--ds-surface-2);
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.terms-accept-form {
  display: grid;
  justify-items: start;
  gap: 14px;
  margin-top: 16px;
}

.terms-check {
  align-items: flex-start;
}

/* ---- toast ------------------------------------------------------------------------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 140;
  max-width: min(420px, calc(100vw - 40px));
  padding: 10px 14px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-md);
  color: var(--ds-toast-text);
  background: var(--ds-toast-bg);
  box-shadow: var(--ds-shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  animation: ds-modal-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- sign in ----------------------------------------------------------------------- */

/* One window, two panes: the brand on a deep navy, the form on the surface. */
.auth-page {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px 64px;
}

.auth-window {
  width: min(1180px, 100%);
  min-height: min(680px, calc(100vh - 96px));
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  overflow: hidden;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-md);
}

.auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 56px;
  overflow: hidden;
  color: #ffffff;
  background: #12365b;
}

.auth-brand::after {
  content: "";
  position: absolute;
  top: 40px;
  right: 40px;
  width: 160px;
  height: 160px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  pointer-events: none;
}

.auth-brand-body {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-brand-logo {
  display: block;
  width: 300px;
  max-width: 100%;
  height: auto;
  margin-bottom: 44px;
}

.auth-brand h1 {
  max-width: 440px;
  margin-bottom: 18px;
  color: #ffffff;
  font-size: 40px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.025em;
}

.auth-brand p {
  max-width: 440px;
  margin-bottom: 36px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 16px;
  line-height: 1.6;
}

.auth-features {
  display: grid;
  gap: 10px;
  max-width: 440px;
}

.auth-feature {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--ds-r-md);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: 14px;
  font-weight: 500;
}

.auth-feature::before {
  content: "";
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #ffffff;
}

.auth-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  max-width: 480px;
  margin-top: 44px;
}

.auth-metrics div {
  padding: 12px 16px;
  border-radius: var(--ds-r-md);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.auth-metrics span {
  display: block;
  color: rgba(255, 255, 255, 0.55);
  font-size: 11.5px;
}

.auth-metrics strong {
  display: block;
  margin-top: 2px;
  color: #ffffff;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-brand-foot {
  position: relative;
  z-index: 1;
  margin-top: 28px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 11.5px;
}

.auth-form-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 56px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-mobile-logo {
  display: none;
  justify-content: center;
  margin-bottom: 28px;
}

.auth-mobile-logo img {
  width: 220px;
  height: auto;
}

.auth-heading {
  margin-bottom: 28px;
}

.auth-heading .eyebrow {
  margin-bottom: 8px;
}

.auth-heading h2 {
  color: var(--ds-text);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.022em;
}

.auth-heading p {
  margin-top: 8px;
  font-size: 14px;
}

/* Sign in / Sign up: a segmented control. */
.auth-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 22px;
  padding: 2px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-md);
  background: var(--ds-surface-2);
}

.auth-tabs .tab {
  flex: 1;
  padding: 6px 12px;
  border-radius: var(--ds-r-sm);
  color: var(--ds-text-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: background-color 100ms ease, color 100ms ease;
}

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

.auth-tabs .tab.active {
  color: var(--ds-text);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-sm), 0 0 0 1px var(--ds-border);
}

:root[data-theme="dark"] .auth-tabs .tab.active {
  background: rgba(255, 255, 255, 0.09);
}

.auth-card form {
  display: grid;
  gap: 16px;
}

.auth-card form .field {
  margin-bottom: 0;
}

.auth-card form input {
  min-height: 40px;
  padding: 9px 12px;
}

.auth-card form .primary {
  width: 100%;
  min-height: 42px;
  margin-top: 2px;
}

.auth-message {
  margin-bottom: 18px;
  padding: 10px 12px;
  border: 1px solid var(--ds-danger-line);
  border-radius: var(--ds-r-md);
  color: var(--ds-danger-text);
  background: var(--ds-danger-bg);
  font-size: 13px;
  font-weight: 500;
}

.auth-secondary-link {
  display: flex;
  justify-content: center;
}

.auth-secondary-link button {
  padding: 7px 12px;
  border-radius: var(--ds-r-md);
  color: var(--ds-accent-text);
  background: var(--ds-accent-soft);
  font-size: 13.5px;
  font-weight: 500;
}

.auth-secondary-link button:hover {
  background: var(--ds-accent-line);
}

.terms-preview {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-lg);
  background: var(--ds-surface-2);
}

.terms-preview > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.terms-preview strong {
  color: var(--ds-text);
  font-size: 13.5px;
}

.terms-preview span {
  color: var(--ds-text-3);
  font-size: 12px;
}

.terms-preview p {
  max-height: 110px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-md);
  color: var(--ds-text-2);
  background: var(--ds-surface);
  font-size: 12.5px;
  white-space: pre-wrap;
}

.auth-footer {
  position: absolute;
  right: 0;
  bottom: 18px;
  left: 0;
  color: var(--ds-text-3);
  font-size: 11.5px;
  text-align: center;
}

.auth-theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  border-color: var(--ds-border-strong);
  background: var(--ds-surface);
  box-shadow: var(--ds-shadow-sm);
}

/* ---- laptop screens ------------------------------------------------------------------
   A MacBook shows the portal about 1,470 px wide; a desktop monitor, 1,920. From 1,600 px
   down the menu narrows and the rows and headings tighten, as on the tracking portal. */
@media (max-width: 1600px) {
  :root {
    --rail-w: 256px;
  }

  .rail-brand {
    padding: 24px 52px 16px 24px;
  }

  .rail-brand img {
    height: 38px;
  }

  .nav-section-title,
  .nav-row.rail-action {
    min-height: 34px;
    gap: 10px;
    font-size: 14px;
  }

  .nav-section-icon,
  .rail-action .nav-icon {
    width: 17px;
    height: 17px;
  }

  .nav-row {
    min-height: 28px;
    font-size: 12.5px;
  }

  .dashboard-copy h2,
  .hero-panel h2,
  .settings-hero h2 {
    font-size: 24px;
  }
}

@media (min-width: 1024px) and (max-width: 1600px) and (-webkit-min-device-pixel-ratio: 2) and (hover: hover) and (pointer: fine),
       (min-width: 1024px) and (max-width: 1600px) and (min-resolution: 2dppx) and (hover: hover) and (pointer: fine) {
  :root {
    --rail-w: 232px;
    --shell-pad: 16px;
  }

  body {
    font-size: 13.5px;
  }

  .nav-section-title,
  .nav-row.rail-action {
    min-height: 31px;
    font-size: 13px;
  }

  .nav-row {
    min-height: 26px;
    font-size: 12px;
  }

  .dashboard-copy h2,
  .hero-panel h2,
  .settings-hero h2 {
    font-size: 22px;
  }
}

@media (min-width: 1601px) {
  .dashboard-copy h2,
  .hero-panel h2,
  .settings-hero h2 {
    font-size: 28px;
  }
}

@media (max-width: 1180px) {
  :root {
    --rail-w: 240px;
  }
}

@media (max-width: 1280px) {
  .plans-grid,
  .kpi-grid,
  .key-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

/* ---- tablets and phones: the menu becomes a drawer ---------------------------------- */
@media (max-width: 1023px) {
  .app-shell,
  .app-shell.rail-collapsed {
    display: block;
    padding: 0;
  }

  .content {
    padding: 64px 14px 20px;
  }

  .mobile-nav-button {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 40;
    display: inline-flex;
    width: 40px;
    height: 40px;
    border-color: var(--ds-border-strong);
    color: var(--ds-text);
    background: var(--ds-surface);
    box-shadow: var(--ds-shadow-sm);
  }

  .mobile-nav-button svg {
    width: 20px;
    height: 20px;
  }

  .rail {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    width: 280px;
    height: 100vh;
    border-radius: 0;
    border-width: 0 1px 0 0;
    transform: translateX(-100%);
    transition: transform 200ms ease;
  }

  .mobile-nav-open .rail {
    transform: none;
  }

  .mobile-nav-open .rail-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: block;
    background: var(--ds-backdrop);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .rail-collapse {
    display: none;
  }

  /* In the drawer the menu is always shown in full. */
  .rail-collapsed .rail-brand {
    justify-content: flex-start;
    padding: 24px 52px 16px 24px;
  }

  :root .rail-collapsed .rail-brand .logo-mark {
    display: none;
  }

  :root .rail-collapsed .rail-brand .logo-light {
    display: block;
  }

  :root[data-theme="dark"] .rail-collapsed .rail-brand .logo-light {
    display: none;
  }

  :root[data-theme="dark"] .rail-collapsed .rail-brand .logo-dark {
    display: block;
  }

  .rail-collapsed .nav-row.rail-action {
    justify-content: flex-start;
    padding: 0 10px;
  }

  .rail-collapsed .nav-row > span,
  .rail-collapsed .rail-account > span:last-child {
    display: block;
  }

  .rail-collapsed .rail-account {
    justify-content: flex-start;
    padding-left: 10px;
  }

  .dashboard-hero,
  .hero-panel,
  .settings-hero,
  .grid.two,
  .grid.three,
  .settings-shell,
  .conversation-logs,
  .auth-window {
    grid-template-columns: 1fr;
  }

  .payfast-chip,
  .hero-panel > .download-button {
    justify-self: start;
  }

  .settings-health {
    justify-content: flex-start;
  }

  .conversation-logs {
    height: min(760px, 78vh);
    grid-template-rows: 220px minmax(0, 1fr);
  }

  .conversation-list {
    border-right: 0;
    border-bottom: 1px solid var(--ds-border);
  }

  .settings-menu {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .auth-brand {
    display: none;
  }

  .auth-mobile-logo {
    display: flex;
  }

  .auth-window {
    width: min(480px, 100%);
    min-height: 0;
  }

  .auth-form-pane {
    padding: 36px 28px;
  }
}

@media (max-width: 720px) {
  .content > * + * {
    margin-top: 14px;
  }

  .dashboard-hero,
  .hero-panel,
  .settings-hero {
    padding: 18px;
  }

  .dashboard-copy h2,
  .hero-panel h2,
  .settings-hero h2 {
    font-size: 22px;
  }

  .form-grid,
  .split,
  .check-grid,
  .plans-grid,
  .kpi-grid,
  .key-card-grid,
  .key-card-metrics,
  .usage-strip,
  .signal-metrics,
  .shortcode-grid,
  .settings-menu {
    grid-template-columns: 1fr;
  }

  .log-composer {
    grid-template-columns: 1fr;
  }

  .message-bubble {
    max-width: 100%;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .key-modal {
    max-height: calc(100vh - 20px);
  }

  .modal-head {
    flex-wrap: wrap;
  }

  .modal-body {
    padding: 16px;
  }

  .auth-form-pane {
    padding: 28px 20px;
  }
}
