/* ==========================================================================
   ASTRACAT Billing — design system.
   Stripe-inspired: light, airy, thin borders, small radii, restrained accent.
   Branding (app_settings BRAND_COLOR / BRAND_COLOR_ACCENT) flows in through
   --brand-color / --brand-accent, so the whole UI re-skins from one setting.
   Everything else is a token; never hard-code a hue in a component.
   Rhythm scale: 4 8 12 16 20 24 32 40 48 (px).
   ========================================================================== */

:root {
  /* --- brand (overridden inline by Branding::cssVars) --- */
  --brand-color: #030c5f;
  --brand-accent: #26b2fc;

  /* --- neutrals: Stripe-like grey ramp --- */
  --ink: #1a1f36;          /* primary text */
  --ink-2: #3c4257;        /* strong secondary */
  --muted: #55606f;        /* secondary text */
  --muted-2: #5f6a7c;      /* tertiary / placeholder */
  --line: #e3e8ee;         /* hairline borders */
  --line-soft: #eff2f5;
  --bg: #f6f8fa;           /* app background: light grey-white */
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --surface-tint: #f0f4f8;
  --surface-brand: color-mix(in srgb, var(--brand-color) 6%, #fff);
  --border-strong: #d5dbe3;

  /* --- semantic --- */
  --success: #14684a; --success-bg: #e6f4ee; --success-line: #bfe3d4;
  --warning: #7d5200; --warning-bg: #fff5db; --warning-line: #f0dcab;
  --danger:  #a81f19; --danger-bg:  #fdeceb; --danger-line:  #f3cdca;
  --info:    #0a5bb5; --info-bg:    #e8f1fd; --info-line:    #c9dffb;

  --on-brand: #ffffff;
  --focus-ring: 0 0 0 4px color-mix(in srgb, var(--brand-color) 16%, transparent);

  /* --- radii: small + consistent (Stripe uses ~6-8px) --- */
  --radius-sm: 6px;
  --radius-control: 8px;
  --radius-card: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* --- elevation: soft, subtle --- */
  --shadow-xs: 0 1px 1px rgb(26 31 54 / 4%);
  --shadow-card: 0 1px 1px rgb(26 31 54 / 4%), 0 2px 5px rgb(26 31 54 / 4%);
  --shadow-pop: 0 4px 12px rgb(26 31 54 / 8%), 0 12px 32px rgb(26 31 54 / 10%);

  /* --- rhythm: one 4px spacing scale, used everywhere --- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --gap: 20px;
  --gap-lg: 24px;
  --pad-x: 24px;

  /* --- type scale: a single ramp, no in-between sizes --- */
  --fs-2xs: 11px;    /* micro labels, eyebrows */
  --fs-xs: 12px;     /* secondary / meta */
  --fs-sm: 13px;     /* UI text, nav */
  --fs-base: 14px;   /* body */
  --fs-md: 15px;     /* emphasis, card titles */
  --fs-lg: 17px;     /* section headings */
  --fs-xl: 22px;     /* h1 */
  --fs-2xl: 28px;    /* hero numbers / auth h1 */
  --fs-3xl: 34px;    /* price display */
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --content-max: 1120px;

  --ease: cubic-bezier(.2,.7,.3,1);
  --dur: 180ms;
}

/* Kept for templates that reference the old token names. */
:root {
  --green: var(--brand-color);
  --lime: var(--brand-accent);
  /* Link/CTA text colour. The raw brand colour can be a very dark navy
     (e.g. #030c5f); in dark mode that is unreadable, so links fall back to a
     lightened brand tint that keeps the identity but stays legible. */
  --link: var(--brand-color);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
  font-feature-settings: "cv02","cv03","cv04","cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: none;
  border-color: var(--brand-color);
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-control);
}
::selection { background: color-mix(in srgb, var(--brand-accent) 40%, #fff); color: var(--ink); }
img, svg { max-width: 100%; }

/* normalize <small> so it lands on the type scale instead of the browser's
   0.8333em default (which produced odd values like 11.6667px) */
small { font-size: var(--fs-xs); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; z-index: 100; top: 12px; left: 12px;
  transform: translateY(-150%);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-control); padding: 8px 12px; font-weight: 600;
  box-shadow: var(--shadow-card);
}
.skip-link:focus { transform: translateY(0); }

/* ==========================================================================
   App shell — sidebar + topbar
   ========================================================================== */

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 20;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 18px 14px 16px; display: flex; flex-direction: column;
}
.brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  color: var(--ink); font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.3px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  border-radius: var(--radius-control);
}
.brand:hover { text-decoration: none; color: var(--ink); background: var(--surface-soft); }
.brand-mark {
  width: 28px; height: 28px; flex: none; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--brand-color); color: var(--brand-accent);
  font-size: var(--fs-md); font-weight: 800; font-style: italic; line-height: 1;
}
.logo, .logo-img {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: grid; place-items: center; flex: none;
}
.logo { background: var(--brand-color); color: var(--brand-accent); font-size: var(--fs-lg); font-style: italic; line-height: 1; }
.logo-img { object-fit: cover; }
.workspace {
  margin: 24px 10px 6px; color: var(--muted-2);
  font-size: var(--fs-2xs); font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase;
}
nav { display: grid; gap: 1px; }
nav a {
  min-height: 38px; padding: 8px 10px; border-radius: var(--radius-control);
  color: var(--ink-2); display: flex; gap: 10px; align-items: center;
  font-size: var(--fs-base); font-weight: 500; border: 1px solid transparent;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar nav a > span:first-child { display: grid; place-items: center; width: 18px; height: 18px; flex: none; font-size: var(--fs-md); line-height: 1; color: var(--muted-2); }
nav a:hover { background: var(--surface-soft); color: var(--ink); text-decoration: none; }
.sidebar nav a:hover > span:first-child { color: var(--muted); }
nav a.selected {
  color: var(--link); background: var(--surface-brand);
  font-weight: 600; box-shadow: inset 2px 0 var(--brand-color);
}
.sidebar nav a.selected > span:first-child { color: var(--link); }
.nav-group { margin-top: 18px; }

.sidebar-bottom {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-card);
  color: var(--ink); background: var(--surface-soft);
}
.sidebar-bottom:hover { background: var(--surface-tint); }
.avatar {
  flex: none; background: var(--surface-brand); color: var(--link);
  border-radius: var(--radius-pill); width: 32px; height: 32px;
  display: grid; place-items: center; font-weight: 650; font-size: var(--fs-sm);
  border: 1px solid color-mix(in srgb, var(--brand-color) 18%, transparent);
}
.account { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); font-weight: 550; }
.account small { display: block; color: var(--muted); font-size: var(--fs-2xs); font-weight: 400; }
.signout {
  border: 0; background: none; color: var(--muted); font-size: var(--fs-md);
  width: 30px; height: 30px; border-radius: var(--radius-sm); flex: none;
}
.signout:hover { background: var(--surface-tint); color: var(--danger); }

