/* Оформление мини-аппа. Цвета берём из темы Telegram, поэтому приложение
   выглядит одинаково уместно и в светлой, и в тёмной теме клиента.
   Значения после запятой — фолбэк на случай запуска вне Telegram. */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --surface: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8b9aa8);
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 14px;
  --tabbar-h: 58px;
  --up: #e5484d;
  --down: #3fa66a;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

/* --------------------------------------------------------------------- */
/* Шапка                                                                  */
/* --------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.chip {
  flex: 1; display: flex; align-items: center; gap: 6px;
  min-width: 0; padding: 8px 12px;
  background: var(--surface); color: var(--text);
  border: none; border-radius: 999px;
  font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.chip span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__caret { color: var(--hint); font-size: 11px; }

.icon-btn {
  flex: none; width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--surface); color: var(--text);
  border: none; border-radius: 50%;
  font-size: 18px; cursor: pointer;
}
.icon-btn.is-busy { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------- */
/* Общие блоки                                                            */
/* --------------------------------------------------------------------- */
.screen { padding: 12px; }

.section-title {
  margin: 18px 4px 8px;
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--hint);
}
.screen > .section-title:first-child { margin-top: 4px; }

.panel { background: var(--surface); border-radius: var(--radius); overflow: hidden; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 13px 14px;
  background: none; border: none; border-bottom: 1px solid var(--line);
  color: var(--text); font: inherit; text-align: left;
}
.row:last-child { border-bottom: none; }
.row--tap { cursor: pointer; }
.row--tap::after { content: "›"; color: var(--hint); }
.row--column { flex-direction: column; align-items: stretch; gap: 10px; }
.row__label { font-size: 13px; color: var(--hint); }
.row__value { color: var(--hint); }
.row--switch { cursor: pointer; }

.switch { appearance: none; width: 46px; height: 28px; flex: none;
  background: var(--line); border-radius: 999px; position: relative;
  transition: background .18s; cursor: pointer; }
