:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #646b78;
  --border: #e2e5ea;
  --accent: #2f6fde;
  --pos: #12805c;
  --neg: #c4322b;
  --warn: #c77a0a;
  --pos-fill: rgba(18, 128, 92, 0.12);
  --neg-fill: rgba(196, 50, 43, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --text: #e8eaee;
    --muted: #9198a5;
    --border: #2a2f38;
    --accent: #6f9cf0;
    --pos: #3cc48f;
    --neg: #f0675f;
    --warn: #f0a63c;
    --pos-fill: rgba(60, 196, 143, 0.14);
    --neg-fill: rgba(240, 103, 95, 0.14);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

button {
  font: inherit;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 16px;
  max-width: 1100px;
  margin: 0 auto;
}
.title { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.badge {
  font-size: 0.8rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.badge:empty { display: none; }
.badge.live { border-color: var(--warn); color: var(--warn); }
.badge.stopped { border-color: var(--neg); color: var(--neg); }

main { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
.card h2 { color: var(--muted); font-weight: 500; margin-bottom: 0.25rem; }
.card p { margin: 0; }
.big { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.meter { height: 6px; background: var(--border); border-radius: 3px; margin-top: 0.5rem; overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.meter div.warn { background: var(--neg); }

.panel { margin-bottom: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.range { display: flex; gap: 4px; }
.range button { padding: 0.25rem 0.7rem; background: transparent; color: var(--muted); border-color: var(--border); }
.range button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.chart svg { width: 100%; height: 240px; display: block; }
.chart .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .zero { stroke: var(--border); stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.chart .up .line { stroke: var(--pos); }
.chart .up .area { fill: var(--pos-fill); }
.chart .down .line { stroke: var(--neg); }
.chart .down .area { fill: var(--neg-fill); }
.chart-legend { font-size: 0.8rem; margin: 0.5rem 0 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
th { color: var(--muted); font-weight: 500; }
td.reason { white-space: normal; color: var(--muted); min-width: 180px; }
.side-buy { color: var(--pos); font-weight: 600; }
.side-sell { color: var(--neg); font-weight: 600; }

.logs { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; font-size: 0.85rem; }
.logs li { display: flex; gap: 0.75rem; padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.logs time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.logs .log-error span { color: var(--neg); }
.logs .log-warning span { color: var(--warn); }

.foot { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 2rem; font-size: 0.8rem; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}
.login-card .notice { color: var(--neg); min-height: 1.5em; margin: 0.25rem 0; }
.login-form { display: grid; gap: 0.9rem; }
.login-form label { display: grid; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.login-form input {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.login-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

@media (max-width: 600px) {
  .big { font-size: 1.25rem; }
  .logs li { flex-direction: column; gap: 0; }
}
