:root {
  --bg: #faf7f2; --fg: #1d1b19; --mut: #77716a; --line: #e9e3da; --card: #ffffff;
  --acc: #b5332e; --acc2: #1f6f5c; --chip: #f1ece4; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --r: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151413; --fg: #f1ede7; --mut: #9a948c; --line: #2b2926; --card: #1e1c1a; --chip: #262421;
          --acc: #e0605a; --acc2: #4fb59a; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(340px, 100%); display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 4px 0 8px; font-weight: 650; letter-spacing: -.02em; }
.logo { width: 56px; height: 56px; margin: 0 auto; border-radius: 50%;
        background: radial-gradient(circle at 35% 30%, #fff8 0 12%, transparent 13%), radial-gradient(circle at 50% 55%, var(--acc), #6d1714); }
.login-card input, .login-card button { height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0 14px; }
.login-card button { background: var(--fg); color: var(--bg); border: 0; font-weight: 600; cursor: pointer; }
.err { color: var(--acc); min-height: 1.2em; margin: 0; }

/* top bar */
.bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center;
       padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
       backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.search { flex: 1; position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%);
              fill: none; stroke: var(--mut); stroke-width: 2; stroke-linecap: round; }
.search input { width: 100%; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
                padding: 0 12px 0 38px; outline: none; font-size: 16px; }
.search input:focus { border-color: var(--fg); }
.tabs { display: flex; gap: 2px; background: var(--chip); border-radius: 10px; padding: 3px; }
.tabs a { padding: 7px 11px; border-radius: 8px; color: var(--mut); text-decoration: none; font-size: 14px; font-weight: 550; }
.tabs a.on { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }

/* filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 14px 2px; }
.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 11px; border-radius: 8px; color: var(--mut); cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }
select { height: 34px; border-radius: 10px; border: 0; background: var(--chip); padding: 0 10px; font-size: 14px; }
.price { display: flex; align-items: center; gap: 4px; color: var(--mut); }
.price input { width: 64px; height: 34px; border-radius: 10px; border: 0; background: var(--chip); padding: 0 8px; font-size: 14px; }
.summary { padding: 8px 14px 4px; color: var(--mut); font-size: 13px; min-height: 26px; }
.summary b { color: var(--fg); font-weight: 600; }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 6px 14px 14px; }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 6px 8px; } }
.tile { position: relative; display: block; aspect-ratio: 1; border-radius: var(--r); overflow: hidden; background: var(--chip);
        cursor: pointer; content-visibility: auto; contain-intrinsic-size: 150px; text-decoration: none; color: inherit; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .18s; }
.tile img.ok { opacity: 1; }
.tile .tag { position: absolute; left: 6px; bottom: 6px; padding: 2px 7px; border-radius: 8px; font-size: 13px; font-weight: 650;
             background: rgba(255,255,255,.92); color: #1d1b19; font-variant-numeric: tabular-nums; }
.tile .dot { position: absolute; right: 7px; top: 7px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; }
.tile .dot.sold { background: var(--acc2); }
.tile .dot.open { background: #c9c2b8; }
.tile:active { transform: scale(.98); }
.more { height: 60px; display: grid; place-items: center; color: var(--mut); font-size: 13px; }

/* sheet (item) */
.sheet { position: fixed; inset: 0; z-index: 20; display: grid; align-items: end; justify-items: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.42); animation: fade .15s; }
.sheet-card { position: relative; width: min(760px, 100%); max-height: 94dvh; overflow: auto; background: var(--bg);
              border-radius: 18px 18px 0 0; padding: 0 0 calc(24px + env(safe-area-inset-bottom)); animation: up .2s cubic-bezier(.2,.8,.2,1); }
@media (min-width: 800px) { .sheet { align-items: center; } .sheet-card { border-radius: 18px; max-height: 90dvh; } }
@keyframes up { from { transform: translateY(24px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }
.close { position: sticky; top: 8px; float: right; margin: 8px 8px 0 0; z-index: 2; width: 36px; height: 36px; border-radius: 50%;
         border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 4px; background: #000; }
.gallery img { flex: 0 0 100%; height: min(62vh, 520px); object-fit: contain; scroll-snap-align: center; background: #000; }
.gal-count { text-align: center; color: var(--mut); font-size: 12px; padding: 6px 0 0; }
.body { padding: 14px 18px; }
.price-big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.status { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.pill { padding: 4px 10px; border-radius: 999px; background: var(--chip); font-size: 13px; color: var(--mut); }
.pill.sold { background: color-mix(in srgb, var(--acc2) 16%, transparent); color: var(--acc2); font-weight: 600; }
.pill.hot { background: color-mix(in srgb, var(--acc) 14%, transparent); color: var(--acc); font-weight: 600; }
.desc { white-space: pre-wrap; margin: 6px 0 2px; }
.from { color: var(--mut); font-size: 13px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--mut); margin: 22px 0 8px; font-weight: 600; }
.comps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.comps div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.comps b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.comps span { color: var(--mut); font-size: 12px; }
.thread { display: grid; gap: 8px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.av { flex: 0 0 30px; height: 30px; border-radius: 50%; background: var(--chip); display: grid; place-items: center;
      font-size: 11px; font-weight: 700; color: var(--mut); }
.av.s { background: var(--fg); color: var(--bg); }
.bubble { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 7px 11px; max-width: 100%; }
.bubble small { color: var(--mut); font-size: 11px; display: block; }
.bubble img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; margin: 6px 6px 0 0; }
.grid.mini { padding: 0; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }

/* stats */
#statsView { padding: 14px; max-width: 900px; margin: 0 auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.kpi b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi span { color: var(--mut); font-size: 13px; }
.chart { display: grid; gap: 6px; margin-top: 10px; }
.row { display: grid; grid-template-columns: 70px 1fr 120px; gap: 10px; align-items: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.row .barw { height: 14px; border-radius: 7px; background: var(--chip); overflow: hidden; }
.row .barw i { display: block; height: 100%; background: var(--acc2); border-radius: 7px; }
.row .r { color: var(--mut); text-align: right; }
.note { color: var(--mut); font-size: 13px; margin-top: 14px; }
.loading { padding: 60px; text-align: center; color: var(--mut); }
