/* qqwork — design system. See docs/STYLE.md for rules. */

/* ------------------------------------------------------------------
   Fonts (temporary — will be replaced with SF Pro + Offbit later).
   ------------------------------------------------------------------ */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap");

/* ------------------------------------------------------------------
   Color tokens
   ------------------------------------------------------------------ */
:root,
[data-theme="light"] {
  --bg:          #fafafa;
  --surface:     #ffffff;
  --surface-2:   #f5f5f5;
  --line:        #e5e5e5;
  --line-strong: #d4d4d4;
  --ink:         #0a0a0a;
  --ink-2:       #262626;
  --muted:       #737373;
  --muted-2:     #a3a3a3;
  --accent:      #0a0a0a;
  --accent-ink:  #ffffff;
  --success:     #15803d;
  --warn:        #a16207;
  --danger:      #b91c1c;
  --success-bg:  #ecfdf5;
  --warn-bg:     #fefce8;
  --danger-bg:   #fef2f2;
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, .04);
  --shadow-md:   0 1px 2px rgba(0, 0, 0, .04), 0 4px 12px rgba(0, 0, 0, .04);
  --shadow-lg:   0 8px 24px rgba(0, 0, 0, .06);

  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: var(--font-sans);   /* alias — switch to Offbit later if needed */
  --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  /* Legacy aliases — старые токены мапятся на новые, чтобы inline-стили
     в шаблонах продолжали работать. Новый код использует основные токены. */
  --red:        var(--danger);
  --green:      var(--success);
  --accent-2:   var(--warn);
  --bg-accent:  var(--surface-2);
  --card:       var(--surface);

  color-scheme: light;
}

[data-theme="dark"] {
  --bg:          #0a0a0a;
  --surface:     #171717;
  --surface-2:   #262626;
  --line:        #2e2e2e;
  --line-strong: #404040;
  --ink:         #fafafa;
  --ink-2:       #e5e5e5;
  --muted:       #a3a3a3;
  --muted-2:     #737373;
  --accent:      #fafafa;
  --accent-ink:  #0a0a0a;
  --success:     #22c55e;
  --warn:        #eab308;
  --danger:      #ef4444;
  --success-bg:  rgba(34, 197, 94, .10);
  --warn-bg:     rgba(234, 179, 8, .12);
  --danger-bg:   rgba(239, 68, 68, .12);
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, .5);
  --shadow-md:   0 1px 2px rgba(0, 0, 0, .5), 0 4px 12px rgba(0, 0, 0, .3);
  --shadow-lg:   0 8px 24px rgba(0, 0, 0, .5);

  color-scheme: dark;
}

/* Auto-dark fallback if user hasn't set a preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg:          #0a0a0a;
    --surface:     #171717;
    --surface-2:   #262626;
    --line:        #2e2e2e;
    --line-strong: #404040;
    --ink:         #fafafa;
    --ink-2:       #e5e5e5;
    --muted:       #a3a3a3;
    --muted-2:     #737373;
    --accent:      #fafafa;
    --accent-ink:  #0a0a0a;
    --success:     #22c55e;
    --warn:        #eab308;
    --danger:      #ef4444;
    --success-bg:  rgba(34, 197, 94, .10);
    --warn-bg:     rgba(234, 179, 8, .12);
    --danger-bg:   rgba(239, 68, 68, .12);
    color-scheme: dark;
  }
}

/* ------------------------------------------------------------------
   Reset + base
   ------------------------------------------------------------------ */
* { box-sizing: border-box; }

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

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

a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 700; margin: 0; color: var(--ink); }
h3 { font-size: 13px; font-weight: 600; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

/* ------------------------------------------------------------------
   Layout: header / nav / main
   ------------------------------------------------------------------ */
header {
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
}

nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }

nav a {
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  transition: color .15s, background .15s;
}
nav a:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--ink); background: var(--surface-2); }

.nav-spacer { flex: 1; }

.nav-user {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted);
  padding: 6px 10px; border-radius: var(--r-sm);
}
.nav-user:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }

main {
  padding: 24px 28px 48px;
  max-width: 1400px;
  margin: 0 auto;
}