.main {
  position: relative; margin-left: var(--sidebar-w); min-height: 100vh;
  padding: 28px clamp(20px, 4vw, 48px) 40px;
}
.main > :not(.theme-toggle) { max-width: var(--content-max); }
.main > .wide { max-width: 1320px; }

/* ==========================================================================
   Type
   ========================================================================== */
header { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin: 0 0 24px; flex-wrap: wrap; }
header > div:first-child { min-width: 0; }
.page-hero { align-items: flex-end; }
h1 { font-size: var(--fs-2xl); line-height: 1.2; letter-spacing: -.6px; margin: 0 0 6px; font-weight: 700; }
h2 { font-size: var(--fs-lg); line-height: 1.35; letter-spacing: -.2px; margin: 0 0 12px; font-weight: 650; }
h3 { margin: 4px 0; font-size: var(--fs-md); font-weight: 650; }
p { margin: 0 0 14px; }
header p:last-child { margin: 0; }
.muted { color: var(--muted); }
.page-hero .muted { max-width: 560px; font-size: var(--fs-base); }
.eyebrow { color: var(--muted-2); font-size: var(--fs-2xs); font-weight: 650; letter-spacing: .6px; text-transform: uppercase; margin: 0 0 8px; }
.amount, .price, .earnings-amount, .control-metrics strong { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--fs-sm); }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.hint { font-size: var(--fs-sm); color: var(--muted); }

/* ==========================================================================
   Components — Button
   ========================================================================== */
