:root {
    --bg: #0f1720;
    --bg-card: #17222e;
    --bg-card-hover: #1d2c3a;
    --border: #263544;
    --primary: #22c55e;
    --primary-dark: #16a34a;
    --danger: #ef4444;
    --text: #e5e9ee;
    --text-muted: #92a2b3;
    --radius: 10px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ---- Topbar ---- */
.topbar { background: var(--bg-card); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; flex-wrap: wrap; gap: 10px; }
.logo { font-size: 1.4rem; font-weight: 800; }
.logo span { color: var(--primary); }
.logo small { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }
.mainnav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; font-size: 0.92rem; }
.mainnav a:hover { color: var(--primary); }
.btn-nav { background: var(--primary); color: #06210f; padding: 6px 14px; border-radius: 6px; font-weight: 600; }

/* ---- Layout ---- */
.page { padding: 30px 20px 60px; min-height: 70vh; }
.hero { text-align: center; padding: 30px 0; }
.hero h1 { font-size: 2rem; margin-bottom: 8px; }
.hero p { color: var(--text-muted); }

/* ---- Flash messages ---- */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.flash-success { background: #163a25; border: 1px solid var(--primary); color: #b7f5c9; }
.flash-error { background: #3a1616; border: 1px solid var(--danger); color: #f8c9c9; }

/* ---- Buttons ---- */
.btn { display: inline-block; padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; font-size: 0.95rem; }
.btn-primary { background: var(--primary); color: #06210f; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-card-hover); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-small { padding: 6px 12px; font-size: 0.85rem; }

/* ---- Forms ---- */
.form { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--text-muted); }
.form input, .form select, .form textarea {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; color: var(--text); font-size: 0.95rem; font-family: inherit;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.auth-box, .form-box, .checkout-box, .tx-box, .chat-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 640px; margin: 0 auto; }
.hint { color: var(--text-muted); font-size: 0.88rem; }

/* ---- Filters ---- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; background: var(--bg-card); padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); }
.filters input, .filters select { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; color: var(--text); }

/* ---- Listing grid ---- */
.listing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.listing-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: transform .15s, background .15s; }
.listing-card:hover { background: var(--bg-card-hover); transform: translateY(-2px); }
.listing-thumb { position: relative; height: 150px; background: #10181f; }
.listing-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-placeholder { display:flex; align-items:center; justify-content:center; height:100%; color: var(--text-muted); font-weight: 700; }
.thumb-placeholder.large { height: 300px; border-radius: var(--radius); background: var(--bg-card); }
.badge { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 6px; font-size: 0.72rem; }
.badge-status { position: static; display: inline-block; background: var(--bg-card-hover); margin-left: 8px; }
.badge-unread { background: var(--primary); color: #06210f; border-radius: 50%; padding: 2px 8px; }
.listing-body { padding: 12px 14px; }
.listing-body h3 { margin: 0 0 6px; font-size: 1rem; }
.listing-meta { color: var(--text-muted); font-size: 0.8rem; margin: 0 0 8px; }
.listing-price { color: var(--primary); font-weight: 700; margin: 0; }
.listing-price.big { font-size: 1.6rem; }

/* ---- Listing detail ---- */
.listing-detail { display: grid; grid-template-columns: 1.1fr 1fr; gap: 30px; }
.listing-gallery img { width: 100%; border-radius: var(--radius); margin-bottom: 10px; }
.listing-info { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.spec-list { list-style: none; padding: 0; margin: 16px 0; }
.spec-list li { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.description-box, .seller-box { margin: 18px 0; }
.safety-note { margin-top: 18px; background: #1c2a1f; border: 1px solid var(--primary); padding: 10px 14px; border-radius: 8px; font-size: 0.85rem; }
@media (max-width: 800px) { .listing-detail { grid-template-columns: 1fr; } }

/* ---- Chat ---- */
.chat-header { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 14px; }
.chat-price { color: var(--primary); font-weight: 700; margin-left: 8px; }
.link-small { font-size: 0.85rem; color: var(--text-muted); text-decoration: underline; }
.chat-messages { max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px 0; }
.chat-msg { max-width: 75%; padding: 8px 12px; border-radius: 10px; background: var(--bg-card-hover); }
.chat-msg.mine { align-self: flex-end; background: var(--primary-dark); color: #06210f; }
.chat-msg-author { font-size: 0.72rem; font-weight: 700; opacity: 0.8; }
.chat-msg p { margin: 4px 0; word-wrap: break-word; }
.chat-msg-time { font-size: 0.68rem; opacity: 0.7; }
.chat-input { display: flex; gap: 10px; margin-top: 14px; }
.chat-input textarea { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; color: var(--text); resize: vertical; min-height: 46px; }

/* ---- Conversation list ---- */
.conv-list { display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.conv-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; position: relative; }
.conv-item.unread { border-color: var(--primary); }
.conv-item div { display: flex; justify-content: space-between; font-weight: 600; }
.conv-item div span { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
.conv-preview { color: var(--text-muted); font-size: 0.85rem; margin: 6px 0 0; }

/* ---- Checkout / Transaction ---- */
.checkout-summary { background: var(--bg); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; }
.pay-option { display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--border); padding: 12px; border-radius: 8px; cursor: pointer; }
.escrow-note { background: #1c2a1f; border: 1px solid var(--primary); padding: 12px; border-radius: 8px; font-size: 0.88rem; }
.tx-status { padding: 12px 16px; border-radius: 8px; background: var(--bg); margin: 14px 0; }
.tx-status-completed { border: 1px solid var(--primary); }
.tx-status-disputed { border: 1px solid var(--danger); }
.deliver-box, .credentials-box { background: var(--bg); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.credentials-box { border: 1px solid var(--primary); }
.tx-timeline { list-style: none; padding: 0; font-size: 0.85rem; color: var(--text-muted); }
.tx-timeline li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.dispute-toggle { margin-top: 20px; }
.dispute-toggle summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.dispute-toggle .form { margin-top: 10px; max-width: 100%; }

/* ---- Dashboard tables ---- */
.dash-section { margin-bottom: 34px; }
.dash-section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dash-table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: var(--radius); overflow: hidden; }
.dash-table th, .dash-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.dash-table th { color: var(--text-muted); font-weight: 600; background: var(--bg-card-hover); }
.link-danger { background: none; border: none; color: var(--danger); cursor: pointer; text-decoration: underline; font-size: 0.85rem; }

.tag { padding: 3px 8px; border-radius: 6px; font-size: 0.75rem; background: var(--bg-card-hover); }
.tag-available, .tag-completed { background: #163a25; color: #b7f5c9; }
.tag-pending, .tag-paid, .tag-delivered { background: #3a3316; color: #f5e2b7; }
.tag-disputed { background: #3a1616; color: #f8c9c9; }
.tag-sold, .tag-removed, .tag-cancelled, .tag-refunded { background: #2a2f36; color: var(--text-muted); }

/* ---- Admin ---- */
.admin-topbar { background: #1a1420; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.stat-card.stat-alert { border-color: var(--danger); }
.stat-num { font-size: 1.6rem; font-weight: 800; }
.dispute-card { background: var(--bg-card); border: 1px solid var(--danger); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }

/* ---- Footer ---- */
.footer { border-top: 1px solid var(--border); padding: 20px; text-align: center; color: var(--text-muted); font-size: 0.82rem; }
.footer-note { max-width: 500px; margin: 6px auto 0; }