.section-title {
  margin: 32px 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: -0.01em;
}
.section-title:first-child { margin-top: 0; }

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

/* ------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------ */
.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: opacity .15s, background .15s, border-color .15s, color .15s;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
}
.button:hover { opacity: .88; text-decoration: none; }
.button:active { opacity: .75; }
.button:disabled, .button[disabled] { opacity: .4; cursor: not-allowed; }

.button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}
.button.ghost:hover { background: var(--surface-2); opacity: 1; }

.button.danger { background: var(--danger); color: #fff; }
.button.danger:hover { opacity: .88; }

/* Ghost + destructive intent: neutral border, red text only */
.button.ghost.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--line-strong);
}
.button.ghost.danger:hover {
  background: var(--danger-bg);
  border-color: var(--line-strong);
  color: var(--danger);
}

.button.small { padding: 6px 10px; font-size: 12px; border-radius: var(--r-sm); }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .15s, color .15s;
  font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ------------------------------------------------------------------
   Inputs
   ------------------------------------------------------------------ */
.input,
input[type="text"].input,
input[type="email"].input,
input[type="password"].input,
input[type="search"].input,
textarea.input,
select.input {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.input:focus, select.input:focus, textarea.input:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .04);
}
[data-theme="dark"] .input:focus { box-shadow: 0 0 0 3px rgba(255, 255, 255, .05); }
.input::placeholder { color: var(--muted-2); }

.input-group {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
}
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .button {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  height: 36px; padding: 0 14px;
}

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

/* ------------------------------------------------------------------
   Hero — the "one action" dashboard block
   ------------------------------------------------------------------ */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  margin-bottom: 16px;
}

.hero-main {
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
  flex: 1;
}

.hero-value {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: center;
}

.hero-label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hero-title { font-size: 16px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.hero-sub { font-size: 13px; color: var(--muted); line-height: 1.4; }

.hero-cta {
  height: 44px;
  padding: 0 20px;
  font-size: 14px;
  white-space: nowrap;
  flex-shrink: 0;
}

.hero.watching .hero-value { color: var(--success); }
.hero.waiting_start .hero-value { color: var(--warn); }
.hero.waiting_devices .hero-value { color: var(--danger); }
.hero.empty .hero-value,
.hero.idle .hero-value { color: var(--muted-2); }

/* Compact stats row under the hero */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.stat-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 58px;
  justify-content: center;
}
.stat-num {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-total { font-size: 15px; color: var(--muted-2); font-weight: 500; }
.stat-key {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  font-weight: 600;
}
.stat-sub { font-size: 12px; color: var(--muted); }
.stat-sub.fail { color: var(--danger); }
.stat-sub.ok { color: var(--success); }

@media (max-width: 720px) {
  .hero { flex-direction: column; align-items: stretch; padding: 18px; gap: 14px; }
  .hero-main { flex-direction: row; align-items: center; gap: 16px; }
  .hero-value { font-size: 44px; min-width: 36px; }
  .hero-cta { width: 100%; justify-content: center; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

/* ------------------------------------------------------------------
   Cards
   ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  margin: 0 0 8px;
  font-size: 11px;
}

.card .value {
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.card .value.ok,
.card .value.green { color: var(--success); }
.card .value.warn { color: var(--warn); }
.card .value.fail { color: var(--danger); }

.card .sub { margin-top: 6px; font-size: 12px; color: var(--muted); }

.card-compact {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 13px;
}

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

/* ------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------ */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  font-size: 13px;
}

th, td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.active td { background: var(--surface-2); }

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

/* Dense table variant for logs */
.table-dense th, .table-dense td { padding: 6px 10px; font-size: 12px; }
.table-dense { font-family: var(--font-mono); }

/* ------------------------------------------------------------------
   Pills — status tags
   ------------------------------------------------------------------ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-sm);          /* 6px — плоский бейдж, не капсула */
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0;
  line-height: 1.4;
}

.pill.ok,
.pill.registered,
.pill.ready,
.pill.online,
.pill.done { background: var(--success-bg); color: var(--success); }

.pill.warn,
.pill.running,
.pill.busy,
.pill.authorized,
.pill.pending-task { background: var(--warn-bg); color: var(--warn); }

.pill.fail,
.pill.failed,
.pill.error { background: var(--danger-bg); color: var(--danger); }

.pill.empty,
.pill.offline,
.pill.pending,
.pill.cancelled { background: var(--surface-2); color: var(--muted); }

.pill.admin {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

/* ------------------------------------------------------------------
   Misc utilities
   ------------------------------------------------------------------ */
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.muted-2 { color: var(--muted-2); }
.small { font-size: 12px; }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--muted);
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 20px 0;
  border: 0;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  font-size: 13px;
}
.empty-state strong { color: var(--ink); font-size: 15px; display: block; margin-bottom: 4px; }

