/* Личный кабинет: адаптивный интерфейс без внешних шрифтов и скриптов (CSP: style-src 'self').
   Мобильные устройства первыми, светлая и тёмная темы по настройке системы. */
:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1100px 520px at 12% -10%, #dfe7ff 0%, rgba(223, 231, 255, 0) 60%),
             radial-gradient(900px 480px at 100% 0%, #e7f5ff 0%, rgba(231, 245, 255, 0) 55%);
  --surface: #ffffff;
  --surface-2: #f1f4fa;
  --text: #121826;
  --muted: #5b667a;
  --border: #e3e8f2;
  --accent: #3d6bff;
  --accent-2: #6a4dff;
  --accent-contrast: #ffffff;
  --accent-soft: #e8edff;
  --ok: #0f9d58;
  --ok-soft: #e4f6ec;
  --warn: #c77700;
  --warn-soft: #fff1d6;
  --off: #667085;
  --off-soft: #eceff4;
  --danger: #d92d20;
  --danger-soft: #fde8e6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 16px;
  --radius-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c111b;
    --bg-grad: radial-gradient(1100px 520px at 12% -10%, #1a2550 0%, rgba(26, 37, 80, 0) 60%),
               radial-gradient(900px 480px at 100% 0%, #122a3a 0%, rgba(18, 42, 58, 0) 55%);
    --surface: #151c2b;
    --surface-2: #1b2437;
    --text: #e8ecf5;
    --muted: #9aa6bd;
    --border: #263147;
    --accent: #6f8dff;
    --accent-2: #8f7bff;
    --accent-soft: #1d2748;
    --ok: #4cd08a;
    --ok-soft: #12301f;
    --warn: #f2b34d;
    --warn-soft: #3a2a0c;
    --off: #9aa6bd;
    --off-soft: #222b3d;
    --danger: #ff7a70;
    --danger-soft: #3c1714;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg) var(--bg-grad) no-repeat; color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
h1 { font-size: clamp(1.45rem, 1.1rem + 1.6vw, 2rem); line-height: 1.2; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
p { margin: 0 0 12px; }
.wrap { width: 100%; max-width: 920px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 460px; }
.hint, .muted { color: var(--muted); }
.hint { font-size: .9rem; }
.page { padding-top: 20px; padding-bottom: 48px; }
.page-head { margin-bottom: 18px; }
.page-sub { color: var(--muted); margin: 0; }

/* верхняя панель */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; min-height: 58px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 16px rgba(61, 107, 255, .35); }
.brand-mark svg { width: 20px; height: 20px; }
.spacer { flex: 1; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 8px 12px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: .95rem; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-form { margin: 0; }
button.link { background: none; border: 0; padding: 8px 10px; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-radius: 999px; box-shadow: none; }
button.link:hover { background: var(--surface-2); color: var(--text); filter: none; }
@media (max-width: 640px) {
  .topbar .wrap { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; row-gap: 6px; }
  .tabs { order: 3; width: 100%; }
  .tabs a { flex: 1; text-align: center; padding: 9px 6px; }
  .brand-name { font-size: .98rem; }
}

/* карточки и поверхности */
.card, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; }
.panel + .panel { margin-top: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(2, 1fr); } }
.device { display: flex; flex-direction: column; gap: 10px; }
.device-top { display: flex; align-items: flex-start; gap: 12px; }
.device-icon { flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); }
.device-icon.off { background: var(--off-soft); color: var(--off); }
.device-icon svg { width: 24px; height: 24px; }
.device-name { font-weight: 700; font-size: 1.1rem; color: var(--text); word-break: break-word; line-height: 1.25; }
.device-meta { color: var(--muted); font-size: .92rem; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem;
  font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-soft); }
.pill.off { color: var(--off); background: var(--off-soft); }
.pill.warn { color: var(--warn); background: var(--warn-soft); }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: .92rem; }
.stat-row b { color: var(--text); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 4px; }

/* кнопки */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border: 1px solid transparent;
  border-radius: 12px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-contrast);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; transition: transform .06s ease, box-shadow .15s ease, filter .15s ease;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 32%, transparent); -webkit-tap-highlight-color: transparent; }
