:root {
  --bg: #f7f5f2;
  --panel: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --line: #e8e4de;
  --brand: #0f766e;
  --brand-soft: #e6f7f5;
  --brand-dark: #0d6560;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }

/* ── Topbar ─────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.topbar nav a, .topbar nav button {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, color 0.15s;
}
.topbar nav a:hover, .topbar nav button:hover { background: var(--bg); color: var(--text); }
.brand { font-size: 20px; font-weight: 800; color: var(--brand); letter-spacing: -0.5px; }

/* ── Layout ──────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* ── Cards ───────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.hero { margin-bottom: 20px; }

/* ── Grid / Stack ────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.two-col { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row, .section-head, .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.section-head { justify-content: space-between; margin-bottom: 16px; }
.actions { justify-content: flex-start; }
.inline { display: inline; }

/* ── Buttons ─────────────────────────────── */
.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  background: var(--bg);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.button:hover, button:hover { background: #ede9e3; }
.button.primary, button.primary { background: var(--brand); color: white; }
.button.primary:hover, button.primary:hover { background: var(--brand-dark); }
.button:active, button:active { transform: scale(0.97); }

/* ── Forms ───────────────────────────────── */
select, input[type="text"], input[type="password"], input[type="number"], input:not([type]), textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font: inherit;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--brand); }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }

