/*
 * Customer dashboard styles (index.html + app.js).
 *
 * Served under a strict CSP (style-src 'self'), so this file is the only place
 * styling can come from: no inline styles, no style="" attributes. Colors are
 * tokens on :root, redefined for dark mode via prefers-color-scheme; spacing
 * follows one 4px-based scale (--s1..--s7). No web fonts — the page makes no
 * third-party requests — so type uses the platform's system stack.
 */

/* ════════════════════════════ Tokens ════════════════════════════ */

:root {
  color-scheme: light dark;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef1f7;
  --border: #e2e7f0;
  --border-strong: #cdd5e3;
  --text: #0f172a;
  --text-2: #3f4b60;
  --text-3: #5f6b80;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-active: #3730a3;
  --accent-fg: #4338ca;          /* accent used for text on light surfaces */
  --accent-soft: #eef0ff;
  --accent-ring: rgba(79, 70, 229, 0.32);
  --on-accent: #ffffff;

  --ok: #047857;
  --ok-soft: #e8f8f1;
  --ok-border: #a7e3c9;
  --danger: #b42318;
  --danger-soft: #fdeeee;
  --danger-border: #f5c2bd;
  --warn: #8a5100;
  --warn-soft: #fff6e5;
  --warn-border: #f1d49a;

  --tg: #1e6fb8;                 /* Telegram-ish blue, >= 4.5:1 with white */
  --tg-hover: #195f9e;
  --bolt: #d97706;               /* the priority icon while priority is on */

  --code-bg: #f1f3fb;
  --topbar-bg: rgba(255, 255, 255, 0.86);
  --toast-bg: #111827;
  --toast-fg: #f9fafb;
  --shimmer: rgba(255, 255, 255, 0.65);
  --glow-1: rgba(99, 102, 241, 0.16);
  --glow-2: rgba(14, 165, 233, 0.12);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px -14px rgba(15, 23, 42, 0.22);
  --shadow-lg: 0 18px 40px -18px rgba(15, 23, 42, 0.45);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f1a;
    --surface: #121826;
    --surface-2: #161d2e;
    --surface-3: #1d2539;
    --border: #243049;
    --border-strong: #35435f;
    --text: #e6eaf2;
    --text-2: #b8c1d3;
    --text-3: #8e9ab0;

    --accent: #5b5cf0;
    --accent-hover: #6a6cf4;
    --accent-active: #4f46e5;
    --accent-fg: #a5b4fc;
    --accent-soft: rgba(99, 102, 241, 0.16);
    --accent-ring: rgba(129, 140, 248, 0.45);

    --ok: #34d399;
    --ok-soft: rgba(16, 185, 129, 0.12);
    --ok-border: rgba(52, 211, 153, 0.35);
    --danger: #f87171;
    --danger-soft: rgba(239, 68, 68, 0.12);
    --danger-border: rgba(248, 113, 113, 0.35);
    --warn: #fbbf24;
    --warn-soft: rgba(245, 158, 11, 0.12);
    --warn-border: rgba(251, 191, 36, 0.35);

    --tg: #1f72bb;
    --tg-hover: #2680cf;
    --bolt: #fbbf24;

    --code-bg: #182033;
    --topbar-bg: rgba(18, 24, 38, 0.86);
    --toast-bg: #242d42;
    --toast-fg: #eef1f7;
    --shimmer: rgba(255, 255, 255, 0.06);
    --glow-1: rgba(99, 102, 241, 0.18);
    --glow-2: rgba(14, 165, 233, 0.08);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px -16px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 18px 44px -16px rgba(0, 0, 0, 0.8);
  }
}

/* ════════════════════════════ Base ════════════════════════════ */

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[hidden] {
  display: none !important;
}

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

