* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--code-bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

/* Topbar */
.topbar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; gap: 24px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none; font-weight: 700; font-size: 16px;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #f39c12);
  color: var(--primary-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800;
}
.nav-links { display: flex; gap: 16px; flex: 1; }
.nav-links a { color: var(--text-muted); font-weight: 500; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.theme-toggle {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; font-size: 14px;
}
.theme-toggle:hover { background: var(--chip-bg); }

.content {
  max-width: 1200px; margin: 0 auto; padding: 24px;
  flex: 1; width: 100%;
}

.footer {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  color: var(--text-muted); font-size: 12px;
}
.footer-inner { max-width: 1200px; margin: 0 auto; display: flex; gap: 12px; }
.footer .sep { opacity: 0.5; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600; font-size: 13px;
  cursor: pointer; transition: transform 0.05s, background 0.15s, border-color 0.15s;
  background: var(--bg-soft); color: var(--text);
}
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-block { width: 100%; }

.btn-action {
  padding: 7px 12px; font-size: 12px; border-radius: 999px;
}
.btn-restart { background: var(--primary); color: var(--primary-text); }
.btn-stop { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-delete { background: var(--danger); color: #fff; }
.btn-refund { background: transparent; border: 1px solid var(--accent); color: var(--accent); }

/* Page head */
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 4px 0; font-size: 22px; }

/* Hero (landing) */
.hero {
  padding: 80px 0 40px;
}
.hero-inner { text-align: center; max-width: 720px; margin: 0 auto; }
.hero h1 { font-size: 52px; margin: 0 0 12px; }
.hero .lede { font-size: 16px; color: var(--text-muted); margin-bottom: 24px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; }
.features {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px; margin-top: 40px;
}
.feature {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}
.feature h3 { margin: 0 0 6px; font-size: 15px; }
.feature p { margin: 0; color: var(--text-muted); font-size: 13px; }

/* Auth */
.auth-shell {
  min-height: 60vh; display: grid; place-items: center;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-muted); }
.auth-card input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 14px;
}
.auth-card input:focus { outline: none; box-shadow: var(--focus); border-color: var(--accent); }
.auth-error { color: var(--danger); font-size: 12px; margin: 0; }

/* Card grid (dashboard) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.group-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.group-card-head {
  display: flex; justify-content: space-between; align-items: center;
}
.group-id { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.group-id .label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.group-id .value { font-family: ui-monospace, SFMono-Regular, monospace; color: var(--text); }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted);
}
.status-dot.status-running { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-dot.status-stopped { background: var(--warn); }
.status-dot.status-pending { background: var(--accent); }
.status-dot.status-failed  { background: var(--danger); }

.chip {
  background: var(--chip-bg); border-radius: 999px;
  padding: 3px 10px; font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600;
}
.chip-running { background: rgba(34, 197, 94, 0.18); color: var(--ok); }
.chip-pending { background: rgba(96, 165, 250, 0.18); color: var(--accent); }
.chip-stopped { background: rgba(245, 158, 11, 0.18); color: var(--warn); }
.chip-failed  { background: var(--danger-soft); color: var(--danger); }
.chip-deleted { background: var(--chip-bg); color: var(--text-muted); }
.chip-credit  { background: rgba(96, 165, 250, 0.12); color: var(--accent); }
.chip-debit   { background: rgba(245, 158, 11, 0.15); color: var(--warn); }
.chip-refund  { background: rgba(34, 197, 94, 0.15); color: var(--ok); }

.group-meta, .group-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  font-size: 12px;
}
.group-meta > div, .group-stats > div {
  background: var(--bg-soft); border-radius: 8px; padding: 8px 10px;
}
.group-meta span, .group-stats small {
  color: var(--text-muted); display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px;
}
.group-meta strong, .group-stats span { color: var(--text); font-weight: 600; font-size: 13px; }

.progress {
  position: relative;
  background: var(--bg-soft); border-radius: 999px; height: 10px; overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #f39c12);
  transition: width 0.3s ease;
}
.progress-text {
  position: absolute; right: 10px; top: -18px;
  font-size: 11px; color: var(--text-muted);
}
.group-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* Modals */
.modal {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-card {
  position: relative; z-index: 1;
  width: min(560px, 90vw);
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow);
  max-height: 90vh; overflow-y: auto;
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.modal-card input, .modal-card select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-size: 14px;
}
.modal-card input:focus, .modal-card select:focus {
  outline: none; box-shadow: var(--focus); border-color: var(--accent);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-error { color: var(--danger); margin: 0; font-size: 12px; }
.inline-check { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--text-muted); display: flex; gap: 16px; align-items: center; }
.inline-check legend { padding: 0 6px; }
.inline-check label { flex-direction: row; gap: 4px; color: var(--text); font-size: 13px; }

/* Tables */
.table {
  width: 100%; border-collapse: collapse;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px;
}
.table th { background: var(--bg-soft); color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.table tr:last-child td { border-bottom: none; }

/* Panels */
.panel {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.panel h2 { margin: 0 0 10px; font-size: 15px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

.api-key-box {
  background: var(--code-bg); border: 1px dashed var(--border);
  padding: 10px 12px; border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px;
  word-break: break-all; display: block;
}

/* Admin stats */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat span { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat strong { font-size: 26px; font-weight: 700; }

/* Chart panel */
.chart-panel {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 24px;
}

.select {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 13px;
}

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 12px; }
  .nav-links { order: 3; flex-basis: 100%; overflow-x: auto; }
  .content { padding: 16px; }
  .hero h1 { font-size: 36px; }
}
