/* ==========================================================================
   APISCALE PWA «Пасечные весы» — дизайн-система (iOS-first)
   Медовая палитра из app2 (seed #F6A609), Material-подобные карточки в iOS-ритме,
   поддержка safe-area (чёлка/домашняя полоска), светлая и тёмная темы.
   ========================================================================== */

:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --card-2: #f2ebe0;
  --card-3: #ece3d6;
  --text: #1e1b16;
  --text-dim: #786b59;
  --primary: #a56a00;
  --on-primary: #ffffff;
  --primary-weak: #ffe7bd;
  --on-primary-weak: #2a1a00;
  --accent: #e69100;
  --green: #1f9d54;
  --red: #cf3f2b;
  --blue: #2f6fd0;
  --border: rgba(20, 15, 5, 0.08);
  --hairline: rgba(20, 15, 5, 0.10);
  --shadow: 0 1px 2px rgba(40, 26, 0, 0.05), 0 6px 20px rgba(40, 26, 0, 0.05);
  --overlay: rgba(20, 14, 0, 0.42);
  --radius: 20px;
  --radius-sm: 14px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
}

/* Тёмная палитра. Применяется когда система тёмная (и не форсирована светлая),
   либо когда тема выбрана вручную (data-theme="dark"). Значения продублированы
   в двух селекторах намеренно — CSS не даёт «миксинов». */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130d;
    --card: #221d14;
    --card-2: #2b2419;
    --card-3: #342c1f;
    --text: #f3ebdd;
    --text-dim: #b6a892;
    --primary: #ffb851;
    --on-primary: #452d00;
    --primary-weak: #533800;
    --on-primary-weak: #ffdfb0;
    --accent: #f6b12e;
    --green: #54c47a;
    --red: #ff6b54;
    --blue: #83b0ff;
    --border: rgba(255, 250, 240, 0.10);
    --hairline: rgba(255, 250, 240, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --overlay: rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --bg: #17130d;
  --card: #221d14;
  --card-2: #2b2419;
  --card-3: #342c1f;
  --text: #f3ebdd;
  --text-dim: #b6a892;
  --primary: #ffb851;
  --on-primary: #452d00;
  --primary-weak: #533800;
  --on-primary-weak: #ffdfb0;
  --accent: #f6b12e;
  --green: #54c47a;
  --red: #ff6b54;
  --blue: #83b0ff;
  --border: rgba(255, 250, 240, 0.10);
  --hairline: rgba(255, 250, 240, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --overlay: rgba(0, 0, 0, 0.55);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

/* Отключаем выделение по всему UI, кроме контента, где текст осмысленно копировать */
body { -webkit-user-select: none; user-select: none; }
input, textarea, .selectable { -webkit-user-select: text; user-select: text; }

button { font-family: inherit; }

/* Базовый размер иконок; контекстные правила ниже переопределяют по месту. */
.i { width: 22px; height: 22px; flex: 0 0 auto; display: inline-block; vertical-align: middle; }

/* ===== Каркас и стек экранов (iOS push-навигация) ========================= */

.app-root {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  will-change: transform;
  transform: translateX(0);
}

.screen.is-animating { transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1); }
.screen.enter-right { transform: translateX(100%); }
.screen.exit-right { transform: translateX(100%); }
/* Экран под верхним слегка утоплен (parallax), как в iOS */
.screen.is-behind { transform: translateX(-22%); }

/* ===== Навбар (верхняя панель) =========================================== */

.navbar {
  flex: 0 0 auto;
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 0.5px solid var(--hairline);
  position: relative;
  z-index: 5;
}

.navbar__row {
  height: 50px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
}

.navbar__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 4px;
}
.navbar--large .navbar__title { text-align: left; }

.navbar__btn {
  flex: 0 0 auto;
  min-width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 12px;
  padding: 0 8px;
}
.navbar__btn:active { opacity: 0.5; }
.navbar__btn .i { width: 26px; height: 26px; }
.navbar__spacer { min-width: 44px; }

/* Крупный заголовок под навбаром (iOS large title) */
.large-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  padding: 4px 20px 6px;
}

/* ===== Область прокрутки ================================================== */

.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px;
  padding-bottom: calc(28px + var(--safe-bottom));
}
.scroll > * + * { margin-top: 14px; }

/* ===== Карточки =========================================================== */

