/* Панель управления — Telegram Mini App.
   Цвета берутся из темы Telegram (--tg-theme-*); значения после запятой —
   запасные, для открытия вне Telegram. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --sbg: var(--tg-theme-secondary-bg-color, #efeff4);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec-hdr: var(--tg-theme-section-header-text-color, var(--hint));
  --sep: var(--tg-theme-section-separator-color, rgba(60, 60, 67, .29));
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --ok: #34c759;
  --warn: #ff9500;
  --radius: 12px;
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #1c1c1d);
    --sbg: var(--tg-theme-secondary-bg-color, #000000);
    --section: var(--tg-theme-section-bg-color, #1c1c1d);
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #98989e);
    --link: var(--tg-theme-link-color, #3e88f7);
    --btn: var(--tg-theme-button-color, #3e88f7);
    --sep: var(--tg-theme-section-separator-color, rgba(84, 84, 88, .65));
    --danger: var(--tg-theme-destructive-text-color, #eb5545);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { background: var(--sbg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  color: var(--text); font-size: 16px; line-height: 1.35;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
.sprite { position: absolute; }
svg.ic { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

#app { padding: 8px 16px calc(96px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; min-height: 100vh; }
body.no-main #app { padding-bottom: calc(32px + var(--safe-bottom)); }

/* Заголовок экрана (у Telegram своя шапка — здесь только крупный заголовок) */
.title { font-size: 28px; font-weight: 700; letter-spacing: -.01em; padding: 8px 4px 4px; }
.subtitle { color: var(--hint); font-size: 15px; padding: 0 4px; }