button:hover, .button:hover { filter: brightness(1.06); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
button.secondary, .button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: none; }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); filter: none; }
.button.small, button.small { padding: 8px 14px; border-radius: 10px; font-size: .92rem; }
.button.wide, button.wide { width: 100%; }
.button.telegram { background: linear-gradient(135deg, #2aabee, #229ed9); box-shadow: 0 8px 20px rgba(34, 158, 217, .35); padding: 14px 18px; font-size: 1.02rem; }
.button svg, button svg { width: 20px; height: 20px; flex: none; }
form.inline { display: inline-block; margin: 0; }

/* формы */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
input[type="text"], input[type="password"], textarea {
  width: 100%; padding: 13px 14px; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1.5px solid var(--border); border-radius: 12px; transition: border-color .15s ease, box-shadow .15s ease, background .15s ease; }
input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input:focus, textarea:focus { outline: none; background: var(--surface); border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.input-wrap { position: relative; }
.input-wrap input { padding-right: 52px; }
.toggle-pw { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; padding: 0;
  background: none; border: 0; box-shadow: none; color: var(--muted); border-radius: 10px; }
.toggle-pw:hover { background: var(--surface-2); filter: none; color: var(--text); }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: .95rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.notice { background: var(--ok-soft); color: var(--ok); }
.alert svg { flex: none; width: 20px; height: 20px; margin-top: 2px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 22px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* вход */
.auth { min-height: 100vh; display: grid; align-items: center; padding-top: 28px; padding-bottom: 40px; }
.auth-card { padding: 28px 24px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; margin-bottom: 22px; }
.auth-logo .brand-mark { width: 60px; height: 60px; border-radius: 18px; }
.auth-logo .brand-mark svg { width: 32px; height: 32px; }
.auth-logo h1 { margin: 0; }
.steps { color: var(--muted); font-size: .9rem; margin: 10px 2px 0; }

/* устройство */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.stat small { display: block; color: var(--muted); font-size: .8rem; }
.stat strong { font-size: 1.15rem; letter-spacing: -.01em; }
.link-box { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; resize: vertical; min-height: 96px; }
.connect { display: grid; gap: 18px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 720px) { .connect { grid-template-columns: 1fr 240px; } }
.qr-wrap { background: #fff; border-radius: 14px; padding: 12px; justify-self: center; border: 1px solid var(--border); }
.qr { display: block; width: 100%; max-width: 216px; height: auto; image-rendering: pixelated; }
.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.bars li { display: grid; grid-template-columns: 3.2em 1fr 6.5em; gap: 10px; align-items: center; font-size: .9rem; }
.bar { width: 100%; height: 10px; border: 0; border-radius: 6px; overflow: hidden; background: var(--surface-2);
  -webkit-appearance: none; appearance: none; }
.bar::-webkit-progress-bar { background: var(--surface-2); }
.bar::-webkit-progress-value { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 6px; }
.bar::-moz-progress-bar { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 6px; }
.amount { text-align: right; color: var(--muted); }
.row-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row-form .field { flex: 1 1 220px; margin: 0; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.back svg { width: 18px; height: 18px; }

/* справка */
.article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; overflow: hidden; }
.article summary { cursor: pointer; font-weight: 700; padding: 14px 16px; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.article summary::-webkit-details-marker { display: none; }
.article summary::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s ease; flex: none; margin-right: 4px; }
.article[open] summary::after { transform: rotate(-135deg); }
.article[open] summary { border-bottom: 1px solid var(--border); }
.text { white-space: pre-line; }
.article .text { padding: 14px 16px 16px; }
.text a { word-break: break-all; }
.intro { margin-bottom: 18px; }

/* пустые состояния и сообщения */
.empty { text-align: center; padding: 34px 18px; }
.empty .device-icon { margin: 0 auto 12px; width: 56px; height: 56px; border-radius: 16px; }
.message { text-align: center; padding: 30px 22px; }
.message .device-icon { margin: 0 auto 14px; }
.settings-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.after-grid { margin-top: 16px; }
.centered { text-align: center; }
.inline-h { margin: 0; }
.section-title { margin: 22px 0 10px; }
button svg + span { margin-left: 0; }
