:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #182b49;
  background: #f4f7fb;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-weight: 400;
}

* { box-sizing: border-box; }
body { min-width: 320px; min-height: 100vh; margin: 0; }
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; }
.topbar {
  min-height: 72px;
  padding: 0 clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #fff;
  border-bottom: 1px solid #e6ebf2;
}
.brand { display: inline-flex; align-items: center; gap: 11px; font-size: 15px; font-weight: 750; letter-spacing: -0.02em; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #1d4ed8;
  color: #fff;
  font-size: 12px;
  letter-spacing: -0.04em;
}
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.topbar-actions form { margin: 0; }
.nav-link { color: #405675; font-size: 13px; font-weight: 650; }
.nav-link:hover, .nav-link-active { color: #245bd6; }
.user-label { display: inline-flex; align-items: center; gap: 8px; color: #63718a; font-size: 13px; }
.user-dot { width: 7px; height: 7px; border-radius: 50%; background: #16a36a; }

.page-content { width: min(100% - 40px, 720px); margin: 0 auto; padding: 64px 0 72px; }
.page-heading { margin-bottom: 28px; }
.eyebrow { margin: 0 0 10px; color: #315fc4; font-size: 11px; font-weight: 750; letter-spacing: 0.11em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(29px, 5vw, 38px); letter-spacing: -0.045em; line-height: 1.12; }
.muted { color: #66758d; line-height: 1.55; }
.page-heading .muted { margin-bottom: 0; font-size: 15px; }

.form-card, .auth-card {
  background: #fff;
  border: 1px solid #e3e9f1;
  border-radius: 16px;
  box-shadow: 0 14px 34px rgb(21 41 73 / 5%);
}
.form-card { padding: clamp(22px, 4vw, 34px); }
.card-heading { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 30px; }
.section-icon {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: #eef3ff;
  color: #315fc4;
  font-size: 12px;
  font-weight: 750;
}
.card-heading h2 { margin: 2px 0 5px; font-size: 17px; letter-spacing: -0.02em; }
.card-heading p { margin-bottom: 0; font-size: 13px; }
.field { margin-bottom: 25px; }
.field > label:first-child, .stack-form > label {
  display: block;
  margin-bottom: 9px;
  color: #293c59;
  font-size: 13px;
  font-weight: 650;
}
select, .stack-form input {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid #d6deea;
  border-radius: 9px;
  background: #fff;
  color: #243752;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.text-input, .file-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid #d6deea;
  border-radius: 9px;
  background: #fff;
  color: #243752;
  outline: none;
}
.text-input:focus, .file-input:focus {
  border-color: #4776df;
  box-shadow: 0 0 0 3px rgb(71 118 223 / 14%);
}
.file-input { padding: 8px; color: #62728a; font-size: 13px; }
.file-input::file-selector-button {
  min-height: 28px;
  margin-right: 10px;
  padding: 0 10px;
  border: 1px solid #d6deea;
  border-radius: 6px;
  background: #f7f9fc;
  color: #3e526f;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.field-hint { margin: 8px 0 0; color: #7a879b; font-size: 12px; line-height: 1.5; }
.field-hint code, .study-info code { color: #536986; font-size: 0.95em; }
select:focus, .stack-form input:focus {
  border-color: #4776df;
  box-shadow: 0 0 0 3px rgb(71 118 223 / 14%);
}

.upload-area {
  min-height: 176px;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px dashed #b8c6da;
  border-radius: 11px;
  background: #fafcff;
  cursor: pointer;
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease;
}
.upload-area:hover, .upload-area:focus-within { border-color: #4776df; background: #f6f9ff; }
.upload-icon {
  width: 36px;
  height: 36px;
  margin-bottom: 10px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #edf3ff;
  color: #315fc4;
  font-size: 22px;
  font-weight: 500;
}
.upload-title { color: #2b4263; font-size: 13px; font-weight: 650; }
.upload-help { margin-top: 6px; color: #7a879b; font-size: 12px; }
.file-name { max-width: 100%; margin-top: 8px; overflow-wrap: anywhere; color: #315fc4; font-size: 12px; font-weight: 650; }
.upload-area input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

.value-format { min-width: 0; padding: 0; border: 0; }
.value-format legend {
  margin-bottom: 9px;
  color: #293c59;
  font-size: 13px;
  font-weight: 650;
}
.option-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 10px;
  color: #41536d;
  font-size: 13px;
  cursor: pointer;
}
.option-row input { width: 16px; height: 16px; margin: 0; accent-color: #245bd6; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 5px; }
.button {
  min-height: 42px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.button:active { transform: translateY(1px); }
.button-primary { background: #245bd6; color: #fff; }
.button-primary:hover { background: #194bbd; }
.button-primary:disabled { cursor: not-allowed; opacity: 0.5; transform: none; }
.button:disabled { cursor: wait; opacity: 0.65; }
.button-secondary { border-color: #d6deea; background: #fff; color: #41536d; }
.button-secondary:hover, .button-subtle:hover { background: #f5f7fb; }
.button-subtle { min-height: 36px; padding: 0 12px; background: transparent; color: #53647c; }
.button-full { width: 100%; margin-top: 7px; }
.processing-note { margin: 15px 3px 0; color: #8390a3; font-size: 12px; }
.process-status { min-height: 0; margin: 0; color: #53647c; font-size: 13px; line-height: 1.5; }
.process-status:not(:empty) { margin: 0 0 16px; }
.process-status[data-state="error"] { color: #a3342c; }
.process-status[data-state="success"] { color: #176b3a; }

.auth-layout { min-height: 100vh; padding: 24px; display: grid; place-items: center; }
.auth-card { width: min(100%, 430px); padding: 34px; }
.auth-heading { margin: 38px 0 25px; }
.auth-heading h1 { font-size: 30px; }
.auth-heading .muted { margin-bottom: 0; font-size: 14px; }
.stack-form { display: grid; grid-template-columns: 1fr; }
.stack-form > label { margin-bottom: 8px; }
.stack-form input { margin-bottom: 18px; }
.auth-footnote { margin: 20px 0 0; color: #8390a3; font-size: 12px; text-align: center; }

.flash-list { margin: 0 0 18px; }
.flash { margin: 0; padding: 12px 14px; border-radius: 9px; font-size: 13px; line-height: 1.5; }
.flash-error { background: #fff0ef; color: #a3342c; }
.flash-info { background: #edf4ff; color: #2855a5; }

.config-card { margin-bottom: 38px; }
.study-list-section { margin-top: 38px; }
.list-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.list-heading h2 { margin: 0 0 5px; font-size: 18px; letter-spacing: -0.02em; }
.list-heading p { margin: 0; font-size: 13px; }
.count-badge { flex: none; padding: 6px 10px; border-radius: 999px; background: #eaf0ff; color: #315fc4; font-size: 11px; font-weight: 700; }
.study-list { overflow: hidden; border: 1px solid #e3e9f1; border-radius: 13px; background: #fff; }
.study-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 22px; }
.study-row + .study-row { border-top: 1px solid #edf0f5; }
.study-info { min-width: 0; }
.study-info h3 { margin: 0 0 5px; font-size: 14px; }
.study-info p { margin: 0 0 7px; color: #77869c; font-size: 12px; line-height: 1.5; }
.download-link { color: #315fc4; font-size: 12px; font-weight: 650; }
.download-link:hover { text-decoration: underline; }
.replace-form {
  flex: none;
  width: min(100%, 430px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.replace-form input[type="file"] { max-width: 250px; color: #697991; font-size: 11px; }
.replace-form .button { white-space: nowrap; }
.replace-form .field-hint { grid-column: 1 / -1; margin: 0; }
.definition-names { overflow-wrap: anywhere; }
.mapping-warning {
  margin: 8px 0;
  padding: 9px 11px;
  border-left: 3px solid #e0a02a;
  border-radius: 5px;
  background: #fff8e8;
  color: #765116;
  font-size: 12px;
  line-height: 1.5;
}
.empty-state { padding: 32px 20px; border: 1px dashed #c8d3e2; border-radius: 13px; background: #fafcff; text-align: center; }
.empty-icon { width: 34px; height: 34px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 10px; background: #edf3ff; color: #315fc4; font-size: 22px; }
.empty-state h3 { margin: 0 0 6px; font-size: 14px; }
.empty-state p { margin: 0; font-size: 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.account-invite-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.account-invite-form .form-actions { grid-column: 1 / -1; }
.account-list { display: grid; }
.account-row { padding: 20px 22px; }
.account-row + .account-row { border-top: 1px solid #edf0f5; }
.account-identity { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; color: #293c59; font-size: 13px; }
.account-state { color: #77869c; font-size: 12px; }
.account-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 12px; }
.account-fields .field { min-width: 0; margin-bottom: 12px; }
.account-fields .field > label { display: block; margin-bottom: 7px; color: #293c59; font-size: 12px; font-weight: 650; }
.account-fields select { width: 100%; min-height: 42px; padding: 0 9px; border: 1px solid #d6deea; border-radius: 9px; background: #fff; color: #243752; font-size: 12px; }
.account-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.resend-invite-form { margin-top: 6px; text-align: right; }
.totp-enrollment { margin: 0 0 22px; text-align: center; }
.totp-enrollment img { display: block; max-width: 100%; height: auto; margin: 0 auto 10px; border: 1px solid #e3e9f1; border-radius: 8px; }
.totp-enrollment code { overflow-wrap: anywhere; }
.email-preview-row { padding: 20px 22px; }
.email-preview-row + .email-preview-row { border-top: 1px solid #edf0f5; }
.email-preview-row p { margin-bottom: 6px; color: #53647c; font-size: 13px; }
.email-preview-row pre { margin: 14px 0 0; padding: 14px; overflow-wrap: anywhere; white-space: pre-wrap; border-radius: 8px; background: #f7f9fc; color: #293c59; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 600px) {
  .topbar { min-height: 64px; padding: 0 18px; }
  .brand { font-size: 13px; }
  .topbar-actions { gap: 5px; }
  .nav-link { font-size: 12px; }
  .user-label { display: none; }
  .page-content { width: calc(100% - 32px); padding-top: 40px; }
  .form-card { padding: 22px 18px; }
  .card-heading { gap: 11px; margin-bottom: 25px; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .study-row { align-items: stretch; flex-direction: column; gap: 14px; padding: 18px; }
  .replace-form { width: 100%; grid-template-columns: minmax(0, 1fr); }
  .replace-form input[type="file"] { max-width: none; }
  .replace-form .button { width: 100%; }
  .auth-card { padding: 26px 22px; }
  .account-invite-form, .account-fields { grid-template-columns: minmax(0, 1fr); }
  .account-invite-form .form-actions { grid-column: auto; }
  .account-actions { align-items: stretch; flex-direction: column; }
  .account-actions .button { width: 100%; }
}
