/* =========================================================================
   Orbit — оболочка PWA. Тёмная тема, системный шрифт, iOS-повадки.
   ========================================================================= */

:root {
  /* Палитра iOS Dark */
  --bg: #000000;
  --card: #1C1C1E;
  --card-2: #2C2C2E;
  --card-3: #3A3A3C;
  --sep: rgba(84, 84, 88, 0.65);
  --fill: rgba(118, 118, 128, 0.24);

  --txt: #FFFFFF;
  --txt-2: rgba(235, 235, 245, 0.6);
  --txt-3: rgba(235, 235, 245, 0.3);

  --blue: #0A84FF;
  --green: #30D158;
  --red: #FF453A;
  --orange: #FF9F0A;
  --violet: #BF5AF2;
  --teal: #64D2FF;
  --pink: #FF375F;

  /* Пружинистый easing, как в UIKit */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);

  /* Safe area */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  /* Высота корня. По умолчанию 100dvh, JS уточняет её по visualViewport:
     на iPhone dvh не поспевает за панелями Safari. */
  --app-h: 100dvh;

  /* Метрики */
  --bar-h: 44px;
  --large-h: 52px;
  --tab-h: 49px;

  color-scheme: dark;
}

/* ---------------------------------------------------------- сброс веба -- */

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: manipulation;
}

html {
  height: 100%;
  height: 100dvh;
  height: var(--app-h);
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  /* НЕ position: fixed. Баг iOS 26: fixed-контейнер размером во весь вьюпорт
     обрезается по 100dvh, и всё внутри него теряет нижнюю часть экрана.
     Обычный поток такого ограничения не имеет. */
  position: relative;
  margin: 0;
  height: 100%;
  height: 100dvh;
  height: var(--app-h);
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.29;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

h1, p { margin: 0; }
svg { display: block; }

/* Ввод — единственное место, где текст выделяется. */
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  font: inherit;
  font-size: 17px;            /* < 16px = iOS зумит поле */
  color: var(--txt);
  background: none;
  border: 0;
  outline: none;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  padding: 0;
}
input::placeholder,
textarea::placeholder { color: var(--txt-3); }

/* Нажатие: короткое сжатие, отпускание — пружиной. */
.press {
  transition: transform 0.24s var(--ease), background-color 0.18s linear;
}
.press:active {
  transform: scale(0.97);
  transition-duration: 0.08s;
}

/* Зонд safe-area: JS читает его computed padding. */
#sa-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ================================================================ каркас */

.app {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* -------------------------------------------------------------- шапка -- */

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  pointer-events: none;
}

.topbar__bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
  height: calc(var(--sat) + var(--bar-h));
  background: rgba(12, 12, 14, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  opacity: 0;
  will-change: opacity;
}
.topbar__bg::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--sep);
  transform: scaleY(0.5);
  transform-origin: 0 100%;
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .topbar__bg { background: #0C0C0E; }
}

.topbar__bar {
  position: relative;
  z-index: 2;
  margin-top: var(--sat);
  height: var(--bar-h);
  padding-left: calc(16px + var(--sal));
  padding-right: calc(8px + var(--sar));
  display: flex;
  align-items: center;
  justify-content: flex-end;
  pointer-events: auto;
}

.topbar__compact {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  pointer-events: none;
  will-change: opacity, transform;
}

.topbar__act {
  position: relative;
  z-index: 3;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--blue);
  pointer-events: auto;
}
.topbar__act svg { width: 23px; height: 23px; }
.topbar__act[hidden] { display: none; }

.topbar__large {
  position: relative;
  z-index: 0;
  height: var(--large-h);
  padding-left: calc(16px + var(--sal));
  padding-right: calc(16px + var(--sar));
  display: flex;
  align-items: flex-end;
  pointer-events: none;
  overflow: visible;
}
.topbar__large h1 {
  font-size: 34px;
  line-height: 41px;
  font-weight: 700;
  letter-spacing: -0.022em;
  transform-origin: left bottom;
  will-change: opacity, transform;
}

/* Крупные заголовки выключены в настройках -> шапка всегда компактная. */
.no-large .topbar__large { display: none; }
.no-large .topbar__compact { opacity: 1 !important; transform: none !important; }
.no-large .scroller { padding-top: calc(var(--sat) + var(--bar-h) + 8px); }
.no-large .topbar__bg { opacity: 1 !important; }

/* -------------------------------------------------------------- экраны - */

.screens {
  position: absolute;
  inset: 0;
}

.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transform: scale(1.014);
  pointer-events: none;
  transition:
    opacity 0.16s var(--ease),
    transform 0.18s var(--ease),
    visibility 0s linear 0.18s;
}
.screen.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
  transition:
    opacity 0.18s var(--ease),
    transform 0.19s var(--ease),
    visibility 0s linear 0s;
}
/* Уходящий экран немного «проваливается» — направление задаёт JS. */
.screen.is-leaving { transform: scale(0.988); }

