/* ============================================================
   base.css — каркас приложения и общие элементы:
   кнопки, карточки, списки, поля ввода, нижнее меню, шторка,
   плавные переходы между экранами.
   Правила: кнопки не ниже 44px, шрифт не меньше 14px, без горизонтальной прокрутки.
   ============================================================ */

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

html, body {
  margin: 0; height: 100%; overflow: hidden;           /* страница не прокручивается, прокручиваются экраны */
  background: var(--bg2); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;         /* как приложение, а не сайт */
}
input, textarea, select { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
img { display: block; max-width: 100%; }

/* ---------- Каркас: экран + нижнее меню + кнопка-панель ---------- */
#app {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  max-width: 480px; margin: 0 auto; background: var(--bg2); overflow: hidden;
}
#viewport { position: relative; flex: 1; overflow: hidden; }

/* Экран */
.screen {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  background: var(--bg2); -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
  transition: transform .26s cubic-bezier(.2, .8, .2, 1), opacity .26s ease;
  will-change: transform, opacity;
}
.screen.enter   { transform: translateX(100%); }            /* въезжает справа */
.screen.under   { transform: translateX(-22%); opacity: .55; } /* уезжает влево под новый */
.screen.leaving { transform: translateX(100%); }            /* уезжает вправо при «Назад» */
.screen.fade-in { opacity: 0; transform: none; }            /* появление при смене вкладки */
.screen.fade-out{ opacity: 0; transform: none; }

/* Шапка экрана */
.scr-head {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  min-height: 56px; padding: 6px 12px 6px 16px; background: var(--bg2);
}
.scr-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -.3px; flex: 1; }
.scr-head .back {
  display: none; width: 44px; height: 44px; margin-left: -12px; border-radius: 50%;
  align-items: center; justify-content: center; font-size: 30px; line-height: 1; color: var(--accent);
}
.no-tg .screen.is-sub .scr-head .back { display: flex; }   /* своя стрелка «назад» только вне Telegram */
.scr-head .head-act { min-width: 44px; height: 44px; border-radius: 22px; color: var(--accent); font-weight: 600; padding: 0 8px; }

.pad { padding: 0 16px; }
.section { margin: 0 16px 16px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .5px; margin: 20px 16px 8px; }
.hint { color: var(--hint); font-size: 14px; }

/* ---------- Карточки и списки ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card.pad-in { padding: 16px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 16px; width: 100%; text-align: left;
  position: relative; transition: background .12s;
}
.row + .row::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--line); }
.row:active { background: var(--accent-soft); }
.row .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { color: var(--hint); font-size: 14px; }
.row .chev { color: var(--hint); font-size: 22px; }

/* ---------- Кнопки (высота не меньше 44px) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; font-size: 16px;
  transition: transform .1s, filter .12s, background .12s; text-align: center;
}
.btn:active { transform: scale(.97); filter: brightness(.94); }
.btn.block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.btn-danger { background: rgba(224, 68, 62, .12); color: var(--danger); }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.btn-lg { min-height: 54px; font-size: 17px; border-radius: 16px; }

/* Чипы (выбор из нескольких вариантов) */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 22px; background: var(--card); color: var(--text);
  box-shadow: var(--shadow); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; transition: transform .1s, background .12s;
}
.chip:active { transform: scale(.96); }
.chip.on { background: var(--accent); color: var(--accent-text); }