a {
  color: var(--accent-fg);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

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

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

main:focus {
  outline: none;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding-left: var(--s5);
  padding-right: var(--s5);
}

.muted {
  color: var(--text-3);
  font-size: 14px;
}

.noscript {
  max-width: 560px;
  margin: var(--s7) auto;
  padding: var(--s4);
  text-align: center;
}

.skip-link {
  position: absolute;
  left: var(--s4);
  top: -60px;
  z-index: 50;
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: var(--s2);
}

/* Off-screen buffer for the execCommand copy fallback. */
.copy-buffer {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ════════════════════════════ Controls ════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 40px;
  padding: 0 var(--s4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.05s;
}

.btn:hover {
  text-decoration: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
}

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

.btn-primary:active:not(:disabled) {
  background: var(--accent-active);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.btn-tg {
  background: var(--tg);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-tg:hover {
  background: var(--tg-hover);
}

.btn-stop {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-stop:hover:not(:disabled) {
  border-color: var(--danger);
}

.btn-sm {
  min-height: 34px;
  padding: 0 var(--s3);
  font-size: 13px;
}

.btn-sm .icon {
  width: 16px;
  height: 16px;
}

.btn-lg {
  min-height: 48px;
  padding: 0 var(--s5);
  font-size: 15px;
}

.btn-block {
  width: 100%;
}

/* Busy state: spinner + alternate label, toggled by the .is-busy class. */
.btn .btn-spinner,
.btn .when-busy {
  display: none;
}

.btn.is-busy .btn-spinner {
  display: inline-block;
}

.btn.is-busy .when-busy {
  display: inline;
}

.btn.is-busy .when-idle {
  display: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

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

.icon-btn .icon {
  grid-area: 1 / 1;
}

.icon-btn-lg {
  width: 40px;
  height: 40px;
}

.icon-btn-lg .icon {
  width: 20px;
  height: 20px;
}

.icon-btn-sm {
  width: 28px;
  height: 28px;
}

.icon-btn-sm .icon {
  width: 15px;
  height: 15px;
}

/* Copy buttons swap to a check mark for a moment after copying. */
.copy-btn .i-check,
.copy-btn.is-copied .i-copy {
  display: none;
}

.copy-btn.is-copied .i-check {
  display: block;
}

.copy-btn.is-copied {
  color: var(--ok);
}

.input,
.select {
  width: 100%;
  min-height: 42px;
  padding: 0 var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder {
  color: var(--text-3);
  opacity: 1;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.input-lg {
  min-height: 48px;
  font-size: 15px;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%238a94a8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
}

.select-sm {
  min-height: 34px;
  width: auto;
  font-size: 13px;
  padding-left: var(--s3);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.check input:disabled,
.check input:disabled + span {
  cursor: not-allowed;
  opacity: 0.6;
}

.field {
  display: grid;
  gap: var(--s2);
}

.field-label {
  display: block;
  margin-bottom: var(--s2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.field .field-label {
  margin-bottom: 0;
}

.hint {
  font-size: 13px;
  color: var(--text-3);
}

.hint-indent {
  padding-left: 26px;
}

.field-error {
  font-size: 13px;
  color: var(--danger);
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s3);
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.alert > .icon {
  margin-top: 1px;
}

.alert-body {
  flex: 1;
  min-width: 0;
}

.alert-body a {
  margin-left: var(--s1);
  font-weight: 600;
  color: inherit;
}

.alert-error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.alert-warn {
  align-items: center;
  margin-bottom: var(--s4);
  color: var(--warn);
  background: var(--warn-soft);
  border-color: var(--warn-border);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: var(--ok-border);
}

.badge-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.badge-neutral {
  color: var(--text-2);
  background: var(--surface-3);
  border-color: var(--border);
}

.badge-mode {
  font-family: var(--mono);
  color: var(--accent-fg);
  background: var(--accent-soft);
}

.spinner {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg {
  width: 36px;
  height: 36px;
  border-width: 3px;
  color: var(--accent);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* ════════════════════════════ Brand ════════════════════════════ */

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-logo {
  flex: none;
  border-radius: 8px;
}

.brand-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ════════════════════════════ Boot & login ════════════════════════════ */

.view-boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.view-login {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-image:
    radial-gradient(900px 520px at 8% -12%, var(--glow-1), transparent 62%),
    radial-gradient(760px 480px at 105% 4%, var(--glow-2), transparent 60%);
  background-repeat: no-repeat;
}

.login-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding-top: var(--s5);
  padding-bottom: var(--s5);
}

.login-top .brand {
  font-size: 17px;
}

.login-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  align-items: start;
  gap: var(--s5);
  max-width: 1000px;
  padding-top: var(--s4);
  padding-bottom: var(--s7);
}

.login-card,
.reg-card {
  padding: var(--s6);
}

.login-badge {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--s4);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-fg);
}

.login-badge .icon {
  width: 22px;
  height: 22px;
}

.login-title {
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.lead {
  margin-top: var(--s2);
  font-size: 15px;
  color: var(--text-2);
}

.features {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s4);
  padding: 0;
  list-style: none;
}

.features li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-2);
}

.features .icon {
  width: 15px;
  height: 15px;
  color: var(--accent-fg);
}

.form {
  display: grid;
  gap: var(--s4);
  margin-top: var(--s5);
}

.key-field {
  position: relative;
}

.key-field .input {
  padding-right: 52px;
  font-size: 14px;
}

.key-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
}

.key-toggle .i-eye-off,
.key-toggle.is-on .i-eye {
  display: none;
}

.key-toggle.is-on .i-eye-off {
  display: block;
}

.reg-card {
  border-top: 3px solid var(--tg);
}

.reg-title {
  font-size: 19px;
  letter-spacing: -0.01em;
}

.reg-lead {
  margin-top: var(--s2);
  color: var(--text-2);
}

.steps {
  display: grid;
  gap: var(--s3);
  margin: var(--s5) 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: start;
  gap: var(--s3);
  counter-increment: step;
  color: var(--text);
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-fg);
  font-size: 13px;
  font-weight: 700;
}

.steps li span {
  padding-top: 3px;
}

.reg-note {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  margin-top: var(--s4);
  font-size: 13px;
  color: var(--text-3);
}

.reg-note .icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.reg-dev {
  display: grid;
  gap: var(--s2);
  margin-top: var(--s5);
  padding-top: var(--s4);
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-2);
}

.link-strong {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  font-weight: 600;
}

.link-strong .icon {
  width: 16px;
  height: 16px;
}

.login-reg {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--s1) var(--s2);
  margin-top: var(--s4);
  font-size: 14px;
  color: var(--text-2);
}

.bot-handle {
  margin-top: var(--s2);
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

.bot-handle .mono {
  color: var(--text-2);
  user-select: all;
}

.login-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--s2) var(--s5);
  padding-bottom: var(--s5);
  font-size: 13px;
}

.login-footer a,
.app-footer a {
  color: var(--text-3);
}

/* ════════════════════════════ Dashboard chrome ════════════════════════════ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s2) var(--s3);
  min-height: 64px;
  padding-top: var(--s2);
  padding-bottom: var(--s2);
}

.topbar-inner .brand {
  margin-right: auto;
}

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

.balance-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 36px;
  padding: 0 var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.balance-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.balance-label {
  font-size: 13px;
  color: var(--text-3);
}

.balance-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.balance-refresh {
  width: 14px;
  height: 14px;
  color: var(--text-3);
}

.balance-chip.is-loading .balance-refresh {
  animation: spin 0.8s linear infinite;
}

.balance-chip.is-low {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.balance-chip.is-low .balance-value {
  color: var(--danger);
}

.lang-picker {
  display: inline-flex;
}

.app-main {
  display: grid;
  gap: var(--s7);
  padding-top: var(--s6);
  padding-bottom: var(--s7);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s4);
  margin-bottom: var(--s4);
}

.section-title {
  font-size: 20px;
  letter-spacing: -0.015em;
}

.section-sub {
  max-width: 64ch;
  margin-top: var(--s1);
  font-size: 14px;
  color: var(--text-3);
}

.app-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--s2) var(--s5);
  padding-top: var(--s5);
  padding-bottom: var(--s6);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-3);
}

.app-footer [data-support-wrap] {
  display: inline-flex;
  gap: 6px;
}

/* ════════════════════════════ States & skeletons ════════════════════════════ */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--s7) var(--s5);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
}

