:root {
  --bg: #0f1420;
  --surface: #1a2130;
  --surface-2: #232c3d;
  --border: #2d374b;
  --text: #e6ebf2;
  --muted: #8a97ab;
  --primary: #3b82f6;
  --primary-hover: #2f6fe0;
  --success: #22c55e;
  --error: #ef4444;
  --running: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }

.muted { color: var(--muted); font-size: 0.875rem; }
.error { color: var(--error); font-size: 0.875rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.8rem; }

/* --- topbar --- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* --- cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* --- buttons --- */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #2b3648; border-color: #3a465c; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; }

/* --- schedule --- */
.schedule-row {
  display: flex;
  align-items: flex-end;
  gap: 1.25rem;
  flex-wrap: wrap;
}
label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}
input[type="text"], input[type="password"], select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  min-width: 180px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; }

.check-inline {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}
.check-inline input { min-width: auto; }

/* --- toggle switch --- */
.switch { flex-direction: row; align-items: center; gap: 0.6rem; cursor: pointer; }
.switch input { display: none; }
.slider {
  width: 42px; height: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  transition: background 0.15s;
}
.slider::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .slider { background: rgba(59,130,246,0.35); border-color: var(--primary); }
.switch input:checked + .slider::after { transform: translateX(18px); background: var(--primary); }
.switch-label { color: var(--text); font-size: 0.9rem; }

/* --- instances --- */
.instance {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
  background: var(--surface-2);
}
.instance-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.tag {
  font-size: 0.72rem;
  background: rgba(59,130,246,0.15);
  color: #93b4f7;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}
.db-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.4rem 1rem;
}
.db-item { padding: 0.2rem 0; }

/* --- history table --- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th { color: var(--muted); font-weight: 500; }
.status {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: capitalize;
}
.status-success { background: rgba(34,197,94,0.15); color: #4ade80; }
.status-error { background: rgba(239,68,68,0.15); color: #f87171; }
.status-running { background: rgba(245,158,11,0.15); color: #fbbf24; }
.err-detail {
  color: var(--error);
  font-size: 0.72rem;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  background: rgba(245,158,11,0.15);
  color: #fbbf24;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
}

/* --- login --- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-card label { color: var(--text); }
.login-card input { width: 100%; }
.login-card .btn { margin-top: 0.5rem; }

/* --- toast --- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 1.1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 100;
}
.toast-error { border-color: var(--error); color: #fca5a5; }