/* Переключатель из двух-трёх сегментов */
.seg { display: flex; background: var(--bg2); border-radius: 14px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 44px; border-radius: 11px; font-weight: 600; color: var(--hint); transition: background .15s, color .15s; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Поля ввода ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 14px; color: var(--hint); margin: 0 4px 6px; }
.input, .textarea, .select {
  width: 100%; min-height: 48px; padding: 12px 14px; font-size: 16px;   /* 16px — чтобы iPhone не увеличивал экран */
  background: var(--card); color: var(--text); border: 1.5px solid transparent; border-radius: 14px; outline: none;
  box-shadow: var(--shadow); font-family: inherit; appearance: none; -webkit-appearance: none;
}
.textarea { min-height: 96px; resize: none; line-height: 1.4; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.input.bad, .textarea.bad { border-color: var(--danger); }
.err { color: var(--danger); font-size: 14px; margin: 6px 4px 0; }

/* Счётчик количества */
.stepper { display: inline-flex; align-items: center; gap: 2px; background: var(--bg2); border-radius: 22px; }
.stepper button { width: 44px; height: 44px; border-radius: 22px; font-size: 24px; font-weight: 500; color: var(--accent); transition: background .12s, transform .1s; }
.stepper button:active { background: var(--accent-soft); transform: scale(.92); }
.stepper b { min-width: 28px; text-align: center; font-size: 17px; }

/* Метки */
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 10px; border-radius: 12px; font-size: 14px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: rgba(43, 154, 74, .14); color: var(--ok); }
.badge.warn { background: rgba(201, 138, 11, .16); color: var(--warn); }
.badge.bad { background: rgba(224, 68, 62, .14); color: var(--danger); }
.badge.gray { background: var(--bg2); color: var(--hint); }

/* Пустое состояние */
.empty { text-align: center; padding: 48px 32px; color: var(--hint); }
.empty .big { font-size: 56px; margin-bottom: 12px; }
.empty h3 { color: var(--text); margin-bottom: 6px; font-size: 18px; }
.empty .btn { margin-top: 20px; }

/* ---------- Нижнее меню (5 вкладок) ---------- */
#tabbar {
  display: none; flex: none; background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#app.has-tabs #tabbar { display: flex; }
#tabbar button {
  flex: 1; min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--hint); font-size: 14px; position: relative; transition: color .15s, transform .1s;
}
#tabbar button:active { transform: scale(.94); }
#tabbar button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabbar button.on { color: var(--accent); font-weight: 600; }
#tabbar .dot { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-size: 14px; font-weight: 700; line-height: 20px; text-align: center; }

/* ---------- Главная кнопка-панель (запасная, вне Telegram) ---------- */
#mainbar { display: none; flex: none; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border-top: 1px solid var(--line); }
#app.has-main #mainbar { display: block; }
#mainbtn { width: 100%; min-height: 52px; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 17px; transition: transform .1s, filter .12s; }
#mainbtn:active { transform: scale(.98); filter: brightness(.94); }
#mainbtn[disabled] { opacity: .45; }
#mainbtn.busy::after { content: ""; display: inline-block; width: 16px; height: 16px; margin-left: 10px; vertical-align: -3px; border: 2.5px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Шторка (нижняя панель поверх экрана) ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45); opacity: 0; transition: opacity .25s; display: flex; align-items: flex-end; justify-content: center; }
.overlay.show { opacity: 1; }
.sheet {
  width: 100%; max-width: 480px; max-height: 88%; overflow-y: auto; background: var(--bg);
  border-radius: 22px 22px 0 0; transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}
.overlay.show .sheet { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 4px; }
.overlay.center { align-items: center; padding: 24px; }
.overlay.center .sheet { border-radius: 20px; transform: scale(.94); max-height: 80%; }
.overlay.center.show .sheet { transform: none; }

/* Всплывающее сообщение */
#toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 80; max-width: calc(100% - 40px); transform: translate(-50%, 20px);
  padding: 12px 18px; border-radius: 14px; background: rgba(20, 28, 38, .92); color: #fff; font-size: 15px; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Скелетон загрузки */
.skel { background: linear-gradient(90deg, var(--line), rgba(127,127,127,.18), var(--line)); background-size: 200% 100%; animation: shine 1.2s infinite; border-radius: 12px; }
@keyframes shine { to { background-position: -200% 0; } }

/* Меньше анимаций, если пользователь так настроил систему */
@media (prefers-reduced-motion: reduce) { * { transition-duration: 0s !important; animation-duration: .01ms !important; } }