.state-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  max-width: 420px;
}

.state-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--s1);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-fg);
}

.state-icon .icon {
  width: 22px;
  height: 22px;
}

.state.is-error .state-icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.state-title {
  font-size: 16px;
  font-weight: 700;
}

.state-body {
  color: var(--text-3);
  font-size: 14px;
}

.state-inner .btn {
  margin-top: var(--s2);
}

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: var(--surface-3);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--shimmer), transparent);
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

/* Product card placeholder: same rows as a real card (head, priority, buy, footer). */
.sk-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 39px;
}

.sk-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.sk-lines {
  display: grid;
  flex: 1;
  gap: 6px;
}

.sk-price {
  flex: none;
  width: 52px;
  height: 22px;
}

.sk-prio {
  width: 55%;
}

.sk-buy {
  display: flex;
  gap: var(--s2);
}

.sk-stepper {
  flex: none;
  width: 102px;
  height: 36px;
}

.sk-btn {
  flex: 1;
  height: 36px;
}

.sk-title {
  height: 18px;
  width: 45%;
}

.sk-line {
  height: 12px;
}

.sk-code {
  height: 36px;
  width: 70%;
}

/* Row heights of a real card, which these must out-rank .sk-line to get:
   the priority bar takes a 26px row like the select, the footer a 20px row
   like "Wait for stock". */
