/* ══ НАСТРОЙКИ — вкладки «Общее» / «Датчики» ══ */

/* Низкоуровневые настройки датчиков (опорное напряжение, резисторы, делители,
   калибровка pH/EC/давления/расхода) — только для admin. */
.st-admin-only { display: none !important; }
body.is-admin .st-admin-only { display: block !important; }

#page-settings { flex-direction: column; height: 100%; width: 100%; }

/* ── Шапка ───────────────────────────────────────────────── */
.st-hdr {
  display: flex; align-items: center;
  background: var(--hbar-bg);
  padding: 0 clamp(16px, calc(1.25 * var(--u)), 38px);
  height: clamp(56px, calc(4.58 * var(--u)), 140px);
  flex-shrink: 0;
  gap: clamp(8px, calc(0.63 * var(--u)), 18px);
}
.st-hdr-title {
  font-size: clamp(14px, calc(1.15 * var(--u)), 35px); font-weight: 800;
  color: #fff; text-transform: uppercase; letter-spacing: 0.05em;
}
.st-hdr-spacer { flex: 1; }

/* ── Вкладки (размер как hbar-btn) ────────────────────────── */
.st-tabs {
  display: flex; gap: clamp(4px, calc(0.31 * var(--u)), 10px);
  margin-left: clamp(12px, calc(1 * var(--u)), 28px);
}
.st-tab {
  height: clamp(36px, calc(2.81 * var(--u)), 86px);
  padding: 0 clamp(14px, calc(1.15 * var(--u)), 35px);
  border-radius: clamp(8px, calc(0.63 * var(--u)), 18px);
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.7);
  font-family: var(--ui); font-weight: 800;
  font-size: clamp(14px, calc(1.15 * var(--u)), 35px);
  display: flex; align-items: center;
  cursor: pointer; transition: 0.15s; text-transform: uppercase; letter-spacing: 0.04em;
}
.st-tab:hover { background: rgba(255,255,255,0.15); color: #fff; }
.st-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Цветные кнопки действий ──────────────────────────────── */
/* Сохранить — неактивный по умолчанию, зелёный+мигание при dirty */
.st-btn-save { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.18); color: rgba(255,255,255,0.35); pointer-events: none; }
.st-btn-save.dirty { background: var(--green); border-color: var(--green); color: #fff; pointer-events: auto; animation: st-save-pulse 1.5s ease-in-out infinite; }
.st-btn-save.dirty:hover { background: #0fc07a; }
@keyframes st-save-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
.st-btn-save.busy, .hbar-btn.busy { opacity: 0.5; pointer-events: none; animation: none; }
/* Загрузить — синий */
.st-btn-load { background: var(--accent); border-color: var(--accent); color: #fff; }
.st-btn-load:hover { background: #1a7aff; }
/* Резервная копия — фиолетовый */
.st-btn-backup { background: #7c3aed; border-color: #7c3aed; color: #fff; }
.st-btn-backup:hover { background: #6d28d9; }
/* Восстановить — оранжевый */
.st-btn-restore { background: var(--orange); border-color: var(--orange); color: #fff; }
.st-btn-restore:hover { background: #f08830; }

/* ── Скролл ───────────────────────────────────────────────── */
.st-scroll {
  flex: 1; overflow-y: auto; padding: clamp(8px, 0.63vw, 18px); background: var(--bg);
}
.st-scroll::-webkit-scrollbar       { width: clamp(10px, 0.83vw, 24px); }
.st-scroll::-webkit-scrollbar-track { background: var(--bg3); }
.st-scroll::-webkit-scrollbar-thumb { background: var(--border2); border-radius: clamp(2px, 0.2vw, 5px); }

/* ── Сетка: 3 колонки ────────────────────────────────────── */
.st-page {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: clamp(8px, 0.63vw, 18px);
  align-items: start;
}
.st-col {
  display: flex; flex-direction: column;
  gap: clamp(8px, 0.63vw, 18px);
}

/* ── Модуль ──────────────────────────────────────────────── */
.st-mod {
  border-radius: var(--r2);
  padding: clamp(8px, 0.63vw, 18px);
  display: flex; flex-direction: column;
  gap: clamp(6px, 0.47vw, 14px);
}
.st-mod-title {
  font-size: clamp(12px, 0.94vw, 28px); font-weight: 800;
  color: var(--text); text-transform: uppercase; letter-spacing: 0.06em;
}

/* Цвета модулей */
.st-mod-program  { background: #dce8f8; border: 1.5px solid #a8c4e6; }
.st-mod-sensors  { background: #d8f0e4; border: 1.5px solid #9dd4b6; }
.st-mod-prot     { background: #fae8d8; border: 1.5px solid #dfc0a0; }
.st-mod-hydro    { background: #dce8f8; border: 1.5px solid #a8c4e6; }
.st-mod-flow     { background: #fae8d8; border: 1.5px solid #dfc0a0; }
.st-mod-system   { background: #e8e4f0; border: 1.5px solid #c0b4d6; }

/* ── Info row (readonly, без степпера) ───────────────────── */
.st-info-row {
  display: flex; align-items: center;
  gap: clamp(5px, 0.35vw, 10px);
  min-height: clamp(21px, 1.65vw, 50px);
}
.st-info-label {
  flex: 1;
  font-size: clamp(9px, 0.7vw, 21px); font-weight: 600;
  color: var(--text2);
}
.st-info-val {
  font-family: var(--mono); font-weight: 600;
  font-size: clamp(10px, 0.78vw, 22px);
  color: var(--text);
}
.st-bar-pulse {
  animation: st-pulse 1.5s ease-in-out infinite;
}
@keyframes st-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.st-update-btn {
  background: none; border: none; cursor: pointer;
  color: var(--orange); margin-left: 8px; padding: 2px;
  vertical-align: middle; opacity: 0.8;
}
.st-update-btn:hover { opacity: 1; transform: scale(1.15);
}
.st-info-unit {
  font-size: clamp(10px, 0.83vw, 24px);
  color: var(--text3); font-weight: 500;
}

/* ── 3-позиц. переключатель (WiFi/Авто/LTE) — как bar/степпер ── */
.st-sw3 {
  flex: 0 0 clamp(112px, 9vw, 270px);
  height: clamp(24px, calc(1.88 * var(--u)), 57px);
  display: flex; align-items: stretch;
  background: var(--bg3); border-radius: clamp(5px, 0.39vw, 12px);
  border: 1.5px solid var(--border2); overflow: hidden;
}
.st-sw3 .sw3-btn {
  flex: 1; display: flex; align-items: center; justify-content: center;
  font-family: var(--ui); font-weight: 700;
  font-size: clamp(9px, 0.7vw, 21px);
  color: var(--text3); cursor: pointer; transition: 0.15s; user-select: none;
  border-right: 1px solid var(--border2);
}
.st-sw3 .sw3-btn:last-child { border-right: none; }
.st-sw3 .sw3-btn:hover {
  background: var(--accent-l);
  color: var(--accent);
}
.st-sw3 .sw3-btn.active {
  background: var(--accent);
  color: #fff;
}
.st-sw3 .sw3-btn.active[data-m="lte"] { background: var(--green); }
.st-sw3 .sw3-btn.active[data-m="auto"] { background: var(--orange); }

/* ── Progress bar (высота/ширина как у степпера в правой колонке) ── */
.st-bar {
  flex: 0 0 clamp(112px, 9vw, 270px);
  height: clamp(24px, calc(1.88 * var(--u)), 57px);
  background: var(--bg3); border-radius: clamp(5px, 0.39vw, 12px);
  border: 1.5px solid var(--border2);
  position: relative; overflow: hidden;
}
.st-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: inherit; z-index: 2;
  transition: width 0.4s, background 0.4s;
}
.st-bar-peak {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0; background: rgba(255, 176, 80, 0.5);
  border-radius: inherit; z-index: 1;
  transition: width 0.4s;
}
.st-bar-threshold {
  position: absolute; top: -2px; bottom: -2px;
  width: 2px; background: var(--red, #e85050);
  z-index: 3; pointer-events: none;
  transition: left 0.4s;
  box-shadow: 0 0 3px rgba(232, 80, 80, 0.6);
}

/* Калибровка бочек: все степперы в едином синем стиле (как active) */
.barrel-cal-card .stepper {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
}
.barrel-cal-card .stepper button {
  background: rgba(0,0,0,0.25) !important;
  color: #fff !important;
}
.barrel-cal-card .stepper button:hover { background: rgba(0,0,0,0.38) !important; }
.barrel-cal-card .stepper input { color: #fff !important; }
.st-bar-text {
  position: relative; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  height: 100%;
  font-family: var(--mono); font-weight: 700;
  font-size: clamp(8px, 0.62vw, 18px);
  color: var(--text);
}

/* ── Карточка ────────────────────────────────────────────── */
.st-card {
  background: rgba(255,255,255,0.7); border: 1px solid rgba(0,0,0,0.06);
  border-radius: var(--r);
  padding: clamp(6px, 0.47vw, 14px);
  display: flex; flex-direction: column; gap: clamp(4px, 0.31vw, 9px);
}
.st-card-title {
  display: flex; align-items: baseline; gap: clamp(5px, 0.35vw, 10px);
  font-size: clamp(8px, 0.62vw, 18px); font-weight: 700;
  color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em;
  padding-bottom: clamp(3px, 0.23vw, 8px); border-bottom: 1px solid rgba(0,0,0,0.08);
}
.st-card-title-val {
  margin-left: auto;
  font-family: var(--mono); font-weight: 700;
  font-size: clamp(10px, 0.78vw, 22px);
  color: var(--text); text-transform: none; letter-spacing: 0;
}

/* ── Ряд: метка | степпер ────────────────────────────────── */
.st-row {
  display: flex; align-items: center;
  gap: clamp(5px, 0.35vw, 10px);
  min-height: clamp(24px, 1.88vw, 57px);
}
.st-row-label {
  flex: 1; min-width: 0;
  font-size: clamp(9px, 0.7vw, 21px); font-weight: 600;
  color: var(--text2); white-space: nowrap;
}
.st-row-hint {
  font-size: clamp(7px, 0.55vw, 15px); color: var(--text3); white-space: nowrap;
}
/* +20% ширины степпера (было 112/270) + кнопки 25% вместо 30% (templates.css:324):
   вместе дают input заметно больше места → длинные числа влазят. */
.st-row .stepper { flex: 0 0 clamp(134px, 10.8vw, 324px); height: clamp(24px, calc(1.88 * var(--u)), 57px); border-width: 1.5px; }
.st-row .stepper button { flex: 0 0 25%; max-width: none; }
.st-row .stepper button svg { width: clamp(13px, calc(1.1 * var(--u)), 32px); height: clamp(13px, calc(1.1 * var(--u)), 32px); }
.st-row .stepper input {
  font-size: clamp(13px, 1.04vw, 30px);                   /* = размеру показаний .dg-val (не крупнее); JS ужмёт если не влазит */
  font-variant-numeric: tabular-nums;                     /* равная ширина цифр — предсказуемо */
  letter-spacing: -0.01em;
  min-width: 0;                                           /* flex:1 (базовый) растянет на весь остаток */
  padding: 0 2px;
}
/* readonly-вариант (авто-опора АЦП v0.1.1): центр, приглушено, без кнопок */
.stepper-ro { justify-content: center; opacity: 0.65; }
.stepper-ro input { text-align: center; cursor: default; }

.st-not-loaded {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  font-family: var(--mono); font-weight: 700;
  font-size: clamp(14px, 1.15vw, 32px); color: var(--text3);
}

.st-sep { height: 0; border-top: 1px dashed rgba(0,0,0,0.1); margin: clamp(2px, 0.16vw, 5px) 0; }

.st-formula {
  font-size: clamp(9px, 0.73vw, 20px); color: var(--text3);
  font-family: var(--mono); padding-top: clamp(2px, 0.16vw, 5px);
  border-top: 1px solid rgba(0,0,0,0.06);
}

/* ── Кнопки канала ───────────────────────────────────────── */
.st-chan-group { display: flex; gap: clamp(4px, 0.31vw, 10px); flex: 0 0 auto; }
.st-chan-btn {
  width: clamp(28px, calc(1.88 * var(--u)), 57px);
  height: clamp(24px, calc(1.88 * var(--u)), 57px);
  border-radius: clamp(5px, 0.39vw, 12px);
  border: 1.5px solid var(--border2); background: var(--bg2);
  color: var(--text3); font-family: var(--mono); font-weight: 700;
  font-size: clamp(10px, 0.78vw, 22px);
  display: flex; align-items: center; justify-content: center;
  transition: 0.15s; cursor: pointer;
}
.st-chan-btn:hover  { border-color: var(--accent); color: var(--accent); background: var(--accent-l); }
.st-chan-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.st-chan-btn:disabled,
.st-chan-btn.disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.st-chan-btn.st-chan-text {
  width: auto; padding: 0 clamp(9px, 0.75vw, 21px);
  font-family: var(--ui); font-size: clamp(8px, 0.66vw, 19px);
}

/* ── Toast ────────────────────────────────────────────────── */
.st-toast {
  position: fixed;
  bottom: clamp(16px, 1.25vw, 38px); right: clamp(16px, 1.25vw, 38px);
  padding: clamp(10px, 0.83vw, 24px) clamp(18px, 1.46vw, 44px);
  border-radius: var(--r2); font-weight: 700; font-size: clamp(12px, 0.94vw, 28px);
  color: #fff; background: #1a2232;
  opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 100;
}
.st-toast.ok  { background: var(--green); }
.st-toast.err { background: var(--red); }
.st-toast.show { opacity: 1; }

/* ══ ДИАГНОСТИКА (встроена в «Датчики») ══ */

.dg-thead {
  display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: clamp(4px, 0.31vw, 10px);
  padding-bottom: clamp(4px, 0.31vw, 10px);
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.dg-th {
  font-size: clamp(9px, 0.73vw, 20px); font-weight: 700;
  color: var(--text3); text-transform: uppercase; letter-spacing: 0.04em;
  text-align: right;
}
.dg-th:first-child { text-align: left; }

.dg-row {
  display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: clamp(4px, 0.31vw, 10px);
  align-items: center;
  min-height: clamp(28px, 2.2vw, 66px);
}
.dg-row-label {
  font-size: clamp(12px, 0.94vw, 28px); font-weight: 600;
  color: var(--text2); white-space: nowrap;
}
.dg-val {
  font-family: var(--mono); font-weight: 500;
  font-size: clamp(13px, 1.04vw, 30px);
  color: var(--text);
  text-align: right;
  transition: color 0.2s;
}
.dg-val[data-vs="err"] { color: var(--red); }
.dg-val[data-vs="no"]  { color: var(--text3); }
.dg-unit {
  font-size: clamp(9px, 0.73vw, 20px);
  color: var(--accent); font-weight: 600;
}

/* Расход: 5 колонок */
.dg-thead-5 { grid-template-columns: 1.2fr 1fr 1fr 1fr 1fr; }
.dg-row-5   { grid-template-columns: 1.2fr 1fr 1fr 1fr 1fr; }

/* ── Кнопка калибровки (той же высоты/ширины что st-bar и степперы) ─── */
.st-cal-btn {
  flex: 0 0 clamp(112px, 9vw, 270px);
  height: clamp(24px, calc(1.88 * var(--u)), 57px);
  padding: 0 clamp(10px, 0.78vw, 20px);
  border-radius: clamp(5px, 0.39vw, 12px);
  border: 1.5px solid var(--accent); background: var(--accent-l);
  color: var(--accent); font-family: var(--ui); font-weight: 700;
  font-size: clamp(10px, 0.78vw, 18px);
  cursor: pointer; transition: 0.15s;
  white-space: nowrap;
}
.st-cal-btn:hover { background: var(--accent); color: #fff; }

/* ── pH Calibration Wizard Overlay ───────────────────── */
.ph-cal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.ph-cal-modal {
  background: #fff; border-radius: var(--r2);
  width: min(90vw, clamp(340px, 30vw, 700px));
  box-shadow: 0 clamp(8px, 0.8vw, 24px) clamp(30px, 3vw, 80px) rgba(0,0,0,0.25);
  overflow: hidden;
}
.ph-cal-title {
  background: var(--accent); color: #fff; padding: clamp(12px, 1vw, 28px) clamp(16px, 1.3vw, 36px);
  font-size: clamp(14px, 1.15vw, 32px); font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.ph-cal-body {
  padding: clamp(16px, 1.3vw, 36px);
  font-size: clamp(13px, 1.04vw, 30px); color: var(--text2);
  line-height: 1.6;
}
.ph-cal-body p { margin: 0 0 clamp(6px, 0.5vw, 14px); }
.ph-cal-body b { color: var(--text); }
.ph-cal-voltage {
  margin-top: clamp(10px, 0.83vw, 24px);
  padding: clamp(10px, 0.83vw, 24px);
  background: var(--bg2); border-radius: var(--r);
  font-family: var(--mono); font-size: clamp(18px, 1.5vw, 42px); font-weight: 700;
  text-align: center; color: var(--text);
}
.ph-cal-info {
  margin-top: clamp(6px, 0.5vw, 14px);
  font-family: var(--mono); font-size: clamp(11px, 0.88vw, 26px);
  color: var(--text3);
}
.ph-cal-result {
  display: flex; flex-direction: column; gap: clamp(4px, 0.3vw, 10px);
  font-family: var(--mono); font-size: clamp(13px, 1.04vw, 30px);
}
.ph-cal-footer {
  display: flex; justify-content: flex-end; gap: clamp(8px, 0.63vw, 18px);
  padding: clamp(12px, 1vw, 28px) clamp(16px, 1.3vw, 36px);
  border-top: 1px solid rgba(0,0,0,0.08);
}
.ph-cal-btn {
  padding: clamp(8px, 0.63vw, 18px) clamp(18px, 1.5vw, 42px);
  border-radius: clamp(6px, 0.52vw, 16px); border: none;
  font-family: var(--ui); font-weight: 700;
  font-size: clamp(12px, 0.94vw, 28px); cursor: pointer;
}
.ph-cal-cancel { background: var(--bg3); color: var(--text2); }
.ph-cal-ok { background: var(--accent); color: #fff; cursor: pointer; transition: background 0.3s; }
.ph-cal-ok:hover { background: #3a90e0; }
.ph-cal-ok.ph-cal-waiting { background: var(--orange); color: #fff; }
.ph-cal-ok.ph-cal-waiting:hover { background: #d06818; }
.ph-cal-ok.ph-cal-ready { background: var(--green); color: #fff; }
.ph-cal-ok.ph-cal-ready:hover { background: #0fc07a; }
.ph-cal-countdown {
  margin-top: clamp(6px, 0.5vw, 14px);
  font-family: var(--mono); font-size: clamp(14px, 1.15vw, 32px); font-weight: 700;
  color: var(--accent); text-align: center;
}

/* EC RAW: 5 равных колонок, все по центру */
.dg-5col { grid-template-columns: 1fr 1fr 1fr 1fr 1fr; }
.dg-5col .dg-th { text-align: center; }
.dg-5col .dg-val { text-align: center; }

/* ── Toggle switch ─── */
.st-toggle-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.st-toggle-row input { display: none; }
.st-toggle-slider { position: relative; width: 40px; height: 22px; border-radius: 11px; background: var(--border2); transition: .2s; flex-shrink: 0; }
.st-toggle-slider::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.st-toggle-row input:checked + .st-toggle-slider { background: var(--accent); }
.st-toggle-row input:checked + .st-toggle-slider::after { left: 21px; }
