:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dde1e7;
  --primary: #3b5bdb;
  --primary-text: #ffffff;
  --primary-hover: #2f4ac0;
  --disabled-bg: #e9ecef;
  --disabled-text: #8a94a3;
  --ok: #1f8a4c;      --ok-bg: #e6f4ec;
  --info: #2f5fb3;    --info-bg: #e8effb;
  --warn: #9a6200;    --warn-bg: #fdf3e1;
  --error: #c0362c;   --error-bg: #fbeae8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --text: #e7eaee;
    --muted: #9aa4b2;
    --border: #2c323b;
    --primary: #6d8cff;
    --primary-text: #0d1020;
    --primary-hover: #8aa2ff;
    --disabled-bg: #242a32;
    --disabled-text: #6b7480;
    --ok: #5cc98a;      --ok-bg: #16281e;
    --info: #7fa6f0;    --info-bg: #172235;
    --warn: #e0a84a;    --warn-bg: #2b2213;
    --error: #f07a70;   --error-bg: #2e1816;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.centered { display: grid; place-items: center; min-height: 100vh; padding: 16px; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
pre {
  white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; margin: 8px 0 0; max-height: 420px; overflow: auto;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.muted { color: var(--muted); }

/* layout */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.who { display: flex; gap: 14px; align-items: center; color: var(--muted); flex-wrap: wrap; }
.container { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.auth-card { width: 100%; max-width: 400px; margin-left: auto; margin-right: auto; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field span { font-size: .875rem; font-weight: 600; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; margin-top: 12px; }
.profile-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 12px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
form.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
form.inline label { display: inline-flex; align-items: center; gap: 8px; }
form.inline select { width: auto; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 20px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--primary); color: var(--primary-text);
  transition: background .15s;
}
.btn:hover:not(:disabled) { background: var(--primary-hover); }
.btn:disabled { background: var(--disabled-bg); color: var(--disabled-text); cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: transparent; color: var(--error); border-color: var(--error); }
.btn-danger:hover:not(:disabled) { background: var(--error-bg); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; text-decoration: underline; }

/* banners & badges */
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.banner.ok    { background: var(--ok-bg);    color: var(--ok);    border-color: currentColor; }
.banner.info  { background: var(--info-bg);  color: var(--info);  border-color: currentColor; }
.banner.error { background: var(--error-bg); color: var(--error); border-color: currentColor; }

.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; white-space: nowrap;
  padding: 2px 9px; border-radius: 999px; background: var(--disabled-bg); color: var(--muted);
}
[data-state="done"]  > .step-head .badge, .badge[data-state="done"]    { background: var(--ok-bg);    color: var(--ok); }
[data-state="ready"] > .step-head .badge, .badge[data-state="ready"]   { background: var(--info-bg);  color: var(--info); }
[data-state="running"] > .step-head .badge, .badge[data-state="running"] { background: var(--warn-bg); color: var(--warn); }
[data-state="failed"] > .step-head .badge, .badge[data-state="failed"]  { background: var(--error-bg); color: var(--error); }
.badge[data-state="needs_profile"] { background: var(--warn-bg); color: var(--warn); }

/* profile section */
details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; }
details > summary::-webkit-details-marker { display: none; }
#profile-details > summary h2 { margin: 0; }
#profile-details > summary::after { content: "▾"; color: var(--muted); margin-left: auto; transition: transform .15s; }
#profile-details:not([open]) > summary::after { transform: rotate(-90deg); }