/* Секции в стиле настроек Telegram */
.hdr { font-size: 13px; color: var(--sec-hdr); padding: 22px 16px 7px; display: flex; justify-content: space-between; gap: 12px; }
.foot { font-size: 13px; color: var(--hint); padding: 7px 16px 0; }
.group { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.cell { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 48px; width: 100%;
  position: relative; text-align: left; color: var(--text); }
button.cell:active, a.cell:active { background: color-mix(in srgb, var(--text) 8%, transparent); }
.cell + .cell::before { content: ""; position: absolute; top: 0; right: 0; left: 58px; height: .5px; background: var(--sep); }
.cell.plain + .cell.plain::before, .cell.plain + .cell::before { left: 16px; }
.cell .body { flex: 1; min-width: 0; padding: 10px 0; }
.cell .body small { display: block; color: var(--subtitle); font-size: 13px; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .val { color: var(--hint); font-size: 15px; display: flex; align-items: center; gap: 6px; text-align: right; }
.cell .chev { color: var(--hint); opacity: .55; width: 16px; height: 16px; stroke-width: 2.2; }
.cell.link .body { color: var(--link); }
.cell.danger .body { color: var(--danger); }
.cell.center .body { text-align: center; }
.cell[disabled] { opacity: .45; pointer-events: none; }

.sq { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; }
.sq svg.ic { width: 18px; height: 18px; stroke-width: 2; }
.c-blue { background: #2f8cf0; } .c-green { background: var(--ok); } .c-purple { background: #8e5cf7; }
.c-orange { background: var(--warn); } .c-gray { background: #8e8e93; } .c-teal { background: #30b0c7; }
.c-red { background: var(--danger); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; flex: none; }
.dot.off { background: color-mix(in srgb, var(--hint) 45%, transparent); }
.pill { font-size: 12px; font-weight: 600; border-radius: 10px; padding: 2px 8px; white-space: nowrap; }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.pill.bad { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* Статус */
.hero { background: var(--section); border-radius: var(--radius); padding: 16px; display: flex; gap: 14px; align-items: center; margin-top: 8px; }
.hero .sq { width: 48px; height: 48px; border-radius: 13px; }
.hero .sq svg.ic { width: 28px; height: 28px; }
.hero b { font-size: 19px; font-weight: 600; display: block; }
.hero small { color: var(--hint); font-size: 14px; display: block; margin-top: 2px; }
.traffic { display: flex; gap: 14px; color: var(--hint); font-size: 13px; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* Карточка клиента */
.who { display: flex; flex-direction: column; align-items: center; padding: 16px 0 4px; text-align: center; }
.who .sq { width: 76px; height: 76px; border-radius: 22px; margin-bottom: 10px; }
.who .sq svg.ic { width: 40px; height: 40px; stroke-width: 1.7; }
.who h1 { font-size: 24px; font-weight: 600; word-break: break-all; }
.who small { color: var(--hint); font-size: 15px; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.acts { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-top: 16px; }
.acts button { background: var(--section); border-radius: var(--radius); padding: 10px 4px 9px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; color: var(--link); font-size: 13px; line-height: 1.2; }
.acts button:active { opacity: .6; }
.acts svg.ic { width: 24px; height: 24px; }

/* Поля ввода */
.field { display: flex; align-items: center; gap: 10px; padding: 0 16px; min-height: 48px; }
.field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 12px 0; font-size: 16px; }
.field input::placeholder { color: var(--hint); }
.field .addbtn { color: var(--link); font-size: 16px; font-weight: 500; padding: 8px 0 8px 8px; }
.field .addbtn[disabled] { opacity: .4; }
.seg { display: flex; background: color-mix(in srgb, var(--hint) 18%, transparent); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { flex: 1; padding: 6px 0; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--text); }
.seg button.on { background: var(--section); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-wrap { padding: 10px 16px; }
.check { color: var(--link); }
.check svg.ic { width: 20px; height: 20px; stroke-width: 2.2; }
.box { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--hint) 60%, transparent);
  display: grid; place-items: center; flex: none; }
.box.on { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.box.on svg.ic { width: 14px; height: 14px; stroke-width: 3; }

pre.out { background: var(--section); border-radius: var(--radius); padding: 12px 14px; font: 12px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; color: var(--text); max-height: 60vh; overflow: auto; }

/* Состояния */
.empty { text-align: center; color: var(--hint); padding: 48px 24px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
#gate { padding-top: 30vh; }
.skel { background: var(--section); border-radius: var(--radius); height: 80px; margin-top: 8px; position: relative; overflow: hidden; }
.skel::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--hint) 12%, transparent), transparent);
  animation: shimmer 1.2s infinite; }
.skel.tall { height: 220px; }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* Нижняя кнопка вне Telegram (в Telegram — нативная MainButton) */
#mainbar { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 16px calc(12px + var(--safe-bottom)); background: var(--sbg); }
#mainbtn { width: 100%; max-width: 608px; margin: 0 auto; display: block; height: 50px; border-radius: 12px; background: var(--btn); color: var(--btn-text);
  font-weight: 600; font-size: 16px; }
#mainbtn[disabled] { opacity: .5; }
#devbar { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: .5px solid var(--sep); display: flex; align-items: center;
  justify-content: center; min-height: 44px; font-size: 15px; font-weight: 600; }
#devback { position: absolute; left: 12px; color: var(--link); font-weight: 400; }

/* Нижний лист (QR, пароль, срок) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease-out; }
.sheet { background: var(--sbg); width: 100%; max-width: 640px; border-radius: 14px 14px 0 0; padding: 8px 16px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow: auto; animation: up .22s ease-out; }
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--hint) 45%, transparent); margin: 0 auto 10px; }
.sheet h2 { font-size: 20px; font-weight: 600; text-align: center; margin-bottom: 4px; }
.sheet .lead { text-align: center; color: var(--hint); font-size: 14px; margin-bottom: 14px; }
.sheet .primary { width: 100%; height: 50px; border-radius: 12px; background: var(--btn); color: var(--btn-text); font-weight: 600; margin-top: 16px; }
.sheet .primary[disabled] { opacity: .5; }
.sheet .secondary { width: 100%; height: 44px; color: var(--link); margin-top: 6px; }
.qr { background: #fff; border-radius: 16px; padding: 14px; width: min(78vw, 320px); margin: 0 auto; }
.qr img { display: block; width: 100%; image-rendering: pixelated; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

#toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translateX(-50%); z-index: 30;
  background: color-mix(in srgb, var(--text) 86%, transparent); color: var(--bg); font-size: 14px; padding: 10px 16px; border-radius: 12px;
  max-width: calc(100vw - 32px); text-align: center; }
#toast.err { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

button.hero { width: 100%; text-align: left; color: var(--text); }
button.hero:active { opacity: .7; }
.hero .body { flex: 1; min-width: 0; }
.field > svg.ic { color: var(--hint); }
