/* PolyCopy - Dark Trading Console Theme */
:root {
  --bg: #0b0d12;
  --bg-elev: #11141b;
  --bg-card: #161a23;
  --bg-hover: #1c2230;
  --border: #232a39;
  --border-strong: #2e374a;
  --text: #e6ebf5;
  --text-muted: #8b94a7;
  --text-dim: #5b6275;
  --accent: #6ee7b7;
  --accent-dim: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --buy: #34d399;
  --sell: #f87171;
  --gold: #f5d76e;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ── App layout ── */
.app {
  display: grid;
  grid-template-columns: 180px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 28px; padding: 4px;
}
.brand-logo {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), #34d399);
  color: #052e1d;
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 18px;
}
.brand-logo.lg { width: 56px; height: 56px; font-size: 26px; border-radius: 14px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--text-muted); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(110,231,183,0.15), transparent);
  color: var(--accent);
  border-left: 2px solid var(--accent);
  padding-left: 10px;
}
.sidebar-footer { padding-top: 16px; border-top: 1px solid var(--border); }
.user-row { display: flex; align-items: center; justify-content: space-between; }
.user-actions { display: flex; gap: 6px; align-items: center; }

.read-only-notice {
  font-size: 13px;
  line-height: 1.6;
  background: rgba(110, 231, 183, 0.05);
  border-left: 3px solid var(--accent);
}
.read-only-notice code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--accent);
}

.main { padding: 24px 28px; overflow-x: auto; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.topbar h1 { font-size: 22px; font-weight: 700; }
.muted { color: var(--text-muted); font-size: 13px; }
.muted.small { font-size: 12px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); }
.status-pill.running .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-pill.live .dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.status-pill.error .dot { background: var(--danger); }

/* ── Engine control card (仪表盘) ────────────────────────────────────── */
.engine-card { padding: 16px 18px; }
.engine-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
}
.engine-status-wrap {
  display: flex; flex-direction: column; gap: 10px;
  min-width: 0; flex: 1 1 auto;
}
.engine-meta {
  display: flex; flex-wrap: wrap; gap: 18px;
  font-size: 12px; color: var(--text-muted);
}
.engine-meta .meta-item { display: inline-flex; gap: 6px; align-items: baseline; }
.engine-meta .meta-label {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
  font-weight: 500;
}
.engine-meta .meta-value {
  color: var(--text);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}
.engine-meta a.meta-item { color: var(--text-muted); transition: color 0.15s; }
.engine-meta a.meta-item:hover { color: var(--accent); }

.engine-actions {
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.engine-actions button {
  padding: 9px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  transition: all 0.15s; white-space: nowrap;
}
.engine-actions .btn-start {
  background: var(--warning); color: #1a1300; border-color: var(--warning);
}
.engine-actions .btn-start:hover { background: #fcd34d; transform: translateY(-1px); }
.engine-actions .btn-stop {
  background: var(--bg-hover); color: var(--text); border-color: var(--border);
}
.engine-actions .btn-stop:hover { background: var(--border); }
.engine-actions .btn-panic {
  background: rgba(248, 113, 113, 0.12); color: var(--danger);
  border-color: var(--danger);
}
.engine-actions .btn-panic:hover {
  background: var(--danger); color: #1a0707;
}
.engine-actions button:disabled {
  opacity: 0.5; cursor: not-allowed; transform: none;
}
.engine-actions .spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: pc-spin 0.6s linear infinite;
  vertical-align: -2px; margin-right: 4px;
}
@keyframes pc-spin { to { transform: rotate(360deg); } }

.engine-foot { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-header h2 { font-size: 14px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }

.stat {
  display: flex; flex-direction: column; gap: 6px;
}
.stat-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat-value.up { color: var(--buy); }
.stat-value.down { color: var(--sell); }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ── Buttons ── */
.btn-primary, .btn-ghost {
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent; transition: all 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: #052e1d;
}
.btn-primary:hover { background: var(--accent-dim); transform: translateY(-1px); }
.btn-ghost {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--border); }

/* ── Danger button + danger card (kill switch) ── */
.btn-danger {
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--danger);
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-danger:hover {
  background: var(--danger);
  color: #1a0707;
  transform: translateY(-1px);
}
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.danger-card {
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: linear-gradient(180deg, rgba(248,113,113,0.05), transparent);
}
.danger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.danger-meta { flex: 1; min-width: 0; }
@media (max-width: 700px) {
  .danger-row { flex-direction: column; align-items: stretch; }
}

/* ── Forms ── */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-muted); }
.form input, .form select, .form textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--accent); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 8px; }
.form.inline { flex-direction: row; align-items: flex-end; gap: 10px; }
.form.inline label { flex: 1; }