/* ── Flash ───────────────────────────────── */
.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 14px; font-weight: 500; }
.flash.error { background: var(--danger-soft); color: var(--danger); border: 1px solid #fca5a5; }
.flash.success { background: var(--success-soft); color: var(--success); border: 1px solid #86efac; }
.notice { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.notice.warn { background: #fef9c3; color: #92400e; border: 1px solid #fde68a; }

/* ── Stats ───────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { text-align: center; padding: 20px 16px; }
.stat strong { display: block; font-size: 28px; font-weight: 800; color: var(--brand); }
.stat span { color: var(--muted); font-size: 13px; }

/* ── Hero ────────────────────────────────── */
.hero { padding: 32px; }
.hero h1 { font-size: 26px; font-weight: 800; margin-bottom: 8px; letter-spacing: -0.5px; }
.hero p { color: var(--muted); margin-bottom: 20px; }

/* ── Products ────────────────────────────── */
.product-card img, .inline-card img, .detail-image {
  width: 100%;
  border-radius: 12px;
  object-fit: cover;
}
.product-card { overflow: hidden; padding: 0; }
.product-card a { display: block; padding: 0; }
.product-card img { height: 170px; border-radius: 12px 12px 0 0; }
.product-card h3 { padding: 12px 14px; font-size: 14px; font-weight: 600; }
.product-card-img-wrap { position: relative; }
.product-sold-badge, .product-reserved-badge {
  position: absolute;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; letter-spacing: 0.03em;
  border-radius: 6px; padding: 4px 10px;
}
.product-sold-badge {
  inset: 0;
  background: rgba(0,0,0,0.45);
  color: #fff;
  border-radius: 12px 12px 0 0;
}
.product-reserved-badge {
  top: 8px; left: 8px;
  background: #f97316;
  color: #fff;
}
.product-card--sold h3 { color: var(--muted); }
.inline-card { display: grid; grid-template-columns: 160px 1fr; gap: 16px; align-items: start; }
.inline-card img { height: 130px; border-radius: 12px; }
.detail { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; }
.detail-image { min-height: 300px; border-radius: var(--radius); border: 1px solid var(--line); }
.price { font-size: 22px; font-weight: 800; color: var(--text); margin: 8px 0; }

/* ── User cards ──────────────────────────── */
.user-card { padding: 16px; }
.user-card-inner { display: flex; gap: 14px; align-items: flex-start; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; flex-shrink: 0;
}
.user-info strong { display: block; font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.user-info p { font-size: 13px; color: var(--muted); margin-bottom: 2px; }

/* ── Badges ──────────────────────────────── */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; margin-top: 4px; }
.badge.muted { background: var(--bg); color: var(--muted); }
.badge.dormant { background: var(--danger-soft); color: var(--danger); }

/* ── Search ──────────────────────────────── */
.search-panel { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search-grid { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* ── Chat tabs ───────────────────────────── */
.chat-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0;
}
.tab-btn {
  padding: 10px 20px;
  border-radius: 10px 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, background 0.15s;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); background: var(--brand-soft); }
.tab-btn:hover:not(.active) { background: var(--bg); color: var(--text); }

/* ── Chat ────────────────────────────────── */
.chat-section { display: flex; flex-direction: column; }
.chat-section h2 { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.chat-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 460px;
  overflow-y: auto;
  margin-bottom: 14px;
  padding: 4px 0;
  scroll-behavior: smooth;
}
.chat-message { display: flex; flex-direction: column; max-width: 72%; }
.chat-message.other { align-self: flex-start; align-items: flex-start; }
.chat-message.mine { align-self: flex-end; align-items: flex-end; }
.chat-name {
  font-size: 12px; font-weight: 700; color: var(--muted);
  margin-bottom: 3px; padding: 0 4px; cursor: pointer;
}
.chat-name:hover { color: var(--brand); }
.bubble { padding: 10px 14px; border-radius: 18px; word-break: break-word; }
.chat-message.other .bubble { background: #f0f0ee; border-radius: 4px 18px 18px 18px; }
.chat-message.mine .bubble { background: var(--brand); color: white; border-radius: 18px 4px 18px 18px; }
.bubble span { display: block; font-size: 14px; line-height: 1.55; }
.bubble small { display: block; font-size: 11px; margin-top: 4px; color: var(--muted); }
.chat-message.mine .bubble small { color: rgba(255,255,255,0.7); }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input { flex: 1; }

/* ── DM list ─────────────────────────────── */
.dm-item {
  display: flex; gap: 12px; align-items: center;
  padding: 14px 16px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line);
  transition: background 0.15s;
}
.dm-item:hover { background: var(--brand-soft); }
.dm-item .avatar { width: 44px; height: 44px; font-size: 16px; }
.dm-item-info { flex: 1; min-width: 0; }
.dm-item-info strong { display: block; font-size: 15px; font-weight: 700; }
.dm-item-info .last-msg { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-item > small { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.dm-item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.dm-item-meta small { font-size: 11px; color: var(--muted); }
.dm-unread-badge {
  background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.dm-item-unread .dm-item-info strong { color: var(--primary); }

/* ── Subcard ─────────────────────────────── */
.subcard {
  display: grid; gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 14px;
}
.subcard span, .subcard small { color: var(--muted); }
.subcard strong { font-weight: 700; }

/* ── Reviews ─────────────────────────────── */
.review-stats { display: flex; gap: 16px; margin-bottom: 12px; font-size: 18px; font-weight: 700; }
.review-like { color: #16a34a; }
.review-dislike { color: #dc2626; }
.review-form { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.rating-row { display: flex; gap: 20px; margin: 8px 0; }
.rating-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 15px; }
.review-focus { border-color: var(--primary) !important; box-shadow: 0 0 0 3px rgba(15,118,110,0.15); }

/* ── Transfer card in chat ───────────────── */
.chat-message-transfer { display: flex; justify-content: center; margin: 12px 0; }
.transfer-card {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 18px;
  max-width: 320px; width: 100%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.transfer-card-icon { font-size: 28px; line-height: 1; }
.transfer-card strong { font-size: 14px; display: block; margin-bottom: 2px; }
.transfer-card small { color: var(--muted); font-size: 12px; display: block; margin-top: 4px; }

/* ── Auth ────────────────────────────────── */
.auth { max-width: 420px; margin: 0 auto; }
.auth h1 { margin-bottom: 24px; font-size: 22px; font-weight: 800; }

/* ── Admin ───────────────────────────────── */
.admin-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.admin-dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 16px; }
.badge { display: inline-block; padding: 2px 7px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.danger { background: #fee2e2; color: #dc2626; }
.badge.warn { background: #fef9c3; color: #92400e; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }

/* ── User popup ──────────────────────────── */
#user-popup-overlay {
  display: none;
  position: fixed; inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.35);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#user-popup {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  min-width: 260px;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 24px 64px rgba(0,0,0,0.18);
}
#user-popup h3 { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
#user-popup p { color: var(--muted); font-size: 14px; }

/* ── Report form ─────────────────────────── */
.report-form { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; }

/* ── Notification badge ──────────────────── */
.notif-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--danger); color: white;
  border-radius: 999px; font-size: 10px; font-weight: 800;
  margin-left: 3px; vertical-align: middle;
}

/* ── Toast ───────────────────────────────── */
.toast {
  position: fixed; top: 68px; right: 16px;
  background: var(--text); color: white;
  padding: 12px 18px; border-radius: 12px;
  font-size: 14px; z-index: 1100; max-width: 300px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  animation: slideDown 0.3s ease;
}
.toast a { color: white; text-decoration: underline; }
.toast.hide { opacity: 0; transition: opacity 0.4s; }
@keyframes slideDown { from { transform: translateY(-12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Read markers ────────────────────────── */
.read-marker, .unread-marker {
  font-size: 11px; font-weight: 700; margin-top: 2px; display: block; text-align: right;
}
.unread-marker { color: var(--brand); }
.read-marker { color: var(--muted); }

/* ── Notifications page ──────────────────── */
.notif-item { display: grid; gap: 4px; text-decoration: none; }
.notif-item.unread { border-left: 3px solid var(--brand); padding-left: 11px; }
.notif-item:hover { background: var(--brand-soft); }

/* ── User search (wallet) ────────────────── */
.user-search-wrap { position: relative; }
.search-dropdown {
  display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1); overflow: hidden; margin-top: 4px;
}
.search-result-item {
  padding: 10px 14px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--brand-soft); }

/* ── DM header ───────────────────────────── */
.dm-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.back-link { color: var(--brand); font-size: 14px; font-weight: 600; }
.leave-btn { background: var(--danger-soft); color: var(--danger); font-size: 13px; padding: 7px 14px; }
.leave-btn:hover { background: #fecaca; }

/* ── PIN Keypad ──────────────────────────── */
.pin-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.45); z-index: 300;
  align-items: center; justify-content: center;
}
.pin-overlay.active { display: flex; }
.pin-box {
  background: var(--panel); border-radius: 24px;
  padding: 32px 28px; text-align: center;
  width: 320px; box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}
.pin-box h3 { font-size: 17px; font-weight: 800; margin-bottom: 6px; }
.pin-box > p { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin-bottom: 24px; }
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent;
  transition: background 0.1s, border-color 0.1s;
}
.pin-dot.filled { background: var(--brand); border-color: var(--brand); }
.pin-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key {
  padding: 16px; border-radius: 12px; font-size: 20px; font-weight: 700;
  background: var(--bg); border: none; cursor: pointer;
  transition: background 0.12s, transform 0.08s;
}
.pin-key:hover { background: var(--brand-soft); color: var(--brand); }
.pin-key:active { transform: scale(0.93); }
.pin-key.del { font-size: 16px; }
.pin-key.empty { background: transparent; cursor: default; pointer-events: none; }
.pin-cancel { margin-top: 16px; font-size: 14px; color: var(--muted); cursor: pointer; }
.pin-cancel:hover { color: var(--text); }

/* ── Hamburger ───────────────────────────── */
.hamburger {
  display: none;
  background: none; border: none;
  font-size: 22px; cursor: pointer;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text); line-height: 1;
  margin-left: auto;
}
.hamburger:hover { background: var(--bg); }

/* ── Responsive ──────────────────────────── */
@media (max-width: 768px) {
  .detail, .inline-card { grid-template-columns: 1fr; }
  .container { padding: 16px; }
  .topbar { padding: 0 16px; flex-wrap: nowrap; }
  .chat-message { max-width: 88%; }
  .hero { padding: 24px; }
  .hamburger { display: flex; }
  #main-nav {
    display: none;
    position: absolute; top: 56px; left: 0; right: 0;
    background: var(--panel);
    border-bottom: 2px solid var(--line);
    flex-direction: column;
    padding: 8px 12px 14px;
    z-index: 99;
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
    gap: 2px;
  }
  #main-nav.open { display: flex; }
  #main-nav a, #main-nav button {
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 15px;
    justify-content: flex-start;
  }
  #main-nav form.inline { display: block; width: 100%; }
  #main-nav form.inline button { width: 100%; }
}

/* Auth Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: var(--panel);
  border-radius: 16px;
  padding: 28px 24px 24px;
  width: 100%; max-width: 400px;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  color: var(--muted); line-height: 1;
  padding: 4px 6px; border-radius: 6px;
}
.modal-close:hover { background: var(--line); color: var(--text); }
.auth-tabs {
  display: flex; gap: 4px;
  margin-bottom: 20px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
}
.auth-tab {
  flex: 1; padding: 8px;
  border: none; border-radius: 8px;
  background: none; cursor: pointer;
  font-size: 14px; font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.auth-tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
