.form-container {
  max-width: 40rem;
  margin: 0 auto;
}

.form-container--wide {
  max-width: 80rem;
}

.form-container--full {
  max-width: none;
}

.form {
  display: flex;
  flex-direction: column;
}

.form-section {
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  background-color: var(--c-base-bg);
  border: 1px solid var(--c-border);
  border-radius: 0.75rem;
  transition: all 0.2s ease;
}

.form-section--valid {
  background-color: rgba(34, 197, 94, 0.05);
  border-color: var(--c-success);
}

.form-section--invalid {
  background-color: rgba(239, 68, 68, 0.1);
  border-color: transparent;
  border-radius: 0.75rem;
  overflow: hidden;
}

.form-section__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--c-base-text);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--c-border);
}

.form-section--valid .form-section__title {
  border-bottom-color: rgba(34, 197, 94, 0.3);
}

.form-section--invalid .form-section__title {
  border-bottom-color: rgba(239, 68, 68, 0.3);
}

.form-section__error {
  display: none;
}

.form-section--invalid .form-section__error {
  display: block;
  margin: 1.5rem -1.5rem -1.5rem -1.5rem;
  padding: 0;
  background-color: var(--c-error);
}

.form-section__error-line {
  display: block;
  padding: 0.35rem 1.5rem;
  color: white;
  font-size: 0.8125rem;
  font-weight: 500;
}

.form-section__error-line:first-child {
  padding-top: 0.5rem;
}

.form-section__error-line:last-child {
  padding-bottom: 0.5rem;
}

.form-divider {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 1.5rem 0;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.form-actions--spread {
  justify-content: space-between;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.page-header-actions {
  display: flex;
  gap: 0.75rem;
}

.page-subtitle {
  color: var(--c-base-subtitle-text);
  margin-top: 0.25rem;
}

.schedule-config {
  margin-top: 1.5rem;
  padding: 1.5rem;
  background-color: var(--c-border);
  border-radius: 0.5rem;
}

/* Auth-method groups (clinic settings, invite form). Staff and patients are configured
   separately, so each list is its own labelled block, set on a subtle surface to read
   as one decision rather than as loose checkboxes among the other fields. */
.auth-group {
  margin-top: 1rem;
  padding: 0.875rem 1rem;
  background-color: var(--c-surface-subtle);
  border: 1px solid var(--c-border);
  border-radius: 0.5rem;
}

.auth-group__hint {
  margin: 0 0 0.5rem;
  color: var(--c-base-subtitle-text);
  font-size: 13px;
}

.auth-group__option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 14px;
}

/* Hidden by the invite form's Stimulus controller when the chosen role cannot use the
   method — kept in the DOM so switching role back restores the previous ticks. */
.auth-group__option[hidden] {
  display: none;
}

/* Configuration that belongs to one sign-in method, shown only when it is enabled.
   Sits on the same surface as the groups it follows from. */
.auth-method-config {
  margin-top: 0.75rem;
  padding: 0.875rem 1rem;
  background-color: var(--c-surface-subtle);
  border: 1px solid var(--c-border);
  border-radius: 0.5rem;
}

/* `hidden` alone would be overridden by the padding/display rules above. */
.auth-method-config[hidden] {
  display: none;
}

/* A sign-in group with nothing chosen. Marked rather than submitted, because the
   server answers a validation failure with a redirect, which would close the modal
   and lose everything typed. */
.auth-group--error {
  border-color: var(--c-error);
}

.auth-group__error {
  margin: 0 0 0.5rem;
  color: var(--c-error);
  font-size: 13px;
}

.auth-group__error[hidden] {
  display: none;
}

/* "Test connection" on the clinic form's Entra block. The result sits under the button
   rather than in a toast: it answers a question about the fields directly above it, and
   a toast would slide away while they are still being corrected. */
.entra-check__status {
  margin: 0.5rem 0 0;
  font-size: 13px;
  color: var(--c-base-subtitle-text);
}

.entra-check__status.entra-check--ok {
  color: var(--c-success);
}

.entra-check__status.entra-check--error {
  color: var(--c-error);
}

/* Clinic form with the Entra guide beside it. The guide is a second column only while
   it is revealed (same toggle as the Entra config block); otherwise the form is the
   single column it always was, so the popup stays its normal width visually. */
.clinic-form:has(.entra-guide:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 20rem);
  gap: 1.5rem;
  align-items: start;
}

.clinic-form__fields {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* The edit page's container is capped for a lone form; with the guide it needs room
   but not the whole screen. */
.clinic-form-container {
  max-width: 64rem;
}

@media (max-width: 56rem) {
  .clinic-form:has(.entra-guide:not([hidden])) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.entra-guide {
  position: sticky;
  top: 1rem;
  padding: 1rem 1.125rem;
  background-color: var(--c-surface-subtle);
  border: 1px solid var(--c-border);
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--c-base-text);
}

.entra-guide[hidden] {
  display: none;
}

.entra-guide__title {
  margin: 0 0 0.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

.entra-guide__intro {
  margin: 0 0 0.75rem;
  color: var(--c-base-subtitle-text);
}

.entra-guide__steps {
  margin: 0;
  padding-left: 1.25rem;
}

.entra-guide__steps li {
  margin-bottom: 0.625rem;
}

.entra-guide__steps li::marker {
  font-weight: 600;
  color: var(--c-brand);
}

/* The redirect URI: shown whole, wrapping rather than scrolling, with a copy button. */
.entra-guide__uri {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-top: 0.375rem;
  padding: 0.5rem 0.625rem;
  background-color: var(--c-popup-bg);
  border: 1px solid var(--c-border);
  border-radius: 0.375rem;
}

.entra-guide__uri code {
  font-size: 0.75rem;
  word-break: break-all;
}

.entra-guide__copy {
  align-self: flex-start;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
}

.entra-guide__pending {
  display: block;
  margin-top: 0.25rem;
  color: var(--c-base-subtitle-text);
  font-style: italic;
}

/* Where a guide step happens, and by whom. */
.entra-guide__where {
  display: block;
  margin-bottom: 0.125rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--c-base-subtitle-text);
}

.entra-guide__where--ava {
  color: var(--c-brand);
}

/* Side-by-side fields; stacks on narrow screens */
.form-grid {
  display: grid;
  gap: 1rem;
}

.form-grid--2 {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 600px) {
  .form-grid--2 {
    grid-template-columns: 1fr;
  }
}
