/* ─── Системный SF стек ──────────────────────────────────────────── */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               system-ui, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ─── Светлая ────────────────────────────────────────────────────── */
:root,
[data-theme="light"] {
  --bg: #f2efe7;
  --paper: #fbfaf5;
  --paper-2: #f5f1e4;
  --ink: #1a1814;
  --ink-soft: #4a463c;
  --hint: #8a8475;
  --line: #e7e2d4;
  --accent: #2f6f4a;
  --accent-soft: #d8e5d8;
  --danger: #b54a3d;
  --danger-soft: #f0d7d2;
  --shadow: 0 1px 0 rgba(20,18,14,.04), 0 8px 24px -12px rgba(20,18,14,.08);
}

/* ─── Тёмная (системная или по toggleType) ────────────────────────── */
[data-theme="dark"] {
  --bg: #14130f;
  --paper: #1d1c17;
  --paper-2: #25241e;
  --ink: #f0ede4;
  --ink-soft: #b8b3a4;
  --hint: #7a7567;
  --line: #2a2922;
  --accent: #6fb88a;
  --accent-soft: #2a3a30;
  --danger: #d97560;
  --danger-soft: #3a2724;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
}

/* ─── Чипы фильтра и сортировки ──────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 6px;
  padding: 0 2px 10px;
  align-items: center;
}
.chip {
  flex: 0 1 auto;
  min-width: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 12.5px;
  border: none;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.chip.active {
  background: var(--ink);
  color: var(--bg);
}
.chip .count {
  opacity: 0.6;
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* Чип сортировки — прижат вправо, отделён внешним видом */
.chip-sort {
  margin-left: auto;
  padding: 6px 10px;
  background: transparent;
  box-shadow: none;
  border: 1px solid var(--line);
}
.chip-sort svg {
  width: 14px; height: 14px;
  pointer-events: none;
}
.chip-sort span {
  pointer-events: none;
}

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

/* На всех кнопках и кликабельных элементах — запрет выделения текста.
   Иначе на Android долгий тап вызывает контекстное меню "Копировать". */
button, .chip, .client, .action-row, .tab, .profile, .icon-btn, .sort-btn {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  padding: 16px 16px calc(80px + env(safe-area-inset-bottom));
}

/* Заголовок страницы */
.page-header {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  align-items: center;
  margin-bottom: 14px;
}
.page-header h1 {
  text-align: center;
  margin: 0;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.015em;
}
.page-header .sub {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--hint);
  text-transform: uppercase;
  margin-top: 2px;
}
.page-header .title-wrap { grid-column: 2; }
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  color: var(--ink-soft);
  cursor: pointer;
  background: none; border: none;
  font-size: 18px;
  font-family: inherit;
}

/* ─── Hero (статус сервера) ──────────────────────────────────────── */
.hero {
  background: var(--paper);
  border-radius: 20px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 500;
}
.badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.badge.off {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge.off .dot { background: var(--danger); }
.pill {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-soft);
}
.hero h2 {
  font-weight: 700;
  font-size: 24px;
  line-height: 1.18;
  letter-spacing: -0.025em;
  margin: 0 0 8px;
}
.hero h2 .status-sub {
  font-weight: 500;
  font-size: 16px;
  color: var(--ink-soft);
  letter-spacing: -0.01em;
}
.hero h2 .flag {
  font-size: 22px;
  vertical-align: -1px;
  margin-right: 2px;
  /* Эмодзи-флаги не должны выделяться */
  user-select: none;
}
.endpoint {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--hint);
  margin-bottom: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--paper-2);
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-value {
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-value .unit {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-left: 3px;
}
.stat-label {
  font-size: 11.5px;
  color: var(--hint);
  margin-top: 2px;
}

/* ─── Quick actions ──────────────────────────────────────────────── */
.quick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 18px;
}
.quick button {
  border: none;
  background: var(--paper);
  border-radius: 16px;
  padding: 14px 4px 11px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  transition: transform .12s ease;
  font-family: var(--font-sans);
  color: var(--ink);
}
.quick button:active { transform: scale(0.96); }
.quick .ico { width: 24px; height: 24px; color: var(--ink-soft); }
.quick .lbl { font-size: 12px; }

/* ─── Список клиентов ────────────────────────────────────────────── */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 6px 10px;
}
.section-head .h {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hint);
}
.section-head .a { font-size: 13px; color: var(--ink-soft); }

.clients {
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.client {
  display: grid;
  grid-template-columns: 38px 1fr 14px;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.client:last-child { border-bottom: none; }
.client:active { background: var(--paper-2); }
.avatar {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
}
.c-name {
  font-weight: 500;
  font-size: 15px;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.c-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--hint);
  margin-top: 2px;
}
.c-meta .sep { opacity: 0.4; margin: 0 4px; }
.c-meta .warp-tag {
  color: var(--accent);
  font-weight: 600;
}
.indicator {
  width: 9px; height: 9px;
  border-radius: 50%;
  justify-self: end;
}
.indicator.on  { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.indicator.off { background: var(--hint); opacity: 0.5; }

/* ─── Карточка клиента ────────────────────────────────────────────── */
.back-row {
  display: flex; align-items: center; gap: 8px;
  color: var(--ink-soft);
  background: none; border: none;
  font-size: 14px;
  padding: 6px 0 14px;
  cursor: pointer;
  font-family: inherit;
}
.client-hero {
  background: var(--paper);
  border-radius: 20px;
  padding: 22px 18px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  text-align: center;
}
.big-avatar {
  width: 64px; height: 64px;
  border-radius: 18px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 19px;
  color: #fff;
}
.client-hero h3 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.client-hero .c-ip {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--hint);
  margin-bottom: 14px;
}
.client-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: left;
}
.client-stats .stat { padding: 10px 12px; }
.client-stats .stat-value { font-size: 14px; }
.client-stats .stat-label { font-size: 10.5px; }

