:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --positive: #059669;
  --negative: #dc2626;
  --warn: #d97706;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", sans-serif;
       background: var(--bg); color: var(--text); }

.topbar {
  background: #111827; color: #fff;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
}
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar nav a { color: #d1d5db; margin-right: 16px; text-decoration: none; }
.topbar nav a:hover { color: #fff; }
.topbar .alerts { margin-left: auto; font-size: 13px; }
.topbar .alerts .badge { background: var(--warn); color: #fff; padding: 2px 8px;
                        border-radius: 10px; margin-left: 8px; }

main { max-width: 1280px; margin: 24px auto; padding: 0 24px; }

/* Cards */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px;
}
.card h3 { margin: 0 0 8px 0; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.card .amount { font-size: 22px; font-weight: 700; }
.card .ts { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Summary */
.summary-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px;
}
.summary-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; text-align: center;
}
.summary-card h3 { margin: 0; font-size: 13px; color: var(--muted); }
.summary-card .net { font-size: 28px; font-weight: 700; margin: 8px 0 4px; }
.summary-card .net.pos { color: var(--positive); }
.summary-card .net.neg { color: var(--negative); }
.summary-card .meta { font-size: 12px; color: var(--muted); margin: 0; }

/* Chart */
.chart-section { background: var(--card); border: 1px solid var(--border);
                 border-radius: 8px; padding: 16px; margin-bottom: 24px; }
.chart-header { display: flex; align-items: center; justify-content: space-between;
                flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chart-header h2 { margin: 0; font-size: 16px; }
.chart-toggles { display: flex; gap: 16px; flex-wrap: wrap; }
.toggle-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.toggle-label input[type=checkbox] { accent-color: var(--c, var(--accent)); width: 15px; height: 15px; cursor: pointer; }

/* Recent trades on dashboard */
.recent-trades-section { margin-top: 24px; }
.recent-trades-section h2 { font-size: 16px; margin-bottom: 12px; }

/* Trades table */
.filter-bar {
  display: flex; gap: 12px; align-items: center; margin-bottom: 12px;
  background: var(--card); padding: 12px; border: 1px solid var(--border); border-radius: 8px;
  flex-wrap: wrap;
}
.filter-bar input, .filter-bar select { padding: 4px 8px; }
.filter-bar button, .btn-csv {
  background: var(--accent); color: #fff; border: 0; padding: 6px 14px;
  border-radius: 6px; cursor: pointer; text-decoration: none; font-size: 13px;
}
.btn-csv { display: inline-block; }

.trades-table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.trades-table th, .trades-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  text-align: left; font-size: 13px;
}
.trades-table th { background: #f9fafb; font-weight: 600; color: var(--muted); }
.trades-table tr:hover { background: #f9fafb; cursor: pointer; }
.trades-table .pos { color: var(--positive); font-weight: 600; }
.trades-table .neg { color: var(--negative); font-weight: 600; }
.status-pill {
  display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px;
  font-weight: 600; text-transform: uppercase;
}
.status-pill.pending { background: #fef3c7; color: #92400e; }
.status-pill.partial { background: #dbeafe; color: #1e40af; }
.status-pill.completed { background: #d1fae5; color: #065f46; }
.status-pill.timeout { background: #fee2e2; color: #991b1b; }
.status-pill.manual { background: #e5e7eb; color: #374151; }
.warn-mark { color: var(--warn); font-weight: 700; }

dialog {
  border: 0; border-radius: 8px; padding: 24px; min-width: 480px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
dialog::backdrop { background: rgba(0,0,0,0.4); }
dialog h2 { margin-top: 0; }
dialog pre { background: #f3f4f6; padding: 12px; border-radius: 6px;
             max-height: 320px; overflow: auto; font-size: 12px; }
dialog textarea { width: 100%; min-height: 80px; margin-top: 8px;
                  border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.dialog-actions button { padding: 6px 14px; border-radius: 6px; border: 0;
                         background: var(--accent); color: #fff; cursor: pointer; }