.product.is-skeleton .sk-prio {
  height: 14px;
  margin-block: 6px;
}

.product.is-skeleton > .sk-line:last-child {
  margin-block: 4px;
}

.w-40 {
  width: 40%;
}

.w-60 {
  width: 60%;
}

/* ════════════════════════════ Product cards ════════════════════════════ */

/* Compact on purpose: production lists ~20 sites, so a desktop shows 3-4
   cards per row and each card is just head, priority, buy row, footer.
   Cards keep their own height (align-items: start) so a purchase in progress
   grows its card without stretching the whole row. */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  align-items: start;
  gap: var(--s3);
}

.product {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  min-width: 0;
  padding: var(--s4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.product:not(.is-skeleton):hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.product-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 800;
}

.tone-0 { background: #fde7f3; color: #b0266f; }
.tone-1 { background: #e6f0ff; color: #1d5fc2; }
.tone-2 { background: #fff1dc; color: #a2560a; }
.tone-3 { background: #e5f7ee; color: #17784a; }
.tone-4 { background: #efe9ff; color: #6337c9; }
.tone-5 { background: #e3f6f8; color: #0f6f7c; }

@media (prefers-color-scheme: dark) {
  .tone-0 { background: rgba(236, 72, 153, 0.16); color: #f9a8d4; }
  .tone-1 { background: rgba(59, 130, 246, 0.16); color: #93c5fd; }
  .tone-2 { background: rgba(245, 158, 11, 0.16); color: #fcd34d; }
  .tone-3 { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }
  .tone-4 { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
  .tone-5 { background: rgba(6, 182, 212, 0.16); color: #67e8f9; }
}

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

.product-name {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

/* What API integrations send as `product`, so it stays whole (wrapping if it must). */
.product-slug {
  display: block;
  margin-top: 1px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--text-3);
  overflow-wrap: anywhere;
}

.product-kind {
  margin-top: var(--s1);
}

.product-price {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: flex-end;
  max-width: 50%;
  text-align: right;
}

/* The narrowest cards (a 4-column row just above its breakpoint) tighten the
   header so the slug still fits on one line. The grid gives each card its
   width, so measuring the card itself is safe. */
.product {
  container-type: inline-size;
}

@container (max-width: 228px) {
  .product-head {
    gap: var(--s2);
  }

  .avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    font-size: 13px;
  }

  .product-slug,
  .price-unit {
    font-size: 11px;
  }

  .price-value {
    font-size: 18px;
  }
}

.price-value {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.price-unit {
  margin-top: 2px;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--text-3);
}

/* Priority: one quiet line — an icon, a word and a small native select. */
.prio {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 6px;
  max-width: 100%;
  font-size: 12.5px;
  color: var(--text-3);
  cursor: pointer;
}

.prio-icon {
  width: 14px;
  height: 14px;
  transition: color 0.15s, fill 0.15s;
}

.prio.is-on .prio-icon {
  color: var(--bolt);
  fill: currentColor;
}

.prio-select {
  min-width: 0;
  height: 26px;
  padding: 0 22px 0 var(--s2);
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%238a94a8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-size: 10px;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.prio-select:hover:not(:disabled) {
  border-color: var(--border-strong);
}

.prio-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.prio-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.buy-row {
  display: flex;
  align-items: stretch;
  gap: var(--s2);
}

.stepper {
  display: inline-flex;
  flex: none;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stepper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.stepper-btn {
  display: grid;
  place-items: center;
  width: 30px;
  padding: 0;
  border: 0;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
}

.stepper-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.stepper-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.stepper-btn .icon {
  width: 14px;
  height: 14px;
}

.stepper-input {
  width: 40px;
  min-height: 34px;
  padding: 0 2px;
  border: 0;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: transparent;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}

.stepper-input:focus {
  outline: none;
}

.stepper-input::-webkit-inner-spin-button,
.stepper-input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.stepper-input:disabled {
  opacity: 0.6;
}

.buy-btn {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
}

.warn-text {
  padding: 6px 10px;
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12.5px;
  line-height: 1.4;
}

.product .field-error {
  font-size: 12.5px;
}

/* "Wait for stock" and, when buying several, the total: one small line. */
.product-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px var(--s3);
  min-height: 20px;
}

.check-sm {
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-3);
}

.check-sm input {
  width: 15px;
  height: 15px;
}

.total {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s1);
  margin-left: auto;
  font-size: 12.5px;
  color: var(--text-3);
  white-space: nowrap;
}

.total-value {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* "No sites match" above a card that its running purchase keeps on screen. */
#products-state:not([hidden]) + .product-grid:not(:empty) {
  margin-top: var(--s3);
}

.input-sm {
  min-height: 36px;
  font-size: 14px;
}

.job {
  display: grid;
  gap: var(--s2);
  padding: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

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

.job-row .spinner {
  color: var(--accent);
}

.job-progress {
  margin-right: auto;
  font-variant-numeric: tabular-nums;
}

.job-status {
  font-size: 13px;
  color: var(--text-3);
}

.progress {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  appearance: none;
  -webkit-appearance: none;
  color: var(--accent);
}

.progress::-webkit-progress-bar {
  border-radius: var(--radius-pill);
  background: var(--surface-3);
}

.progress::-webkit-progress-value {
  border-radius: var(--radius-pill);
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress::-moz-progress-bar {
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px var(--s2);
  padding: var(--s2) var(--s3);
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.result a {
  margin-left: auto;
  font-weight: 700;
  color: inherit;
}

.result.is-ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: var(--ok-border);
}

.result.is-warn {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: var(--warn-border);
}

.result.is-error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

/* ════════════════════════════ Orders ════════════════════════════ */

/* Beside the heading when there's room, else a full-width row of its own. */
.section-head > :first-child {
  flex: 1 1 320px;
  min-width: 0;
}

.filters {
  display: flex;
  gap: var(--s2);
  flex: 1 1 400px;
  max-width: 600px;
}

.search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.search .icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search .input {
  padding-left: 38px;
}

/* After .search (same specificity) so it wins on wide screens; the <=600px
   ".search { flex: 1 1 100% }" rule further down still makes it full width. */
.product-search {
  flex: 0 1 260px;
}

.product-filter {
  flex: 0 0 200px;
  min-width: 0;
}

.orders {
  display: grid;
  gap: var(--s3);
}

.order {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 340px);
  gap: var(--s4) var(--s5);
  padding: var(--s4) var(--s5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, background-color 0.2s;
}

.order.is-watched {
  border-color: var(--accent-ring);
}

.order.is-dead {
  background: var(--surface-2);
}

.order.is-dead .email-chip {
  color: var(--text-3);
}

.order.is-enter {
  animation: order-enter 0.35s ease-out;
}

.order.is-flash {
  border-color: var(--accent);
  animation: order-flash 1.8s ease-out 3;
}

@keyframes order-enter {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@keyframes order-flash {
  0% {
    box-shadow: 0 0 0 0 var(--accent-ring);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(0, 0, 0, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
}

.order.is-skeleton .order-main {
  display: grid;
  gap: var(--s2);
}

.order-main {
  min-width: 0;
}

.order-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px var(--s2);
}

.order-product {
  font-size: 15px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.order-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 0;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-3);
}

.order-meta > :not([hidden]) ~ :not([hidden])::before {
  content: "·";
  margin: 0 6px;
}

.order-price {
  font-variant-numeric: tabular-nums;
}

.email-row {
  display: flex;
  align-items: center;
  gap: var(--s1);
  min-width: 0;
  margin-top: var(--s3);
}

.email-chip {
  min-width: 0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  font-size: 14px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.order-codes {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--s2);
  min-width: 0;
  padding-left: var(--s5);
  border-left: 1px solid var(--border);
}

.code-block .field-label {
  margin-bottom: 2px;
}

.code-latest {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.code-value {
  min-width: 0;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.08em;
  color: var(--text);
  overflow-wrap: anywhere;
  user-select: all;
}

.code-when {
  font-size: 12px;
  color: var(--text-3);
}

.code-older summary {
  width: max-content;
  max-width: 100%;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  cursor: pointer;
}

.code-older summary:hover {
  color: var(--text);
}

.code-older ul {
  display: grid;
  gap: 2px;
  margin-top: var(--s1);
  padding: 0;
  list-style: none;
}

.code-older-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 13px;
}

.code-older-value {
  min-width: 0;
  font-weight: 600;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}

.code-older-item .code-when {
  margin-left: auto;
}

.watching {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-fg);
}

.watching.is-waiting {
  min-height: 56px;
  font-size: 15px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 var(--ok-border);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(0, 0, 0, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
}

.no-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s2);
}

.dead-note {
  font-size: 13px;
  color: var(--danger);
}

.orders-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
  margin-top: var(--s4);
}

/* ════════════════════════════ Toasts ════════════════════════════ */

.toasts {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s2) var(--s2) var(--s2) var(--s4);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.2s, transform 0.2s;
}

.toast-success {
  border-left-color: #10b981;
}

.toast-error {
  border-left-color: #ef4444;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
}

.toast-text {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  overflow-wrap: anywhere;
}

.toast-close {
  color: inherit;
  opacity: 0.7;
}

.toast-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  opacity: 1;
}

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

/* ════════════════════════════ Responsive ════════════════════════════ */

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

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

  .order-codes {
    padding-top: var(--s3);
    padding-left: 0;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .topbar {
    position: static;
  }

  .filters {
    max-width: none;
  }
}

@media (max-width: 600px) {
  .container {
    padding-left: var(--s4);
    padding-right: var(--s4);
  }

  .login-card,
  .reg-card {
    padding: var(--s5);
  }

  .login-title {
    font-size: 22px;
  }

  .app-main {
    gap: var(--s6);
    padding-top: var(--s5);
  }

  .filters {
    flex-wrap: wrap;
  }

  .search,
  .product-filter {
    flex: 1 1 100%;
  }

  .order {
    padding: var(--s4);
  }

  .code-value {
    font-size: 26px;
  }

  .toasts {
    right: var(--s4);
    bottom: var(--s4);
    left: var(--s4);
    width: auto;
  }
}

/* Icon-only secondary actions on narrow phones (their labels stay available
   through aria-label). */
@media (max-width: 480px) {
  .hide-sm {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions #topup-link {
    margin-right: auto;
  }

  .balance-label {
    display: none;
  }
}

/* ════════════════════════════ Motion ════════════════════════════ */

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

  /* Activity indicators still need to read as "working" — just slower. */
  .spinner,
  .balance-chip.is-loading .balance-refresh {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }

  .skeleton::after {
    display: none;
  }

  /* A static ring instead of the pulsing highlight. */
  .order.is-flash {
    box-shadow: 0 0 0 3px var(--accent-ring);
  }
}