.button {
  display: inline-flex; justify-content: center; align-items: center; gap: 8px;
  min-height: 38px; padding: 8px 14px; border: 1px solid transparent;
  border-radius: var(--radius-control); background: var(--brand-color); color: var(--on-brand);
  font-size: var(--fs-base); font-weight: 600; line-height: 1.2; text-align: center; white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.button:hover { background: color-mix(in srgb, var(--brand-color) 88%, #000); text-decoration: none; }
.button:active { transform: translateY(.5px); box-shadow: none; }
.button.full { width: 100%; }
.button.small { min-height: 32px; padding: 6px 12px; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.button.large { min-height: 46px; padding: 12px 20px; font-size: var(--fs-md); border-radius: var(--radius-control); }
.button.light { background: var(--surface-brand); color: var(--link); border-color: color-mix(in srgb, var(--brand-color) 22%, transparent); box-shadow: none; }
.button.light:hover { background: color-mix(in srgb, var(--brand-color) 10%, #fff); border-color: color-mix(in srgb, var(--brand-color) 34%, transparent); }
.button.secondary { background: var(--surface); border-color: var(--border-strong); color: var(--ink-2); box-shadow: var(--shadow-xs); }
.button.secondary:hover { background: var(--surface-soft); border-color: var(--muted-2); color: var(--ink); }
.button.danger { background: var(--danger); box-shadow: none; }
.button.danger:hover { background: color-mix(in srgb, var(--danger) 84%, #000); }
.button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); box-shadow: none; }
.button.ghost:hover { background: var(--surface-tint); color: var(--ink); }
.button.link { background: none; border: 0; color: var(--link); box-shadow: none; padding: 0; min-height: 0; }
.button.link:hover { text-decoration: underline; }
button:disabled, .button:disabled, .button[aria-disabled="true"] {
  cursor: not-allowed; opacity: .55; transform: none; box-shadow: none; pointer-events: none;
}
.button.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.button.is-loading::after {
  content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 45%); border-top-color: #fff;
  animation: spin .6s linear infinite;
}
.button.secondary.is-loading::after, .button.light.is-loading::after, .button.ghost.is-loading::after {
  border-color: color-mix(in srgb, var(--brand-color) 30%, transparent); border-top-color: var(--brand-color);
}
@keyframes spin { to { transform: rotate(360deg); } }

.inline-layout-1 { display: inline; }
.inline-layout-2 { width: auto; display: inline; }
.inline-layout-3 { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-layout-4 { height: 38px; padding: 3px; }
.align-end { align-self: end; margin-bottom: 18px; }
.compact { padding: 0 0 18px; }

/* ==========================================================================
   Components — Input / Select / Label
   ========================================================================== */
label { display: block; font-size: var(--fs-sm); font-weight: 550; line-height: 1.4; margin-bottom: 16px; color: var(--ink-2); }
label small { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--muted); margin-top: 5px; line-height: 1.5; }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea {
  display: block; width: 100%; min-height: 38px; margin-top: 6px; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-xs); min-width: 0;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  border-color: var(--brand-color); box-shadow: var(--focus-ring); outline: none;
}
select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' stroke='%23697386' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-color); width: 16px; height: 16px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 14%, transparent); }

.row-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row-form label { flex: 1; min-width: 180px; margin: 0; }
.row-form .button { white-space: nowrap; }
.admin-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px 18px; }
.admin-form button { align-self: end; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 20px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid label { min-width: 0; }
.span-two { grid-column: span 2; }
.save-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  position: sticky; bottom: 12px; padding: 14px 16px; margin-top: 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow-pop);
}
.save-bar p { margin: 0; font-size: var(--fs-sm); color: var(--muted); }

/* ==========================================================================
   Components — Card / Panel
   ========================================================================== */
.panel, .plan, .auth-card, .side-card, .merge-panel, .connection,
.control-metrics article, .ops-kpi article, .simulation article, .graph-node, .admin-nav,
.stat-card, .summary-card, .list-card {
  border: 1px solid var(--line); border-radius: var(--radius-card);
  background: var(--surface); box-shadow: var(--shadow-card);
}
.panel { margin-top: var(--gap-lg); overflow: hidden; }
/* every card's content edge sits at the same inset (--pad-x), so panels,
   headers, tables and nested panels all line up on one vertical grid */
.panel.detail { padding: var(--pad-x); }
.panel.flush { padding: 0; }
.panel > .panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px var(--pad-x); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.panel > .panel-head h2 { margin: 0; }
.panel > .panel-body { padding: 20px var(--pad-x); }
.section-heading {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px var(--pad-x); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
/* a section-heading that is the first child of an already-padded panel
   must not add its own horizontal inset (that caused nested drift) */
.panel.detail > .section-heading:first-child,
.merge-panel > .section-heading:first-child { padding: 0 0 14px; }
.detail > .section-heading:first-child { padding: 0 0 14px; }
.section-heading h2 { font-size: var(--fs-md); margin: 0; }
.section-heading a, .section-heading > span { font-size: var(--fs-sm); font-weight: 500; }
.separator { height: 1px; background: var(--line); margin: 20px 0; }
.section-title { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.section-title h2 { margin: 0 0 4px; }
.section-title p { font-size: var(--fs-sm); margin: 0; }
.section-number {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  background: var(--surface-tint); color: var(--muted); border-radius: var(--radius-sm);
  font-size: var(--fs-xs); font-weight: 700;
}

/* ==========================================================================
   Components — StatCard (labelled metric)
   ========================================================================== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat-card { padding: 16px; }
.stat-card .stat-label { display: block; color: var(--muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .3px; text-transform: uppercase; margin-bottom: 8px; }
.stat-card .stat-value { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.5px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-card .stat-meta { display: block; margin-top: 4px; font-size: var(--fs-xs); color: var(--muted); }
.stat-card.accent { background: var(--surface-brand); border-color: color-mix(in srgb, var(--brand-color) 16%, var(--line)); }
.stat-card.accent .stat-value { color: var(--link); }

/* ==========================================================================
   Components — Badge / status
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: var(--radius-pill); padding: 2px 8px;
  background: var(--surface-tint); color: var(--ink-2);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge.fulfilled, .badge.active, .badge.success, .badge.paid { color: var(--success); background: var(--success-bg); }
.badge.pending, .badge.provisioning, .badge.processing { color: var(--warning); background: var(--warning-bg); }
.badge.canceled, .badge.failed, .badge.expired, .badge.error { color: var(--danger); background: var(--danger-bg); }
.badge.refunded, .badge.refund { color: var(--info); background: var(--info-bg); }
.badge.trial, .badge.limited { color: var(--info); background: var(--info-bg); }
.badge.disabled { color: var(--muted); background: var(--surface-tint); }

/* ==========================================================================
   Components — Alert
   ========================================================================== */
.notice, .success, .alert {
  border-radius: var(--radius-control); border: 1px solid var(--border-strong);
  padding: 11px 14px; font-size: var(--fs-base);
}
.alert { display: flex; gap: 8px; align-items: flex-start; }
.alert > .alert-icon { flex: none; font-size: var(--fs-md); line-height: 1.4; }
.alert-info { background: var(--info-bg); border-color: var(--info-line); color: #0b3f7d; }
.alert-success, .success { background: var(--success-bg); border-color: var(--success-line); color: #145c42; }
.alert-warning, .notice { background: var(--warning-bg); border-color: var(--warning-line); color: #7a5200 !important; }
.alert-danger { background: var(--danger-bg); border-color: var(--danger-line); color: #8c1d18; }
.success { padding: 12px 16px; }

/* ==========================================================================
   Components — EmptyState
   ========================================================================== */
.empty {
  text-align: center; padding: 44px 24px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.empty > span {
  display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 10px;
  border-radius: var(--radius-pill); background: var(--surface-tint);
  color: var(--muted-2); font-size: var(--fs-xl);
}
.empty h3 { margin: 0; font-size: var(--fs-md); color: var(--ink); }
.empty p { font-size: var(--fs-base); margin: 4px 0 12px; max-width: 380px; }
.empty a { font-size: var(--fs-base); font-weight: 600; }

/* ==========================================================================
   Components — Skeleton / loading
   ========================================================================== */
.skeleton {
  display: block; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-tint) 25%, var(--line-soft) 37%, var(--surface-tint) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease-in-out infinite;
  height: 14px; margin: 8px 0;
}
.skeleton.line-sm { width: 40%; }
.skeleton.line-lg { width: 75%; height: 22px; }
.skeleton.block { height: 84px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ==========================================================================
   Components — Table
   ========================================================================== */
.table-wrap,
.panel:has(> table),
.panel.detail:has(table) { overflow-x: auto; }
.table-wrap { scrollbar-color: var(--border-strong) transparent; }
table { border-collapse: collapse; width: 100%; margin: 0; font-size: var(--fs-base); }
th, thead th {
  text-align: left; padding: 9px var(--pad-x); color: var(--muted);
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  border-bottom: 1px solid var(--line); background: var(--surface-soft);
}
td { padding: 13px var(--pad-x); border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.detail table th:first-child, .detail table td:first-child { padding-left: 0; }
.detail table th:last-child, .detail table td:last-child { padding-right: 0; }
tbody tr:hover { background: var(--surface-soft); }
tbody tr:last-child td { border-bottom: 0; }
td strong { font-weight: 600; }
td small { display: block; font-size: var(--fs-xs); color: var(--muted); }
td form { display: inline-block; margin: 0; }
td .button { margin: 2px 0; }
.table-actions { text-align: right; }

/* ==========================================================================
   Components — Tabs
   ========================================================================== */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a, .tabs button {
  padding: 10px 12px; font-size: var(--fs-base); font-weight: 550; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; border-top: 0; border-left: 0; border-right: 0;
}
.tabs a:hover, .tabs button:hover { color: var(--ink); text-decoration: none; }
.tabs a.selected, .tabs button.selected, .tabs [aria-current="page"] { color: var(--link); border-bottom-color: var(--brand-color); }
.admin-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding-bottom: 0; margin-bottom: 16px; flex-wrap: wrap; }
.admin-tabs a { font-size: var(--fs-base); padding: 9px 12px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.admin-tabs a:hover { background: var(--surface-soft); text-decoration: none; }
.admin-tabs a.selected { background: var(--surface-soft); color: var(--link); border-bottom-color: var(--brand-color); }
.admin-back { display: inline-block; font-size: var(--fs-sm); font-weight: 550; color: var(--muted); margin-bottom: 18px; }
.admin-back:hover { color: var(--link); text-decoration: none; }

/* ==========================================================================
   Components — Toast / Popover / Modal / Tooltip
   ========================================================================== */
.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: grid; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 360px;
  padding: 12px 14px; border-radius: var(--radius-card); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow-pop); font-size: var(--fs-base);
  animation: toast-in .22s var(--ease);
}
.toast.success { border-color: var(--success-line); }
.toast.error { border-color: var(--danger-line); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.modal { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); padding: 0; width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow-pop); }
.modal::backdrop { background: rgb(26 31 54 / 45%); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); font-weight: 650; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-soft); }
.popover {
  border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface);
  box-shadow: var(--shadow-pop); padding: 6px; min-width: 180px;
}
.popover a, .popover button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); font-size: var(--fs-base); color: var(--ink-2); border: 0; background: none; }
.popover a:hover, .popover button:hover { background: var(--surface-soft); color: var(--ink); text-decoration: none; }
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%) translateY(3px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; font-size: var(--fs-xs); font-weight: 500;
  padding: 5px 8px; border-radius: var(--radius-sm); white-space: nowrap;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); z-index: 50;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   Overview / hero blocks (client home)
   ========================================================================== */
.overview { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, .9fr); gap: var(--gap); align-items: start; }
.connection {
  background: var(--surface); padding: var(--pad-x);
  position: relative; overflow: hidden;
}
.connection .section-top { color: var(--muted); }
.connection h2 { font-size: var(--fs-xl); letter-spacing: -.3px; max-width: 440px; margin-bottom: 10px; }
.connection p { font-size: var(--fs-base); }
.connection-empty { padding: 26px 0 8px; }
.connection-icon { font-size: var(--fs-md); color: var(--muted-2); }
.orb { display: none; }
.connection .subscription { border-bottom: 1px solid var(--line-soft); }
.side-card {
  background: var(--surface-soft); border-color: var(--line);
  padding: var(--pad-x); display: flex; flex-direction: column; align-items: flex-start;
}
.side-card h2 { font-size: var(--fs-lg); letter-spacing: -.2px; margin-bottom: 8px; }
.side-card p { font-size: var(--fs-base); color: var(--muted); }
.side-card > a { margin-top: 12px; font-size: var(--fs-base); font-weight: 600; }
.side-card .separator { align-self: stretch; margin-top: 18px; }
.tile-icon {
  width: 36px; height: 36px; display: grid; place-items: center; margin-bottom: 18px;
  background: var(--surface); color: var(--link); border: 1px solid var(--line);
  border-radius: var(--radius-control); font-size: var(--fs-lg); box-shadow: var(--shadow-xs);
}

