/* Пульт Lakomka — веб-пульт (Telegram Mini App). Сначала телефон и iPad.
   Цвета графиков — проверенная палитра (светлая и тёмная тема отдельно), текст — только
   текстовыми токенами, фон страницы — из темы Telegram. */

:root {
  color-scheme: light;
  --page: var(--tg-theme-secondary-bg-color, #f2f2ef);
  --page-text: var(--tg-theme-text-color, #0b0b0b);
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: var(--tg-theme-button-color, #2a78d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2a78d6);
  --good: #006300;
  --bad: #d03b3b;
  --band: rgba(12, 163, 12, 0.10);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #6250d6;
  --s8: #e34948;
  --other: #b5b3ab;
  --radius: 12px;
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: var(--tg-theme-secondary-bg-color, #0d0d0d);
    --page-text: var(--tg-theme-text-color, #f0efec);
    --surface: #1a1a19;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.06);
    --good: #0ca30c;
    --bad: #e66767;
    --band: rgba(12, 163, 12, 0.16);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #008300;
    --s7: #9085e9;
    --s8: #e66767;
    --other: #5c5b56;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: var(--tg-theme-secondary-bg-color, #0d0d0d);
  --page-text: var(--tg-theme-text-color, #f0efec);
  --surface: #1a1a19;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --wash: rgba(255, 255, 255, 0.06);
  --good: #0ca30c;
  --bad: #e66767;
  --band: rgba(12, 163, 12, 0.16);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;
  --other: #5c5b56;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--page);
  color: var(--page-text);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--link);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px calc(84px + var(--safe-bottom));
}

h1 {
  font-size: 20px;
  margin: 4px 0 12px;
}

h2 {
  font-size: 16px;
  margin: 0 0 8px;
  color: var(--text);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hint {
  color: var(--text-2);
  font-size: 13px;
}

.card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 12px;
}

.stack > * + * {
  margin-top: 8px;
}

/* --- Нижнее меню разделов ------------------------------------------------------------ */

nav.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: var(--tg-theme-bg-color, var(--surface));
  border-top: 1px solid var(--border);
  z-index: 10;
}

nav.tabs a {
  flex: 1;
  max-width: 160px;
  text-align: center;
  text-decoration: none;
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 12px;
  padding: 4px 2px;
  border-radius: 10px;
}

nav.tabs a .icon {
  display: block;
  font-size: 20px;
  line-height: 1.2;
}

nav.tabs a[aria-current="page"] {
  color: var(--accent);
  background: var(--wash);
  font-weight: 600;
}

/* --- Переключатели и кнопки ---------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.segmented {
  display: inline-flex;
  background: var(--wash);
  border-radius: 10px;
  padding: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--page-text);
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 600;
}

.btn.secondary {
  background: var(--wash);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.5;
}

.link-btn {
  border: 0;
  background: none;
  color: var(--link);
  padding: 4px 0;
  cursor: pointer;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

label.field {
  display: block;
  font-size: 13px;
  color: var(--text-2);
}

label.field > input,
label.field > textarea,
label.field > select {
  margin-top: 4px;
}

.switch {
  appearance: none;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--axis);
  position: relative;
  cursor: pointer;
  flex: none;
  margin: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  transition: left 0.15s;
}

.switch:checked {
  background: var(--accent);
}

.switch:checked::after {
  left: 21px;
}

/* --- Показатели ---------------------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

@media (min-width: 640px) {
  .tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.tile {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.tile .label {
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile .value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 2px;
}

.tile .sub {
  font-size: 13px;
  color: var(--text-2);
}

.delta {
  font-size: 13px;
  font-weight: 600;
}

.delta.up {
  color: var(--good);
}

.delta.down {
  color: var(--bad);
}

.delta.flat {
  color: var(--text-2);
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

.line-key {
  display: inline-block;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  flex: none;
  vertical-align: middle;
}

/* --- Графики ------------------------------------------------------------------------- */

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.chart-head .hint {
  margin: 0 0 6px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 4px 0 8px;
  font-size: 13px;
  color: var(--text-2);
}

.legend button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: none;
  padding: 2px 0;
  cursor: pointer;
  color: var(--text-2);
}

.legend button[aria-pressed="false"] {
  opacity: 0.4;
}

.chart {
  position: relative;
  touch-action: pan-y;
}

.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.chart text {
  font-size: 11px;
  fill: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart .label-strong {
  fill: var(--text-2);
  font-weight: 600;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
  min-width: 140px;
  z-index: 5;
}

.tooltip .title {
  color: var(--text-2);
  margin-bottom: 4px;
}

.tooltip .row {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tooltip .row b {
  font-variant-numeric: tabular-nums;
}

.tooltip .row span {
  color: var(--text-2);
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th,
td {
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--text-2);
  font-weight: 600;
}

/* --- Отчёты -------------------------------------------------------------------------- */

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin: 0 0 8px;
  cursor: pointer;
}

.list-item .when {
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
}

.report {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.report blockquote {
  margin: 4px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--axis);
  background: var(--wash);
  border-radius: 6px;
}

.report code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--wash);
  padding: 1px 4px;
  border-radius: 4px;
}

/* --- Конкуренты ---------------------------------------------------------------------- */

.offers {
  margin-top: 14px;
}

.offers h3 {
  font-size: 15px;
  margin: 0 0 2px;
}

/* Строка магазина: имя и цена, под ними товар, ниже метки — на узком экране ничего не сжимается */
.offer,
.run {
  display: block;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
  color: var(--text);
  text-decoration: none;
}

.offer:last-child,
.run:last-child {
  border-bottom: 0;
}

.offer .line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.offer .num {
  white-space: nowrap;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.offer .go {
  color: var(--link);
}

.offer small,
.run small {
  display: block;
  color: var(--text-2);
  overflow-wrap: anywhere;
}

.run small.error {
  color: var(--bad);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--wash);
  color: var(--text-2);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
}

.site {
  display: flex;
  align-items: center;
  gap: 10px;
}

.site .info {
  flex: 1;
  min-width: 0;
}

.state {
  font-size: 13px;
  color: var(--text-2);
}

.state.bad::before {
  content: "⛔ ";
}

.state.ok::before {
  content: "✅ ";
}

.notice {
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--wash);
  color: var(--text);
  font-size: 14px;
}

.notice.error::before {
  content: "⚠️ ";
}

.empty {
  color: var(--text-2);
  text-align: center;
  padding: 24px 8px;
}

.loading {
  opacity: 0.5;
  transition: opacity 0.2s;
}

details summary {
  cursor: pointer;
  color: var(--link);
  font-size: 14px;
}