.switch::after { content: ""; position: absolute; inset: 3px auto 3px 3px;
  width: 22px; background: #fff; border-radius: 50%; transition: transform .18s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.meta { margin: 14px 4px 4px; font-size: 12px; color: var(--hint); text-align: center; }
.empty { padding: 28px 16px; text-align: center; color: var(--hint); }

/* --------------------------------------------------------------------- */
/* Переключатели                                                          */
/* --------------------------------------------------------------------- */
.segmented {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface); border-radius: 12px;
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented--wrap { flex-wrap: wrap; overflow: visible; }
.segmented button {
  flex: 1 0 auto; padding: 8px 12px;
  background: none; border: none; border-radius: 9px;
  color: var(--hint); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.segmented button.is-active { background: var(--accent); color: var(--accent-text); }

.switch-row { display: flex; gap: 8px; margin: 10px 0; }
.pill {
  flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 10px;
  background: none; color: var(--hint); font: inherit; font-weight: 600; cursor: pointer;
}
.pill.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggles button {
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: none;
  color: var(--hint); font: inherit; font-size: 13px; cursor: pointer;
}
.toggles button.is-on { border-color: transparent; color: #fff; }

/* --------------------------------------------------------------------- */
/* Цены                                                                   */
/* --------------------------------------------------------------------- */
.averages { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; }
.avg {
  padding: 10px 8px; background: var(--surface); border-radius: 12px; text-align: center;
}
.avg__label { font-size: 11px; color: var(--hint); }
.avg__value { font-size: 17px; font-weight: 700; margin-top: 2px; }

.cards { display: flex; flex-direction: column; gap: 8px; }
.card { padding: 12px 14px; background: var(--surface); border-radius: var(--radius); }
.card__name { font-weight: 600; margin-bottom: 8px; }
.card__prices { display: flex; flex-wrap: wrap; gap: 6px; }
.tagp {
  display: flex; align-items: baseline; gap: 5px;
  padding: 4px 9px; border-radius: 8px;
  background: color-mix(in srgb, var(--hint) 14%, transparent);
  font-size: 13px;
}
.tagp b { font-variant-numeric: tabular-nums; }
.tagp i { font-style: normal; color: var(--hint); font-size: 11px; }

/* --------------------------------------------------------------------- */
/* Рейтинг                                                                */
/* --------------------------------------------------------------------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.summary div { padding: 9px 6px; background: var(--surface); border-radius: 11px; text-align: center; }
.summary span { display: block; font-size: 11px; color: var(--hint); }
.summary b { font-size: 15px; }

.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rank li {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 11px 13px; background: var(--surface); border-radius: 12px; overflow: hidden;
}
/* Полоса под строкой — доля цены в разбросе области: видно «дёшево/дорого»
   без чтения цифр. */
.rank li::before {
  content: ""; position: absolute; inset: 0 auto 0 0;
  width: var(--fill, 0%); background: var(--bar, var(--accent)); opacity: .16;
}
.rank .place { position: relative; width: 22px; color: var(--hint); font-variant-numeric: tabular-nums; }
.rank .name { position: relative; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .price { position: relative; font-weight: 700; font-variant-numeric: tabular-nums; }
.rank li.is-best .price { color: var(--down); }
.rank li.is-worst .price { color: var(--up); }

/* --------------------------------------------------------------------- */
/* График                                                                 */
/* --------------------------------------------------------------------- */
.chart-wrap { margin-top: 12px; background: var(--surface); border-radius: var(--radius); padding: 10px 6px 4px; }
#chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 10px; font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* --------------------------------------------------------------------- */
/* Нефть                                                                  */
/* --------------------------------------------------------------------- */
.quote { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.quote__title { font-weight: 700; font-size: 17px; }
.quote__symbol { font-size: 11px; color: var(--hint); }
.quote__price { font-size: 22px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.quote__change { font-size: 13px; text-align: right; }
.up { color: var(--up); } .down { color: var(--down); }

.table-wrap { background: var(--surface); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 14px; text-align: right; white-space: nowrap; }
th { font-size: 11px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .05em; }
td:first-child, th:first-child { text-align: left; }
tbody tr { border-top: 1px solid var(--line); }

/* --------------------------------------------------------------------- */
/* Админ-панель                                                           */
/* --------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
.stat { padding: 11px 8px; background: var(--surface); border-radius: 12px; text-align: center; }
.stat b { display: block; font-size: 19px; }
.stat span { font-size: 11px; color: var(--hint); }

.user { display: flex; align-items: center; gap: 10px; padding: 11px 13px; background: var(--surface); border-radius: 12px; }
.user__dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--hint); }
.user__dot.is-online { background: var(--down); }
.user__body { flex: 1; min-width: 0; }
.user__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user__sub { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user__btn {
  flex: none; padding: 7px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: none; color: var(--text); font: inherit; font-size: 12px; cursor: pointer;
}
.user__btn.is-block { color: var(--up); border-color: color-mix(in srgb, var(--up) 45%, transparent); }
.user__btn.is-allow { color: var(--down); border-color: color-mix(in srgb, var(--down) 45%, transparent); }
.user.is-blocked .user__name { text-decoration: line-through; opacity: .65; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; color: var(--hint); font-size: 13px; }
.pager button { padding: 6px 14px; border-radius: 9px; border: 1px solid var(--line); background: none; color: var(--text); font: inherit; cursor: pointer; }
.pager button:disabled { opacity: .35; }

.about { margin: 22px 4px 8px; font-size: 12px; color: var(--hint); text-align: center; line-height: 1.6; }

/* --------------------------------------------------------------------- */
/* Нижние вкладки и модалка                                               */
/* --------------------------------------------------------------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--hint); font: inherit; font-size: 10px; cursor: pointer;
}
.tab span { font-size: 19px; line-height: 1; }
.tab.is-active { color: var(--accent); }

.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet__body {
  position: relative; width: 100%; max-height: 78vh;
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(18px); opacity: .4; } }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 12px; }
.region-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.region-list button {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border: none; border-radius: 11px;
  background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.region-list button.is-active { background: var(--accent); color: var(--accent-text); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 22px); z-index: 50;
  transform: translateX(-50%);
  max-width: 88vw; padding: 10px 16px; border-radius: 11px;
  background: rgba(0,0,0,.86); color: #fff; font-size: 13px; text-align: center;
}
.skeleton { height: 68px; border-radius: var(--radius); background: var(--surface); opacity: .55;
  animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