.actions {
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 14px;
}
.action-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  color: var(--ink);
  font-size: 15px;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.action-row:last-child { border-bottom: none; }
.action-row:active { background: var(--paper-2); }
.action-row svg { width: 20px; height: 20px; color: var(--ink-soft); }
.action-row .chev { color: var(--hint); font-size: 18px; }
.action-row.danger { color: var(--danger); }
.action-row.danger svg { color: var(--danger); }
.action-row[disabled] { opacity: 0.45; pointer-events: none; }

.toggle {
  width: 42px; height: 25px;
  background: var(--line);
  border-radius: 999px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.toggle.on::after { transform: translateX(17px); }

/* ─── Экран добавления ───────────────────────────────────────────── */
.add-hero {
  background: var(--paper);
  border-radius: 20px;
  padding: 20px 18px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.add-hero h3 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0 0 6px;
  line-height: 1.2;
}
.add-hero p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-size: 14px;
}
.field-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hint);
  padding: 0 6px 8px;
}
.input {
  width: 100%;
  background: var(--paper-2);
  border: 1.5px solid transparent;
  border-radius: 12px;
  padding: 13px 14px;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
.input.error { border-color: var(--danger); }
.input::placeholder { color: var(--hint); }

.profiles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.profile {
  background: var(--paper);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: border-color .15s;
}
.profile.selected { border-color: var(--accent); }
.profile .p-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.profile .p-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-soft);
  text-transform: uppercase;
  align-self: center;
}
.profile.selected .p-tag {
  background: var(--accent-soft);
  color: var(--accent);
}
.profile .p-desc {
  grid-column: 1 / -1;
  font-size: 12.5px;
  color: var(--hint);
  line-height: 1.35;
}

.primary-btn {
  width: 100%;
  border: none;
  background: var(--ink);
  color: var(--bg);
  padding: 15px;
  border-radius: 14px;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:active { opacity: 0.85; }
.primary-btn[disabled] { opacity: 0.5; pointer-events: none; }

/* ─── QR-модал ───────────────────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--paper);
  border-radius: 22px;
  padding: 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.modal h3 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}
.modal .modal-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--hint);
  margin-bottom: 16px;
}
.modal img {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto 16px;
  background: #fff;
  padding: 12px;
  border-radius: 14px;
}
.modal pre {
  background: var(--paper-2);
  padding: 12px;
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: left;
  overflow-x: auto;
  max-height: 240px;
  margin: 0 0 14px;
  white-space: pre-wrap;
  word-break: break-all;
}
.modal-actions {
  display: flex;
  gap: 8px;
}
.modal-actions button {
  flex: 1;
  border: none;
  padding: 12px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.modal-actions .close-btn {
  background: var(--paper-2);
  color: var(--ink);
}
.modal-actions .copy-btn {
  background: var(--ink);
  color: var(--bg);
}

/* ─── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 1000;
  transition: transform .25s ease;
  max-width: 90%;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.danger { background: var(--danger); color: #fff; }

/* ─── Spinner / skeleton ─────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--paper-2) 0%, var(--line) 50%, var(--paper-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Экраны ─────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ─── Пустое состояние ───────────────────────────────────────────── */
.empty {
  background: var(--paper);
  border-radius: 18px;
  padding: 30px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  color: var(--hint);
  font-size: 14px;
  margin-bottom: 16px;
}

/* ─── Repair-отчёт (модал) ───────────────────────────────────────── */
.repair-list {
  text-align: left;
  margin: 0 0 14px;
  max-height: 60vh;
  overflow-y: auto;
}
.repair-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  align-items: start;
}
.repair-item:last-child { border-bottom: none; }
.repair-icon {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}
.repair-icon.ok    { background: var(--accent); }
.repair-icon.fixed { background: #4a7c5a; }
.repair-icon.warn  { background: #d4a13a; }
.repair-icon.fail  { background: var(--danger); }
.repair-name {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}
.repair-detail {
  font-size: 12px;
  color: var(--hint);
  font-family: var(--font-mono);
  margin-top: 2px;
  word-break: break-word;
}
.repair-summary {
  padding: 10px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 12px;
  text-align: center;
}
.repair-summary.ok { background: var(--accent-soft); color: var(--accent); }
.repair-summary.warn { background: var(--danger-soft); color: var(--danger); }

/* ─── Спиннер на кнопках действий ────────────────────────────────── */
.action-row.busy { opacity: 0.6; pointer-events: none; }
.action-row .row-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
.action-row.busy .row-spinner { display: inline-block; }
.action-row.busy .chev { display: none; }

/* ─── Тумблер темы в шапке ───────────────────────────────────────── */
.icon-btn svg {
  width: 20px; height: 20px;
}