.switch-row {
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.switch-row input[type="checkbox"] {
  width: 40px; height: 22px;
  appearance: none;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.switch-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  background: white;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: left 0.2s;
}
.switch-row input[type="checkbox"]:checked { background: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { left: 20px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.table thead th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-elev);
  position: sticky; top: 0;
}
.table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--bg-hover); }
.table .addr { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.table .pos { color: var(--buy); font-weight: 600; }
.table .neg { color: var(--sell); font-weight: 600; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge.buy, .badge.filled, .badge.copied, .badge.open { background: rgba(52, 211, 153, 0.15); color: var(--buy); }
.badge.sell, .badge.failed { background: rgba(248, 113, 113, 0.15); color: var(--sell); }
.badge.pending, .badge.submitted, .badge.preparing { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge.skipped, .badge.closed { background: rgba(139, 148, 167, 0.15); color: var(--text-muted); }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  margin-right: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.tag-allow {
  background: rgba(110, 231, 183, 0.12);
  color: var(--accent);
  border: 1px solid rgba(110, 231, 183, 0.3);
}
.tag-deny {
  background: rgba(248, 113, 113, 0.12);
  color: var(--sell);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding-top: 12px; }

/* ── Event list ── */
.event-list { list-style: none; max-height: 420px; overflow-y: auto; }
.event-list li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 26px 70px 1fr auto;
  gap: 12px;
  align-items: center;
  font-size: 12px;
  transition: background 0.1s;
}
.event-list li:hover { background: rgba(255,255,255,0.02); }
.event-time {
  color: var(--text-dim);
  font-family: "SF Mono", monospace;
  font-size: 11px;
  white-space: nowrap;
}
.event-icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  background: var(--bg-elev);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.event-icon.up   { background: rgba(52, 211, 153, 0.15); color: var(--buy);  border-color: rgba(52, 211, 153, 0.35); }
.event-icon.down { background: rgba(248, 113, 113, 0.15); color: var(--sell); border-color: rgba(248, 113, 113, 0.35); }
.event-icon.warn { background: rgba(251, 191, 36, 0.15); color: var(--warning); border-color: rgba(251, 191, 36, 0.35); }
.event-icon.muted { background: var(--bg-elev); color: var(--text-muted); }
.event-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.event-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event-title .ev-side-buy  { color: var(--buy);  font-weight: 600; }
.event-title .ev-side-sell { color: var(--sell); font-weight: 600; }
.event-sub {
  color: var(--text-muted);
  font-size: 11px;
  font-family: "SF Mono", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event-pnl {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.event-pnl.up   { color: var(--buy); }
.event-pnl.down { color: var(--sell); }
.event-pnl.dim  { color: var(--text-muted); }

.event-empty {
  /* 覆盖 .event-list li 的 4 列 grid，让占位文字整段横排 */
  display: block !important;
  padding: 30px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 9999;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }

/* ── Goldsky Sync Panel ── */
.sync-panel { display: flex; flex-direction: column; gap: 10px; }
.sync-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--bg-hover); border-radius: 8px;
}
.sync-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.sync-value { font-size: 13px; color: var(--text); font-family: "SF Mono", Consolas, monospace; }
.sync-value.ok { color: var(--accent); }
.sync-value.warn { color: #f5a623; }
.sync-value.err { color: var(--danger); }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 8px 14px; background: transparent; border: 1px solid transparent;
  border-radius: 8px; color: var(--text-muted); font-size: 13px; cursor: pointer;
}
.tab.active { background: var(--bg-card); border-color: var(--border); color: var(--text); }

.filters { display: flex; gap: 10px; }
.filters select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 6px; font-size: 12px;
}

.dl.kv, dl.kv {
  display: grid; grid-template-columns: 1fr 2fr; gap: 8px 16px;
  margin-bottom: 14px; font-size: 13px;
}
dl.kv dt { color: var(--text-muted); }
dl.kv dd { font-family: "SF Mono", monospace; word-break: break-all; }

/* ── Dialog ── */
dialog {
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 22px; min-width: 420px; max-width: 560px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); }
dialog h3 { margin-bottom: 16px; }