/* the three steps */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 12px; }
.step {
  display: flex; flex-direction: column; gap: 10px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  transition: border-color .2s, opacity .2s;
}
.step p { margin: 0; flex: 1; }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-head h3 { margin: 0; flex: 1; }
.step-num {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: .875rem; background: var(--disabled-bg); color: var(--muted);
}
.step[data-state="ready"], .step[data-state="failed"] { border-color: var(--primary); }
.step[data-state="ready"] .step-num, .step[data-state="running"] .step-num { background: var(--primary); color: var(--primary-text); }
.step[data-state="done"] .step-num { background: var(--ok); color: var(--surface); }
.step[data-state="locked"], .step[data-state="needs_profile"] { opacity: .65; }
.step[data-state="running"] .btn::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite;
}
.step-error { color: var(--error); font-size: .875rem; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* results */
.result { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-top: 10px; }
.result > summary { font-weight: 600; }

/* admin */
.credentials { border-color: var(--ok); }
.credentials dl, .profile-view { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; }
.credentials dt, .profile-view dt { font-weight: 600; color: var(--muted); }
.credentials dd, .profile-view dd { margin: 0; word-break: break-word; }
.credentials code { font-size: 1rem; user-select: all; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table pre { max-height: 240px; }

@media (max-width: 760px) {
  .steps, .profile-grid { grid-template-columns: 1fr; }
  .inline-form { flex-direction: column; }
  .credentials dl, .profile-view { grid-template-columns: 1fr; }
}

/* ================================================================ login page (always dark) */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

body.login-page {
  --l-bg: #050505;
  --l-panel: #0a0a0a;
  --l-line: rgba(255, 255, 255, .08);
  --l-text: #f4f4f4;
  --l-muted: #a3a3a3;
  --l-faint: #6e6e6e;
  --l-field: #141414;
  --l-field-line: rgba(255, 255, 255, .16);
  background: var(--l-bg);
  color: var(--l-text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  color-scheme: dark;
}

.login-shell {
  display: flex;
  min-height: 100vh;
  background: var(--l-panel);
}
@media (min-width: 900px) {
  body.login-page { padding: 24px; background: #1c1c1c; }
  .login-shell {
    min-height: calc(100vh - 48px);
    border-radius: 18px;
    border: 1px solid var(--l-line);
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  }
}

/* slim left rail */
.login-rail {
  width: 76px;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
  border-right: 1px solid var(--l-line);
  background: linear-gradient(180deg, #0d0d0d, #070707);
}
.login-logo { width: 30px; height: 30px; color: var(--l-text); }
.login-rail-avatar {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #262626, #161616);
  border: 1px solid var(--l-line);
  color: #d4d4d4;
}
.login-rail-avatar svg { width: 20px; height: 20px; }

/* stage with spotlight */
.login-stage {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 48px 16px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 45% at 50% 32%, rgba(255, 255, 255, .07), transparent 70%),
    radial-gradient(ellipse 40% 60% at 8% 50%, rgba(255, 255, 255, .025), transparent 70%),
    var(--l-panel);
}
.login-beam {
  position: absolute;
  top: -6%;
  left: 50%;
  width: 180px;
  height: 58%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse 50% 100% at 50% 0%, rgba(255, 255, 255, .55), rgba(255, 255, 255, .12) 45%, transparent 75%);
  filter: blur(26px);
  opacity: .85;
  pointer-events: none;
  animation: beam 7s ease-in-out infinite alternate;
}
.login-beam::after {
  content: "";
  position: absolute;
  left: 50%; top: 0;
  width: 26px; height: 85%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(255, 255, 255, .7), transparent);
  filter: blur(10px);
}
@keyframes beam { from { opacity: .7; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .login-beam { animation: none; } }

.login-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  text-align: center;
  margin-top: 6vh;
}
.login-content h1 {
  font-family: "Inter Tight", Inter, system-ui, sans-serif;
  font-weight: 500;
  font-size: clamp(1.75rem, 3.6vw, 2.6rem);
  line-height: 1.22;
  letter-spacing: -0.025em;
  margin: 0 0 14px;
  color: #fff;
  text-shadow: 0 2px 30px rgba(0, 0, 0, .6);
}
.login-sub {
  margin: 0 0 40px;
  color: var(--l-muted);
  font-size: 1rem;
}

.login-error {
  margin: -16px 0 20px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(240, 90, 80, .1);
  border: 1px solid rgba(240, 90, 80, .35);
  color: #ff9d94;
  font-size: .9rem;
}

.login-form { display: flex; flex-direction: column; gap: 14px; }

.login-input {
  position: relative;
  display: flex;
  align-items: center;
  height: 56px;
  border-radius: 10px;
  background: var(--l-field);
  border: 1px solid var(--l-field-line);
  transition: border-color .15s, box-shadow .15s;
}
.login-input:focus-within {
  border-color: rgba(255, 255, 255, .45);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .06);
}
.login-input > svg { width: 22px; height: 22px; margin-left: 16px; flex: none; color: #bdbdbd; }
.login-input input {
  flex: 1;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--l-text);
  font: inherit;
  font-size: .95rem;
  padding: 0 14px 0 12px;
  border-radius: 10px;
}
.login-input input::placeholder { color: var(--l-faint); }
.login-input input:-webkit-autofill {
  -webkit-text-fill-color: var(--l-text);
  -webkit-box-shadow: 0 0 0 100px var(--l-field) inset;
  caret-color: var(--l-text);
}
.login-reveal {
  flex: none;
  width: 44px; height: 44px; margin-right: 6px;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 8px;
  color: var(--l-faint); cursor: pointer;
}
.login-reveal:hover, .login-reveal.is-on { color: var(--l-text); }
.login-reveal svg { width: 20px; height: 20px; }

.login-submit {
  height: 56px;
  margin-top: 6px;
  border-radius: 10px;
  border: 1px solid var(--l-line);
  background: #161616;
  color: #8c8c8c;
  font: inherit;
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
  transition: background .2s, color .2s, box-shadow .2s, transform .1s;
}
.login-submit.is-ready {
  background: #fff;
  color: #0a0a0a;
  border-color: #fff;
  box-shadow: 0 8px 30px rgba(255, 255, 255, .12);
}
.login-submit.is-ready:hover { background: #e9e9e9; }
.login-submit:active { transform: translateY(1px); }
.login-submit:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.login-submit { display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.login-submit.is-loading { cursor: progress; pointer-events: none; }
.login-submit.is-loading::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite;
}
.login-content { animation: login-in .5s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes login-in { from { opacity: 0; transform: translateY(12px); } }
.login-error { animation: login-shake .4s ease; }
@keyframes login-shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.login-reveal { transition: color .15s; }
@media (prefers-reduced-motion: reduce) {
  .login-content, .login-error, .login-submit.is-loading::before { animation: none; }
}

@media (max-width: 640px) {
  .login-rail { display: none; }
  .login-content h1 br { display: none; }
  .login-content { margin-top: 0; }
}
