:root {
  --bg: #0d0d10;
  --bg-elevated: #17171b;
  --bg-elevated-2: #1f1f24;
  --bg-hover: #232329;
  --border: #2a2a30;
  --border-hover: #3a3a42;
  --text: #f2f2f4;
  --text-muted: #9a9aa4;
  --text-faint: #6c6c76;
  --accent: #6366f1;
  --accent-hover: #7678f7;
  --accent-text: #ffffff;
  --danger: #f85149;
  --danger-hover: #ff6a63;
  --success: #3fb950;
  --radius-lg: 12px;
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  line-height: 1.5;
}

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

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }

/* ---- top bar ---- */

header.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
header.topbar h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; }
header.topbar .actions { display: flex; align-items: center; gap: 8px; }

/* ---- buttons ---- */

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  border: 1px solid transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
button:disabled { cursor: default; opacity: 0.5; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-elevated-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated-2); color: var(--text); }

.btn-danger-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-danger-ghost:hover:not(:disabled) { background: rgba(248, 81, 73, 0.12); color: var(--danger-hover); border-color: rgba(248, 81, 73, 0.4); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---- profile cards ---- */

.profile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 12px;
  transition: border-color 0.12s ease;
}
.profile:hover { border-color: var(--border-hover); }
.profile .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.profile h3 { margin: 0; font-size: 15px; font-weight: 600; }
.profile .meta { color: var(--text-muted); font-size: 13px; margin: 4px 0 0; font-family: ui-monospace, monospace; }
.profile .actions { display: flex; gap: 6px; flex-shrink: 0; }
.status { margin-top: 10px; font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; color: var(--text-muted); }
.status.running { color: var(--text-muted); }
.status.succeeded { color: var(--success); }
.status.failed { color: var(--danger); }

#empty-state { color: var(--text-faint); border: 1px dashed var(--border); border-radius: var(--radius-lg); padding: 32px; text-align: center; }

/* ---- dialog ---- */

dialog {
  position: relative;
  background: var(--bg-elevated);
  color: var(--text);
  width: 640px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 24px 28px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 16px; padding-right: 32px; font-size: 17px; }

.dialog-close {
  position: absolute; top: 16px; right: 16px; width: 30px; height: 30px;
  padding: 0; line-height: 1; font-size: 18px; border-radius: 999px;
  background: transparent; color: var(--text-muted); border: 1px solid transparent;
}
.dialog-close:hover { background: var(--bg-elevated-2); color: var(--text); }

dialog form { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; align-items: start; }
.field { display: flex; flex-direction: column; margin-top: 10px; min-width: 0; }
.field-full { grid-column: 1 / -1; }

dialog label {
  font-size: 12px; font-weight: 600; margin-bottom: 6px;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em;
}
dialog input, dialog select, dialog textarea {
  padding: 8px 10px; font-size: 13px; width: 100%; box-sizing: border-box;
  font-family: inherit; background: var(--bg-elevated-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
dialog input::placeholder, dialog textarea::placeholder { color: var(--text-faint); }
dialog input:focus, dialog select:focus, dialog textarea:focus {
  outline: none; border-color: var(--accent);
}
dialog input[type="checkbox"] { width: auto; }
dialog textarea { font-family: ui-monospace, monospace; min-height: 56px; }
dialog input[type="file"] {
  padding: 8px 10px; background: var(--bg-elevated-2); cursor: pointer;
}
dialog input[type="file"]::file-selector-button {
  font-family: inherit; font-size: 12px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-hover); color: var(--text); padding: 5px 10px; margin-right: 10px;
}

.hint { color: var(--text-faint); font-size: 12px; margin: 6px 0 0; text-transform: none; letter-spacing: normal; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-error {
  color: var(--danger); font-size: 13px; background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3); border-radius: var(--radius-sm); padding: 8px 12px;
}

/* ---- toggle switch (checkboxes styled as switches) ---- */

.toggle-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.toggle-row label { margin-bottom: 0; text-transform: none; font-weight: 500; color: var(--text); font-size: 13px; }
.toggle {
  position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0;
}
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle .track {
  position: absolute; inset: 0; background: var(--border-hover); border-radius: 999px;
  transition: background-color 0.15s ease;
}
.toggle .thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform 0.15s ease;
}
.toggle input:checked ~ .track { background: var(--accent); }
.toggle input:checked ~ .thumb { transform: translateX(16px); }
.toggle input:focus-visible ~ .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- fieldset groups ---- */

fieldset {
  border: 1px solid var(--border); border-radius: var(--radius); margin-top: 10px;
  padding: 4px 12px 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px;
}
legend { font-size: 11px; color: var(--text-faint); padding: 0 6px; text-transform: uppercase; letter-spacing: 0.03em; }

.hidden { display: none !important; }

/* ---- login page ---- */

body.login-body {
  max-width: none; display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 32px; width: 320px; max-width: 100%;
}
.login-card h1 { font-size: 18px; margin: 0 0 20px; text-align: center; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card input {
  padding: 9px 12px; font-size: 14px; background: var(--bg-elevated-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card input::placeholder { color: var(--text-faint); }
.login-card button { margin-top: 4px; padding: 10px; }
.login-card .error {
  color: var(--danger); font-size: 13px; background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3); border-radius: var(--radius-sm); padding: 8px 12px;
  margin: 0 0 14px;
}