.form-narrow { max-width: 480px; margin: 0 auto; }

/* ------------------------------------------------------------------
   Toolbar — top of list pages (filters + search + action)
   ------------------------------------------------------------------ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin-bottom: 12px;
}
.toolbar .input { flex: 1; min-width: 180px; }
.toolbar .spacer { flex: 1; }

/* Tabs — filter chips above a table */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.tab {
  padding: 6px 12px;
  border-radius: var(--r-md);         /* 10px, как кнопки — не капсула */
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  transition: color .15s, background .15s, border-color .15s;
}
.tab:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.tab.active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
.tab .count {
  display: inline-block; margin-left: 6px;
  padding: 0 6px; border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 600;
}
.tab.active .count {
  background: rgba(255, 255, 255, .18); color: var(--accent-ink);
}
[data-theme="dark"] .tab.active .count { background: rgba(0, 0, 0, .18); }

/* Message bar (success / error) — мягкий фон без яркой рамки */
.msg {
  padding: 9px 12px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
}
.msg.ok   { background: var(--success-bg); color: var(--success); }
.msg.err,
.msg.fail { background: var(--danger-bg);  color: var(--danger); }
.msg.warn { background: var(--warn-bg);    color: var(--warn); }

/* Two-column action row (accounts: add phones + import) */
.cols-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

/* Action box — a card with a title and form inside */
.action-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.action-box h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: none;
  letter-spacing: -0.01em;
  margin: 0 0 2px;
}
.action-box .hint { font-size: 12px; color: var(--muted); }
.action-box .footer-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.action-box .footer-row .meta {
  font-size: 12px; color: var(--muted);
}

/* File input — make the default prettier */
input[type="file"].input {
  padding: 6px 10px; line-height: 1.4;
}
input[type="file"].input::file-selector-button {
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 3px 10px; margin-right: 10px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
}
input[type="file"].input::file-selector-button:hover {
  background: var(--line);
}

/* Inline icon-edit pair for device name / account fields */
.inline-edit {
  display: inline-flex; align-items: center; gap: 4px;
}
.inline-edit .input {
  height: 28px; font-size: 13px; padding: 0 8px;
  background: transparent; border-color: transparent;
}
.inline-edit .input:hover { background: var(--surface); border-color: var(--line); }
.inline-edit .input:focus { background: var(--surface); border-color: var(--ink); }
.inline-edit-pen {
  font-size: 11px; color: var(--muted-2); pointer-events: none;
}

/* ------------------------------------------------------------------
   HTMX loading state (for swapped partials)
   ------------------------------------------------------------------ */
.htmx-request { opacity: 0.6; transition: opacity .2s; }

/* ------------------------------------------------------------------
   Telegram Mini App — dedicated mobile layout (routes/tgapp.py)
   ------------------------------------------------------------------ */
