:root {
  --bg: #0e1116;
  --panel: #161b23;
  --panel-2: #1d232d;
  --line: #2a323f;
  --text: #e6edf3;
  --muted: #8b97a8;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

a { color: var(--accent); }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: .02em; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 600; font-size: 16px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--line); }

main { padding: 18px; max-width: 1400px; margin: 0 auto; }

/* --------------------------------------------------------------- card */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card.login { width: min(360px, 92vw); display: flex; flex-direction: column; gap: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------ controls */
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.row.wrap { flex-wrap: wrap; }
label { color: var(--muted); font-size: 12px; display: block; margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin: 0; white-space: nowrap; }
/* Checkboxes must not stretch the way text inputs do. */
input[type=checkbox] { flex: 0 0 auto; min-width: 0; width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }

input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input, select, textarea { flex: 1; min-width: 110px; }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=number] { max-width: 120px; }
.account-select { max-width: 240px; }

button { cursor: pointer; flex: 0 0 auto; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; }
button.danger { color: var(--err); }
button.tiny { padding: 4px 8px; font-size: 12px; }

code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* -------------------------------------------------------------- tables */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
table.grid td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tr:last-child td { border-bottom: none; }
table td { padding: 4px 8px; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }

/* -------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: rgba(52, 211, 153, .4); }
.badge.err { color: var(--err); border-color: rgba(248, 113, 113, .4); }
.badge.warn { color: var(--warn); border-color: rgba(251, 191, 36, .4); }

/* --------------------------------------------------------------- stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .value { font-size: 26px; font-weight: 600; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

/* ------------------------------------------------------------ messages */
.messages { max-height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.msg {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.msg.out { border-left-color: var(--accent); }
.msg.hit { border-left-color: var(--warn); }
.msg .meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg mark { background: rgba(251, 191, 36, .28); color: inherit; border-radius: 3px; padding: 0 2px; }

/* --------------------------------------------------------------- misc */
.alert { padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.alert.error { background: rgba(248, 113, 113, .12); color: var(--err); border: 1px solid rgba(248, 113, 113, .3); }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  z-index: 100;
  max-width: 420px;
}
.toast.err { border-color: rgba(248, 113, 113, .5); color: var(--err); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-card { width: min(440px, 92vw); margin: 0; }
