:root {
  --bg: var(--tg-theme-bg-color, #f2f3f7);
  --bg2: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #15161a);
  --hint: var(--tg-theme-hint-color, #8b8d97);
  --link: var(--tg-theme-link-color, #2f80ed);
  --button: var(--tg-theme-button-color, #2f80ed);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #2f80ed;
  --accent-soft: #eaf2fe;
  --danger: #ef5b5b;
  --success: #2ecc71;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 14px rgba(20,20,30,0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Top bar ───────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.back-btn {
  border: none;
  background: var(--bg);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.top-title { font-size: 16px; font-weight: 800; }

.app {
  padding: 14px;
  padding-bottom: 100px;
  max-width: 560px;
  margin: 0 auto;
}

.app.view-anim {
  animation: viewIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.top-title { transition: opacity 0.15s ease; }

.hidden { display: none !important; }

/* ── Tap feedback ──────────────────────────────────────────────────────── */

.card, .home-tile, .chip, .seg, .nav-item, .btn, .option-pill, .list-item {
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

.card:active, .home-tile:active, .option-pill:active, .list-item:active, .btn:active {
  transform: scale(0.96);
  opacity: 0.85;
}

.chip:active, .seg:active, .nav-item:active { opacity: 0.6; }

/* ── Skeleton loaders ──────────────────────────────────────────────────── */

.skel-card { border-radius: var(--radius-md); overflow: hidden; background: var(--bg2); box-shadow: var(--shadow); }
.skel-img { height: 132px; }
.skel-line { height: 11px; margin: 10px 11px 6px; border-radius: 6px; }
.skel-line.short { width: 55%; }

.skel-img, .skel-line {
  background: linear-gradient(90deg, #e9ecf3 25%, #f4f6fa 37%, #e9ecf3 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ── Bottom navigation ─────────────────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  background: var(--bg2);
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  border: none;
  background: transparent;
  color: var(--hint);
  font-family: inherit;
  cursor: pointer;
}

.nav-item .icon { font-size: 20px; }
.nav-item .lbl { font-size: 10.5px; font-weight: 600; }
.nav-item.active { color: var(--accent); }

/* ── Hero / welcome ────────────────────────────────────────────────────── */

.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #6aa8f5 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  margin-bottom: 16px;
}

.hero .title { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.hero .subtitle { font-size: 13px; opacity: 0.92; line-height: 1.6; }

/* ── Home grid ─────────────────────────────────────────────────────────── */

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.home-tile {
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 18px 10px;
  text-align: center;
  cursor: pointer;
  border: none;
  font-family: inherit;
  box-shadow: var(--shadow);
}

.home-tile .icon-circle {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  margin: 0 auto 8px;
}

.home-tile .label { font-size: 12.5px; font-weight: 700; color: var(--text); }

/* ── Section / lists ───────────────────────────────────────────────────── */

.section-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--hint);
  margin: 18px 4px 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.list-item {
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 15px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.list-item .title { font-size: 14px; font-weight: 600; }
.list-item .chevron { color: var(--hint); font-size: 16px; }

.page-body {
  background: var(--bg2);
  border-radius: var(--radius-lg);
  padding: 18px;
  line-height: 1.9;
  font-size: 14.5px;
  box-shadow: var(--shadow);
}

.page-body a { color: var(--link); }

/* ── Search bar ────────────────────────────────────────────────────────── */

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.search-bar .icon { color: var(--hint); font-size: 14px; }

/* ── Segmented sort control ───────────────────────────────────────────── */

.segmented {
  display: flex;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.segmented .seg {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--hint);
}

.segmented .seg.active { background: var(--accent); color: #fff; }

/* ── Filter chips ──────────────────────────────────────────────────────── */

.filters {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 6px;
  margin-bottom: 12px;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.filters::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 16px;
  background: var(--bg2);
  color: var(--text);
  font-size: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.chip.active { background: var(--accent); color: #fff; box-shadow: none; }

/* ── Marketplace / roommate grid cards ────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.card {
  background: var(--bg2);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.card .img-wrap {
  position: relative;
  width: 100%;
  height: 132px;
  background: linear-gradient(135deg, #e9ecf3, #dde1ea);
  display: flex; align-items: center; justify-content: center;
}

.card .img-wrap img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.card .img-wrap .placeholder-icon { font-size: 30px; opacity: 0.35; }

.card .price-badge {
  position: absolute;
  bottom: 8px; right: 8px;
  background: rgba(20,20,30,0.78);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 8px;
}

.card .cat-badge {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(255,255,255,0.92);
  font-size: 14px;
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.card .body { padding: 10px 11px 12px; }

.card .title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 32px;
}

.card .meta { font-size: 11px; color: var(--hint); display: flex; align-items: center; gap: 4px; }

.empty {
  text-align: center;
  color: var(--hint);
  padding: 50px 14px;
  font-size: 14px;
}

.empty .emoji { font-size: 34px; display: block; margin-bottom: 10px; }

/* ── Detail sheet ──────────────────────────────────────────────────────── */

.detail {
  position: fixed;
  inset: 0;
  background: rgba(10,10,15,0.45);
  display: flex;
  align-items: flex-end;
  z-index: 50;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.detail-card {
  background: var(--bg2);
  color: var(--text);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  position: relative;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp { from { transform: translateY(24px); } to { transform: translateY(0); } }

.detail-close {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--bg);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
  z-index: 5;
}

.img-fullscreen {
  position: fixed;
  inset: 0;
  background: rgba(5,5,8,0.94);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

.img-fullscreen img {
  max-width: 94%;
  max-height: 90%;
  object-fit: contain;
  border-radius: 6px;
}

.img-fullscreen-close {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  z-index: 5;
}

.detail-card img {
  width: 100%;
  max-height: 230px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.detail-card h2 { font-size: 18px; margin: 10px 0 12px; }
.detail-row { font-size: 14px; margin-bottom: 8px; line-height: 1.6; }
.detail-row b { color: var(--hint); font-weight: 600; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--button);
  color: var(--button-text);
  font-weight: 700;
  text-decoration: none;
  font-size: 14px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.btn.secondary { background: var(--bg); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .btn { margin-top: 0; }

.fab {
  position: fixed;
  bottom: 78px;
  left: 14px;
  right: 14px;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(47,128,237,0.35);
}

/* ── Forms ─────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--hint);
  margin-bottom: 7px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0,0,0,0.08);
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.form-group textarea { resize: vertical; min-height: 90px; }

.option-row { display: flex; flex-wrap: wrap; gap: 8px; }

.option-pill {
  flex: 1;
  min-width: 110px;
  text-align: center;
  padding: 13px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
  box-shadow: var(--shadow);
}

.option-pill.selected { border-color: var(--accent); font-weight: 700; color: var(--accent); background: var(--accent-soft); }

.photo-slots { display: flex; gap: 8px; }

.photo-slot {
  width: 84px; height: 84px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 2px dashed rgba(0,0,0,0.12);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  color: var(--hint);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot.uploading { opacity: 0.5; }
.photo-slot.filled { border-style: solid; border-color: var(--success); }

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1c1e;
  color: #fff;
  padding: 11px 20px;
  border-radius: 22px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 18px rgba(0,0,0,0.25);
}

/* ── Admin ─────────────────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat-box {
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-box .num { font-size: 24px; font-weight: 800; color: var(--accent); }
.stat-box .lbl { font-size: 11px; color: var(--hint); margin-top: 5px; }

.pending-card {
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 15px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.pending-card .meta-line { font-size: 13px; margin-bottom: 5px; }
.pending-card .meta-line b { color: var(--hint); }