body.tgapp {
  background: var(--bg);
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
body.tgapp main {
  padding: 12px 12px 78px;        /* bottom = tabbar height + gap */
  max-width: 560px;
  margin: 0 auto;
}
body.tgapp .hero {
  padding: 16px 16px;
  margin-bottom: 10px;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  border-radius: var(--r-md);
}
body.tgapp .hero-main { flex-direction: row; align-items: center; gap: 14px; }
body.tgapp .hero-value { font-size: 40px; min-width: 36px; }
body.tgapp .hero-cta { width: 100%; justify-content: center; height: 44px; }

body.tgapp .section-title {
  margin: 14px 0 6px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
}
body.tgapp .section-title:first-child { margin-top: 0; }

body.tgapp .stat-row {
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
body.tgapp .stat-item { padding: 10px 12px; }
body.tgapp .stat-num { font-size: 20px; }
body.tgapp .stat-key { font-size: 10px; }
body.tgapp .stat-sub { font-size: 11px; }

/* Card list — vertical stack, used instead of tables */
.tg-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tg-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ink);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tg-card:hover,
.tg-card:active { text-decoration: none; background: var(--surface-2); }

.tg-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.tg-card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tg-card-sub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.tg-card-sub .dot {
  width: 3px; height: 3px; border-radius: 50%;
  background: var(--muted-2); display: inline-block;
}
.tg-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

/* Bottom tab-bar navigation */
.tg-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.tg-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 9px 4px 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  text-decoration: none;
  transition: color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.tg-tab:hover,
.tg-tab:active { text-decoration: none; background: var(--surface-2); }
.tg-tab-icon { font-size: 20px; line-height: 1; }
.tg-tab.active { color: var(--ink); }

/* Sticky bottom single action (above tabbar) */
.tg-sticky-action {
  position: fixed;
  left: 0; right: 0; bottom: 56px;    /* above tabbar */
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  z-index: 25;
}
.tg-sticky-action .button { flex: 1; height: 44px; font-size: 14px; justify-content: center; }

/* ==================================================================
   Help page (/help) — hero + tabs + accordions
   ================================================================== */

.help-wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 0 48px;
}

/* --- Inline building blocks shared with the help content --- */

kbd {
  display: inline-block;
  padding: 1px 7px;
  font-family: var(--font-sans);
  font-size: 0.88em;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  box-shadow: 0 1px 0 var(--line);
  white-space: nowrap;
}

.callout {
  padding: 14px 16px;
  border-left: 3px solid var(--muted-2);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  margin: 14px 0 16px;
  font-size: 14px;
  line-height: 1.55;
}
.callout strong { font-weight: 700; }
.callout.tip    { border-left-color: var(--success); background: var(--success-bg); }
.callout.warn   { border-left-color: var(--warn);    background: var(--warn-bg); }
.callout.note   { border-left-color: var(--muted-2); background: var(--surface-2); }
.callout.danger { border-left-color: var(--danger);  background: var(--danger-bg); }

.help-pre {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  margin: 4px 0;
}

/* --- HERO --- */

.help-hero {
  padding: 40px 24px 32px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  margin-bottom: 24px;
  text-align: center;
}
.help-hero-title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0 0 12px;
  line-height: 1.1;
}
.help-wave {
  display: inline-block;
  transform-origin: 70% 70%;
  animation: help-wave 2.4s ease-in-out 1s 2;
}
@keyframes help-wave {
  0%, 100% { transform: rotate(0deg); }
  15% { transform: rotate(14deg); }
  30% { transform: rotate(-8deg); }
  45% { transform: rotate(14deg); }
  60% { transform: rotate(-4deg); }
  75% { transform: rotate(10deg); }
}
.help-hero-lead {
  font-size: 16px;
  line-height: 1.6;
  color: var(--muted);
  max-width: 560px;
  margin: 0 auto 32px;
}
.help-hero-lead strong { color: var(--ink); font-weight: 700; }
.help-hero-sub {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 16px;
}

.help-hero-steps {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  list-style: none;
  padding: 0;
  margin: 0;
}
.help-hero-step {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  user-select: none;
}
.help-hero-step:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}
.help-hero-step:active { transform: translateY(0); box-shadow: none; }
.help-hero-step .step-num {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-hero-step .step-icon { font-size: 28px; line-height: 1; margin-top: 6px; }
.help-hero-step .step-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
}
.help-hero-step .step-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  line-height: 1.3;
}

/* --- TABS --- */

.help-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  position: sticky;
  top: 8px;
  z-index: 10;
}
.help-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.help-tab:hover { color: var(--ink); }
.help-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.help-tab span { font-size: 16px; line-height: 1; }

/* --- PANE --- */

.help-pane { display: block; }
.help-pane[hidden] { display: none; }

/* --- ACCORDION (top-level sections) --- */

