/* Цвета берём у Telegram: приложение должно выглядеть родным и в светлой,
   и в тёмной теме. Запасные значения — на случай открытия в браузере,
   где переменных темы нет вообще. */
:root {
  --bg:        var(--tg-theme-bg-color, #ffffff);
  --fg:        var(--tg-theme-text-color, #14181f);
  --hint:      var(--tg-theme-hint-color, #7a8699);
  --link:      var(--tg-theme-link-color, #2f7bd8);
  --btn:       var(--tg-theme-button-color, #2f7bd8);
  --btn-fg:    var(--tg-theme-button-text-color, #ffffff);
  --card:      var(--tg-theme-secondary-bg-color, #f1f3f6);
  --danger:    var(--tg-theme-destructive-text-color, #d1453b);
  /* серый с прозрачностью, а не color-mix: старые WebView Telegram его не знают */
  --line:      rgba(128, 138, 155, .28);
  --tabs-h:    62px;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;               /* по горизонтали не ездим ни при каких данных */
}

.hidden { display: none !important; }

/* ------------------------------------------------------------ загрузка */

.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.boot-inner { max-width: 340px; text-align: center; }
.boot p { margin: 14px 0 0; }
.spinner {
  width: 26px; height: 26px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--btn);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hint { color: var(--hint); font-size: 14px; }
.hint code { word-break: break-all; }

/* ------------------------------------------------------------- каркас */

.head {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top)) 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  font-weight: 600;
}
#head-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--card); color: var(--hint); white-space: nowrap;
}
.chip.on { color: #1f9254; background: rgba(31, 146, 84, .15); }
.chip.off { color: var(--danger); background: rgba(209, 69, 59, .14); }
.chip.warn { color: #b5730a; background: rgba(214, 143, 20, .16); }

main { padding: 14px 14px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)) 14px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  appearance: none; border: 0; background: none; color: var(--hint);
  font: inherit; font-size: 11px; padding: 9px 2px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer;
}
.tab .ico { font-size: 19px; line-height: 1; }
.tab.active { color: var(--link); }

/* ------------------------------------------------------------ элементы */

h2 { font-size: 15px; margin: 18px 2px 8px; color: var(--hint); font-weight: 600; }
h2:first-child { margin-top: 2px; }

.card {
  background: var(--card); border-radius: 14px; padding: 13px 14px; margin-bottom: 10px;
}
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.kw {
  font-weight: 700; font-size: 15px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card .title { font-weight: 600; }
.card .sub, .card .link { color: var(--hint); font-size: 14px; word-break: break-word; }
.card .link { margin-top: 2px; }
.card-actions { display: flex; gap: 8px; margin-top: 11px; }

.btn {
  appearance: none; border: 0; border-radius: 11px; font: inherit; font-weight: 600;
  padding: 13px 16px; background: var(--btn); color: var(--btn-fg); cursor: pointer;
  width: 100%; min-height: 46px;
}
.btn:active { opacity: .75; }
.btn.sec { background: transparent; color: var(--link); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; }
.card-actions .btn { padding: 9px 12px; min-height: 40px; font-size: 14px; }

label { display: block; margin: 12px 0 5px; font-size: 13px; color: var(--hint); }
input, textarea {
  width: 100%; font: inherit; color: var(--fg); background: var(--card);
  border: 1px solid transparent; border-radius: 11px; padding: 12px;
}
input:focus, textarea:focus { outline: none; border-color: var(--link); }
textarea { min-height: 92px; resize: vertical; }

/* Переключатель «включено» — крупный, чтобы попадать пальцем. */
.sw { position: relative; width: 46px; height: 27px; flex: 0 0 auto; }
.sw input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; z-index: 1; }
.sw span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line);
  transition: background .15s;
}
.sw span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
  border-radius: 50%; background: #fff; transition: transform .15s;
}
.sw input:checked + span { background: var(--btn); }
.sw input:checked + span::after { transform: translateX(19px); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 10px; text-align: center; }
.stat b { display: block; font-size: 23px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--hint); }

.row {
  display: flex; gap: 10px; align-items: baseline;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .num { color: var(--hint); font-size: 14px; white-space: nowrap; }
.row .stage { font-size: 12px; color: var(--hint); }

.empty { color: var(--hint); text-align: center; padding: 26px 10px; }
.err { color: var(--danger); }

/* --------------------------------------------------------------- лист */

.sheet {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; overscroll-behavior: contain;
}
.sheet-body {
  background: var(--bg); width: 100%; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-body h3 { margin: 2px 0 4px; font-size: 18px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: 88vw; padding: 11px 16px; border-radius: 12px;
  background: rgba(20,24,31,.92); color: #fff; font-size: 14px; text-align: center;
}

/* Лента готовых фраз под полем. Горизонтальный свайп, а не перенос строк:
   вариантов до пяти, в столбик они съели бы весь экран телефона и утопили
   само поле ввода, ради которого человек сюда пришёл. */
.hints {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 8px;
  margin-top: -6px;
  scrollbar-width: none;              /* полоса прокрутки на телефоне только мешает */
  -webkit-overflow-scrolling: touch;
}
.hints::-webkit-scrollbar { display: none; }

.hint {
  flex: 0 0 auto;                     /* иначе flex сожмёт чипы и текст обрежется */
  border: 0;
  border-radius: 14px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--hint);
  background: var(--card);
  cursor: pointer;
  white-space: nowrap;
}
.hint:active { opacity: .6; }

/* выбранный вариант: видно, взят готовый текст или человек написал свой */
.hint.on {
  color: var(--btn-fg);
  background: var(--btn);
}
