:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-soft: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.5rem; }
code { background: rgba(99, 102, 241, 0.15); padding: 0.1rem 0.3rem; border-radius: 4px; font-size: 0.85em; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* ---------- Auth ---------- */
body.auth {
  display: grid; place-items: center;
  background: radial-gradient(circle at top, #1e293b 0%, #0f172a 55%);
}
.auth-card {
  width: min(420px, 92vw);
  background: var(--card);
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 1.5rem; }
.brand h1 { font-size: 1.75rem; margin: 0.5rem 0 0.25rem; }
.tagline { color: var(--muted); font-size: 0.9rem; }
.logo-mark {
  display: inline-grid; place-items: center;
  width: 56px; height: 56px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff; font-size: 1.8rem; font-weight: 600;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tab {
  flex: 1; background: transparent; color: var(--muted);
  border: none; padding: 0.75rem; font-size: 0.95rem; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.form { display: flex; flex-direction: column; gap: 0.9rem; }
.form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.form input, .form textarea, .form select, .inline-form input, .inline-form select {
  background: var(--card-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
}
.form input:focus, .form textarea:focus, .form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary, .btn-ghost {
  padding: 0.6rem 1rem; border-radius: 6px;
  font-size: 0.9rem; font-weight: 500; cursor: pointer;
  transition: background 120ms, transform 120ms;
}
.btn-primary { background: var(--accent); color: white; border: none; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--card-soft); }
.error { color: var(--err); min-height: 1.2em; font-size: 0.85rem; margin-top: 0.75rem; }
.foot { text-align: center; color: var(--muted); font-size: 0.75rem; margin-top: 1.5rem; }

/* ---------- App Layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 2rem;
  background: var(--card);
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand-mini { display: flex; align-items: center; gap: 0.5rem; font-size: 1.1rem; }
.brand-mini .logo-mark { width: 32px; height: 32px; font-size: 1.1rem; border-radius: 8px; }
.nav-links { display: flex; gap: 1.25rem; flex: 1; }
.nav-links a { color: var(--muted); padding: 0.35rem 0.5rem; border-radius: 4px; }
.nav-links a.active, .nav-links a:hover { color: var(--text); background: var(--card-soft); }
.user-slot { font-size: 0.85rem; color: var(--muted); display: flex; gap: 0.75rem; align-items: center; }
.user-slot button { font-size: 0.8rem; }

.layout {
  display: grid; gap: 1.25rem;
  max-width: 1200px; margin: 1.5rem auto; padding: 0 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.list { display: flex; flex-direction: column; gap: 0.5rem; }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--card-soft);
  border-radius: 6px;
  font-size: 0.9rem;
}
.row:hover { background: #304057; cursor: pointer; }
.row .meta { color: var(--muted); font-size: 0.8rem; }
.row-right { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 0.5rem; }
.status-pill { font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 10px; font-weight: 500; }
.status-queued { background: #374151; color: #d1d5db; }
.status-running { background: #fef3c7; color: #92400e; }
.status-succeeded { background: #d1fae5; color: #065f46; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-cancelled { background: #e5e7eb; color: #374151; }

.output {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
  color: #d1d5db;
}

.inline-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; }

.plan { padding: 1rem; background: var(--card-soft); border-radius: 6px; margin-bottom: 1rem; }
.plan .plan-name { font-size: 1.1rem; font-weight: 600; color: var(--text); }
.plan .plan-meta { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.75rem; }
.plan-card {
  background: var(--card-soft); border: 1px solid var(--border);
  border-radius: 6px; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem;
}
.plan-card.current { border-color: var(--accent); }
.plan-card h4 { margin: 0; font-size: 1rem; }
.plan-card .price { font-size: 1.3rem; font-weight: 600; }
.plan-card ul { list-style: none; padding: 0; margin: 0; font-size: 0.8rem; color: var(--muted); }
.plan-card li { padding: 0.1rem 0; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.7);
  display: grid; place-items: center;
  z-index: 100;
}
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: min(480px, 92vw);
  box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 1rem; }
.modal form { display: flex; flex-direction: column; gap: 0.85rem; }
.modal label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.modal input, .modal select, .modal textarea {
  background: var(--card-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.5rem 0.7rem; font-size: 0.9rem; font-family: inherit;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 200; pointer-events: none;
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: slideIn 180ms ease-out;
  pointer-events: auto;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--err); }
.toast.warn { border-left: 3px solid var(--warn); }
@keyframes slideIn {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