.help-acc {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin-bottom: 10px;
  scroll-margin-top: 80px;
  transition: border-color .15s, box-shadow .15s;
  overflow: hidden;
}
.help-acc[open] {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.help-acc > summary {
  list-style: none;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  grid-template-rows: auto auto;
  grid-column-gap: 12px;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.help-acc > summary::-webkit-details-marker { display: none; }
.help-acc > summary:hover { background: var(--surface-2); }
.help-acc .acc-icon {
  grid-column: 1;
  grid-row: 1 / span 2;
  font-size: 28px;
  line-height: 1;
  text-align: center;
}
.help-acc .acc-title {
  grid-column: 2;
  grid-row: 1;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}
.help-acc .acc-hint {
  grid-column: 2;
  grid-row: 2;
  font-size: 12px;
  color: var(--muted);
}
.help-acc .acc-chevron {
  grid-column: 3;
  grid-row: 1 / span 2;
  font-size: 24px;
  font-weight: 400;
  color: var(--muted-2);
  transition: transform .2s;
  line-height: 1;
}
.help-acc[open] > summary .acc-chevron { transform: rotate(90deg); }
.help-acc[open] > summary { border-bottom: 1px solid var(--line); background: var(--surface-2); }

.help-acc .acc-body {
  padding: 20px 24px 24px;
}
.help-acc .acc-body > :first-child { margin-top: 0; }
.help-acc .acc-body > :last-child { margin-bottom: 0; }
.help-acc .acc-body h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-2);
  margin: 22px 0 10px;
  text-transform: none;
  letter-spacing: 0;
}
.help-acc .acc-body h3:first-child { margin-top: 4px; }
.help-acc .acc-body p { font-size: 14px; margin: 0 0 12px; line-height: 1.6; }
.help-acc .acc-body p.lead { font-size: 15px; color: var(--ink-2); }
.help-acc .acc-body ul,
.help-acc .acc-body ol { font-size: 14px; margin: 0 0 12px; padding-left: 22px; line-height: 1.6; }
.help-acc .acc-body li { margin-bottom: 6px; }
.help-acc .acc-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 1px 6px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  color: var(--ink-2);
}

/* --- NESTED SUB-ACCORDION (Частые проблемы) --- */

.help-sub-acc {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 0 14px;
  margin-top: 16px;
}
.help-sub-acc > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  -webkit-tap-highlight-color: transparent;
}
.help-sub-acc > summary::-webkit-details-marker { display: none; }
.help-sub-acc > summary:hover { color: var(--ink); }
.help-sub-acc > summary::after {
  content: "›";
  float: right;
  font-size: 18px;
  color: var(--muted-2);
  transition: transform .2s;
  display: inline-block;
}
.help-sub-acc[open] > summary::after { transform: rotate(90deg); }
.help-sub-acc[open] > summary { border-bottom: 1px solid var(--line); }
.help-sub-acc ul { margin: 12px 0 14px !important; padding-left: 22px; font-size: 13px !important; }
.help-sub-acc li { margin-bottom: 8px; }

/* --- MINI-CARDS: способы импорта, SMS-режимы и т.п. --- */

.help-mini-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 8px 0 16px;
}
.mini-card {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini-card > :first-child { margin-top: 0; }
.mini-card > :last-child { margin-bottom: 0; }
.mini-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}
.mini-card p { font-size: 13px !important; margin: 0 0 6px !important; line-height: 1.5 !important; }
.mini-card ul { margin: 4px 0 !important; padding-left: 20px !important; font-size: 13px !important; }
.mini-card li { margin-bottom: 4px !important; }

/* --- PILL-GRID: статусы + описание --- */

.help-pill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 6px;
  margin: 8px 0 16px;
  font-size: 13px;
}
.help-pill-grid > div {
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  line-height: 1.5;
}
.help-pill-grid .pill { margin-right: 6px; }

/* --- NUMBERED STEPS (inside acc-body) --- */

