/* Limbot Control Panel — Stake-like dark theme */
:root {
  --bg: #0F212E;
  --surface: #1A2C38;
  --surface-2: #213743;
  --border: #2F4553;
  --text: #FFFFFD;
  --muted: #B1BAD3;
  --faint: #6F8494;
  --green: #00E701;
  --green-soft: rgba(0, 231, 1, 0.14);
  --red: #FF4E4E;
  --red-soft: rgba(255, 78, 78, 0.14);
  --blue: #1475E1;
  --amber: #ED9F04;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--muted); }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-start { background: var(--green); color: #05290a; }
.btn-stop { background: var(--red); color: #fff; }
.btn-primary { background: var(--blue); }
.btn-ghost { background: transparent; color: var(--muted); padding: 7px 10px; }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger-ghost { background: transparent; color: var(--red); border: 1px solid var(--red-soft); }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
textarea { font-family: var(--mono); font-size: 12px; min-height: 360px; resize: vertical; }
label.field { display: block; }
label.field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

.check { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--green); }

/* ---------- layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 17px; letter-spacing: 0.2px; }
.brand span { color: var(--green); }
.spacer { flex: 1; }

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.card-head .spacer { min-width: 8px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- status pill & badges ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.pill.running { color: var(--green); }
.pill.running::before { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.pill.stopped { color: var(--amber); }
.pill.stopped::before { background: var(--amber); }
.pill.offline { color: var(--red); }
.pill.offline::before { background: var(--red); }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge.admin { background: rgba(20, 117, 225, 0.2); color: #6fb1ff; }

/* ---------- status card ---------- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 16px;
}
.status-grid .label { color: var(--muted); font-size: 12px; }
.status-grid .value { font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pattern-tail { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 2px; }
.pattern-tail i {
  font-style: normal;
  font-size: 10px;
  font-weight: 800;
  width: 15px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}
.pattern-tail i.w { background: var(--green-soft); color: var(--green); }
.pattern-tail i.l { background: var(--red-soft); color: var(--red); }

.controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.remote-info { align-self: center; margin-left: auto; color: var(--faint); font-size: 12px; }
.remote-info b { color: var(--amber); font-weight: 700; }
.lock-hint { background: rgba(237, 159, 4, 0.12); color: var(--amber); border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
.msg { margin-top: 10px; font-size: 13px; min-height: 18px; }
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.seg button.active { background: var(--border); color: var(--text); }
.seg.small button { padding: 4px 10px; font-size: 12px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 6px; }
.kpi .value { font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { color: var(--faint); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.hero .value { font-size: 24px; }

.chart-wrap { position: relative; height: 340px; }
@media (max-width: 600px) { .chart-wrap { height: 260px; } }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--faint); }

/* ---------- streak tiles ---------- */
.mini-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 480px) { .mini-tiles { grid-template-columns: repeat(2, 1fr); } }
.mini { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; min-width: 0; }
.mini .label { color: var(--muted); font-size: 12px; }
.mini .value { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: right;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { text-align: right; padding: 6px 8px; border-bottom: 1px solid rgba(47, 69, 83, 0.5); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
td.wrap { white-space: normal; text-align: left; color: var(--muted); font-size: 12px; min-width: 220px; }
tr.win td.res { color: var(--green); font-weight: 700; }
tr.loss td.res { color: var(--red); font-weight: 700; }
tr.obs td { color: var(--faint); }
.dist-bar { display: inline-block; height: 8px; border-radius: 2px; vertical-align: middle; min-width: 1px; }
.dist-bar.l { background: var(--red); }
.dist-bar.w { background: var(--green); }
td.bar-cell { width: 34%; text-align: left; }
.empty-row td { text-align: center; color: var(--faint); padding: 18px; }
.table-scroll { max-height: 420px; overflow-y: auto; }

/* ---------- settings ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--green); }
.tabs button .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); margin-left: 6px; vertical-align: middle; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.form-hint { color: var(--faint); font-size: 12px; margin-top: 10px; }
.settings-footer { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }

.mode-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.mode-card {
  display: block;
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
}
.mode-card input { display: none; }
.mode-card b { display: block; font-size: 15px; }
.mode-card span { color: var(--muted); font-size: 12px; }
.mode-card.selected { border-color: var(--green); }

/* generic settings tree editor */
.tree details { background: var(--surface-2); border-radius: 6px; margin: 8px 0; }
.tree details details { background: rgba(15, 33, 46, 0.55); }
.tree summary { cursor: pointer; padding: 8px 12px; font-weight: 600; color: var(--muted); }
.tree details[open] > summary { color: var(--text); }
.tree .tree-body { padding: 4px 12px 12px; }
.tree .fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
.tree .fields label.field > span { font-family: inherit; }
.tree .bool-field { display: flex; align-items: center; gap: 8px; padding-top: 18px; color: var(--muted); font-size: 12px; }
.tree .bool-field input { width: 16px; height: 16px; accent-color: var(--green); }
.json-error { color: var(--red); font-size: 12px; margin-top: 6px; }
.preview-table td, .preview-table th { font-size: 12px; }

/* ---------- activity ---------- */
.activity { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; font-size: 13px; }
.activity li { padding: 6px 0; border-bottom: 1px solid rgba(47, 69, 83, 0.5); display: flex; gap: 10px; }
.activity time { color: var(--faint); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 12px; padding: 28px 24px; }
.login-card .brand { font-size: 22px; text-align: center; margin-bottom: 18px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card .seg { width: 100%; display: flex; margin-bottom: 16px; background: var(--bg); }
.login-card .seg button { flex: 1; }
.login-card .btn { justify-content: center; padding: 11px; }
.login-card .hint { color: var(--faint); font-size: 12px; text-align: center; margin-top: 12px; }

@media (max-width: 600px) {
  main { padding: 12px; gap: 12px; }
  .topbar { padding: 8px 12px; gap: 6px; flex-wrap: wrap; }
  .card { padding: 12px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi .value { font-size: 17px; }
  .kpi.hero .value { font-size: 19px; }
  .controls .btn { flex: 1 1 auto; justify-content: center; }
}
th.left { text-align: left; }
.bot-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); display: inline-block; margin-right: 6px; vertical-align: middle; }
.bot-dot.on { background: var(--amber); }
.bot-dot.running { background: var(--green); }

/* ---------- Systemstatus ---------- */
.health-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); display: inline-block; }
.health-dot.ok { background: var(--green); }
.health-dot.warn { background: var(--amber); }
.health-dot.bad { background: var(--red); }
.health-summary { font-size: 13px; font-weight: 600; }
.health-summary.ok { color: var(--green); }
.health-summary.warn { color: var(--amber); }
.health-summary.bad { color: var(--red); }
.checks { list-style: none; margin: 0 0 8px; padding: 0; }
.checks li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(47, 69, 83, 0.6); }
.checks li:last-child { border-bottom: 0; }
.check-icon {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #0F212E;
}
.check-icon.ok { background: var(--green); }
.check-icon.warn { background: var(--amber); }
.check-icon.bad { background: var(--red); color: #fff; }
.check-icon.info { background: var(--border); color: var(--muted); }
.check-label { font-weight: 600; }
.check-detail { color: var(--muted); font-size: 12px; margin-top: 1px; word-break: break-word; }
.check-detail code { font-family: var(--mono); background: var(--bg); padding: 1px 5px; border-radius: 4px; user-select: all; }
.bot-block { background: var(--surface-2); border-radius: 8px; padding: 4px 12px; margin-bottom: 10px; }
.bot-block h4 { margin: 8px 0 2px; font-size: 14px; }