/* ==========================================================================
   Plans / pricing selector
   ========================================================================== */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: stretch; margin-bottom: 20px; }
.plan { display: flex; flex-direction: column; padding: 22px; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.plan:hover { border-color: var(--border-strong); box-shadow: var(--shadow-pop); }
.plan.featured { border-color: color-mix(in srgb, var(--brand-color) 42%, var(--line)); }
.plan.featured::before { content: "ПОПУЛЯРНЫЙ"; display: block; align-self: flex-start; margin: 0 0 12px; color: var(--link); font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .8px; }
.plan .section-top { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft); color: var(--muted); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .4px; text-transform: uppercase; }
.plan h2 { font-size: var(--fs-lg); letter-spacing: -.2px; margin-bottom: 8px; }
.price { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: -1px; line-height: 1.15; }
.plan ul { list-style: none; padding: 14px 0 6px; margin: 16px 0 14px; border-top: 1px solid var(--line-soft); font-size: var(--fs-base); min-height: 0; }
.plan li { margin: 9px 0; display: flex; gap: 8px; align-items: flex-start; }
.plan li::before { content: '✓'; color: var(--success); font-weight: 700; flex: none; }
.plan form:first-of-type { margin-top: auto; }
.plan form + form { margin-top: 8px; }
.plan form label { margin-bottom: 10px; }

/* pricing selector (client plans page) */
.pricing { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 24px; align-items: start; }
.term-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; min-width: 0; }
.term-list > li { min-width: 0; }
.term {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface);
  cursor: pointer; min-width: 0;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.term:hover { border-color: var(--border-strong); background: var(--surface-soft); }
