/* =========================================================================
   Component — the four view states
   -------------------------------------------------------------------------
   Every view that fetches renders ALL FOUR: loading, empty, error, forbidden.
   (The sign-in form is not such a view — see FRONTEND_STRUCTURE.md.) A 403 is
   shown AS a 403 — never as an empty list, because "no permission" and "no
   data" look identical once they collapse into the same empty state, and the
   permission bug then hides forever.
   ========================================================================= */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 24px;
  text-align: center;
  border: 1px solid var(--doc-line);
  border-radius: var(--radius-lg);
  background: var(--doc-panel);
}

.state-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.state-detail {
  margin: 0;
  font-size: 14px;
  color: var(--doc-ink-soft);
}

.state-code {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--doc-ink-soft);
  word-break: break-all;
}

.state-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
}

.state-error {
  border-color: var(--sd-error-bd);
  background: var(--sd-error-bg);
}

.state-forbidden {
  border-color: var(--sd-warning-bd);
  background: var(--sd-warning-bg);
}

/* --- Loading: a spinner plus a live-region label ------------------------- */

.state-loading .spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--sd-border);
  border-top-color: var(--sd-secondary);
  border-radius: 50%;
  animation: sd-spin .8s linear infinite;
}

@keyframes sd-spin {
  to { transform: rotate(360deg); }
}

/* --- Busy: a write still running after a moment (U-2205) --------------- */

/* The layer lies over the form, or over the open dialog the form is in. A modal
   dialog is already positioned; giving it `relative` would pull it out of the
   top layer's centring. */
.busy-host:not(dialog) {
  position: relative;
}

.busy-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: inherit;
  background: color-mix(in srgb, var(--doc-panel) 70%, transparent);
  cursor: progress;
}

/* In a lightbox the layer covers the part in view, not the top of a dialog
   scrolled down (U-2226): `busy-layer.js` sets the scroll offset and the
   visible height, and the dialog holds still while it is held. */
dialog.busy-host {
  overflow: hidden;
}

dialog.busy-host > .busy-layer {
  inset: auto 0;
  top: var(--busy-top, 0);
  height: var(--busy-height, 100%);
}

.busy-layer .spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--sd-border);
  border-top-color: var(--sd-secondary);
  border-radius: 50%;
  animation: sd-spin .8s linear infinite;
}

.busy-layer-label {
  font-size: 13px;
  color: var(--doc-ink-soft);
}

/* The submitter of a locked form: it looks pressed, and a second press is
   refused in `busy-layer.js`, not by `disabled`, which the form's own handler
   owns. */
[aria-disabled="true"].is-busy {
  opacity: .6;
  cursor: progress;
}

@media (prefers-reduced-motion: reduce) {
  .state-loading .spinner,
  .busy-layer .spinner {
    animation: none;
    border-top-color: var(--sd-border);
  }
}

/* --- Skeleton rows for a list that is loading ---------------------------- */

/* A skeleton is the ABSENCE of a row. It has to sit below the surface it will
   be filled on, in both themes -- on --sd-surface-alt it was a bright bar on
   the panel in dark mode, which reads as content having arrived. */
.skeleton {
  height: 14px;
  border-radius: var(--radius);
  background: var(--sd-sunk);
}
