/*
 * Erstellen-/Bearbeiten-Formulare (create_survey, create_event, edit_survey, edit_event) – 2026-09-28.
 * Ergänzt style.css (dort nichts ändern): Fehler am Feld, visuell versteckte Labels,
 * Auswahl-Chips als echte Radiogruppe.
 */

/* Nur für Screenreader sichtbar */
.wj-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Fehler direkt am Feld */
.wj-field-error {
    color: var(--danger, #DC2626);
    font-size: 0.85rem;
    font-weight: 600;
    margin: 6px 0 0;
}
.wj-field-error[hidden] { display: none; }
.wj-field-error::before {
    content: "\26A0\FE0E\00A0";
}
.wannja-input[aria-invalid="true"],
.wannja-option-input[aria-invalid="true"],
.form-control[aria-invalid="true"] {
    border-color: var(--danger, #DC2626);
}
.wj-date-row .wj-field-error {
    flex: 1 1 100%;
    order: 99;
    margin-top: 0;
}

/* Auswahl-Chips als Radiogruppe: Radio visuell versteckt, Label trägt das Aussehen von .wannja-radio-chip */
.wannja-radio-group { position: relative; }
.wj-chip-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    pointer-events: none;
}
.wj-chip-input:checked + .wannja-radio-chip {
    background: var(--wannja-blue);
    border-color: var(--wannja-blue);
    color: white;
}
.wj-chip-input:focus-visible + .wannja-radio-chip {
    outline: 3px solid var(--wannja-blue);
    outline-offset: 2px;
}
.wannja-radio-group > label.wannja-radio-chip {
    margin: 0;
    user-select: none;
}

/* «Max. Plätze» je Termin/Option (2026-09-30): kleines Zahlenfeld in der Zeile, Hinweis darunter */
.wj-dfield-max { flex: 0 1 125px; max-width: 135px; }
.wj-dfield-max > input::placeholder { font-size: 0.85rem; }
.wj-opt-max { flex: 0 0 135px; max-width: 135px; padding-left: 12px; padding-right: 8px; }
.wj-opt-max::placeholder { font-size: 0.9rem; }
.edit-option-wrap .wj-opt-max { flex: 0 0 125px; max-width: 125px; }
.wj-cap-hint { color: var(--gray-500); font-size: 0.85rem; margin: 10px 0 0; }
.wj-cap-hint strong { color: var(--gray-600); font-weight: 600; }
.wj-cap-already { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; color: #166534; font-size: 0.82rem; font-weight: 600; }
.wj-date-row .wj-cap-already { align-self: center; margin-top: 0; }
.wj-cap-already.is-over { color: var(--danger, #DC2626); }
@media (max-width: 600px) {
    .wj-dfield.wj-dfield-max { flex: 1 1 100%; max-width: none; }
    /* Event erstellen (2026-09-30): Zeile 1 = Symbol + Optionstext in voller Breite; Zeile 2 = «Max. Plätze»,
       «Frage hinzufügen» und Löschen. Vorher brach die Zeile auf vier Zeilen um (256 px hoch bei 390 px Breite).
       Zeile und Fragen-Editor werden dafür aufgelöst (display: contents) und die Teile neu geordnet. */
    .wannja-option-row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
    .wannja-option-row-wrap > .wannja-option-row,
    .wannja-option-row-wrap > .wjq,
    .wannja-option-row-wrap > .wjq > .wjq-addbar { display: contents; }
    .wannja-option-row-wrap .wannja-option-icon { order: 1; width: 44px; height: 44px; margin: 0; }
    .wannja-option-row-wrap .option-input { order: 1; flex: 1 1 calc(100% - 52px); min-width: 0; }
    .wannja-option-row-wrap .wj-opt-max { order: 2; flex: 0 1 108px; max-width: 108px; min-width: 0; margin-left: 0; padding: 10px 8px 10px 10px; font-size: 0.95rem; }
    .wannja-option-row-wrap .wj-opt-max::placeholder { font-size: 0.8rem; }
    .wannja-option-row-wrap .wjq-add { order: 3; flex: 1 1 0; min-width: 0; margin-top: 0; min-height: 44px; padding: 6px 8px; font-size: 0.82rem; line-height: 1.2; }
    .wannja-option-row-wrap .wjq-max { order: 3; flex: 1 1 0; min-width: 0; margin-top: 0; }
    .wannja-option-row-wrap .wannja-option-delete { order: 4; flex: 0 0 44px; width: 44px; height: 44px; margin-left: auto; }
    .wannja-option-row-wrap .wj-field-error { order: 5; flex: 1 1 100%; margin-top: 0; }
    .wannja-option-row-wrap > .wjq > * { order: 6; flex: 1 1 100%; min-width: 0; }
    .wannja-option-row-wrap > .wjq > .wjq-list:empty,
    .wannja-option-row-wrap > .wjq > [hidden] { display: none; }
}

/* Fragen an Teilnehmende – Editor + Vorschau pro Option (js/event-questions.js, 2026-09-29) */
.wjq { padding-left: 62px; margin-top: 6px; } /* = Icon 50px + Abstand 12px (Erstellen-Formular) */
.edit-option-wrap .wjq { padding-left: 0; }
.wjq-list { display: flex; flex-direction: column; gap: 10px; }
.wjq-list:empty { display: none; }
.wjq-q { border: 1px solid var(--gray-200); border-radius: 10px; padding: 10px 12px 12px; background: var(--gray-50, #F9FAFB); min-width: 0; }
.wjq-q-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.wjq-q-type { font-weight: 700; font-size: 0.9rem; color: var(--wannja-blue); flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.wjq-badge { font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--gray-100); color: var(--gray-600); flex: none; }
.wjq-badge.is-req { background: var(--wannja-blue-light); color: var(--wannja-blue); }
.wjq-q-remove, .wjq-choice-remove { flex: none; width: 36px; height: 36px; border: 1px solid var(--gray-200); border-radius: 8px; background: var(--white, #fff); color: var(--gray-500); cursor: pointer; }
.wjq-q-remove:hover, .wjq-choice-remove:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }
.wjq-choice-remove:disabled { opacity: 0.4; cursor: not-allowed; }
.wjq-field-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--gray-600); margin: 6px 0 4px; }
.wjq-input { width: 100%; min-width: 0; padding: 8px 10px; font-size: 0.95rem; border: 1px solid var(--gray-300, #D1D5DB); border-radius: 8px; background: var(--white, #fff); color: var(--gray-800); }
.wjq-input:focus { outline: none; border-color: var(--wannja-blue); box-shadow: var(--focus-ring); }
.wjq-input[aria-invalid="true"] { border-color: var(--danger, #DC2626); }
.wjq-choice-rows { display: flex; flex-direction: column; gap: 6px; }
.wjq-choice-row { display: flex; gap: 6px; align-items: center; }
.wjq-add-choice, .wjq-add, .wjq-menu-cancel { border: 1px dashed var(--gray-300, #D1D5DB); background: var(--white, #fff); color: var(--wannja-blue); border-radius: 8px; padding: 6px 12px; font-size: 0.88rem; font-weight: 600; cursor: pointer; margin-top: 6px; min-height: 36px; }
.wjq-add:hover, .wjq-add-choice:hover { background: var(--gray-100); } /* einheitlich: leichter Grauton, Rahmen bleibt (2026-10-03) */
.wjq-add:focus-visible, .wjq-add-choice:focus-visible, .wjq-menu-item:focus-visible, .wjq-menu-cancel:focus-visible, .wjq-q-remove:focus-visible, .wjq-choice-remove:focus-visible { outline: 3px solid var(--wannja-blue); outline-offset: 2px; }
.wjq-add[hidden], .wjq-add-choice[hidden], .wjq-max[hidden], .wjq-edit-err[hidden] { display: none; }
.wjq-addbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.wjq-max { font-size: 0.82rem; color: var(--gray-500); margin-top: 6px; }
.wjq-hint { font-size: 0.8rem; color: var(--gray-500); margin: 4px 0 0; }
.wjq-menu { margin-top: 8px; padding: 12px; border: 1px solid var(--gray-200); border-radius: 12px; background: var(--white, #fff); box-shadow: 0 6px 20px rgba(20, 33, 61, 0.08); }
.wjq-menu[hidden] { display: none; }
.wjq-menu-title { margin: 0 0 8px; font-weight: 700; font-size: 0.9rem; color: var(--gray-800); }
.wjq-menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.wjq-menu-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--gray-200); border-radius: 10px; background: var(--gray-50, #F9FAFB); cursor: pointer; min-width: 0; }
.wjq-menu-item:hover { background: var(--gray-100); }
.wjq-menu-name { font-weight: 700; font-size: 0.9rem; color: var(--wannja-blue); overflow-wrap: anywhere; }
.wjq-menu-desc { font-size: 0.78rem; color: var(--gray-600); overflow-wrap: anywhere; }
.wjq-edit-err { margin-top: 6px; }
.wjq-preview { margin-top: 10px; padding: 10px 12px 12px; border: 1px dashed var(--wannja-blue); border-radius: 10px; background: var(--white, #fff); min-width: 0; }
.wjq-preview[hidden] { display: none; }
.wjq-preview-title { margin: 0; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--wannja-blue); }
.wjq-preview-when { margin: 2px 0 8px; font-size: 0.85rem; color: var(--gray-600); overflow-wrap: anywhere; }
.wjq-preview-box { padding: 8px 12px; background: var(--gray-50, #F9FAFB); border-left: 3px solid var(--wannja-blue); border-radius: 8px; }
.wjq-pv-q { margin-bottom: 10px; min-width: 0; }
.wjq-pv-q:last-child { margin-bottom: 0; }
.wjq-pv-q .wannja-label-sm { overflow-wrap: anywhere; }
.wjq-preview input:disabled { opacity: 1; background: var(--white, #fff); }
.wjq-mode { border: 0; padding: 0; margin: 10px 0 0; min-width: 0; }
.wjq-mode > legend { padding: 0; float: none; width: auto; }
.wjq-mode-opt { display: flex; align-items: flex-start; gap: 8px; min-height: 40px; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--gray-200); border-radius: 8px; background: var(--white, #fff); cursor: pointer; font-size: 0.9rem; color: var(--gray-800); overflow-wrap: anywhere; }
.wjq-mode-opt input { width: 18px; height: 18px; flex: none; margin: 1px 0 0; accent-color: var(--wannja-blue); }
.wjq-mode-opt:has(input:checked) { border-color: var(--wannja-blue); background: var(--wannja-blue-light); }
.wjq-mode-opt:has(input:focus-visible) { outline: 3px solid var(--wannja-blue); outline-offset: 2px; }
.wjq-mode-hint { margin: 6px 0 0; font-size: 0.8rem; color: var(--gray-600); }
.wjq-mode-hint[hidden] { display: none; }
.wjq-preview .wjq-step { cursor: default; width: 36px; height: 36px; }
@media (max-width: 600px) {
    .wjq { padding-left: 0; }
    .wjq-menu-grid { grid-template-columns: 1fr; }
}