dialog .market-filter {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px 4px;
  margin: 4px 0 12px;
  background: rgba(255,255,255,0.02);
}
dialog .market-filter legend {
  padding: 0 6px;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}
dialog .market-filter code {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--accent);
}
dialog .market-filter label + label { margin-top: 10px; }
dialog .market-filter .muted.small { display: block; margin-top: 4px; }

/* ── Login ── */
.login-page {
  display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(circle at 30% 20%, rgba(110,231,183,0.08), transparent 40%), var(--bg);
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px;
  width: 360px; box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 24px; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* ── Polymarket-style Portfolio Cards (shared by positions + trades) ── */
.pm-grid { display: flex; flex-direction: column; gap: 12px; }
.pm-card {
  display: grid;
  grid-template-columns: 320px 1fr;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}
.pm-card:hover { border-color: var(--border-strong); }
.pm-card.closed { opacity: 0.55; }

.pm-head {
  display: flex; gap: 14px; padding: 16px 18px;
  border-right: 1px solid var(--border);
}
.pm-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--bg-elev);
  overflow: hidden;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 22px; color: var(--text-dim);
}
.pm-icon img { width: 100%; height: 100%; object-fit: cover; }

.pm-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.pm-title h3 {
  font-size: 14px; font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.pm-title .pm-sub {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
  flex-wrap: wrap;
}
.pm-title .pm-sub .dot { color: var(--text-dim); }
.pm-title .pm-outcome-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(110, 231, 183, 0.12);
  color: var(--accent);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  width: max-content;
}
.pm-title .pm-outcome-badge.sell { background: rgba(248, 113, 113, 0.12); color: var(--danger); }

.pm-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: center;
  padding: 16px 22px;
  gap: 18px;
}
.pm-stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pm-stat-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 500;
}
.pm-stat-value {
  font-size: 14px; font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pm-stat-value.up { color: var(--buy); }
.pm-stat-value.down { color: var(--sell); }
.pm-stat-value.dim { color: var(--text-muted); }
.pm-stat-value .arrow { font-size: 11px; margin-left: 4px; }

.pm-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  grid-column: 1 / -1;            /* 横跨整行，避免窄屏溢出 */
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.02);
  flex-wrap: wrap;
}
.pm-actions .time {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}
.pm-actions .source {
  font-family: "SF Mono", monospace;
  background: var(--bg-elev);
  padding: 2px 6px;
  border-radius: 4px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* mobile/tablet */
@media (max-width: 1100px) {
  .pm-card { grid-template-columns: 1fr; }
  .pm-head { border-right: none; border-bottom: 1px solid var(--border); }
  .pm-stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .pm-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ── Positions Table ─────────────────────────────────────────────── */
.pm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;       /* 关键：固定布局，<th> 的 width 才生效 */
}
.pm-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-base);
  position: sticky;
  top: 0;
  z-index: 1;
}
.pm-table th.num,
.pm-table td.num {
  text-align: right;
}
.pm-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.pm-table td.num {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.pm-row { transition: background 0.1s; }
.pm-row:hover { background: rgba(255,255,255,0.03); }
.pm-row:last-child td { border-bottom: none; }

/* outcome badge in table */
.pm-outcome-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(0, 200, 100, 0.12);
  color: var(--buy);
  letter-spacing: 0.04em;
}
.pm-outcome-badge.sell {
  background: rgba(255, 80, 80, 0.12);
  color: var(--sell);
}

