/*
 * Reset, typography and form basics for Helder Werkblad.
 * Everything reads from the semantic token layer.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  /* The parts we did not draw still carry the design. */
  accent-color: var(--primary);
  caret-color: var(--primary);
  scrollbar-color: var(--grey-300) var(--surface-desk);
  scrollbar-width: thin;
}

body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd,
ul,
ol {
  margin: 0;
  padding: 0;
}

/* The browser's default fieldset frame belongs to no design system. */
fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

ul,
ol {
  list-style: none;
}

body {
  min-height: 100vh;
  background: var(--surface-desk);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--blue-100);
  color: var(--ink);
}

img,
picture,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* ============================================================
   Type. One family; weight and size carry the hierarchy.
   ============================================================ */

h1,
h2,
h3,
h4 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--track-display);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-xl);
}

h2 {
  font-size: var(--text-lg);
}

h3 {
  font-size: var(--text-md);
}

h4 {
  font-size: var(--text-base);
}

p {
  max-width: var(--prose-max);
  line-height: var(--leading-prose);
}

strong {
  font-weight: var(--weight-semibold);
}

a {
  color: var(--primary-ink);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

/* A small label that names a figure or a value. Sentence case, muted. */
.legend {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
}

.narrow {
  font-stretch: var(--wd-narrow);
}

/* ============================================================
   Focus. One blue ring, never removed.
   Somebody works four hundred rows from the keyboard.
   ============================================================ */

:focus-visible {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: var(--focus-offset);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================================
   Forms. Boxed fields on white with a hairline edge; the focus
   ring is the blue, drawn as a soft halo around the box.
   ============================================================ */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-faint);
  line-height: var(--leading-normal);
  max-width: var(--prose-max);
}

.field__error {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--danger);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 2.375rem;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-field);
  border: var(--width-hair) solid var(--rule-hair);
  border-radius: var(--radius);
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--rule-mid);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--ring);
  outline: none;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgb(220 38 38 / 0.12);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--grey-500);
}

.input[type="file"] {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  cursor: pointer;
}

.input[type="file"]::file-selector-button {
  margin-right: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-soft-button);
  color: var(--text);
  font: inherit;
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}

.input[type="file"]::file-selector-button:hover {
  background: var(--surface-soft-button-hover);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  color: var(--text-faint);
  border-color: var(--rule-hair);
  background: var(--surface-inset);
  cursor: not-allowed;
}

.checkbox:disabled,
.checkbox-label:has(:disabled) {
  cursor: not-allowed;
  opacity: 0.55;
}

.textarea {
  min-height: 9rem;
  line-height: var(--leading-prose);
  resize: vertical;
  padding: var(--space-3);
}

.select {
  appearance: none;
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235b6370' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-position: right var(--space-3) center;
  background-size: 14px 14px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.checkbox {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
  flex: none;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  max-width: var(--prose-max);
}

.checkbox-label span {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

legend {
  padding: 0;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
}

input[type="range"] {
  accent-color: var(--primary);
  width: 100%;
  height: 1.25rem;
}

/* ============================================================
   Utilities. A handful. Anything used often becomes a component.
   ============================================================ */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--text-muted);
}

.faint {
  color: var(--text-faint);
}

.small {
  font-size: var(--text-sm);
}

.tiny {
  font-size: var(--text-xs);
}

.prose {
  font-size: var(--text-md);
  line-height: var(--leading-prose);
  max-width: var(--prose-max);
}

.nowrap {
  white-space: nowrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* For two things in one section that are different kinds: a list, and the form that adds to it. */
.stack-lg {
  display: flex;
  flex-direction: column;
  gap: var(--space-9);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
}

.wrap {
  flex-wrap: wrap;
}

.grow {
  flex: 1;
  min-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
