/*
 * Netzmal Designsystem: Formulare
 * -------------------------------
 * Raster, Felder, Tooltips, Checkboxen, Radios und Apple-Schalter.
 * Native readonly- und disabled-Zustände werden sichtbar unterschieden.
 */

/* Formular- und Feldraster */
.nm-form {
    display: grid;
    gap: 22px;
}

.nm-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.nm-field {
    display: grid;
    gap: 8px;
}

.nm-field label,
.nm-field legend {
    color: var(--nm-color-text);
    font-weight: 700;
}

.nm-field input,
.nm-field select,
.nm-field textarea {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--nm-color-line);
    border-radius: var(--nm-radius);
    background: var(--nm-color-page);
    color: var(--nm-color-text);
    font: inherit;
}

.nm-field input[readonly],
.nm-field textarea[readonly] {
    border-color: var(--nm-color-line);
    background: var(--nm-color-surface);
    color: var(--nm-color-text-muted);
}

.nm-field input:disabled,
.nm-field select:disabled,
.nm-field textarea:disabled {
    border-color: var(--nm-color-line);
    background: var(--nm-color-secondary-soft);
    color: var(--nm-color-text-muted);
    cursor: not-allowed;
    opacity: 0.65;
}

.nm-field textarea {
    min-height: 150px;
    resize: vertical;
}

.nm-field input:focus,
.nm-field select:focus,
.nm-field textarea:focus {
    border-color: var(--nm-color-primary);
    outline: 3px solid color-mix(in srgb, var(--nm-color-primary) 20%, var(--nm-color-transparent));
}

/* Hilfezeichen und Tooltip innerhalb eines Eingabefeldes */
.nm-label-row {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.nm-help-tooltip {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: auto;
    height: auto;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--nm-color-transparent);
    color: var(--nm-color-text-muted);
    font: inherit;
    font-size: 1rem;
    font-weight: 900;
    line-height: 1;
    cursor: help;
}

.nm-help-tooltip:hover,
.nm-help-tooltip:focus-visible {
    color: var(--nm-color-text);
}

.nm-input-wrap {
    position: relative;
}

.nm-field .nm-input-wrap input,
.nm-field .nm-input-wrap select {
    padding-right: 44px;
}

.nm-input-help {
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
}

.nm-help-tooltip::after {
    position: absolute;
    z-index: 20;
    top: calc(100% + 9px);
    right: 0;
    width: max-content;
    max-width: min(280px, 75vw);
    padding: 9px 11px;
    border-radius: var(--nm-radius);
    background: var(--nm-color-secondary);
    color: var(--nm-color-on-secondary);
    box-shadow: var(--nm-shadow-control);
    content: attr(data-tooltip);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0;
    line-height: 1.45;
    opacity: 0;
    pointer-events: none;
    text-align: left;
    text-transform: none;
    transform: translateY(-4px);
    transition: opacity 140ms ease, transform 140ms ease;
}

.nm-help-tooltip:hover::after,
.nm-help-tooltip:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

.nm-input-help:hover::after,
.nm-input-help:focus-visible::after {
    transform: translateY(4px);
}

/* Checkboxen und Radio-Gruppen */
.nm-check {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    color: var(--nm-color-text-muted);
}

.nm-check input {
    display: grid;
    flex: 0 0 22px;
    place-content: center;
    width: 22px;
    height: 22px;
    margin: 0;
    appearance: none;
    border: 1px solid var(--nm-color-line);
    border-radius: var(--nm-radius);
    background: var(--nm-color-page);
    color: var(--nm-color-on-primary);
    cursor: pointer;
    transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.nm-check input[type='checkbox']::before {
    width: 11px;
    height: 6px;
    border-bottom: 2px solid var(--nm-color-on-primary);
    border-left: 2px solid var(--nm-color-on-primary);
    content: '';
    transform: translateY(-1px) rotate(-45deg) scale(0);
    transition: transform 140ms ease;
}

.nm-check input[type='checkbox'] {
    border-radius: 0;
}

.nm-check input[type='checkbox']:checked {
    border-color: var(--nm-color-primary);
    background: var(--nm-color-primary);
}

.nm-check input[type='checkbox']:checked::before {
    transform: translateY(-1px) rotate(-45deg) scale(1);
}

.nm-check input[type='radio'] {
    border-radius: 50%;
}

.nm-check input[type='radio']::before {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--nm-color-on-primary);
    content: '';
    transform: scale(0);
    transition: transform 140ms ease;
}

.nm-check input[type='radio']:checked {
    border-color: var(--nm-color-primary);
    background: var(--nm-color-primary);
}

.nm-check input[type='radio']:checked::before {
    transform: scale(1);
}

.nm-check input:focus-visible {
    border-color: var(--nm-color-primary);
    outline: 3px solid color-mix(in srgb, var(--nm-color-primary) 20%, var(--nm-color-transparent));
}

.nm-check input:disabled {
    border-color: var(--nm-color-line);
    background: var(--nm-color-secondary-soft);
    cursor: not-allowed;
}

.nm-check:has(input:disabled),
.nm-switch:has(input:disabled) {
    cursor: not-allowed;
    opacity: 0.55;
}

.nm-fieldset {
    display: grid;
    gap: 12px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.nm-fieldset legend {
    margin-bottom: 4px;
    color: var(--nm-color-text);
    font-weight: 700;
}

.nm-choice-group {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 24px;
}

/* Apple-artiger Ein-/Aus-Schalter */
.nm-switch {
    display: inline-flex;
    gap: 11px;
    align-items: center;
    cursor: pointer;
}

.nm-switch input {
    position: absolute;
    opacity: 0;
}

.nm-switch-track {
    width: 44px;
    height: 26px;
    padding: 2px;
    border-radius: 26px;
    background: var(--nm-color-line);
    transition: background 180ms ease;
}

.nm-switch-track::after {
    display: block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--nm-color-switch-thumb);
    box-shadow: var(--nm-shadow-switch-thumb);
    content: '';
    transition: transform 180ms ease;
}

.nm-switch input:checked + .nm-switch-track { background: var(--nm-color-primary); }
.nm-switch input:checked + .nm-switch-track::after { transform: translateX(18px); }
.nm-switch input:disabled + .nm-switch-track { background: var(--nm-color-line); }

/* Einspaltige Formulare auf kleinen Bildschirmen */
@media (max-width: 640px) {
    .nm-form-grid { grid-template-columns: 1fr; }
}
