/* Кабинет Pricer. Цвета — токенами: светлая и тёмная темы, внутри Telegram — его тема. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15171c;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #2458d6;
  --accent-text: #ffffff;
  --accent-soft: #e8efff;
  --good: #137a3a;
  --good-bg: #e2f6e8;
  --warn: #946000;
  --warn-bg: #fff4d6;
  --bad: #b42318;
  --bad-bg: #fde8e7;
  --neutral-bg: #eef0f3;
  --chart-line: #2458d6;
  --chart-target: #137a3a;
  --chart-grid: #e8ebf0;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #eceef2;
    --muted: #98a2b3;
    --line: #2b303a;
    --accent: #7aa2ff;
    --accent-text: #0b1020;
    --accent-soft: #1d2a4a;
    --good: #5fd68b;
    --good-bg: #13301f;
    --warn: #f0c35a;
    --warn-bg: #33290f;
    --bad: #ff8a80;
    --bad-bg: #3a1716;
    --neutral-bg: #262a33;
    --chart-line: #7aa2ff;
    --chart-target: #5fd68b;
    --chart-grid: #262b34;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242c;
  --text: #eceef2;
  --muted: #98a2b3;
  --line: #2b303a;
  --accent: #7aa2ff;
  --accent-text: #0b1020;
  --accent-soft: #1d2a4a;
  --good: #5fd68b;
  --good-bg: #13301f;
  --warn: #f0c35a;
  --warn-bg: #33290f;
  --bad: #ff8a80;
  --bad-bg: #3a1716;
  --neutral-bg: #262a33;
  --chart-line: #7aa2ff;
  --chart-target: #5fd68b;
  --chart-grid: #262b34;
  --shadow: none;
  color-scheme: dark;
}

/* Внутри Telegram — его цвета: кабинет выглядит частью приложения. */
html.tg {
  --bg: var(--tg-theme-secondary-bg-color, #f5f6f8);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-2: var(--tg-theme-secondary-bg-color, #f0f2f5);
  --text: var(--tg-theme-text-color, #15171c);
  --muted: var(--tg-theme-hint-color, #667085);
  --accent: var(--tg-theme-button-color, #2458d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --chart-line: var(--tg-theme-link-color, #2458d6);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1 {
  font-size: 22px;
  line-height: 1.25;
  margin: 0;
}

h2 {
  font-size: 16px;
  margin: 0 0 12px;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* --- шапка ------------------------------------------------------------------ */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px max(16px, calc((100% - 1120px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}

.tabs {
  display: flex;
  gap: 4px;
}

.tabs a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
}

.tabs a.active {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}

html.tg .tabs a.active {
  background: var(--surface-2);
}

.top-side {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.view {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* --- общие элементы ------------------------------------------------------------ */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.button:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.button.primary:hover {
  filter: brightness(1.07);
}

.button.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

.button.big {
  min-height: 46px;
  padding: 10px 22px;
  font-size: 16px;
  font-weight: 600;
}

.button.wide {
  width: 100%;
}

.button:disabled {
  opacity: 0.55;
  cursor: default;
}

.danger-text {
  color: var(--bad);
}

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

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

.chip:hover {
  background: var(--surface-2);
}

.input {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--neutral-bg);
  color: var(--muted);
  white-space: nowrap;
}

.badge.good {
  background: var(--good-bg);
  color: var(--good);
}

.badge.paused {
  background: var(--warn-bg);
  color: var(--warn);
}

.good-text {
  color: var(--good);
}

.bad-text {
  color: var(--bad);
}

.warn-text {
  color: var(--warn);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 16px;
}

.loading,
.empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 8px;
}

.empty-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 16px;
}

/* --- список ------------------------------------------------------------------ */

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

.filters > * {
  flex: 1 1 130px;
}

.filters input[type="search"] {
  flex: 2 1 200px;
}

.bulk {
  position: sticky;
  top: 57px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

html.tg .bulk {
  top: 0;
  background: var(--surface);
}

.bulk-count {
  font-weight: 600;
  margin-right: 4px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table th.num,
.table td.num {
  text-align: right;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tr.picked td {
  background: var(--accent-soft);
}

html.tg .table tr.picked td {
  background: var(--surface-2);
}

.table .pick {
  width: 36px;
  padding-right: 0;
}

.table input[type="checkbox"],
.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.sort {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.sort.active {
  color: var(--accent);
}

.table th:nth-child(4),
.table th:nth-child(5),
.table th:nth-child(6) {
  text-align: right;
}

.product .title {
  color: var(--text);
  font-weight: 600;
}

.product .title:hover {
  color: var(--accent);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin-top: 4px;
  font-size: 13px;
}

.market {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.market.ozon {
  color: #1f5fd6;
}

.market.wb {
  color: #a0198f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .market.ozon {
    color: #7aa2ff;
  }

  :root:not([data-theme="light"]) .market.wb {
    color: #e38ad8;
  }
}

.note {
  color: var(--muted);
}

.meta-region {
  display: none;
  color: var(--muted);
}

.price {
  font-weight: 600;
}

.list-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
}

/* --- карточка ---------------------------------------------------------------- */

.back {
  margin: 0 0 12px;
}

.card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-meta {
  margin: 6px 0 16px;
}

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

.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.tile-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tile-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.insight-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.grade {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-weight: 700;
  margin-right: 10px;
  background: var(--neutral-bg);
}

.grade.good {
  background: var(--good-bg);
  color: var(--good);
}

.grade.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.grade.bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.grade-note {
  color: var(--muted);
}

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

.segmented button {
  border: 0;
  background: none;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.chart-box {
  margin: 8px 0 0;
}

.chart {
  width: 100%;
  height: auto;
  display: block;
  touch-action: pan-y;
  user-select: none;
}

.chart .grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart .axis {
  fill: var(--muted);
  font-size: 12px;
}

.chart .price {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2.25;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart .dot {
  fill: var(--chart-line);
}

.chart .target {
  stroke: var(--chart-target);
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
}

.chart .target-label {
  fill: var(--chart-target);
  font-size: 12px;
  font-weight: 600;
}

.chart .gap {
  stroke: var(--muted);
  stroke-width: 2;
  opacity: 0.6;
}

.chart .lowest {
  fill: var(--surface);
  stroke: var(--chart-target);
  stroke-width: 2;
}

.chart .last {
  fill: var(--chart-line);
  stroke: var(--surface);
  stroke-width: 2;
}

.chart .cursor-line {
  stroke: var(--muted);
  stroke-dasharray: 3 3;
}

.chart .cursor-dot {
  fill: var(--chart-line);
  stroke: var(--surface);
  stroke-width: 2;
}

.chart .tip {
  fill: var(--text);
  opacity: 0.92;
}

.chart .tip-price {
  fill: var(--surface);
  font-size: 13px;
  font-weight: 700;
}

.chart .tip-date {
  fill: var(--surface);
  font-size: 11px;
  opacity: 0.85;
}

.chart-empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 8px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.key::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 0;
  margin-right: 6px;
  vertical-align: middle;
  border-top: 2px solid var(--chart-line);
}

.key-target::before {
  border-top: 2px dashed var(--chart-target);
}

.key-lowest::before {
  width: 8px;
  height: 8px;
  border: 2px solid var(--chart-target);
  border-radius: 50%;
}

.key-gap::before {
  width: 2px;
  height: 10px;
  border: 0;
  background: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px 16px;
  margin: 14px 0 0;
}

.stats div {
  display: flex;
  flex-direction: column;
}

.stats dt {
  font-size: 12px;
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sent {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sent li {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.sent li:last-child {
  border-bottom: 0;
}

.sent-when {
  color: var(--muted);
}

/* --- экономия ---------------------------------------------------------------- */

.total {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 16px;
}

.total-value {
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.total-value.good {
  color: var(--good);
}

.total-value.bad {
  color: var(--bad);
}

/* --- вход -------------------------------------------------------------------- */

.login {
  max-width: 440px;
  margin: 12vh auto 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.login h1 {
  font-size: 30px;
}

.lead {
  font-size: 16px;
  margin: 0;
}

/* --- диалоги и сообщения ------------------------------------------------------ */

.dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 25%);
}

.dialog::backdrop {
  background: rgb(10 12 16 / 45%);
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

.dialog-title {
  font-size: 18px;
  margin: 0;
}

.dialog-body p {
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.dialog-error {
  color: var(--bad);
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-weight: 600;
  font-size: 14px;
}

.field-hint {
  font-size: 13px;
  color: var(--muted);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 20%);
}

.toast[data-tone="bad"] {
  background: var(--bad);
  color: #fff;
}

/* --- телефон и Mini App ------------------------------------------------------------ */

@media (max-width: 760px) {
  .top {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 16px;
  }

  .top-side {
    gap: 6px;
  }

  .tabs {
    order: 3;
    width: 100%;
  }

  .tabs a {
    flex: 1;
    text-align: center;
  }

  .view {
    padding: 14px 12px 40px;
  }

  .filters > * {
    flex-basis: 140px;
  }

  .filters input[type="search"] {
    flex-basis: 100%;
  }

  .bulk {
    top: 0;
  }

  /* Таблица становится стопкой карточек: колонки в телефон не помещаются. */
  .table thead {
    display: none;
  }

  .table,
  .table tbody,
  .table tr,
  .table td {
    display: block;
    width: 100%;
  }

  .table tr {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 6px 10px;
    padding: 12px 12px 12px 44px;
    border-bottom: 1px solid var(--line);
  }

  .table tbody tr:last-child {
    border-bottom: 0;
  }

  .table td {
    padding: 0;
    border: 0;
    text-align: left;
  }

  .table td.num {
    text-align: left;
  }

  .table td.pick {
    position: absolute;
    left: 12px;
    top: 12px;
    width: auto;
  }

  .table td.product {
    grid-column: 1 / -1;
  }

  /* Регион — в строке под названием: колонке под него на телефоне места нет. */
  .table td.region {
    display: none;
  }

  .meta-region {
    display: inline;
  }

  .table td[data-label]:not(.product)::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .table.savings tr {
    padding-left: 12px;
  }

  .card-title {
    flex-direction: column;
  }

  .tile-value {
    font-size: 22px;
  }

  .sent li {
    grid-template-columns: 1fr auto;
  }

  .sent-when {
    grid-column: 1 / -1;
  }
}

html.tg .top {
  position: static;
}

html.tg .brand {
  display: none;
}
