/* Оформление мини-приложения.
   Цвета берём из темы Telegram: приложение должно выглядеть частью клиента,
   а не сайтом внутри него. Своя палитра сломалась бы у всех, кто сидит в
   светлой теме, и наоборот. */
:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --fg: var(--tg-theme-text-color, #000);
  --hint: var(--tg-theme-hint-color, #8b8b8b);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-fg: var(--tg-theme-button-text-color, #fff);
  --card: var(--tg-theme-secondary-bg-color, #f3f3f6);
  --danger: #e05c4b;
  --ok: #3aa76d;
  --radius: 14px;
  --gap: 12px;
}

* { 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;
  overscroll-behavior-y: none;
}

/* Нижняя панель перекрывает контент, поэтому запас снизу обязателен. */
.screen {
  padding: var(--gap) var(--gap)
           calc(76px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  margin: 0 auto;
}

h2 { font-size: 20px; margin: 4px 0 12px; }
p  { margin: 0 0 10px; }
.hint { color: var(--hint); font-size: 14px; }
.center { text-align: center; }

/* --- карточки --- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: var(--gap);
}
.card-title { font-weight: 600; margin-bottom: 8px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid rgba(128, 128, 128, .18);
}
.row:last-child { border-bottom: none; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 500; overflow-wrap: anywhere; }
.row-sub { color: var(--hint); font-size: 13px; overflow-wrap: anywhere; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--btn);
  color: var(--btn-fg);
  white-space: nowrap;
}
.badge.grey { background: rgba(128, 128, 128, .25); color: var(--fg); }
.badge.red  { background: var(--danger); color: #fff; }
.badge.green { background: var(--ok); color: #fff; }

/* --- плитки статистики --- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.tile b { display: block; font-size: 26px; line-height: 1.1; }
.tile span { color: var(--hint); font-size: 13px; }

/* --- кнопки --- */
.btn {
  display: block;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius);
  background: var(--btn);
  color: var(--btn-fg);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
}
.btn:active { opacity: .75; }
.btn.ghost {
  background: var(--card);
  color: var(--fg);
}
.btn:disabled { opacity: .5; }

/* --- переключатель --- */
.switch {
  position: relative;
  width: 50px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 20px;
  border: none;
  background: rgba(128, 128, 128, .35);
  cursor: pointer;
  transition: background .18s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }

/* --- полоса расхода лимита --- */
.bar {
  height: 8px;
  border-radius: 6px;
  background: rgba(128, 128, 128, .25);
  overflow: hidden;
  margin: 8px 0 4px;
}
.bar i {
  display: block;
  height: 100%;
  border-radius: 6px;
  background: var(--ok);
  transition: width .3s;
}
.bar i.warn { background: #e0a23a; }
.bar i.full { background: var(--danger); }

/* --- поля ввода --- */
.input, .textarea {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(128, 128, 128, .3);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  margin-bottom: 10px;
}
.textarea { min-height: 96px; resize: vertical; }

/* Сегменты — выбор из нескольких чисел без клавиатуры. */
.segments { display: flex; gap: 6px; flex-wrap: wrap; }
.seg {
  flex: 1 1 auto;
  min-width: 46px;
  padding: 9px 0;
  border: none;
  border-radius: 10px;
  background: rgba(128, 128, 128, .18);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg.on { background: var(--btn); color: var(--btn-fg); }

/* --- сообщения списков --- */
.msg-text {
  margin-top: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-old {
  color: var(--hint);
  text-decoration: line-through;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.empty { text-align: center; color: var(--hint); padding: 42px 16px; }
.empty span { display: block; font-size: 40px; margin-bottom: 10px; }

/* --- скелет загрузки --- */
.skeleton {
  height: 68px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: linear-gradient(90deg,
    rgba(128, 128, 128, .14) 25%,
    rgba(128, 128, 128, .24) 37%,
    rgba(128, 128, 128, .14) 63%);
  background-size: 400% 100%;
  animation: shine 1.3s infinite;
}
@keyframes shine { to { background-position: -135% 0; } }

/* --- нижние вкладки --- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid rgba(128, 128, 128, .2);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}
.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--hint);
  font: inherit;
  font-size: 10px;
  padding: 7px 0 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tab span { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .65; }
.tab.on { color: var(--link); }
.tab.on span { filter: none; opacity: 1; }

/* --- всплывающее сообщение --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 16px);
  max-width: 88%;
  padding: 11px 18px;
  border-radius: 22px;
  background: rgba(0, 0, 0, .84);
  color: #fff;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