.term.selected { border-color: var(--brand-color); box-shadow: 0 0 0 1px var(--brand-color); background: var(--surface-brand); }
.term input[type="radio"] { margin: 0; flex: none; }
.term-body { flex: 1; min-width: 0; }
.term-name { font-weight: 600; font-size: var(--fs-base); }
.term-meta { font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.term-price { font-weight: 700; font-size: var(--fs-md); font-variant-numeric: tabular-nums; white-space: nowrap; }
.term-badge { font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .4px; color: var(--link); background: var(--surface-brand); border: 1px solid color-mix(in srgb, var(--brand-color) 20%, transparent); border-radius: var(--radius-pill); padding: 2px 8px; white-space: nowrap; }
.summary { position: sticky; top: 20px; }
.summary-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; font-size: var(--fs-base); }
.summary-row span:first-child { color: var(--muted); }
.summary-total { display: flex; justify-content: space-between; gap: 12px; padding: 14px 0 0; margin-top: 8px; border-top: 1px solid var(--line); font-size: var(--fs-md); font-weight: 700; }
.summary-total .price { font-size: var(--fs-2xl); }
.feature-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; font-size: var(--fs-base); }
.feature-list li { display: flex; gap: 8px; align-items: flex-start; }
.feature-list li::before { content: '✓'; color: var(--success); font-weight: 700; flex: none; }

/* ==========================================================================
   Detail / steps / subscription
   ========================================================================== */
.detail h2 { margin-top: 6px; }
.detail h2:first-child { margin-top: 0; }
.detail p { max-width: 720px; }
.steps { display: flex; gap: 20px; font-size: var(--fs-sm); color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.steps .complete { color: var(--success); font-weight: 600; }
.steps .current { color: var(--ink); font-weight: 600; }
.subscription { padding: 18px 0; border-bottom: 1px solid var(--line-soft); }
.subscription:last-child { border: 0; padding-bottom: 0; }
.subscription h2 { margin-top: 8px; }
.subscription > a, .subscription form { display: inline-flex; margin: 4px 10px 0 0; vertical-align: middle; }
.subscription form .button { margin: 0; }
.subscription .button.small { white-space: nowrap; }
.token {
  display: block; overflow-wrap: anywhere; background: var(--surface-soft);
  padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius-control);
  margin: 16px 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--fs-sm);
}
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--radius-card); overflow: hidden; margin: 18px 0; }
.meta-item { padding: 14px 16px; border-right: 1px solid var(--line-soft); }
.meta-item:last-child { border-right: 0; }
.meta-label { display: block; font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .3px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.meta-value { font-size: var(--fs-md); font-weight: 650; font-variant-numeric: tabular-nums; }
.merge-panel { padding: var(--pad-x); margin-top: 16px; background: var(--surface-soft); }
.merge-panel > .section-heading { padding: 0 0 14px; }
.progress { height: 6px; border-radius: var(--radius-pill); background: var(--surface-tint); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand-color); border-radius: var(--radius-pill); }

/* ==========================================================================
   Auth
   ========================================================================== */
.auth-main {
  max-width: none; min-height: 100vh; margin: 0 auto;
  padding: 56px 20px 32px; display: flex; flex-direction: column; align-items: center;
}
.auth-main > * { width: 100%; max-width: 400px; }
.auth-card { padding: var(--sp-8); box-shadow: var(--shadow-pop); }
.auth-card .brand { margin-bottom: 26px; padding: 0; font-size: var(--fs-lg); }
.auth-card h1 { font-size: var(--fs-xl); letter-spacing: -.4px; }
.auth-card > p { font-size: var(--fs-base); }
.auth-card > p:last-child { margin-bottom: 0; }
.auth-card form { margin: 20px 0; }
.auth-main footer { max-width: 400px; margin: 20px auto 0; border: 0; padding: 0; justify-content: center; }
.auth-symbol { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 18px; background: var(--surface-brand); color: var(--link); border-radius: var(--radius-card); font-size: var(--fs-xl); }
.auth-divider { display: flex; align-items: center; gap: 12px; text-align: center; font-size: var(--fs-xs); color: var(--muted); margin: 18px 0; }
.auth-divider::before, .auth-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.login-status { margin: 18px 0; font-size: var(--fs-base); color: var(--muted); }
.telegram-button { background: #217eaa; box-shadow: none; }
.telegram-button:hover { background: #196184; }
.security-card { max-width: 640px; }
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; }
.recovery-grid code { background: var(--surface-soft); padding: 10px; letter-spacing: 1px; border-radius: var(--radius-sm); border: 1px solid var(--line); font-size: var(--fs-sm); }
.readiness-list article { display: flex; align-items: center; gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line-soft); }
.readiness-list article:last-child { border: 0; }
.readiness-list article > div { flex: 1; }
.readiness-list h3 { font-size: var(--fs-base); }
.readiness-list p { font-size: var(--fs-sm); color: var(--muted); margin: 3px 0; }
.check-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius-pill); flex: none; }
.check-icon.good { background: var(--success-bg); color: var(--success); }
.check-icon.warning { background: var(--warning-bg); color: var(--warning); }

/* ==========================================================================
   Dashboard / admin metrics
   ========================================================================== */
