:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --fg: #111827;
  --fg-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-fg: #ffffff;
  --ok: #059669;
  --bad: #dc2626;
  --busy: #d97706;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .3em; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 24px; }
h3 { font-size: 16px; }
.muted { color: var(--fg-muted); margin: 0; }
.hint { color: var(--fg-muted); font-size: 13px; margin: .4em 0 0; }
.empty { color: var(--fg-muted); padding: 20px 0; margin: 0; }
.loading { padding: 60px; text-align: center; color: var(--fg-muted); }

/* ---------------------------------------------------------------- layout */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px; height: 60px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  border: 0; background: none; font: inherit; font-weight: 700;
  cursor: pointer; padding: 0; color: inherit;
}
.topnav { display: flex; gap: 4px; }
.topnav button {
  border: 0; background: none; font: inherit; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; color: var(--fg-muted);
}
.topnav button:hover { background: var(--bg); color: var(--fg); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.credits {
  font-size: 13px; font-weight: 600; padding: 4px 10px;
  background: var(--bg); border-radius: 999px;
}
.who { font-size: 13px; color: var(--fg-muted); }
.content { max-width: 940px; margin: 0 auto; padding: 28px 24px 80px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
.link-back {
  border: 0; background: none; font: inherit; font-size: 13px;
  color: var(--fg-muted); cursor: pointer; padding: 0 0 4px;
}
.link-back:hover { color: var(--fg); }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.bot-card {
  text-align: left; cursor: pointer; font: inherit; color: inherit;
  display: flex; flex-direction: column; gap: 8px; margin: 0;
  transition: border-color .15s ease, transform .15s ease;
}
.bot-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.bot-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bot-name { font-weight: 600; }
.bot-id {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
  color: var(--fg-muted);
}
.bot-stats { display: flex; gap: 14px; font-size: 13px; color: var(--fg-muted); }

/* ----------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs button {
  border: 0; background: none; font: inherit; cursor: pointer;
  padding: 10px 14px; color: var(--fg-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--fg); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ----------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; }
label { font-size: 13px; font-weight: 600; margin: 14px 0 5px; }
label:first-of-type { margin-top: 0; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"],
textarea, select {
  width: 100%; padding: 9px 11px; font: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: inherit;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.file-label { display: block; margin-top: 18px; }
input[type="file"] { font-size: 13px; margin-top: 4px; }

.btn {
  align-self: flex-start; margin-top: 18px;
  padding: 9px 16px; font: inherit; font-weight: 600;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--fg); cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--fg-muted); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-quiet { margin: 0; padding: 6px 10px; font-size: 13px; font-weight: 500; }
.inline-form .btn { margin: 0; }
.page-head .btn { margin: 0; }

.form-error { color: var(--bad); font-size: 13px; min-height: 1.2em; margin: 10px 0 0; }
.danger { border-color: #fecaca; }
.danger h3 { color: var(--bad); }

/* ----------------------------------------------------------------- lists */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title {
  font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-sub { font-size: 12.5px; color: var(--fg-muted); }
.row-error { font-size: 12.5px; color: var(--bad); }
.row-balance {
  font-variant-numeric: tabular-nums; font-size: 13px;
  color: var(--fg-muted); min-width: 60px; text-align: right;
}
.delta { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.delta-up { color: var(--ok); }
.delta-down { color: var(--fg-muted); }

.pill {
  font-size: 12px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; white-space: nowrap;
}
.pill-ok { background: #d1fae5; color: #065f46; }
.pill-bad { background: #fee2e2; color: #991b1b; }
.pill-busy { background: #fef3c7; color: #92400e; }
.pill-off { background: var(--bg); color: var(--fg-muted); }

/* ----------------------------------------------------------------- stats */
.stats { display: flex; gap: 32px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--fg-muted); }
.meter-wrap { flex-basis: 100%; margin-top: 6px; }
.meter { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--primary); }

.snippet {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px;
  border-radius: 8px; overflow-x: auto; margin: 12px 0 0;
  font-size: 12.5px; line-height: 1.6;
}
.snippet code { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ----------------------------------------------------------------- login */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; margin: 0; }
.login-card h1 { font-size: 20px; }
.login-card .btn { align-self: stretch; text-align: center; }

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: 22px; left: 50%;
  transform: translate(-50%, 12px); opacity: 0;
  padding: 11px 18px; border-radius: 8px; z-index: 100;
  background: var(--fg); color: #fff; font-size: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .2);
  transition: opacity .2s ease, transform .2s ease;
}
.toast-shown { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--bad); }

@media (max-width: 640px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .who { display: none; }
  .content { padding: 20px 14px 60px; }
  .stats { gap: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .bot-card, .toast { transition: none; }
}

/* --------------------------------------------------------------- banner */
.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 24px; background: #fef3c7; color: #78350f;
  border-bottom: 1px solid #fde68a; font-size: 14px;
}
.linkish {
  border: 0; background: none; padding: 0; font: inherit;
  color: var(--primary); cursor: pointer; text-decoration: underline;
}
.linkish:disabled { opacity: .5; cursor: not-allowed; }
.alt-action {
  display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
  margin: 18px 0 0; font-size: 14px;
}
.login-card form { display: flex; flex-direction: column; }
.login-card .btn { align-self: stretch; text-align: center; }

/* ----------------------------------------------------------------- plans */
.plan-grid {
  display: grid; gap: 12px; margin-top: 4px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.plan {
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px; border: 1px solid var(--border); border-radius: var(--radius);
}
.plan-current { border-color: var(--primary); }
.plan-name { font-weight: 600; }
.plan-price { font-size: 22px; font-weight: 700; }
.plan-features {
  list-style: none; padding: 0; margin: 4px 0 10px;
  font-size: 13px; color: var(--fg-muted); flex: 1;
}
.plan-features li { padding: 1px 0; }
.plan .btn { margin: 0; align-self: stretch; text-align: center; }
