/* ── 防護：禁止選取/拖曳 ── */
body {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
input, textarea, select {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}
img { pointer-events: none; }

:root {
  --bg: #f5f5f5;
  --ink: #1a1a1a;
  --accent: #e74c3c;
  --accent-hover: #c0392b;
  --card: #ffffff;
  --border: #e0e0e0;
  --ok: #27ae60;
  --warn: #f39c12;
  --err: #e74c3c;
  --muted: #888;
  --tag-game: #3498db;
  --tag-account: #9b59b6;
  --tag-item: #e67e22;
  --tag-power: #1abc9c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Top Bar ─────────────────────────────── */
.top-bar {
  background: #fff;
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 24px;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-tab {
  padding: 8px 18px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 6px;
  transition: all 0.15s;
}

.nav-tab:hover { background: #f0f0f0; color: var(--ink); }
.nav-tab.active { background: var(--accent); color: #fff; }

#connectBtn {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

#connectBtn:hover { background: var(--accent-hover); }

/* ── Status Bar ──────────────────────────── */
.status {
  max-width: 1100px;
  margin: 0 auto;
  padding: 6px 20px;
  min-height: 28px;
  font-size: 13px;
}

.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }

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

/* ── Pages ───────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── Filter Bar ──────────────────────────── */
.filter-bar {
  margin-bottom: 16px;
}

.category-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.cat-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.cat-tab:hover { color: var(--ink); }
.cat-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-row select,
.filter-row input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}

.filter-row input { flex: 1; min-width: 160px; }

#refreshBtn {
  padding: 7px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

#refreshBtn:hover { background: #f8f8f8; }

/* ── Listings List ───────────────────────── */
.listings-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.listing-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: #fff;
  gap: 12px;
  transition: background 0.1s;
}

.listing-row:hover { background: #fafafa; }

.listing-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  min-width: 48px;
  text-align: center;
}

.tag-0 { background: var(--tag-game); }
.tag-1 { background: var(--tag-account); }
.tag-2 { background: var(--tag-item); }
.tag-3 { background: var(--tag-power); }

.listing-info {
  flex: 1;
  min-width: 0;
}

.listing-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.listing-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.listing-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  min-width: 100px;
  text-align: right;
}

.listing-price small {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.listing-actions {
  display: flex;
  gap: 8px;
}

/* ── Buttons ─────────────────────────────── */
.btn-buy {
  padding: 6px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn-buy:hover { background: var(--accent-hover); }

.btn-cancel {
  padding: 6px 14px;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.btn-cancel:hover { border-color: var(--err); color: var(--err); }

.btn-primary {
  padding: 10px 32px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  margin-top: 16px;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-confirm {
  padding: 6px 14px;
  background: var(--ok);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.btn-claim {
  padding: 6px 14px;
  background: var(--warn);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.btn-delivered {
  padding: 6px 14px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn-delivered:hover { background: #2980b9; }

.btn-cancel-order {
  padding: 6px 14px;
  background: #95a5a6;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  margin-left: 8px;
}

.btn-cancel-order:hover { background: #7f8c8d; }

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Form Panel ──────────────────────────── */
.form-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  max-width: 700px;
}

.form-panel h2 {
  margin-bottom: 20px;
  font-size: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #555;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.field.full { grid-column: 1 / -1; }

/* ── Order Tabs ──────────────────────────── */
.order-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.order-tab {
  padding: 10px 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.order-tab:hover { color: var(--ink); }
.order-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Orders List ─────────────────────────── */
.orders-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.order-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.order-id {
  font-weight: 700;
  font-size: 14px;
}

.order-status {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.status-awaiting { background: #fff3cd; color: #856404; }
.status-completed { background: #d4edda; color: #155724; }
.status-refunded { background: #f8d7da; color: #721c24; }
.status-claimed { background: #d1ecf1; color: #0c5460; }
.status-disputed { background: #f8d7da; color: #721c24; }

.order-body {
  font-size: 13px;
  color: #555;
  line-height: 1.7;
}

.order-body strong { color: var(--ink); }

.order-countdown {
  font-size: 13px;
  color: var(--warn);
  font-weight: 600;
  margin-top: 6px;
}

.order-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

/* ── Empty / Loading ─────────────────────── */
.loading, .empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ── Modal ────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  max-width: 560px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}
.modal-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted);
}

.detail-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.detail-game { font-size: 13px; color: var(--muted); }
.detail-title { font-size: 20px; margin: 0 0 8px; }
.detail-price { font-size: 28px; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.detail-seller { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.detail-desc { font-size: 13px; line-height: 1.6; padding: 12px; background: #f9f9f9; border-radius: 8px; margin-bottom: 12px; }
.detail-contact { font-size: 13px; padding: 10px 12px; background: #fff3cd; border-radius: 8px; margin-bottom: 12px; color: #856404; }
.detail-flow { font-size: 13px; padding: 12px; background: #e8f4fd; border-radius: 8px; margin-bottom: 16px; }
.detail-flow ol { margin: 6px 0 0 18px; padding: 0; }
.detail-flow li { margin-bottom: 4px; }

.btn-buy-large {
  display: block; width: 100%; padding: 14px;
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  font-size: 16px; font-weight: 700; cursor: pointer; text-align: center;
}
.btn-buy-large:hover { background: var(--accent-hover); }

/* ── Order extras ────────────────────────── */
.order-contact { font-size: 13px; padding: 8px 12px; background: #d4edda; border-radius: 6px; margin-top: 6px; color: #155724; }
.order-desc { font-size: 12px; color: var(--muted); margin-top: 4px; }
.order-flow-hint { font-size: 13px; padding: 10px 12px; background: #e8f4fd; border-radius: 6px; margin-top: 8px; color: #0c5460; }

/* ── Form hint ───────────────────────────── */
.form-hint { font-size: 12px; color: var(--muted); margin-top: 12px; line-height: 1.6; }

/* ── Autocomplete ────────────────────────── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); max-height: 180px; overflow-y: auto;
}
.autocomplete-list.hidden { display: none; }
.autocomplete-item {
  padding: 8px 12px; cursor: pointer; font-size: 14px;
}
.autocomplete-item:hover { background: #f0f0f0; }

/* ── Section label ───────────────────────── */
.section-label {
  font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 12px 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}

/* ── Dispute button ──────────────────────── */
.btn-dispute {
  padding: 6px 14px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn-dispute:hover { background: #c0392b; }

/* ── Admin panel ─────────────────────────── */
.admin-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}

.admin-panel h2 { margin-bottom: 8px; font-size: 18px; }

.admin-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

.admin-card.admin-disputed {
  border-left: 4px solid #e74c3c;
}

.admin-reason {
  margin-top: 6px;
  padding: 8px 12px;
  background: #f8d7da;
  border-radius: 6px;
  color: #721c24;
  font-size: 13px;
}

.admin-resolve-info {
  margin-top: 8px;
  padding: 8px 12px;
  background: #fff3cd;
  border-radius: 6px;
  color: #856404;
  font-size: 13px;
}

.btn-resolve-refund {
  padding: 8px 16px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn-resolve-refund:hover { background: #2980b9; }

.btn-resolve-release {
  padding: 8px 16px;
  background: #27ae60;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn-resolve-release:hover { background: #219a52; }

/* ── Responsive ──────────────────────────── */
@media (max-width: 700px) {
  .top-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; }
  .nav-tabs { order: 3; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .listing-row { flex-wrap: wrap; }
  .listing-price { min-width: auto; text-align: left; }
}