/* Анимация переходов выключена в настройках. */
.no-motion .screen { transition-duration: 0s, 0s, 0s; }

/* ------------------------------------------------------------ скроллер - */

.scroller {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;   /* инерция на старых iOS */
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding-top: calc(var(--sat) + var(--bar-h) + var(--large-h));
  padding-bottom: calc(var(--sab) + var(--tab-h) + 24px);
  padding-left: var(--sal);
  padding-right: var(--sar);
}
.scroller::-webkit-scrollbar { display: none; }

/* -------------------------------------------------------------- таб-бар */

.tabbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  padding-bottom: var(--sab);
  padding-left: var(--sal);
  padding-right: var(--sar);
  background: rgba(16, 16, 18, 0.78);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  transition: transform 0.28s var(--ease);
}
.tabbar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--sep);
  transform: scaleY(0.5);
  transform-origin: 0 0;
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .tabbar { background: #101012; }
}
/* Клавиатура открыта — таб-бар уезжает вниз. */
body.kb-open .tabbar { transform: translate3d(0, 110%, 0); }

.tab {
  flex: 1 1 0;
  height: var(--tab-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--txt-2);
  transition: color 0.18s linear, transform 0.24s var(--ease);
}
.tab.is-active { color: var(--blue); }
.tab__icon svg { width: 26px; height: 26px; }
.tab__icon {
  transition: transform 0.24s var(--ease);
}
.tab.is-active .tab__icon { transform: scale(1.02); }
.tab__label {
  font-size: 10px;
  line-height: 12px;
  font-weight: 500;
  letter-spacing: 0.005em;
}

/* ================================================================ списки */

.group-title {
  margin: 26px 16px 7px;
  font-size: 13px;
  line-height: 16px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--txt-2);
}
.scroller > .group-title:first-child,
form > .group-title:first-child { margin-top: 12px; }

.list {
  margin: 0 16px;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
}
.list--pad { padding: 11px 16px; }

.footnote {
  margin: 8px 16px 0;
  font-size: 13px;
  line-height: 17px;
  color: var(--txt-2);
}

.pad { margin: 0 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

/* ---------------------------------------------------------------- ячейка */

.cell {
  position: relative;
  width: 100%;
  min-height: 44px;
  padding: 9px 16px 9px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  color: var(--txt);
  background: var(--card);
}
.cell::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--sep);
  transform: scaleY(0.5);
  transform-origin: 0 100%;
}
.cell:last-child::after { display: none; }
.cell:has(.mono)::after { left: 62px; }

button.cell:active { background: var(--card-2); }
.cell--static { cursor: default; }

