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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --orange: #d29922;
  --blue: #58a6ff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.header-left h1 {
  font-size: 1.2rem;
  font-weight: 700;
}

.header-left .tag {
  background: var(--green);
  color: #000;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  vertical-align: middle;
  font-weight: 600;
}

nav { display: flex; gap: 4px; }

.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: all 0.15s;
}
.nav-link:hover { background: var(--border); color: var(--text); }
.nav-link.active { background: var(--accent); color: #fff; }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#userInfo {
  font-size: 0.8rem;
  color: var(--green);
  font-family: monospace;
}

/* Buttons */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-outline:hover { border-color: var(--text-dim); color: var(--text); }
.btn-green { background: var(--green); }
.btn-red { background: var(--red); }

/* Main */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
}

.page { display: none; }
.page.active { display: block; }

/* Market */
.market-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.market-header h2 { font-size: 1.3rem; }

.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.filter-btn {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 5px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Ad Cards */
.ads-list { display: flex; flex-direction: column; gap: 10px; }

.ad-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  transition: border-color 0.15s;
}
.ad-card:hover { border-color: var(--accent); }

.ad-info { flex: 1; }
.ad-info .ad-type {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
}
.ad-type.sell { background: var(--red); color: #fff; }
.ad-type.buy { background: var(--green); color: #000; }

.ad-price {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.ad-detail {
  font-size: 0.8rem;
  color: var(--text-dim);
}
.ad-user {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Trade Cards */
.trades-list { display: flex; flex-direction: column; gap: 10px; }

.trade-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.trade-card:hover { border-color: var(--accent); }

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

.trade-status {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}
.trade-status.created { background: var(--orange); color: #000; }
.trade-status.btct_deposited,
.trade-status.doge_deposited { background: var(--blue); color: #fff; }
.trade-status.both_deposited,
.trade-status.releasing { background: var(--accent); color: #fff; }
.trade-status.completed { background: var(--green); color: #000; }
.trade-status.expired,
.trade-status.cancelled { background: var(--red); color: #fff; }
.trade-status.refunded { background: var(--text-dim); color: #000; }

.trade-amounts {
  display: flex;
  gap: 24px;
  font-size: 0.9rem;
}

/* Trade Detail */
#tradeDetail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}

.trade-detail-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
}

.trade-detail-main {
  min-width: 0;
}

.escrow-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}

.escrow-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.escrow-box h4 {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text-dim);
}
.escrow-box .amount {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.escrow-box .addr {
  font-family: monospace;
  font-size: 0.75rem;
  word-break: break-all;
  color: var(--accent);
  cursor: pointer;
}
.escrow-box .status-badge {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
}
.status-badge.waiting { background: var(--orange); color: #000; }
.status-badge.done { background: var(--green); color: #000; }

.timer {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--orange);
  margin: 16px 0;
}
.timer.expired { color: var(--red); }

/* Quick Send Panel */
.quick-send-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  position: sticky;
  top: 20px;
  height: fit-content;
}

.quick-send-panel h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  color: var(--text);
}

.qs-section {
  margin-bottom: 16px;
}

.qs-section label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  font-weight: 600;
}

.qs-wallet-info {
  display: flex;
  gap: 8px;
}

.qs-coin-tab {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.qs-coin-tab:hover {
  border-color: var(--accent);
}

.qs-coin-tab.active {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
}

.qs-coin-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.qs-addr {
  font-family: monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.qs-balance {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--green);
}

.qs-to-addr {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--accent);
  background: var(--surface);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.qs-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: monospace;
}

.qs-input:focus {
  outline: none;
  border-color: var(--accent);
}

.qs-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 16px;
  font-size: 0.8rem;
}

.qs-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.qs-row:last-child {
  margin-bottom: 0;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-weight: 600;
}

#qsSendBtn {
  width: 100%;
  padding: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

/* Chat */
.chat-section {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.chat-messages {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
}
.chat-msg {
  margin-bottom: 6px;
  font-size: 0.85rem;
}
.chat-msg .sender {
  font-family: monospace;
  font-size: 0.7rem;
  color: var(--accent);
}
.chat-msg .text { color: var(--text); }
.chat-msg .time { font-size: 0.65rem; color: var(--text-dim); }

.chat-input {
  display: flex;
  gap: 8px;
}
.chat-input input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* Modals */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 440px;
}
.modal-content h3 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}
.modal-content label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 10px 0 4px;
}
.modal-content input,
.modal-content select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
}
.modal-content input:focus,
.modal-content select:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* Utils */
.hidden { display: none !important; }
.error { color: var(--red); font-size: 0.8rem; margin-top: 8px; }
.success-text { color: var(--green); font-weight: 600; }
.info-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin: 8px 0;
  font-size: 0.85rem;
}
.address-box {
  font-family: monospace;
  font-size: 0.8rem;
  word-break: break-all;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  cursor: pointer;
  margin: 6px 0;
}
.small { font-size: 0.75rem; color: var(--text-dim); }
.fee-notice { color: #f0ad4e; margin-top: 6px; }

/* DOGE Wallet */
.btn-full { width: 100%; }
.wallet-select {
  width: 100%;
  padding: 8px 10px;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: 'Courier New', monospace;
  cursor: pointer;
  margin-top: 6px;
}
.wallet-select option {
  background: #1a1a2e;
  color: #e0e0e0;
}
.wallet-select:focus { outline: none; border-color: var(--primary); }
.wallet-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.wallet-actions .btn {
  flex: 1;
  min-width: 100px;
  font-size: 0.8rem;
  padding: 6px 10px;
}
.btn-danger { border-color: #e74c3c !important; color: #e74c3c !important; background: rgba(231, 76, 60, 0.1) !important; }
.btn-danger:hover { background: #e74c3c !important; color: #fff !important; }
.wallet-backup-box {
  background: #1a1a2e;
  border: 1px solid #f0ad4e;
  border-radius: 8px;
  padding: 14px;
  margin-top: 10px;
}
.wallet-backup-box h4 { color: #f0ad4e; margin: 0 0 8px; font-size: 0.95rem; }
.wif-display {
  word-break: break-all;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: all;
}
.mono { font-family: 'Courier New', monospace; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
details summary { cursor: pointer; color: var(--text-dim); }
details summary:hover { color: var(--text); }
.help-icon {
  display: inline-block;
  margin-left: 6px;
  cursor: help;
  font-size: 1rem;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.help-icon:hover { opacity: 1; }
.help-box {
  background: rgba(240, 173, 78, 0.1);
  border: 1px solid rgba(240, 173, 78, 0.3);
  border-radius: 6px;
  padding: 12px;
  margin: 8px 0;
  font-size: 0.85rem;
  line-height: 1.5;
}
.help-box p { margin: 6px 0; }
.help-box ul { margin: 4px 0 8px 20px; padding: 0; }
.help-box li { margin: 4px 0; }
.loading, .empty {
  text-align: center;
  padding: 32px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* Footer */
footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 24px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Responsive */
@media (max-width: 600px) {
  header { padding: 10px 12px; }
  main { padding: 16px 10px; }
  .trade-detail-layout { grid-template-columns: 1fr; }
  .escrow-section { grid-template-columns: 1fr; }
  .ad-card { flex-direction: column; align-items: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-table-wrap { font-size: 0.75rem; }
}

/* ===================== ADMIN PAGE ===================== */
.admin-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.admin-header h2 { margin: 0; }
.admin-badge {
  background: var(--red);
  color: #fff;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.sc-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sc-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}
.sc-value.warn { color: var(--orange); }

/* Admin Tabs */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.admin-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 18px;
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: 6px 6px 0 0;
  transition: all 0.2s;
}
.admin-tab:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.admin-tab.active {
  color: var(--accent);
  background: rgba(88,166,255,0.1);
  border-bottom: 2px solid var(--accent);
}

/* Admin Table */
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.admin-table th {
  background: var(--surface);
  color: var(--text-dim);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table tr:hover { background: rgba(255,255,255,0.03); }
.admin-table .mono {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 0.78rem;
}
.admin-table .dim { color: var(--text-dim); }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.active { background: rgba(63,185,80,0.15); color: var(--green); }
.badge.deleted { background: rgba(248,81,73,0.15); color: var(--red); }
.badge.sell { background: rgba(248,81,73,0.15); color: var(--red); }
.badge.buy { background: rgba(63,185,80,0.15); color: var(--green); }
.badge.created { background: rgba(88,166,255,0.15); color: var(--accent); }
.badge.btct_deposited,
.badge.doge_deposited { background: rgba(210,153,34,0.15); color: var(--orange); }
.badge.both_deposited { background: rgba(210,153,34,0.2); color: var(--orange); }
.badge.releasing { background: rgba(210,153,34,0.25); color: var(--orange); }
.badge.completed { background: rgba(63,185,80,0.15); color: var(--green); }
.badge.expired,
.badge.cancelled,
.badge.refunded { background: rgba(248,81,73,0.1); color: var(--text-dim); }
.badge.closed { background: rgba(139,148,158,0.15); color: var(--text-dim); }
.badge.paused { background: rgba(210,153,34,0.15); color: var(--orange); }

/* Danger Button */
.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
}
.btn-danger:hover { opacity: 0.85; }

/* ===================== WALLET PAGE ===================== */
.wallet-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 16px;
}

.wallet-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.wallet-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.wallet-coin-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.wallet-coin-label {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.wallet-balance {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.balance-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.balance-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--green);
  font-family: 'SFMono-Regular', Consolas, monospace;
}

.wallet-section {
  margin-bottom: 12px;
}

.wallet-section h4 {
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: var(--text);
}

.wallet-card .address-box {
  font-size: 0.75rem;
}

.wallet-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-top: 4px;
}

.wallet-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.wallet-card label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 10px 0 4px;
}

@media (max-width: 1000px) {
  .trade-detail-layout {
    grid-template-columns: 1fr;
  }
  .quick-send-panel {
    position: static;
    margin-top: 20px;
  }
}

@media (max-width: 700px) {
  .wallet-cards {
    grid-template-columns: 1fr;
  }
}
