/* ==========================================================================
   Панель дома — Mini App. Визуальная система повторяет vpnbot:
   Telegram-темы + aurora-фон, карточки radius 14, семантические токены.
   ========================================================================== */

:root {
  /* Telegram theme defaults (fallback вне WebApp SDK) */
  --tg-theme-bg-color: #17212b;
  --tg-theme-text-color: #ffffff;
  --tg-theme-hint-color: #708499;
  --tg-theme-link-color: #6ab3f3;
  --tg-theme-button-color: #5288c1;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #232e3c;
  --tg-theme-section-bg-color: #1a2634;
  --tg-theme-section-separator-color: #0f1822;

  --color-bg: var(--tg-theme-bg-color);
  --color-bg-secondary: var(--tg-theme-secondary-bg-color);
  --color-bg-section: var(--tg-theme-section-bg-color);
  --color-bg-elevated: #243140;
  --color-text: var(--tg-theme-text-color);
  --color-text-hint: var(--tg-theme-hint-color);
  --color-link: var(--tg-theme-link-color);
  --color-button: var(--tg-theme-button-color);
  --color-button-text: var(--tg-theme-button-text-color);
  --color-separator: var(--tg-theme-section-separator-color);
  --color-success: #22c55e;
  --color-warning: #eab308;
  --color-danger: #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

html { background: var(--color-bg); }

body {
  background:
    linear-gradient(180deg,
      var(--color-bg) 0%,
      color-mix(in srgb, var(--color-bg) 88%, #1e3a5f) 60%,
      color-mix(in srgb, var(--color-bg) 82%, #27496b) 100%);
  background-attachment: fixed;
  transition: background-color .25s ease, color .25s ease;
}

/* ---------- Aurora (как в vpnbot) ---------- */
.aurora-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.aurora-layer::before,
.aurora-layer::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .75;
  will-change: transform;
}
.aurora-layer::before {
  width: 420px; height: 420px; top: -120px; left: -80px;
  background: radial-gradient(circle, rgba(106,179,243,.38) 0%, rgba(106,179,243,0) 65%);
  animation: aurora-a 18s ease-in-out infinite alternate;
}
.aurora-layer::after {
  width: 380px; height: 380px; bottom: -140px; right: -100px;
  background: radial-gradient(circle, rgba(139,92,246,.32) 0%, rgba(139,92,246,0) 65%);
  animation: aurora-b 22s ease-in-out infinite alternate-reverse;
}
@keyframes aurora-a { from { transform: translate3d(0,0,0); } to { transform: translate3d(90px,140px,0); } }
@keyframes aurora-b { from { transform: translate3d(0,0,0); } to { transform: translate3d(-110px,-120px,0); } }

#app {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 var(--space-4) calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 14px 0 12px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--color-bg) 92%, transparent) 60%, transparent);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; font-size: 19px;
  background: linear-gradient(145deg, #2a3d52, #1b2b3d);
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.brand-text { min-width: 0; }
.brand-title { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.brand-sub { font-size: 11.5px; color: var(--color-text-hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 12px; border: 1px solid rgba(255,255,255,.07);
  background: rgba(255,255,255,.04);
  color: var(--color-text-hint); cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.icon-btn:active { transform: scale(.94); background: rgba(255,255,255,.08); }
.icon-btn.spin svg { animation: spin .6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */
.card {
  background: var(--color-bg-section);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
}
.section-label {
  display: block;
  margin: 18px 2px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-text-hint);
}
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 2px 8px; }
.section-head .section-label { margin: 0; }
.text-btn {
  background: none; border: 0; padding: 2px 0;
  color: var(--color-link); font-size: 13px; font-weight: 600; cursor: pointer;
}
.text-btn:disabled { opacity: .5; }

/* ---------- Printer status ---------- */
.status-card {
  display: flex; align-items: center; gap: 12px;
  margin-top: 4px;
}
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--color-text-hint);
  box-shadow: 0 0 0 4px rgba(112,132,153,.14);
  flex: 0 0 10px;
  transition: background .2s ease, box-shadow .2s ease;
}
.status-dot.online { background: var(--color-success); box-shadow: 0 0 0 4px rgba(34,197,94,.16); }
.status-dot.offline { background: var(--color-warning); box-shadow: 0 0 0 4px rgba(234,179,8,.14); }
.status-main { flex: 1; min-width: 0; }
.status-name { font-weight: 600; font-size: 14.5px; }
.status-hint { font-size: 12.5px; color: var(--color-text-hint); }
.pill {
  font-size: 11.5px; font-weight: 650; padding: 5px 10px; border-radius: 999px;
  background: rgba(255,255,255,.06); color: var(--color-text-hint);
  white-space: nowrap;
}
.pill.online { background: rgba(34,197,94,.14); color: #6ee7a0; }
.pill.offline { background: rgba(234,179,8,.14); color: #fbbf24; }

/* ---------- Upload ---------- */
.upload-card {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 22px 16px;
  margin-top: 12px;
  border: 1.5px dashed rgba(106,179,243,.35);
  background: linear-gradient(180deg, rgba(82,136,193,.10), rgba(82,136,193,.03));
  color: var(--color-text);
  cursor: pointer;
  font: inherit;
  transition: border-color .2s ease, transform .12s ease;
}
.upload-card:active { transform: scale(.985); border-color: rgba(106,179,243,.6); }
.upload-icon { font-size: 26px; }
.upload-title { font-weight: 650; font-size: 15px; }
.upload-hint { font-size: 12px; color: var(--color-text-hint); text-align: center; }
.upload-progress { font-size: 12.5px; color: var(--color-link); margin-top: 6px; }

/* ---------- Draft ---------- */
.draft-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.draft-title { font-weight: 650; font-size: 15px; word-break: break-word; }
.draft-meta { font-size: 12.5px; color: var(--color-text-hint); }

.pages {
  display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.pages::-webkit-scrollbar { display: none; }
.page-thumb {
  position: relative; flex: 0 0 92px; width: 92px;
  padding: 0; border: 0; border-radius: 10px; overflow: hidden;
  background: #0e1620; cursor: pointer;
  box-shadow: 0 0 0 2px transparent, 0 4px 12px rgba(0,0,0,.25);
  transition: box-shadow .18s ease, transform .12s ease;
  scroll-snap-align: start;
}
.page-thumb img { display: block; width: 92px; height: 130px; object-fit: cover; opacity: .82; transition: opacity .18s ease; }
.page-thumb.selected { box-shadow: 0 0 0 2px var(--color-link), 0 6px 16px rgba(0,0,0,.3); }
.page-thumb.selected img { opacity: 1; }
.page-thumb:not(.selected)::after {
  content: ""; position: absolute; inset: 0; background: rgba(10,16,24,.45);
}
.page-num {
  position: absolute; left: 6px; bottom: 6px; z-index: 2;
  font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #fff;
}
.page-check {
  position: absolute; right: 6px; top: 6px; z-index: 2;
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px;
  background: var(--color-link); color: #06121f;
  opacity: 0; transform: scale(.7); transition: opacity .15s ease, transform .15s ease;
}
.page-thumb.selected .page-check { opacity: 1; transform: scale(1); }

.quick-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.range-preview { margin-left: auto; font-size: 12px; color: var(--color-text-hint); font-variant-numeric: tabular-nums; }

.chip {
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
  color: var(--color-text);
  border-radius: 999px; padding: 6px 12px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.chip:active { transform: scale(.96); }
.chip.active {
  background: rgba(106,179,243,.16);
  border-color: rgba(106,179,243,.45);
  color: #9fd0ff;
}

/* ---------- Params ---------- */
.params { margin-top: 12px; padding: 4px 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.row-label { font-size: 14px; }
.divider { height: 1px; background: var(--color-separator); opacity: .8; }

.stepper { display: flex; align-items: center; gap: 2px; background: rgba(255,255,255,.05); border-radius: 10px; padding: 2px; }
.stepper button {
  width: 34px; height: 32px; border: 0; border-radius: 8px;
  background: transparent; color: var(--color-text);
  font-size: 18px; font-weight: 600; cursor: pointer;
}
.stepper button:active { background: rgba(255,255,255,.09); }
.stepper span { min-width: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.segmented { display: flex; background: rgba(255,255,255,.05); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--color-text-hint);
  font-size: 12.5px; font-weight: 600; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.segmented button.active { background: var(--color-button); color: var(--color-button-text); }

.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex: 0 0 46px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; border-radius: 999px;
  background: rgba(255,255,255,.12); transition: background .2s ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3);
  transition: transform .2s ease;
}
.switch input:checked + .switch-track { background: var(--color-success); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }

/* ---------- CTA ---------- */
.cta {
  width: 100%; margin-top: 14px; padding: 15px 16px;
  border: 0; border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #5f9ad6, #4a7fbe);
  color: #fff; font-size: 15.5px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(74,127,190,.32);
  transition: transform .12s ease, filter .15s ease;
}
.cta:active { transform: scale(.985); filter: brightness(.96); }
.cta:disabled { opacity: .55; cursor: default; }
.cta-ghost {
  width: 100%; margin-top: 8px; padding: 12px;
  border: 0; background: none; color: var(--color-text-hint);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
}

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--color-bg-section);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.item-main { flex: 1; min-width: 0; }
.item-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12px; color: var(--color-text-hint); margin-top: 2px; }
.item-actions { display: flex; gap: 6px; }
.mini-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04); color: var(--color-text);
  font-size: 15px; cursor: pointer;
}
.mini-btn:active { background: rgba(255,255,255,.1); }
.mini-btn.danger { color: #ff8b8b; }
.empty { text-align: center; color: var(--color-text-hint); font-size: 13px; padding: 14px 8px; }

/* ---------- DNS card ---------- */
.dns-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.dns-left { display: flex; align-items: center; gap: 12px; }
.dns-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  font-size: 20px; background: rgba(106,179,243,.12); border: 1px solid rgba(106,179,243,.2);
}
.dns-title { font-weight: 650; font-size: 15px; }
.dns-hint { font-size: 12px; color: var(--color-text-hint); }

/* ---------- Summary ---------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.summary-item {
  background: var(--color-bg-section); border: 1px solid rgba(255,255,255,.05);
  border-radius: var(--radius-md); padding: 12px 10px; text-align: center;
}
.summary-value { display: block; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-label { font-size: 11px; color: var(--color-text-hint); }

/* ---------- Chips row ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips .chip { flex: 0 0 auto; }

/* ---------- Device card ---------- */
.device {
  background: var(--color-bg-section);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.device-top { display: flex; align-items: center; gap: 12px; }
.device-icon {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 20px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.06);
}
.device-info { flex: 1; min-width: 0; }
.device-name { font-size: 14.5px; font-weight: 650; display: flex; align-items: center; gap: 6px; }
.device-online { width: 7px; height: 7px; border-radius: 50%; background: #4b5a6b; flex: 0 0 7px; }
.device-online.on { background: var(--color-success); box-shadow: 0 0 0 3px rgba(34,197,94,.14); }
.device-meta { font-size: 11.5px; color: var(--color-text-hint); font-variant-numeric: tabular-nums; margin-top: 2px; }
.device-mac { opacity: .7; }
.device-edit {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid rgba(255,255,255,.07);
  background: rgba(255,255,255,.04); color: var(--color-text-hint); cursor: pointer; font-size: 14px;
}
.device-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.05);
  border-radius: 10px; padding: 8px 10px;
}
.toggle-label { font-size: 12px; color: var(--color-text-hint); display: flex; align-items: center; gap: 6px; }
.toggle-row .switch { width: 38px; height: 23px; flex: 0 0 38px; }
.toggle-row .switch-track::after { width: 17px; height: 17px; top: 3px; left: 3px; }
.toggle-row .switch input:checked + .switch-track::after { transform: translateX(15px); }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; justify-content: center; gap: 6px;
  background: color-mix(in srgb, var(--color-bg) 78%, transparent);
  backdrop-filter: blur(18px);
  border-top: 1px solid rgba(255,255,255,.06);
}
.tab {
  flex: 1; max-width: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; cursor: pointer;
  color: var(--color-text-hint); font-size: 11px; font-weight: 600;
  transition: color .15s ease;
}
.tab-icon { font-size: 20px; line-height: 1; filter: grayscale(.6); transition: filter .15s ease, transform .15s ease; }
.tab.active { color: var(--color-link); }
.tab.active .tab-icon { filter: none; transform: translateY(-1px); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(8px);
  z-index: 40; max-width: min(88vw, 420px);
  padding: 11px 16px; border-radius: 12px;
  background: #253446; color: #fff; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 14px 34px rgba(0,0,0,.4);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #4a1f24; color: #ffb4b4; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(4,8,14,.6); backdrop-filter: blur(3px);
}
.modal-card {
  width: 100%; max-width: 640px;
  background: var(--color-bg-secondary);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  box-shadow: 0 -18px 44px rgba(0,0,0,.45);
  animation: sheet-up .22s ease;
}
@keyframes sheet-up { from { transform: translateY(28px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-sub { font-size: 12px; color: var(--color-text-hint); margin-top: 2px; font-variant-numeric: tabular-nums; }
.input {
  width: 100%; margin-top: 14px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.05); color: var(--color-text);
  font-size: 15px; outline: none;
}
.input:focus { border-color: rgba(106,179,243,.6); }
.type-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.type-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px; border-radius: 11px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.07); background: rgba(255,255,255,.03);
  color: var(--color-text); font-size: 17px;
}
.type-btn span { font-size: 10px; color: var(--color-text-hint); }
.type-btn.active { border-color: rgba(106,179,243,.55); background: rgba(106,179,243,.14); }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn-ghost, .btn-primary {
  flex: 1; padding: 13px; border-radius: 12px; font-size: 14.5px; font-weight: 700; cursor: pointer;
}
.btn-ghost { border: 1px solid rgba(255,255,255,.1); background: transparent; color: var(--color-text-hint); }
.btn-primary { border: 0; background: var(--color-button); color: var(--color-button-text); }

/* ---------- Auth error ---------- */
.auth-error {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--color-bg);
}
.auth-error-card { text-align: center; max-width: 320px; }
.auth-icon { font-size: 40px; }
.auth-title { font-size: 18px; font-weight: 700; margin-top: 10px; }
.auth-text { color: var(--color-text-hint); font-size: 13.5px; margin-top: 6px; }

.hidden { display: none !important; }