.control-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 20px; }
.control-metrics article { padding: 16px; }
.control-metrics small { display: block; color: var(--muted); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.control-metrics strong { display: block; margin: 6px 0 2px; font-size: var(--fs-xl); line-height: 1.25; }
.control-metrics span { font-size: var(--fs-xs); color: var(--muted); }
.control-metrics .metric-attention { border-color: var(--warning-line); background: var(--warning-bg); }
.control-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: var(--gap); }
.control-layout .panel { margin-top: 0; }
.system-healthy { display: inline-block; margin-left: 10px; font-size: var(--fs-base); letter-spacing: 0; color: var(--success); vertical-align: middle; }
.health-list article { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.health-list article:last-child { border: 0; }
.health-list article > div { flex: 1; }
.health-list strong, .health-list small { display: block; }
.health-list small { font-size: var(--fs-xs); color: var(--muted); }
.health-dot { font-size: var(--fs-md); }
.health-dot.healthy, .health-label.healthy { color: var(--success); }
.health-dot.attention, .health-label.attention { color: var(--warning); }
.health-dot.failed, .health-label.failed { color: var(--danger); }
.health-label { font-size: var(--fs-xs); font-weight: 600; }
.attention-list p { font-size: var(--fs-base); }
.earnings-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.earnings-card { display: flex; flex-direction: column; gap: 4px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: var(--radius-control); padding: 16px; }
.earnings-card:first-child { background: var(--brand-color); border-color: var(--brand-color); }
.earnings-card:first-child .earnings-label, .earnings-card:first-child .earnings-meta { color: color-mix(in srgb, #fff 76%, var(--brand-accent)); }
.earnings-card:first-child .earnings-amount { color: #fff; }
.earnings-label { font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .4px; color: var(--muted); text-transform: uppercase; }
.earnings-amount { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.6px; }
.earnings-meta { font-size: var(--fs-xs); color: var(--muted); }
.config-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; }
.config-layout .panel:first-child { margin-top: 0; }
.config-aside { min-width: 0; }
.config-aside .panel { position: sticky; top: 20px; }
.config-aside form { margin: 12px 0; }
.config-aside h2 { font-size: var(--fs-md); }
.config-aside p { font-size: var(--fs-base); }
.config-aside .hint { margin: 16px 4px; position: relative; }
.panel code { overflow-wrap: anywhere; }
.panel p code { font-size: var(--fs-sm); }
.audit { font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }

/* ==========================================================================
   Support / footer
   ========================================================================== */
.support-link { display: inline-flex; margin-top: 24px; font-size: var(--fs-base); }
footer {
  display: flex; justify-content: space-between; gap: 20px;
  color: var(--muted-2); font-size: var(--fs-xs); padding: 20px 0; margin-top: 20px;
  border-top: 1px solid var(--line);
}
.customer-timeline { list-style: none; margin: 0; padding: 2px 0; }
.customer-timeline li { display: grid; grid-template-columns: 56px 1fr; gap: 12px; padding: 10px 0 10px 18px; border-left: 2px solid color-mix(in srgb, var(--brand-color) 28%, var(--line)); position: relative; }
.customer-timeline li::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-color); position: absolute; left: -5px; top: 16px; }
.customer-timeline li:last-child { border-left-color: transparent; }
.customer-timeline time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }

