/* Цвета берём из темы Telegram, чтобы приложение не выглядело чужим внутри
   мессенджера. Значения после запятой — запасные, если открыли вне Telegram. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f3f5);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #7a8290);
  --link: var(--tg-theme-link-color, #2f7fd8);
  --button: var(--tg-theme-button-color, #2f7fd8);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --ok: #2eab5b;
  --warn: #d9822b;
  --danger: #d64545;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Классы .gate и .sheet задают display, а он сильнее атрибута hidden из
   стилей браузера: без этой строки экран проверки доступа и шторка мастера
   не прячутся никогда и перекрывают приложение. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 16px 40px;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.hint { color: var(--hint); font-size: 13px; margin: 4px 0 10px; }

/* --- Экран проверки доступа --- */
.gate {
  min-height: 70vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; text-align: center; color: var(--hint);
}
.gate.error { color: var(--text); }
.gate.error .spinner { display: none; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--secondary-bg); border-top-color: var(--link);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Счётчик --- */
.counter { padding: 24px 0 8px; text-align: center; }
.counter-pct {
  font-size: 56px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.counter-sign { font-size: 28px; margin-left: 2px; color: var(--hint); }
.counter-sub { margin: 6px 0 18px; color: var(--hint); font-size: 14px; }
.counter-abs { margin: 12px 0 2px; font-size: 15px; font-variant-numeric: tabular-nums; }
.counter-left { margin: 2px 0; font-size: 14px; color: var(--warn); }
.counter-left.reached { color: var(--ok); font-weight: 600; }
.counter-units { margin: 6px 0 0; font-size: 13px; color: var(--hint); }

.bar {
  position: relative; height: 12px; border-radius: 6px;
  background: var(--secondary-bg); overflow: visible;
}
.bar-fill {
  height: 100%; width: 0; border-radius: 6px;
  background: var(--link); transition: width .5s ease;
}
.bar-fill.reached { background: var(--ok); }
.bar-mark {
  position: absolute; top: -4px; bottom: -4px; width: 2px;
  background: var(--text); opacity: .55;
}
.bar-mark span {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--hint); white-space: nowrap;
}

/* --- Блоки --- */
.block { margin-top: 34px; }

.cards { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.card {
  background: var(--secondary-bg); border-radius: var(--radius);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; }
.card-sub { font-size: 13px; color: var(--hint); }
.card-empty { color: var(--hint); font-size: 14px; padding: 4px 0 8px; }

.rows { display: flex; flex-direction: column; gap: 10px; }
.row-line { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.row-name { color: var(--text); }
.row-val { color: var(--hint); font-variant-numeric: tabular-nums; }
.row-bar { height: 6px; border-radius: 3px; background: var(--secondary-bg); }
.row-bar > div { height: 100%; border-radius: 3px; background: var(--link); transition: width .4s; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--secondary-bg); border-radius: 8px;
  padding: 4px 8px; font-size: 13px; font-variant-numeric: tabular-nums;
}
.chip-empty { color: var(--hint); font-size: 14px; }

/* --- Кнопки и формы --- */
.btn {
  appearance: none; border: 0; width: 100%;
  padding: 13px 16px; border-radius: var(--radius);
  background: var(--secondary-bg); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn:active { opacity: .7; }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--secondary-bg); }
.btn-danger { color: var(--danger); }
.btn-sm { width: auto; padding: 8px 12px; font-size: 13px; }

.form-row { display: flex; gap: 8px; margin-bottom: 8px; }
.form-row > * { flex: 1; min-width: 0; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--hint); }
input, select {
  width: 100%; padding: 12px; font-size: 15px; color: var(--text);
  background: var(--secondary-bg); border: 0; border-radius: var(--radius);
}
.admin-group { margin-bottom: 22px; }
.admin-only { border-top: 1px solid var(--secondary-bg); padding-top: 20px; }

/* --- Шторка мастера --- */
.sheet {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; z-index: 20;
}
.sheet-body {
  background: var(--bg); width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 22px 16px calc(24px + env(safe-area-inset-bottom));
  position: relative; animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(24px); opacity: .4; } }
.sheet-close {
  position: absolute; top: 10px; right: 12px;
  border: 0; background: transparent; color: var(--hint);
  font-size: 30px; line-height: 1; cursor: pointer;
}
.sheet h2 { margin-bottom: 4px; padding-right: 30px; }

.choice-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.choice {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px; border-radius: var(--radius);
  background: var(--secondary-bg); border: 0; width: 100%;
  color: var(--text); font-size: 15px; text-align: left; cursor: pointer;
}
.choice:disabled { opacity: .4; cursor: default; }
.choice-note { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; }
.unit-list { max-height: 46vh; overflow-y: auto; margin-top: 10px; }
.confirm-box {
  background: var(--secondary-bg); border-radius: var(--radius);
  padding: 16px; margin: 16px 0; text-align: center;
}
.confirm-title { font-size: 19px; font-weight: 700; }
.confirm-sub { color: var(--hint); font-size: 14px; margin-top: 4px; }
.done-icon { font-size: 44px; text-align: center; margin-bottom: 4px; }

.footer {
  margin-top: 40px; padding-top: 16px;
  border-top: 1px solid var(--secondary-bg);
  color: var(--hint); font-size: 12px; line-height: 1.5;
}

/* --- Всплывающее сообщение --- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 24px; z-index: 40;
  background: var(--text); color: var(--bg);
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 14px; text-align: center;
  animation: rise .2s ease;
}
.toast.error { background: var(--danger); color: #fff; }