.cell__text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cell__title {
  font-size: 17px;
  line-height: 22px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell__sub {
  font-size: 14px;
  line-height: 18px;
  color: var(--txt-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell__meta {
  flex: 0 0 auto;
  font-size: 15px;
  color: var(--txt-3);
  font-variant-numeric: tabular-nums;
}

.chev {
  flex: 0 0 auto;
  width: 8px;
  height: 13px;
  fill: none;
  stroke: var(--txt-3);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* монограмма */
.mono {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}
.mono--blue   { background: linear-gradient(160deg, #0A84FF, #0050C8); }
.mono--violet { background: linear-gradient(160deg, #BF5AF2, #7A2FD0); }
.mono--green  { background: linear-gradient(160deg, #30D158, #17914A); }
.mono--orange { background: linear-gradient(160deg, #FF9F0A, #D96C00); }
.mono--teal   { background: linear-gradient(160deg, #64D2FF, #0F87C7); }
.mono--pink   { background: linear-gradient(160deg, #FF375F, #C1123E); }
.mono--red    { background: linear-gradient(160deg, #FF453A, #B81E17); }

/* новая запись приезжает сверху */
@keyframes cell-in {
  from { opacity: 0; transform: translate3d(0, -10px, 0) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.cell--new { animation: cell-in 0.24s var(--ease); }

/* =============================================================== switch */

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 51px;
  height: 31px;
}
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  z-index: 2;
}
.switch__track {
  position: absolute;
  inset: 0;
  border-radius: 15.5px;
  background: #39393D;
  transition: background-color 0.25s var(--ease);
}
.switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.34), 0 1px 1px rgba(0, 0, 0, 0.22);
  transition: transform 0.28s var(--ease), width 0.2s var(--ease);
}
.switch input:checked ~ .switch__track { background: var(--green); }
.switch input:checked ~ .switch__track .switch__thumb { transform: translate3d(20px, 0, 0); }
.switch input:active ~ .switch__track .switch__thumb { width: 31px; }
.switch input:checked:active ~ .switch__track .switch__thumb { transform: translate3d(16px, 0, 0); }

/* ============================================================ segmented */

.seg {
  position: relative;
  display: flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}
.seg__ind {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc((100% - 4px) / 3);
  border-radius: 7px;
  background: #636366;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transform: translate3d(0, 0, 0);
  transition: transform 0.3s var(--ease);
}
.seg__opt {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  height: 32px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--txt);
  transition: transform 0.24s var(--ease), opacity 0.18s linear;
}
.seg__opt:active { transform: scale(0.97); }
.seg__opt:not(.is-on) { opacity: 0.72; font-weight: 500; }

/* ============================================================== stepper */

.stepper {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  width: 94px;
  height: 32px;
  border-radius: 8px;
  background: var(--fill);
  overflow: hidden;
}
.stepper__btn {
  flex: 1 1 0;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--txt);
}
.stepper__btn svg { width: 19px; height: 19px; }
.stepper__btn[disabled] { opacity: 0.32; }
.stepper__div {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.16);
}
.stepper__val {
  flex: 0 0 auto;
  min-width: 26px;
  text-align: right;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  color: var(--txt-2);
}

/* ================================================================ форма */

.cell--field { gap: 10px; }
.field__label {
  flex: 0 0 96px;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.cell--field input {
  flex: 1 1 auto;
  min-width: 0;
  height: 26px;
}

textarea {
  display: block;
  width: 100%;
  min-height: 92px;
  resize: none;
  line-height: 22px;
}

.btn {
  width: 100%;
  height: 50px;
  border-radius: 12px;
  background: var(--card);
  color: var(--blue);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: grid;
  place-items: center;
}
.btn--primary { background: var(--blue); color: #fff; }
.btn--danger { color: var(--red); }

.form-result {
  margin: 14px 16px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(48, 209, 88, 0.16);
  color: var(--green);
  font-size: 15px;
  line-height: 20px;
  animation: cell-in 0.22s var(--ease);
}
.form-result[hidden] { display: none; }

/* ========================================================== диагностика */

.version-card {
  margin-top: 8px;
  padding: 18px 18px 16px;
  border-radius: 16px;
  background: linear-gradient(155deg, #1F1F23, #171719);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.version-card__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--txt-3);
}
.version-card__value {
  font-size: 44px;
  line-height: 50px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.version-card__cache {
  font-size: 13px;
  color: var(--txt-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.kv { gap: 10px; }
.kv__k {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15px;
  line-height: 20px;
  color: var(--txt-2);
}
.kv__v {
  flex: 0 0 auto;
  max-width: 55%;
  text-align: right;
  font-size: 15px;
  line-height: 20px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kv__v.is-good { color: var(--green); }
.kv__v.is-bad { color: var(--red); }
.kv__v.is-warn { color: var(--orange); }
.kv__v.is-dim { color: var(--txt-3); }

.bar {
  display: block;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--fill);
  overflow: hidden;
}
.bar__fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--blue);
  transition: width 0.4s var(--ease);
}

.ua {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 17px;
  color: var(--txt-2);
  word-break: break-word;
}

/* ====================================================== доступность ==== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ====================================================== калибровка ==== */
/* Рисует физические края вьюпорта поверх интерфейса: по скриншоту видно,
   где вебвью реально стоит на экране и куда уходит недостача высоты. */

.calib {
  position: absolute;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  display: none;
}
body.calib-on .calib { display: block; }

.calib__topband {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-top, 0px);
  background: rgba(255, 45, 149, 0.45);
}
.calib__topline {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: #FF2D95;
}
.calib__botband {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-bottom, 0px);
  background: rgba(0, 229, 255, 0.45);
}
.calib__botline {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: #00E5FF;
}
.calib__barline {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #30D158;
}
.calib__legend {
  position: absolute;
  top: 50%;
  left: 16px;
  right: 16px;
  transform: translateY(-50%);
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.72);
  font-size: 12px;
  line-height: 17px;
  text-align: center;
  color: #fff;
}

/* значение, которому можно переноситься на несколько строк */
.kv__v--wrap {
  white-space: normal;
  max-width: 62%;
}

/* Зонды единиц высоты. Невидимы, из потока не выбиваются. */
#unit-probe {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}
#unit-probe i { display: block; width: 0; }
#unit-probe i[data-u="vh"] { height: 100vh; }
#unit-probe i[data-u="dvh"] { height: 100dvh; }
#unit-probe i[data-u="lvh"] { height: 100lvh; }
#unit-probe i[data-u="svh"] { height: 100svh; }

#fixed-probe {
  position: fixed;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

/* ============================================ компенсация мёртвой полосы */
/* Вебвью короче экрана, полоса снизу вне документа. Резервировать padding
   под home-индикатор, которого в вебвью нет, — только поднимать бар выше.
   Убираем его и красим бар непрозрачно чёрным, в цвет полосы: шов исчезает. */

body.dead-strip .tabbar {
  padding-bottom: 0;
  background: #000;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
body.dead-strip .scroller {
  padding-bottom: calc(var(--tab-h) + 24px);
}

/* Маркер последнего пикселя корня для теста растяжения. */
.stretch-probe {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background: #FF3B30;
  display: none;
  z-index: 9998;
  pointer-events: none;
}
body.stretch-test .stretch-probe { display: block; }