/* Command palette (staff) */
.command-palette { width: min(600px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); padding: 8px; box-shadow: var(--shadow-pop); }
.command-palette::backdrop { background: rgb(26 31 54 / 45%); }
.command-palette input { margin: 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-size: var(--fs-md); padding: 11px; box-shadow: none; }
.command-results { display: grid; gap: 2px; padding: 6px 0; }
.command-results a { display: flex; justify-content: space-between; padding: 8px 11px; border-radius: var(--radius-sm); color: var(--ink-2); font-size: var(--fs-base); }
.command-results a.selected, .command-results a:hover { background: var(--surface-tint); text-decoration: none; }
.command-results a span, .command-palette p { color: var(--muted); font-size: var(--fs-xs); }
.command-palette p { margin: 5px 10px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1150px) {
  .config-layout { grid-template-columns: 1fr; }
  .config-aside .panel { position: static; }
  .form-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .earnings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pricing { grid-template-columns: 1fr; }
  .summary { position: static; }
}
@media (max-width: 1024px) {
  .sidebar { width: 216px; padding: 14px 10px; }
  :root { --sidebar-w: 216px; }
  .overview { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .control-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .control-layout { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  /* ---- compact mobile app bar + single scrollable nav rail ---- */
  .sidebar {
    position: sticky; top: 0; inset: auto; width: 100%; height: auto;
    display: grid; grid-template-columns: 1fr auto auto; grid-template-areas: "brand toggle account" "nav nav nav";
    align-items: center; gap: 8px 8px; padding: 8px 12px 0;
    border-right: 0; border-bottom: 1px solid var(--line); z-index: 30;
  }
  .brand { grid-area: brand; font-size: var(--fs-md); padding: 0; min-width: 0; }
  .brand > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .workspace { display: none; }
  /* both navs become full-width, wrapping rails that read as one block */
  .nav-group { margin: 0; grid-column: 1 / -1; }
  .sidebar nav {
    grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 2px 2px;
    margin: 0; padding: 0;
  }
  nav a {
    min-height: 34px; padding: 8px 10px; white-space: nowrap;
    font-size: var(--fs-sm); border-radius: var(--radius-control);
  }
  .sidebar nav a > span:first-child { display: none; }
  nav a.selected { background: var(--surface-brand); box-shadow: none; }
  /* account block compact in the top bar */
  .sidebar-bottom {
    grid-area: account; margin: 0; padding: 0; border: 0; background: none; gap: 7px;
  }
  .sidebar-bottom:hover { background: none; }
  .avatar { width: 30px; height: 30px; font-size: var(--fs-xs); }
  .account { max-width: 34vw; font-size: var(--fs-xs); }
  .account small { display: none; }
  .signout { width: 32px; height: 32px; }

  /* ---- comfortable tap targets on phones ---- */
  .support-link, .main p a, .main td a, .main li a, footer a, .panel a:not(.button):not(.brand), .side-card a:not(.button) {
    display: inline-flex; align-items: center; min-height: 36px;
  }
  .table-cards td.table-actions a, .table-cards .table-actions a {
    display: inline-flex; align-items: center; justify-content: flex-end;
    min-height: 36px; padding: 0 4px;
  }
  .signout { width: 36px; height: 36px; }
  .theme-toggle, button, .button { min-height: 36px; }
  .button.small { min-height: 32px; }

  .main { margin-left: 0; padding: 18px 16px 32px; }
  /* theme toggle lives in the top bar's account area on phones so it
     never floats over content */
  body .sidebar .theme-toggle {
    position: static; grid-area: toggle; align-self: center; justify-self: end;
    height: 32px; min-height: 32px; width: 32px; padding: 0; justify-content: center;
    border-radius: var(--radius-pill); box-shadow: none;
  }
  body .sidebar .theme-toggle [data-theme-label] { display: none; }
  body .sidebar .theme-toggle [data-theme-icon] { font-size: var(--fs-md); }
  /* anonymous pages keep the toggle pinned top-right, away from content */
  body .auth-main > .theme-toggle { position: fixed; top: 16px; right: 16px; width: 40px; height: 36px; padding: 0; justify-content: center; z-index: 40; }
  body .auth-main > .theme-toggle [data-theme-label] { display: none; }
  .plans { grid-template-columns: 1fr; }
  header { align-items: flex-start; flex-direction: column; gap: 8px; }
  .admin-form { grid-template-columns: 1fr; }
  .auth-card { padding: 24px; }
  /* stack action rows full width instead of ragged side-by-side */
  .inline-layout-3 { gap: 8px; }
  .inline-layout-3 > .button, .inline-layout-3 > form, .inline-layout-3 > form .button { flex: 1 1 100%; width: 100%; }
  .inline-layout-3 > form { display: block; }
}
@media (max-width: 640px) {
  /* one inset for every card/panel/table on phones */
  :root { --pad-x: 16px; }
  h1 { font-size: var(--fs-xl); }
  .price { font-size: var(--fs-2xl); }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .span-two { grid-column: auto; }
  .save-bar { position: static; align-items: stretch; flex-direction: column; }
  .readiness-list article { padding: 16px; flex-wrap: wrap; }
  .recovery-grid { grid-template-columns: 1fr; }
  /* keep two columns so the block stays compact, not a tall stack */
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; }
  .meta-item { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
  .meta-item:nth-child(2n) { border-right: 0; }
  .meta-item:nth-last-child(-n+2) { border-bottom: 0; }
  h2 { font-size: var(--fs-md); }
  /* form controls stack full-width so they are never ragged */
  .row-form { flex-direction: column; align-items: stretch; gap: 10px; }
  .row-form label, .row-form select, .row-form .button { flex: 1 1 auto; width: 100%; min-width: 0; }
}

@media (max-width: 400px) {
  /* very narrow phones: let the term row breathe without forcing width */
  .term { flex-wrap: wrap; gap: 6px 12px; }
  .term-body { flex-basis: calc(100% - 30px); }
  .term-price { margin-left: 26px; }
  .term-badge { order: 3; }
  .pricing { gap: 16px; }
}

/* ---- Compact card rows for tables on phones ---- */
@media (max-width: 640px) {
  .table-cards { overflow-x: visible; }
  .table-cards table, .table-cards thead, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards thead { display: none; }
  /* each row reads as one tidy card: title line, then a meta line */
  .table-cards tr {
    display: grid; grid-template-columns: 1fr auto auto; align-items: center;
    gap: 4px 12px; padding: 12px 16px;
    border-bottom: 1px solid var(--line-soft);
  }
  .table-cards tr:last-child { border-bottom: 0; }
  .table-cards td { padding: 0; border: 0; min-height: 0; }
  .table-cards td::before { content: none; }
  /* the description cell is the card title, first line, full width */
  .table-cards td[data-label="Описание"] { order: -1; grid-column: 1 / -1; margin: 0; }
  .table-cards td[data-label="Описание"] strong { font-size: var(--fs-md); font-weight: 600; }
  .table-cards td[data-label="Описание"] small { display: block; color: var(--muted-2); font-size: var(--fs-xs); margin-top: 1px; }
  /* date + status sit quietly on the meta line */
  .table-cards td[data-label="Дата"] { order: 0; color: var(--muted); font-size: var(--fs-xs); justify-self: start; }
  .table-cards td[data-label="Статус"] { order: 1; justify-self: start; }
  .table-cards td.table-actions, .table-cards .table-actions { order: 2; text-align: right; white-space: nowrap; justify-self: end; }
  /* generic tables without a description cell: first cell becomes the title */
  .table-cards td:first-child { font-weight: 600; }
  .table-cards td:not([data-label="Описание"]):not(:first-child) { color: var(--muted); font-size: var(--fs-sm); }
}

/* ---- Mobile sticky primary action ---- */
@media (max-width: 640px) {
  .action-bar-mobile { position: sticky; bottom: 0; z-index: 15; margin: 16px -16px -32px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom,0px)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
  .action-bar-mobile .button { width: 100%; }
}

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

/* ==========================================================================
   Dark theme
   ========================================================================== */
html[data-theme="dark"] {
  --ink: #f0f3f8;
  --ink-2: #cbd3e0;
  --muted: #9aa7bb;
  --muted-2: #8593a8;
  --line: #262f3d;
  --line-soft: #1f2734;
  --bg: #0e131b;
  --surface: #161c26;
  --surface-soft: #1b2230;
  --surface-tint: #222b3b;
  --surface-brand: color-mix(in srgb, var(--brand-color) 22%, #161c26);
  --border-strong: #384355;
  --success: #5fd1a0; --success-bg: #123027; --success-line: #1f5744;
  --warning: #e3b341; --warning-bg: #322a14; --warning-line: #5c4a1e;
  --danger:  #f0857d; --danger-bg:  #351c1a; --danger-line:  #5f2f2a;
  --info:    #79b4f5; --info-bg:    #14263c; --info-line:    #2a4a6e;
  --shadow-card: 0 1px 1px rgb(0 0 0 / 25%), 0 2px 5px rgb(0 0 0 / 22%);
  --shadow-pop: 0 8px 26px rgb(0 0 0 / 45%);
}
html[data-theme="dark"] .alert-info { color: #cfe2fb; }
html[data-theme="dark"] .alert-success, html[data-theme="dark"] .success { color: #bdeed3; }
html[data-theme="dark"] .alert-warning, html[data-theme="dark"] .notice { color: #ffe9a8 !important; }
html[data-theme="dark"] .alert-danger { color: #f7c7c3; }
html[data-theme="dark"] { --link: color-mix(in srgb, var(--brand-color) 42%, #ffffff); }
html[data-theme="dark"] .telegram-button { background: #2a6f95; }
html[data-theme="dark"] .telegram-button:hover { background: #245f80; }
html[data-theme="dark"] ::selection { background: color-mix(in srgb, var(--brand-accent) 34%, #000); color: var(--ink); }

/* ==========================================================================
   Utilities
   --------------------------------------------------------------------------
   The Content-Security-Policy forbids inline style="" attributes (style-src
   has a nonce and no 'unsafe-inline'), so every layout tweak must live in a
   class here. Keep this list small and named for intent.
   ========================================================================== */
.mt-0 { margin-top: 0 !important; }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-18 { margin-top: 18px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: var(--gap-lg); }
.mt-40 { margin-top: 40px; }
.mb-0 { margin-bottom: 0 !important; }
.mb-14 { margin-bottom: 14px; }
.m-0 { margin: 0 !important; }
.px-0 { padding-left: 0; padding-right: 0; }
.pt-0 { padding-top: 0; }
.pb-0 { padding-bottom: 0; }
.block { display: block; }
.inline { display: inline; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.plain { border: 0; margin: 0; padding: 0; }
.lead-actions { padding: 16px 0; text-align: left; align-items: flex-start; }
.lead-actions-lg { padding: 20px 0; text-align: left; align-items: flex-start; }
.narrow { max-width: 520px; }
.narrow-560 { max-width: 560px; margin-top: 40px; }
.narrow-640 { max-width: 640px; }
.simple-head { padding: 0 0 14px; }
.simple-head-16 { padding: 0 0 16px; }

/* a row separator inside an already-padded panel-body: no extra horizontal
   inset (the body supplies it), just vertical rhythm + a hairline */
.head-soft { padding: 16px 0; border-bottom: 1px solid var(--line-soft); }
.head-soft:last-child { border-bottom: 0; }
.pad-page { padding: 40px 20px; }
.bar-line { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.positive-box { background: var(--success-bg); color: var(--success); }
.is-hidden { display: none !important; }
.fs-14 { font-size: var(--fs-base); }
.mt-14 { margin-top: 16px; }
.py-16 { padding: 16px 0; }
.py-24 { padding: 24px 0; }

/* Admin operation details: keep identifiers, actions and event steps readable. */
.main:has(> .admin-nav) > header h1 { overflow-wrap: anywhere; }
.main:has(> .admin-nav) .op-card { display: grid; gap: 18px; }
.op-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; min-width: 0; }
.op-title-block { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.op-title-block > div { min-width: 0; overflow-wrap: anywhere; }
.op-title-block h2, .op-client, .op-amount { overflow-wrap: anywhere; }
.op-client, .op-amount { margin: 0; }
.op-icon { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: var(--radius-control); background: var(--surface-brand); color: var(--link); font-weight: 800; }
.op-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; min-width: min(100%, 280px); }
.metadata-grid, .support-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.meta-item, .support-item { min-width: 0; padding: 12px; border: 1px solid var(--line-soft); border-radius: var(--radius-control); background: var(--surface-soft); overflow-wrap: anywhere; }
.meta-label, .support-item small { display: block; margin-bottom: 7px; color: var(--muted-2); font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .6px; }
.meta-value, .support-item strong { display: block; min-width: 0; line-height: 1.35; }
.support-summary h3 { margin: 0 0 12px; font-size: var(--fs-lg); }
.support-item.ok { border-color: var(--success-line); }
.support-item.fail { border-color: var(--danger-line); }
.support-item.pending { border-color: var(--warning-line); }
.problem-box { margin-top: 12px; padding: 12px; border: 1px solid var(--danger-line); border-radius: var(--radius-control); background: var(--danger-bg); overflow-wrap: anywhere; }
.main:has(> .admin-nav) code, .main:has(> .admin-nav) .json-viewer { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.main:has(> .admin-nav) .json-viewer { max-width: 100%; overflow-x: auto; }
.timeline-container { position: relative; padding-left: 22px; }
.timeline-container::before { content: ""; position: absolute; left: 6px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.timeline-step { position: relative; padding: 0 0 14px 18px; }
.step-dot { position: absolute; left: -20px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-color); }
.step-content { min-width: 0; border: 1px solid var(--line-soft); border-radius: var(--radius-control); background: var(--surface-soft); overflow: hidden; }
.step-header { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 8px; align-items: center; width: 100%; padding: 10px 12px; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.step-header:hover { background: var(--surface-tint); }
.step-name, .step-duration, .step-time, .step-details { min-width: 0; overflow-wrap: anywhere; }
.step-duration, .step-time { color: var(--muted); font-size: var(--fs-sm); }
.step-details { padding: 0 12px 12px; color: var(--muted); }
.step-children { margin: 10px 0 0 12px; }
.main:has(> .admin-nav) .customer-timeline li { grid-template-columns: minmax(0, 1fr); gap: 4px; }
.main:has(> .admin-nav) .customer-timeline time { overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .op-header { display: grid; gap: 14px; }
  .op-actions { justify-content: stretch; min-width: 0; }
  .op-actions .button { flex: 1 1 150px; }
  .metadata-grid, .support-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step-header { grid-template-columns: auto minmax(0, 1fr); }
  .step-duration, .step-time { grid-column: 2; justify-self: start; }
}
@media (max-width: 390px) {
  .metadata-grid, .support-grid { grid-template-columns: minmax(0, 1fr); }
}
