/* Хаб — дизайн-токены. Светлая/тёмная темы выбраны отдельно (не автоинверсия). */

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --hairline: #e1e0d9;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --hairline: #2c2c2a;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --good-text: #0ca30c;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--page);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem 1.5rem 3rem;
  transition: background 0.2s, color 0.2s;
}

main {
  width: 100%;
  max-width: 860px;
}

/* ── Шапка ─────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.subtitle {
  color: var(--ink-3);
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.head-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.logout-button {
  height: 38px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.85rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.logout-button:hover { color: var(--crit); border-color: var(--crit); }
.logout-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.logout-button[hidden] { display: none; }

.icon-sun { display: none; }
.icon-moon { display: block; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ── Секции ────────────────────────────────── */

.section { margin-bottom: 2.25rem; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.section-title {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.section-meta {
  font-size: 0.75rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.placeholder {
  color: var(--ink-3);
  font-size: 0.85rem;
  padding: 1rem 0;
}

/* ── Серверы ───────────────────────────────── */

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.75rem;
}

.server-card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  padding: 0.95rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.server-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.server-name { font-weight: 650; font-size: 0.95rem; }

.server-host {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-3);
  margin-left: auto;
}

/* Статус: точка + подпись (никогда только цвет) */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.74rem;
  font-weight: 600;
}

.status-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-online { color: var(--good-text); }
.status-online .dot { background: var(--good); }
.status-offline { color: var(--crit); }
.status-offline .dot { background: var(--crit); }

/* Диск: тонкий метр + подпись */
.meter-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--ink-2);
}

.meter-label { flex-shrink: 0; color: var(--ink-3); }

.meter {
  flex: 1;
  min-width: 3rem;
  height: 6px;
  border-radius: 3px;
  background: var(--hairline);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--good);
}

.meter-fill.warning { background: var(--warn); }
.meter-fill.critical { background: var(--crit); }

.meter-value {
  min-width: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.meter-alert, .meter-unavailable { color: var(--serious); font-weight: 600; }
.meter-critical { color: var(--crit); font-weight: 600; }

/* Оплата */
.paid-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.paid-expired { color: var(--crit); font-weight: 600; }
.paid-soon { color: var(--ink); font-weight: 600; }
.paid-unverified { color: var(--serious); font-weight: 600; }
.paid-soon .paid-ico, .paid-expired .paid-ico, .paid-unverified .paid-ico { flex-shrink: 0; }

/* Пробы */
.probe-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.probe {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--ink-2);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-variant-numeric: tabular-nums;
}

.probe-mark { font-weight: 700; }
.probe-ok .probe-mark { color: var(--good-text); }
.probe-fail { border-color: var(--crit); }
.probe-fail .probe-mark { color: var(--crit); }

/* Бекап */
.backup-row {
  font-size: 0.75rem;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.backup-row .probe-mark { font-weight: 700; }
.backup-ok .probe-mark { color: var(--good-text); }
.backup-fail { color: var(--crit); }
.backup-row code { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-3); }

/* Кнопки конфигов */
.config-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.btn {
  font-family: var(--font);
  font-size: 0.76rem;
  font-weight: 550;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--ring);
  border-radius: 8px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

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

.btn-quiet { color: var(--ink-2); }

/* Раскрытый конфиг */
.config-reveal {
  border-top: 1px solid var(--hairline);
  padding-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.config-reveal[hidden] { display: none; }

.config-reveal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 600;
}

.btn-close {
  background: none;
  border: none;
  color: var(--ink-3);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0 0.25rem;
}
.btn-close:hover { color: var(--crit); }

.config-uri {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--ink-2);
  word-break: break-all;
  background: var(--page);
  border: 1px solid var(--hairline);
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  max-height: 96px;
  overflow-y: auto;
}

.config-note { font-size: 0.72rem; color: var(--ink-3); }
.config-error { font-size: 0.78rem; color: var(--crit); }

.config-qr {
  align-self: center;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
  line-height: 0;
}
.config-qr img { width: 220px; height: 220px; image-rendering: pixelated; }

