/* Avito Watch terminal. Telegram's theme carries the surfaces; our own colours only carry meaning:
   gain (worth it), warn (a catch), bad (a defect). Figures are monospace so columns line up like a tape. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #eff0f3);
  --text: var(--tg-theme-text-color, #14161a);
  --hint: var(--tg-theme-hint-color, #80858f);
  --link: var(--tg-theme-link-color, #2b78e4);
  --btn: var(--tg-theme-button-color, #2b78e4);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, rgba(120, 125, 135, 0.18));
  --gain: #12884a;
  --warn: #a2650c;
  --bad: #c3372f;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Roboto Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) { --bg: var(--tg-theme-bg-color, #15171b); --bg2: var(--tg-theme-secondary-bg-color, #0d0e11); --text: var(--tg-theme-text-color, #e9ebef); --hint: var(--tg-theme-hint-color, #8a8f99); }
}
:root[data-scheme="dark"] { --gain: #3fc67a; --warn: #e3a546; --bad: #ff6b62; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
img { display: block; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

/* Header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg2); padding: 8px 12px 6px; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.tabs button { border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-weight: 500; color: var(--hint); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--btn); color: var(--btn-text); }
.alert { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 500; background: color-mix(in srgb, var(--warn) 14%, var(--bg)); color: var(--warn); }
.alert.down { background: color-mix(in srgb, var(--bad) 12%, var(--bg)); color: var(--bad); }
.alert.calm { background: var(--bg2); color: var(--hint); }

.view { padding: 4px 12px 0; display: grid; gap: 8px; }
.empty { text-align: center; color: var(--hint); padding: 40px 12px; max-width: 36ch; margin: 0 auto; }
.empty b { display: block; color: var(--text); font-size: 16px; font-weight: 600; margin-bottom: 6px; }

/* Filter bars: one scrolling row each */
.bar { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; }
.bar::-webkit-scrollbar { display: none; }
.bar button { flex: none; border: 1px solid var(--sep); background: var(--bg); border-radius: 8px; padding: 5px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.bar button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.bar .count { opacity: 0.6; margin-left: 4px; }
.bar .pin { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }

/* The tape: age | photo | what and what is wrong | price and net */
.tape { background: var(--bg); border-radius: 12px; overflow: hidden; }
.line { border-top: 1px solid var(--sep); }
.line:first-child { border-top: 0; }
.line > button { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; display: grid; grid-template-columns: 46px 44px 1fr auto; gap: 8px; align-items: start; padding: 9px 10px; }
.age { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--hint); padding-top: 2px; text-align: right; }
.age.fresh { color: var(--gain); }
.thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--sep); }
.what { min-width: 0; display: grid; gap: 3px; }
.model { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model .v { font-weight: 400; color: var(--hint); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 1px 6px; border-radius: 5px; background: var(--bg2); color: var(--hint); line-height: 18px; }
.chip.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 11%, var(--bg)); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--bg)); }
.why1 { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.why1.bad { color: var(--bad); }
.why1.warn { color: var(--warn); }
.money { text-align: right; display: grid; gap: 2px; }
.money .price { font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.money .net { font-family: var(--mono); font-size: 13px; font-weight: 600; white-space: nowrap; }
.net.gain { color: var(--gain); }
.net.low { color: var(--hint); }
.net.loss { color: var(--bad); }

.money .cap { font-size: 10px; text-transform: none; }
.cap.gain { color: var(--gain); }
.cap.low, .cap.loss { color: var(--hint); }

/* Top of the terminal: what and when, the three outcomes, the order */
.pickers { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pickers button { border: 0; background: var(--bg); border-radius: 10px; padding: 7px 10px; text-align: left; cursor: pointer; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pickers .lbl { display: block; font-size: 11px; font-weight: 400; color: var(--hint); }
.verdicts { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.verdicts button { border: 0; background: none; border-radius: 8px; padding: 7px 4px; font-size: 13px; cursor: pointer; color: var(--hint); }
.verdicts button[aria-selected="true"] { background: var(--bg2); color: var(--text); font-weight: 600; }
.verdicts .count { font-family: var(--mono); opacity: 0.7; }
.sortline { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--hint); padding: 0 2px; }
.sortline button { border: 0; background: none; padding: 3px 6px; border-radius: 6px; font-size: 12px; color: var(--hint); cursor: pointer; }
.sortline button[aria-pressed="true"] { color: var(--text); background: var(--bg); font-weight: 600; }

/* An opened line */
.more { padding: 0 10px 12px 52px; display: grid; gap: 8px; }
.title-full { color: var(--hint); font-size: 13px; }
.mkt { font-family: var(--mono); font-size: 12px; display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 2px 14px; }
.mkt dt { color: var(--hint); font-family: inherit; }
.mkt dd { margin: 0; font-weight: 600; }
.breakdown { display: grid; gap: 3px; background: var(--bg2); border-radius: 9px; padding: 8px 10px; font-size: 13px; }
.b-row { display: flex; justify-content: space-between; gap: 10px; }
.b-row small { color: var(--hint); font-size: 11px; }
.b-row.total { border-top: 1px solid var(--sep); padding-top: 4px; margin-top: 2px; font-weight: 700; }
.b-row.total.gain .num { color: var(--gain); }
.b-row.total.loss .num { color: var(--bad); }
.basis { font-size: 12px; color: var(--hint); }
.basis.low { color: var(--warn); }
.why { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 13px; }
.why .bad { color: var(--bad); }
.why .warn { color: var(--warn); }
.why .note { color: var(--hint); font-size: 12px; }
.acts { display: flex; gap: 6px; }
.primary { flex: 1; border: 0; border-radius: 9px; background: var(--btn); color: var(--btn-text); font-weight: 600; padding: 10px; cursor: pointer; text-align: center; text-decoration: none; }
.acts .ghost { padding: 10px 16px; }
.mark { border: 0; border-radius: 9px; background: var(--bg2); padding: 8px 12px; font-size: 16px; cursor: pointer; }
.mark[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }

/* Market table */
.mrow { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; display: grid; grid-template-columns: 1fr 66px 66px 38px; gap: 6px; align-items: baseline; padding: 8px 10px; border-top: 1px solid var(--sep); }
.mrow:first-child { border-top: 0; }
.mrow.head { cursor: default; font-size: 11px; color: var(--hint); padding-top: 6px; padding-bottom: 6px; }
.mrow .name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mrow .name .v { color: var(--hint); }
.mrow .c { text-align: right; font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.mrow.low .c { color: var(--hint); }
.mrow .sub { grid-column: 1 / -1; font-size: 11px; color: var(--hint); margin-top: -2px; }

/* Settings */
.section-title { font-size: 12px; color: var(--hint); margin: 8px 4px -2px; font-weight: 500; }
.card { background: var(--bg); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }
.facts { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 13px; }
.facts dt { color: var(--hint); }
.facts dd { margin: 0; font-family: var(--mono); text-align: right; }
.stream { border-top: 1px solid var(--sep); padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.stream:first-child { border-top: 0; }
.stream .sub { font-size: 12px; color: var(--hint); }
.stream .del { justify-self: start; border: 0; background: none; color: var(--hint); padding: 2px 0; font-size: 12px; cursor: pointer; }
.switch { position: relative; width: 44px; height: 26px; border-radius: 13px; border: 0; background: var(--sep); cursor: pointer; padding: 0; grid-row: span 2; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.16s ease; }
.switch[aria-checked="true"] { background: var(--gain); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--hint); }
.field input { font: inherit; font-size: 16px; color: var(--text); background: var(--bg2); border: 1px solid transparent; border-radius: 9px; padding: 9px 11px; }
.field input:focus { outline: none; border-color: var(--link); }
.setting { display: grid; gap: 6px; }
.setting > span { font-size: 13px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--sep); background: var(--bg); border-radius: 8px; padding: 6px 11px; font-size: 13px; cursor: pointer; font-family: var(--mono); }
.seg button[aria-pressed="true"] { border-color: var(--btn); background: var(--btn); color: var(--btn-text); }
.ghost { border: 0; background: var(--bg2); border-radius: 9px; padding: 10px 12px; font-weight: 500; cursor: pointer; }
.wide { width: 100%; }
.error-text { color: var(--bad); font-size: 13px; margin: 0; }

/* Bottom panel: hide reasons, categories, age */
.picklist { display: grid; gap: 2px; max-height: 60vh; overflow-y: auto; }
.picklist button { border: 0; background: none; text-align: left; padding: 11px 8px; border-radius: 8px; font-size: 15px; cursor: pointer; }
.picklist button:active, .picklist button[aria-pressed="true"] { background: var(--bg2); }
.picklist .v { color: var(--hint); }
.picklist .none { color: var(--hint); }

/* 👎 reasons */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.4); display: flex; align-items: flex-end; }
.sheet-backdrop[hidden] { display: none; }
.sheet { width: 100%; background: var(--bg); border-radius: 16px 16px 0 0; padding: 16px 12px calc(14px + env(safe-area-inset-bottom)); display: grid; gap: 10px; animation: rise 0.18s ease-out; }
.sheet h2 { margin: 0; font-size: 15px; text-align: center; font-weight: 600; }
.reasons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.reasons button { border: 0; background: var(--bg2); border-radius: 9px; padding: 11px 8px; font-size: 13px; cursor: pointer; }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .switch::after { transition: none; } }
.card > .wide + .facts { margin-top: 10px; }