.help-steps { list-style: none; counter-reset: hstep; padding: 0; margin: 4px 0 16px !important; }
.help-steps > li {
  counter-increment: hstep;
  position: relative;
  padding: 10px 14px 10px 44px !important;
  margin-bottom: 8px !important;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 14px;
  line-height: 1.5;
}
.help-steps > li::before {
  content: counter(hstep);
  position: absolute;
  left: 12px;
  top: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-steps > li > ul { margin: 8px 0 0 !important; padding-left: 18px !important; font-size: 13px !important; }

.help-steps-line {
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: 12px !important;
  line-height: 1.7 !important;
}

/* --- FAQ GRID (tab: Проблемы) --- */

.help-faq-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}
.faq-card {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color .15s, box-shadow .15s;
}
.faq-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.faq-card h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 8px;
  line-height: 1.4;
}
.faq-card p {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  line-height: 1.55;
}
.faq-card p em { color: var(--ink-2); font-style: normal; font-weight: 500; }

/* --- GLOSSARY (tab: Словарь) --- */

.help-glossary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 0 24px;
  margin: 0;
}
.help-glossary > div {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.help-glossary dt {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}
.help-glossary dd {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

/* --- FOOTER CONTACT CARD --- */

.help-footer { margin-top: 32px; }
.help-footer-card {
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  text-align: center;
}
.help-footer-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}
.help-footer-card p { margin: 4px 0 12px; font-size: 14px; }
.help-footer-card .button {
  font-size: 15px;
  padding: 10px 24px;
}

/* --- Help banner card on tgapp dashboard (kept) --- */
.help-banner { background: var(--surface-2); }

/* ==================================================================
   Tasks page: manual SMS input clarity + «жду SMS» badge + retry pin
   ================================================================== */

/* Badge next to task status — «⏳ жду SMS» blinking to attract operator */
.badge-waiting {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  white-space: nowrap;
  animation: badge-waiting-pulse 1.4s ease-in-out infinite;
}
@keyframes badge-waiting-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* Inline SMS-code form in task row — крупнее, с ID+phone слева */
.sms-manual-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  border-radius: var(--r-sm);
}
.sms-manual-label {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.1;
  margin-right: 2px;
}
.sms-manual-id {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}
.sms-manual-phone {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.5px;
}
.sms-manual-code {
  width: 80px;
  height: 30px;
  font-size: 14px;
  font-weight: 600;
  padding: 0 6px;
  letter-spacing: 3px;
  text-align: center;
}

/* Retry button with a «same device» checkbox */
.retry-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.retry-pin {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.retry-pin input[type=checkbox] {
  margin: 0;
  cursor: pointer;
}
.retry-pin:hover { color: var(--ink); }

/* ------------------------------------------------------------------
   Mobile
   ------------------------------------------------------------------ */
@media (max-width: 720px) {
  header { padding: 12px 16px; flex-direction: column; align-items: flex-start; gap: 8px; }
  nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  main { padding: 16px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  table { font-size: 12px; }
  th, td { padding: 8px 10px; }
  h1 { font-size: 18px; }

  /* Help page — mobile adjustments */
  .help-wrap { padding: 0 0 32px; }
  .help-hero { padding: 28px 16px 24px; }
  .help-hero-title { font-size: 30px; }
  .help-hero-lead { font-size: 14px; margin-bottom: 24px; }
  .help-hero-steps { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .help-hero-step:nth-child(4),
  .help-hero-step:nth-child(5) {
    grid-column: span 1;
  }
  .help-hero-step { padding: 14px 6px 12px; }
  .help-hero-step .step-icon { font-size: 24px; }
  .help-hero-step .step-label { font-size: 12px; }
  .help-hero-step .step-hint { display: none; }

  .help-tabs {
    padding: 3px;
    gap: 2px;
  }
  .help-tab { padding: 8px 6px; font-size: 12px; gap: 4px; }
  .help-tab span { font-size: 14px; }

  .help-acc > summary { padding: 14px 16px; grid-template-columns: 36px 1fr auto; grid-column-gap: 10px; }
  .help-acc .acc-icon { font-size: 24px; }
  .help-acc .acc-title { font-size: 15px; }
  .help-acc .acc-hint { font-size: 11px; }
  .help-acc .acc-body { padding: 16px 16px 18px; }

  .help-mini-cards { grid-template-columns: 1fr; }
  .help-pill-grid { grid-template-columns: 1fr; }
  .help-faq-grid { grid-template-columns: 1fr; }
  .help-glossary { grid-template-columns: 1fr; }
}