/* ── Доступ к VPN-конфигам ────────────────── */

.auth-dialog {
  width: min(420px, calc(100vw - 2rem));
  max-width: none;
  margin: auto;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

.auth-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(2px);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
}

.auth-dialog-head { margin-bottom: 0.15rem; }

.auth-dialog-head h2 {
  font-size: 1.05rem;
  line-height: 1.3;
  margin-bottom: 0.3rem;
}

.auth-dialog-head p {
  color: var(--ink-2);
  font-size: 0.82rem;
}

.auth-dialog-head code {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.auth-label {
  color: var(--ink-2);
  font-size: 0.78rem;
  font-weight: 600;
}

.auth-label code {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.76rem;
}

.auth-yandex {
  width: 100%;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  color: #fff;
  background: #111;
  border: 1px solid #111;
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.auth-yandex:hover {
  background: #292929;
  border-color: #292929;
}

.auth-yandex:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.auth-yandex-mark {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #e00000;
  background: #fff;
  border-radius: 50%;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ink-3);
  font-size: 0.72rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  height: 1px;
  flex: 1;
  background: var(--hairline);
}

.auth-input {
  width: 100%;
  min-height: 42px;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--hairline);
  border-radius: 9px;
  padding: 0.55rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.9rem;
}

.auth-input:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 1px;
}

.auth-error {
  color: #b42318;
  font-size: 0.78rem;
}

.auth-error[hidden] { display: none; }

.auth-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.auth-actions .btn {
  min-height: 38px;
  padding-inline: 1rem;
}

.auth-submit {
  color: #fff;
  background: #1d63b8;
  border-color: #1d63b8;
}

.auth-submit:hover {
  color: #fff;
  background: #174f94;
}

:root[data-theme="dark"] .auth-error {
  color: #ff8a80;
}

:root[data-theme="dark"] .auth-submit,
:root[data-theme="dark"] .auth-submit:hover {
  color: #07111f;
  background: #7db5f8;
  border-color: #7db5f8;
}

:root[data-theme="dark"] .auth-submit:hover {
  background: #9bc5fa;
}

.auth-submit:disabled,
.auth-actions .btn:disabled,
.auth-yandex:disabled {
  cursor: wait;
  opacity: 0.58;
}

/* ── API balance tiles ─────────────────────── */

.stat-row {
  margin-top: 0.75rem;
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.stat-row[hidden],
.stat-tile[hidden] { display: none; }

.stat-tile {
  flex: 1 1 300px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  padding: 0.8rem 1.1rem;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s;
}

.stat-tile[href]:hover { border-color: var(--accent); }

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stat-value.low { color: var(--crit); }

.stat-sub {
  color: var(--accent);
  font-size: 0.74rem;
  text-decoration: none;
}

.stat-sub:hover { text-decoration: underline; }

/* ── Приложения ────────────────────────────── */

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 0.75rem;
}

.app-tile {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s;
}

.app-tile:hover { border-color: var(--accent); }

.app-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.app-icon-b24 { background: transparent; }

.app-body { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }

.app-name {
  font-size: 0.92rem;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.app-name .ext { color: var(--ink-3); }

.app-desc { font-size: 0.78rem; color: var(--ink-2); }

.app-host {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Состояние системы ─────────────────────── */

.health-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 10px;
  padding: 0.55rem 1rem;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
}

.health-label {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.health-label .dot { width: 8px; height: 8px; border-radius: 50%; }
.health-label .dot.ok { background: var(--good); }
.health-label .dot.warn { background: var(--warn); }
.health-label .dot.bad { background: var(--crit); }

.health-value {
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.73rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

/* ── Подвал ────────────────────────────────── */

.page-foot {
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-3);
  margin-top: 0.5rem;
}

/* ── Адаптив ───────────────────────────────── */

@media (max-width: 560px) {
  body { padding: 1.25rem 1rem 2rem; }
  .server-grid, .app-grid { grid-template-columns: 1fr; }
  .stat-row { flex-direction: column; }
  .stat-tile { width: 100%; }
  .server-host { margin-left: 0; width: 100%; order: 3; }
}