/* role badge (taker / maker) — 中性灰底，避免与买卖方向视觉冲突 */
.pm-role-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 500;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.03em;
  background: rgba(139, 148, 167, 0.12);
  color: var(--text-muted);
  border: 1px solid rgba(139, 148, 167, 0.25);
}
.pm-role-badge.taker {
  background: rgba(110, 231, 183, 0.10);
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.30);
}
.pm-role-badge.maker {
  background: rgba(245, 215, 110, 0.08);
  color: var(--gold);
  border-color: rgba(245, 215, 110, 0.25);
}

/* arrow/change in table */
.arrow.up  { color: var(--buy);  font-size: 11px; }
.arrow.down { color: var(--sell); font-size: 11px; }

/* small icon for table rows */
.pm-icon-sm {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-elev);
  overflow: hidden;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 14px; color: var(--text-dim);
}
.pm-icon-sm img { width: 100%; height: 100%; object-fit: cover; }

/* table pagination */
.pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.btn-sm { padding: 4px 10px; font-size: 12px; }

@media (max-width: 900px) {
  .pm-table th:nth-child(6),
  .pm-table td:nth-child(6),
  .pm-table th:nth-child(7),
  .pm-table td:nth-child(7) { display: none; }
  /* 交易表：保「状态」列与「盈亏」列，隐藏「成交价」「当前价」「结算方向」「成本」四列 */
  #trades-table th:nth-child(8),
  #trades-table td:nth-child(8),
  #trades-table th:nth-child(9),
  #trades-table td:nth-child(9) { display: none; }
  /* 持仓-Open 表：隐藏 Avg. Price 与 Current(7 列信息密度太高) */
  #table-open th:nth-child(4),
  #table-open td:nth-child(4),
  #table-open th:nth-child(5),
  #table-open td:nth-child(5) { display: none; }
  /* 持仓-Closed 表：保留 Market / Outcome / Result / Settled，隐藏数字细节列 */
  #table-closed th:nth-child(3),
  #table-closed td:nth-child(3),
  #table-closed th:nth-child(4),
  #table-closed td:nth-child(4),
  #table-closed th:nth-child(5),
  #table-closed td:nth-child(5),
  #table-closed th:nth-child(6),
  #table-closed td:nth-child(6) { display: none; }
}

/* 「结算方向」列两行对齐：
 *  - 结算后下挂 $1.00 / $0.00 小字 → 单元格两行
 *  - 未结算时只有「—」 → 单元格一行
 *  min-height 锁定行高，避免混合数据时行高错乱 */
#trades-table td:nth-child(8) { min-height: 38px; }
@media (max-width: 640px) {
  .pm-table { font-size: 12px; }
  .pm-table th, .pm-table td { padding: 8px 10px; }
  .pm-table th:nth-child(4),
  .pm-table td:nth-child(4) { display: none; }
  /* 交易表：移动端保留状态列；隐藏「份额」列 */
  #trades-table th:nth-child(6),
  #trades-table td:nth-child(6) { display: none; }
  /* 持仓-Open 表：再隐藏 Time，腾出空间给 P&L */
  #table-open th:nth-child(10),
  #table-open td:nth-child(10) { display: none; }
}

/* ── Trades: 紧凑表格 ──────────────────────────────────────── */
#trades-table th,
#trades-table td { padding: 9px 12px; }
#trades-table .pm-icon-sm { width: 28px; height: 28px; font-size: 12px; }
#trades-table .pm-outcome-badge { padding: 1px 7px; font-size: 10.5px; }

/* 市场单元格：标题 + 副标题（slug）严格单行截断
 * 这套样式被 positions + trades 两张表共用 */
.pm-market-title {
  font-weight: 500;
  font-size: 13px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.pm-market-link {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  transition: color 0.15s, border-color 0.15s;
}
.pm-market-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.pm-market-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