.card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card__pad { padding: 16px; }
.card__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 0 12px;
  letter-spacing: 0.01em;
}

.card--hero {
  background: linear-gradient(160deg, var(--primary-weak), color-mix(in srgb, var(--primary-weak) 82%, var(--card)));
  color: var(--on-primary-weak);
}
.card--tappable { cursor: pointer; transition: transform 0.12s ease, filter 0.12s ease; }
.card--tappable:active { transform: scale(0.985); filter: brightness(0.97); }

/* ===== Плитки меню (главный экран) ======================================= */

.menu-tile {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  border: none;
  background: var(--card-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.menu-tile:active { transform: scale(0.985); }
.menu-tile__icon {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: var(--primary-weak);
  color: var(--on-primary-weak);
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-tile__icon .i { width: 28px; height: 28px; }
.menu-tile__body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.menu-tile__title { font-size: 17px; font-weight: 700; display: block; }
.menu-tile__sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; display: block; }
.menu-tile__chev { flex: 0 0 auto; color: var(--text-dim); }

/* ===== Кнопки ============================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 0 20px;
  border: none;
  border-radius: 16px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--tonal { background: var(--primary-weak); color: var(--on-primary-weak); }
.btn--outline { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 1.5px var(--border); }
.btn--auto { width: auto; }

/* Пилюли периодов и переключатель масса/дельта */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.pill:active { opacity: 0.6; }
.pill.is-active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
.pill .i { width: 16px; height: 16px; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.segment { display: flex; gap: 8px; }

/* ===== Чипы датчиков и метки ============================================= */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}
.chip .i { width: 16px; height: 16px; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }

/* Переключатель датчика на графике (иконка + id) */
.sensor-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.sensor-toggle .i { width: 16px; height: 16px; }
.sensor-toggle.is-on { border-width: 1.5px; }

/* Бейдж дельты (+/-) */
.delta-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.delta-badge .i { width: 16px; height: 16px; }
.delta-badge .i--info { width: 13px; height: 13px; opacity: 0.7; }
.delta-badge.is-pos { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.delta-badge.is-neg { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }

/* Статус получения данных */
.status-badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; }
.status-badge .i { width: 18px; height: 18px; }
.status-badge.s-on { color: var(--green); }
.status-badge.s-off { color: var(--red); }
.status-badge.s-winter { color: var(--blue); }

/* ===== Плитки Период/Сигнал/Прошивка ==================================== */

.tiles { display: flex; gap: 12px; }
.tiles > * { flex: 1 1 0; }
/* Сетка плиток 2×2 (Отправка/Сигнал/Период/Прошивка) */
.tiles-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.info-tile {
  background: var(--card-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 6px;
  text-align: center;
}
.info-tile .i { width: 24px; height: 24px; color: var(--text-dim); }
.info-tile__val { font-size: 18px; font-weight: 700; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-tile__lbl { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ===== Прогресс-бары (заряд, заполнение) ================================ */

.bar-block__head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.bar-block__head .i { width: 18px; height: 18px; }
.bar-block__val { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-block__lbl { color: var(--text-dim); font-size: 13px; }
.bar-track {
  height: 8px;
  border-radius: 8px;
  background: var(--card-3);
  overflow: hidden;
  margin-top: 8px;
}
.bar-fill { height: 100%; border-radius: 8px; }

/* ===== Списки строк ====================================================== */

.hero__name { font-size: 20px; font-weight: 700; }
.hero__big { font-size: 44px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hero__unit { font-size: 15px; opacity: 0.8; }
.hero__row { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.hero__row .i { width: 16px; height: 16px; flex: 0 0 auto; }

.row { display: flex; align-items: center; gap: 8px; }
.row--between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-h { font-size: 15px; font-weight: 600; color: var(--text-dim); margin: 6px 2px; }

/* ===== График =========================================================== */

.chart-box { position: relative; height: 280px; }
.chart-box canvas { max-width: 100%; }

/* ===== Поля ввода (вход) ================================================= */

.field { position: relative; margin-bottom: 12px; }
.field input {
  width: 100%;
  min-height: 52px;
  padding: 0 44px 0 44px;
  border: none;
  border-radius: 14px;
  background: var(--card-2);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.field input:focus { box-shadow: inset 0 0 0 2px var(--primary); }
.field__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-dim); }
.field__icon .i { width: 22px; height: 22px; }
.field__toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; color: var(--text-dim); cursor: pointer;
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
}

/* ===== Состояния (загрузка / пусто / ошибка / ожидание) ================= */

.center-box {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 32px 24px;
  padding-bottom: calc(32px + var(--safe-bottom));
}
.center-box .i--xl { width: 64px; height: 64px; color: var(--text-dim); }
.center-box h2 { font-size: 18px; font-weight: 700; margin: 0; }
.center-box p { margin: 0; color: var(--text-dim); max-width: 34ch; }

.spinner {
  width: 26px; height: 26px;
  border: 2.6px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner--sm { width: 20px; height: 20px; border-width: 2.2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Модальное окно (пояснение дельты) ================================ */

.modal-host {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: var(--overlay);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-host.is-open { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 340px;
  background: var(--card); color: var(--text);
  border-radius: 20px; padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  transform: scale(0.94); transition: transform 0.2s ease;
}
.modal-host.is-open .modal { transform: scale(1); }
.modal h3 { margin: 0 0 10px; font-size: 18px; }
.modal p { margin: 0 0 8px; color: var(--text-dim); font-size: 14px; }
.modal .btn { margin-top: 16px; }

/* ===== Тосты ============================================================= */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 32px);
  pointer-events: none;
}
.toast {
  background: #2b2b2b;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-show { opacity: 1; transform: translateY(0); }

/* ===== Прочее =========================================================== */

.cover { width: 100%; height: auto; display: block; }
.badge-offline {
  font-size: 13px;
  color: var(--text-dim);
  padding: 0 8px;
}
.hairline { height: 0.5px; background: var(--hairline); margin: 4px 0; }

.info-strip {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--primary-weak);
  color: var(--on-primary-weak);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
}
.info-strip .i { width: 22px; height: 22px; flex: 0 0 auto; }

.link-inline { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ===== Экранные мелочи =================================================== */

.center-col { max-width: 440px; margin: 0 auto; width: 100%; }
.tac { text-align: center; }
.hint { color: var(--text-dim); font-size: 13px; }
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.mt24 { margin-top: 24px; }

.cover-wrap { display: flex; justify-content: center; padding: 6px 0 14px; }
.cover-wrap img { max-height: 230px; width: auto; max-width: 100%; }

.login-logo {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--primary-weak);
  display: flex; align-items: center; justify-content: center;
  margin: 12px auto 0; overflow: hidden;
}
.login-logo img { width: 74px; height: 74px; display: block; }
.login-title { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin: 18px 0 2px; }

.error-inline {
  display: flex; gap: 8px; align-items: flex-start;
  background: color-mix(in srgb, var(--red) 15%, transparent);
  color: var(--red);
  border-radius: 12px; padding: 12px; font-size: 14px; margin-bottom: 14px;
}
.error-inline .i { width: 20px; height: 20px; flex: 0 0 auto; }

.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.steps li { display: flex; gap: 12px; align-items: flex-start; padding: 9px 0; font-size: 15px; }
.steps li::before {
  counter-increment: step; content: counter(step);
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.dt-input {
  width: 100%; min-height: 48px; border: none; border-radius: 12px;
  background: var(--card-2); color: var(--text); font-size: 16px; padding: 0 14px; outline: none;
}

.big-wrap { display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; }
.hero__meta { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.stack-gap > * + * { margin-top: 10px; }

/* Переключатель темы (Авто / Светлая / Тёмная) */
.theme-card { display: flex; align-items: center; gap: 12px; }
.theme-card__title { font-size: 16px; font-weight: 600; }
.seg3 { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.seg3 button {
  border: none; background: transparent; color: var(--text-dim);
  padding: 8px 12px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.seg3 button + button { border-left: 1px solid var(--border); }
.seg3 button.is-active { background: var(--primary); color: var(--on-primary); }
.seg3 .i { width: 20px; height: 20px; }

/* Крупный процент заполнения улья */
.fill-pct { display: flex; align-items: baseline; gap: 8px; }
.fill-pct__num { font-size: 26px; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.fill-pct__lbl { color: var(--text-dim); font-size: 14px; }
.hint-row { display: flex; gap: 8px; align-items: flex-start; color: var(--text-dim); font-size: 14px; }
.hint-row .i { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
