:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #171717);
  --hint: var(--tg-theme-hint-color, #757575);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --brand: #007782;
  --gap: color-mix(in srgb, var(--bg2) 70%, var(--bg));
  --brand-ink: #ffffff;
  --new: #ff6a3d;
  --radius: 10px;
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: contain;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(8px + var(--safe-top)) 12px 0;
  background: var(--bg);
  box-shadow: 0 1px 0 var(--sep);
}
.top-line { display: flex; gap: 8px; align-items: center; }
.top-line .search { flex: 1; min-width: 0; }
.home { position: relative; flex: none; height: 40px; border-radius: 10px; background: var(--bg2); }
.home select {
  height: 100%; padding: 0 26px 0 12px; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 15px; font-weight: 600; -webkit-appearance: none; appearance: none;
}
.home::after { content: ""; position: absolute; right: 11px; top: 16px; width: 6px; height: 6px; border: solid var(--hint); border-width: 0 2px 2px 0; transform: rotate(45deg); pointer-events: none; }
.search {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 6px 0 12px;
  border-radius: 10px; background: var(--bg2);
}
.search svg { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--hint); stroke-width: 2.2; stroke-linecap: round; }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }
#q-clear {
  flex: none; width: 26px; height: 26px; border-radius: 50%; font-size: 17px; line-height: 26px;
  background: color-mix(in srgb, var(--hint) 35%, transparent); color: var(--bg);
}

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13px; white-space: nowrap;
  border: 1px solid var(--sep); background: var(--bg);
}
.chip small { margin-left: 4px; font-size: 10px; font-weight: 600; color: var(--hint); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip.on small { color: rgba(255,255,255,.75); }
.chip.paused { opacity: .5; }

/* New items pill */
.fresh {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(112px + var(--safe-top)); z-index: 6;
  padding: 8px 14px; border-radius: 999px; background: var(--brand); color: var(--brand-ink);
  font-weight: 600; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

/* Grid */
main { padding: 12px 12px 40px; max-width: 1280px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 10px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px 14px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.card { display: block; text-align: left; min-width: 0; padding: 0; }
.card .ph { position: relative; aspect-ratio: 3 / 4; border-radius: 6px; overflow: hidden; background: var(--bg2); }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.card img.ok { opacity: 1; }
.card .fav {
  position: absolute; right: 6px; bottom: 6px; display: flex; align-items: center; gap: 3px;
  padding: 3px 7px; border-radius: 999px; font-size: 11px; background: rgba(255,255,255,.94); color: #333;
}
.card .fav svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2.4; }
.card .badge {
  position: absolute; left: 6px; top: 6px; padding: 2px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: .3px; background: var(--brand); color: #fff;
}
.card .meta { padding: 7px 1px 0; }
.card .brand { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .price { margin-top: 4px; font-size: 14px; font-weight: 500; color: var(--text); }
.card .total { display: flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 600; color: var(--brand); }
.card .total svg { width: 12px; height: 12px; fill: currentColor; }
.card .when { font-size: 11px; color: var(--hint); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.arrive { animation: arrive .45s cubic-bezier(.2,.8,.2,1); }
@keyframes arrive { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

.state { padding: 40px 18px; text-align: center; color: var(--hint); }
.state b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.state:empty, .more:empty { display: none; }
.more { padding: 18px; text-align: center; color: var(--hint); font-size: 13px; }

/* Detail sheet (Vinted app item screen) */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--gap); display: flex; flex-direction: column; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet[hidden] { display: none; }
.sheet-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

.sheet-bar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-top)) 6px 6px;
  transition: background .2s, box-shadow .2s;
}
.sheet-bar.solid { background: var(--bg); box-shadow: 0 1px 0 var(--sep); }
.bar-title {
  flex: 1; min-width: 0; text-align: center; font-size: 17px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity .2s;
}
.sheet-bar.solid .bar-title { opacity: 1; }
.icon-btn { flex: none; width: 40px; height: 40px; display: grid; place-items: center; color: #fff; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); }
.icon-btn .dots3 { fill: currentColor; stroke: none; }
.sheet-bar.solid .icon-btn { color: var(--text); }
.sheet-bar.solid .icon-btn svg { filter: none; }

.hero { position: relative; background: var(--bg2); }
/* Height follows the screen: 3:4 of the width on phones, capped so the title stays visible on short/wide screens */
.gallery {
  display: flex; width: 100%; height: min(calc(100vw * 4 / 3), 70vh, 860px);
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery img { flex: 0 0 100%; width: 100%; height: 100%; object-fit: cover; scroll-snap-align: start; scroll-snap-stop: always; }
.dots { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; gap: 5px; pointer-events: none; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); }
.dots i.on { background: #fff; }
.fav-btn {
  position: absolute; right: 12px; bottom: 12px; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(30,30,30,.55); color: #fff;
}
.fav-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }

.blk { background: var(--bg); padding: 16px; margin-bottom: 10px; }
.blk:last-child { margin-bottom: 0; }
.d-title { margin: 0; font-size: 18px; font-weight: 600; }
.d-summary { margin-top: 3px; font-size: 15px; color: var(--hint); }
.d-summary a { color: var(--brand); text-decoration: underline; }
.d-flags:empty { display: none; }
.d-flags { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.d-flags span { font-size: 12px; padding: 3px 8px; border-radius: 6px; background: color-mix(in srgb, #f59e0b 18%, transparent); color: #d97706; }
.d-price { margin-top: 14px; font-size: 14px; color: var(--hint); }
.d-total { display: flex; align-items: center; gap: 4px; font-size: 16px; color: var(--brand); }
.d-total svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.d-ship { margin-top: 4px; font-size: 13px; color: var(--hint); }
.d-ship:empty { display: none; }

.blk-head { font-size: 14px; color: var(--hint); margin-bottom: 14px; }
.d-desc { margin: 0; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.d-desc.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.link { padding: 0; color: var(--brand); text-decoration: underline; font-size: 15px; }
#desc-more { margin-top: 4px; }

.seller { display: flex; align-items: center; gap: 12px; }
.seller-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.avatar {
  flex: none; width: 48px; height: 48px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: #8fa3ad; color: #fff; font-size: 20px; font-weight: 500;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.who { min-width: 0; }
.who b { display: block; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stars { font-size: 15px; color: #f5b301; letter-spacing: 1px; }
.stars .off { color: color-mix(in srgb, var(--hint) 45%, transparent); }
.stars small { color: var(--hint); letter-spacing: 0; margin-left: 4px; font-size: 14px; }
.badges:empty { display: none; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.badges span {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; font-size: 13px;
  background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand);
}

.safe { display: flex; gap: 12px; align-items: flex-start; }
.safe-ico { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--brand) 18%, transparent); color: var(--brand); }
.safe-ico svg { width: 20px; height: 20px; fill: currentColor; }
.safe b { font-size: 16px; }
.safe p { margin: 3px 0 0; font-size: 14px; color: var(--hint); }

.sheet-actions { padding: 12px 16px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--sep); background: var(--bg); display: grid; gap: 8px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { height: 44px; border-radius: 6px; border: 1px solid var(--brand); color: var(--brand); font-weight: 500; font-size: 16px; background: transparent; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.small { flex: none; height: 38px; padding: 0 14px; font-size: 15px; }
.btn:disabled { opacity: .45; }
.small-link { justify-self: center; font-size: 13px; }
.skeleton { background: linear-gradient(90deg, var(--bg2), color-mix(in srgb, var(--bg2) 60%, var(--bg)), var(--bg2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; min-height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

/* Telegram dark theme: lighter teal like the Vinted dark app */
body.dark { --brand: #4aa6ae; --brand-ink: #0f1a1b; --gap: color-mix(in srgb, var(--bg) 70%, #000); }

/* Tablets / desktop: header and item screen keep a phone-like readable column */
.top > * { max-width: 1256px; margin-left: auto; margin-right: auto; }
@media (min-width: 700px) {
  .sheet { background: color-mix(in srgb, #000 55%, transparent); align-items: center; }
  .sheet-scroll, .sheet-actions { width: 100%; max-width: 640px; background: var(--gap); }
  .sheet-bar { left: 50%; right: auto; width: 100%; max-width: 640px; transform: translateX(-50%); }
  .gallery { height: min(853px, 72vh); }
}

/* Account / offer modals, toast */
.acc-btn { position: relative; flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--bg2); display: grid; place-items: center; }
.acc-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; }
.acc-btn i { position: absolute; right: 7px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.acc-btn i.on { background: #22c55e; }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; background: var(--bg); color: var(--text);
  border-radius: 14px 14px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
@media (min-width: 700px) { .modal { align-items: center; } .modal-card { border-radius: 14px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; font-size: 17px; margin-bottom: 6px; }
.modal-x { width: 32px; height: 32px; font-size: 24px; color: var(--hint); }
.modal-card p { margin: 8px 0; font-size: 14px; }
.modal-card .btn { width: 100%; margin-top: 10px; }
.muted { color: var(--hint); }
.small { font-size: 12px !important; }
.modal-card code { font-size: 12px; background: var(--bg2); padding: 1px 4px; border-radius: 4px; }
.fld { display: block; margin-top: 10px; font-size: 12px; color: var(--hint); }
.fld textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--sep);
  background: var(--bg2); color: var(--text); font: 13px/1.3 ui-monospace, Menlo, monospace; resize: vertical;
}
.err { color: #e5484d; font-size: 14px; }
.offer-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.offer-row input {
  flex: 1; min-width: 0; height: 48px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--bg2); color: var(--text); font: 600 22px/1 inherit; outline: 0;
}
.offer-row span { font-size: 20px; color: var(--hint); }
.offer-chips { display: flex; gap: 8px; margin-top: 10px; }
.offer-chips button { flex: 1; height: 36px; border-radius: 8px; border: 1px solid var(--sep); font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px;
  background: #222; color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.toast[hidden] { display: none; }
.toast .link { color: #6fd3dc; white-space: nowrap; }
.btn.busy { opacity: .6; pointer-events: none; }

/* In-app Vinted login: remote browser */
.acc-tokens { margin-top: 14px; }
.acc-tokens summary { color: var(--hint); font-size: 14px; cursor: pointer; }
#acc-signin-off { margin-top: 6px; }
.rb { position: fixed; inset: 0; z-index: 60; background: #fff; display: flex; flex-direction: column; }
.rb[hidden] { display: none; }
.rb-bar { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-top)) 6px 6px; background: var(--bg); border-bottom: 1px solid var(--sep); }
.rb-bar .icon-btn { color: var(--text); }
.rb-bar .icon-btn svg { filter: none; }
.rb-title { flex: 1; text-align: center; font-weight: 600; font-size: 16px; color: var(--text); }
.rb-title small { display: block; font-weight: 400; font-size: 12px; color: var(--hint); }
.rb-stage { flex: 1; min-height: 0; display: flex; align-items: flex-start; justify-content: center; overflow: hidden; background: #fff; touch-action: none; }
.rb-stage img { width: 100%; max-width: 430px; height: auto; display: block; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.rb-input { position: absolute; left: -9999px; top: 0; opacity: 0; width: 1px; height: 1px; font-size: 16px; }
