:root {
  --bg: #0b0d10;
  --bg-2: #14181d;
  --card: #161b22;
  --border: #232a33;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4ade80;
  --danger: #f87171;
  --warn: #fbbf24;
  --link: #58a6ff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--link); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--bg-2); border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 16px; color: var(--muted); }
.badge {
  font-size: 10px; padding: 2px 8px; border-radius: 4px;
  background: var(--warn); color: #1a1a1a; margin-left: 8px; font-weight: 700;
}
.badge.live { background: var(--danger); color: white; }

button {
  background: var(--accent); color: #0b0d10; border: none; padding: 8px 16px;
  border-radius: 6px; font-weight: 600; cursor: pointer;
}
button:hover { opacity: 0.9; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: white; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 16px 24px;
}
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px;
}
.card.full { grid-column: 1 / -1; }
.card h2 { margin: 0 0 12px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }

.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.kpi-grid > div { display: flex; flex-direction: column; }
.kpi-grid .label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.kpi-grid .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

table {
  width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums;
}
table th, table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
table tr:hover td { background: rgba(255,255,255,0.02); }
.pnl-pos { color: var(--accent); }
.pnl-neg { color: var(--danger); }

.bots-status { display: flex; flex-direction: column; gap: 8px; }
.bot-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg-2); border-radius: 6px;
}
.bot-row .name { font-weight: 600; }
.status-pill {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; text-transform: uppercase;
}
.status-active { background: rgba(74,222,128,0.15); color: var(--accent); }
.status-inactive { background: rgba(248,113,113,0.15); color: var(--danger); }
.status-failed { background: rgba(251,191,36,0.15); color: var(--warn); }

.events-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.event {
  padding: 6px 10px; background: var(--bg-2); border-radius: 4px; font-size: 12px;
}
.event .t { color: var(--muted); margin-right: 8px; }
.event .type { font-weight: 700; margin-right: 8px; }
.event .type.error { color: var(--danger); }
.event .type.started { color: var(--accent); }
.event .type.stopped { color: var(--warn); }

.code {
  background: var(--bg-2); padding: 12px; border-radius: 6px; font-size: 12px;
  white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow-y: auto;
}

.error {
  background: rgba(248,113,113,0.12); color: var(--danger);
  padding: 10px; border-radius: 6px; margin-bottom: 12px; font-size: 13px;
}

.login-body {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #0b0d10 0%, #1a1f2e 100%);
}
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 32px; width: 100%; max-width: 360px;
}
.login-card h1 { margin: 0 0 4px; }
.login-card .muted { color: var(--muted); margin: 0 0 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.login-card input {
  background: var(--bg-2); border: 1px solid var(--border); padding: 10px;
  border-radius: 6px; color: var(--text); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--link); }
.login-card button { margin-top: 8px; }

.chart-box {
  position: relative;
  height: 240px;
  width: 100%;
}
.chart-box canvas { max-height: 240px; }

.prices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.price-tile {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; display: flex; flex-direction: column; gap: 6px;
}
.price-tile .pt-head { display: flex; justify-content: space-between; align-items: baseline; }
.price-tile .pt-sym { font-weight: 700; font-size: 14px; }
.price-tile .pt-change { font-size: 12px; font-weight: 600; }
.price-tile .pt-price { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 600; }
.price-tile .pt-hl { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.price-tile .pt-spark { height: 50px; position: relative; }
.price-tile .pt-spark canvas { max-height: 50px; }
.price-tile .pt-sig {
  font-size: 10px; text-transform: uppercase; padding: 2px 6px; border-radius: 3px;
  background: var(--bg); align-self: flex-start; letter-spacing: 0.5px;
}
.price-tile.has-pos { border-color: var(--accent); }

.pt-indicators {
  border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px;
  display: flex; flex-direction: column; gap: 3px;
}
.ind-row {
  display: flex; justify-content: space-between; font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.ind-lbl { color: var(--muted); }
.ind-val { font-weight: 600; }
.imminence-warn { color: var(--warn); }

.imminence-bar {
  margin-top: 6px; position: relative; height: 18px;
  background: var(--bg); border-radius: 3px; overflow: hidden;
}
.imminence-fill {
  position: absolute; left: 0; top: 0; bottom: 0; transition: width 0.3s;
}
.imminence-low { background: rgba(139,148,158,0.4); }
.imminence-med { background: rgba(251,191,36,0.4); }
.imminence-high { background: rgba(248,113,113,0.5); animation: pulse 2s ease-in-out infinite; }
.imminence-label {
  position: relative; z-index: 1; display: block; text-align: center;
  font-size: 10px; line-height: 18px; color: var(--text);
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.ghost-link {
  color: var(--text); text-decoration: none; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.ghost-link:hover { background: var(--bg-2); }

.small { font-size: 12px; }
.muted { color: var(--muted); }

.fieldset-group {
  border: 1px solid var(--border); border-radius: 8px; padding: 16px;
  margin-bottom: 16px; background: var(--bg-2);
}
.fieldset-group legend {
  padding: 0 8px; font-weight: 600; color: var(--text); font-size: 13px;
}
.fieldset-group label {
  display: grid; grid-template-columns: 240px 1fr; gap: 12px;
  align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.fieldset-group label:last-child { border-bottom: none; }
.fieldset-group .field-label { font-size: 13px; font-weight: 500; }
.fieldset-group .field-key {
  font-size: 10px; color: var(--muted); font-family: monospace;
  display: block; margin-top: 2px;
}
.fieldset-group input {
  background: var(--bg); border: 1px solid var(--border); padding: 8px 10px;
  border-radius: 4px; color: var(--text); font-size: 13px; font-family: monospace;
}
.fieldset-group input:focus { outline: none; border-color: var(--link); }

.form-actions {
  display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap;
}

.msg {
  padding: 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px;
}
.msg.ok { background: rgba(74,222,128,0.12); color: var(--accent); }
.msg.err { background: rgba(248,113,113,0.12); color: var(--danger); }

.test-row { display: flex; align-items: center; gap: 12px; }
.test-row button { min-width: 140px; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; padding: 12px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .fieldset-group label { grid-template-columns: 1fr; }
}
