/*
 * formulare.css – Formulare: Felder, Eingabeelemente, Validierung, Auswahl, Kombinationsfeld
 *
 * Jedes Feld folgt dem Muster aus src/View/helpers.php (field()):
 *
 *   <div class="field [is-invalid|is-valid]">
 *       <label>Beschriftung <span class="opt">optional</span></label>
 *       <div class="control"> <input|select|textarea> </div>
 *       <span class="msg">Meldung der Validierung</span>
 *   </div>
 *
 * Die Klassen is-invalid / is-valid setzt der Server (templates) oder js/validate.js.
 */

/* ---- Formularbreite und Gruppen ---------------------------------------------------------------- */
form {
    max-width: var(--measure);
}

form.wide {
    max-width: var(--wide);
}

form.inline {
    display: inline; /* kleine Aktionsformulare (ein Knopf) im Fliesstext oder in Tabellenzellen */
}

fieldset {
    border: 0;
    padding: 0;
    margin: 0 0 1.5rem;
    min-width: 0; /* sonst sprengen breite Kinder das Grid in Chrome */
}

legend {
    font-size: 1.35rem;
    font-weight: 300;
    color: var(--black);
    margin-bottom: .75rem;
    padding: 0;
}

/* Rechtliche Bestätigungen (AGB, Richtigkeit) als grauer Kasten */
fieldset.legal {
    background: var(--grey-very-light);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

fieldset.legal legend {
    float: left; /* legend innerhalb des Kastens statt auf dem Rand */
    width: 100%;
    margin-bottom: .5rem;
}

fieldset.legal p {
    margin: .4rem 0;
}

fieldset.minor {
    margin-top: 1.5rem;
}

.hint {
    color: var(--grey);
    font-size: .92rem;
    margin: .25rem 0 0;
}

.note {
    color: var(--grey);
    font-size: .95rem;
}

.note.warn {
    color: var(--red);
}

/* ---- Feld und Beschriftung ------------------------------------------------------------------- */
.field {
    margin: 0 0 1.1rem;
}

.field > label,
.field > .label {
    display: block;
    font-weight: 700;
    color: var(--black);
    margin-bottom: .35rem;
    font-size: .98rem;
}

.field .label {
    display: block;
    font-weight: 700;
    margin-bottom: .35rem;
}

/* «optional» hinter der Beschriftung */
.field > label .opt {
    font-weight: 400;
    color: var(--grey);
    font-size: .88rem;
    margin-left: .4rem;
}

.control {
    position: relative; /* Bezug für den grünen Haken (is-valid) */
}

/* Vorwahl + Nummer: «+41» als Text vor einem kurzen Feld */
.control.prefix {
    display: flex;
    align-items: center;
    gap: .3rem;
}

.control.prefix span {
    color: var(--grey);
    font-size: 1.1rem;
}

.control.prefix input {
    width: 5rem;
}

.narrow-ctl .control {
    max-width: 12rem;
}

/* ---- Eingabeelemente ------------------------------------------------------------------------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
    width: 100%;
    padding: .7rem .9rem;
    font: inherit;
    color: var(--black);
    background: var(--white);
    border: 1px solid var(--grey-mid-darker);
    border-radius: var(--radius);
    min-height: var(--control-height);
    transition: border-color var(--speed), box-shadow var(--speed);
}

/* Eigener Pfeil statt des Browser-Pfeils, damit alle Browser gleich aussehen */
select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2.6rem;
    background-image: var(--icon-chevron);
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

select[multiple] {
    height: auto;
}

textarea {
    min-height: 7rem;
    resize: vertical;
}

input:hover,
select:hover,
textarea:hover {
    border-color: var(--grey-dark);
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid transparent; /* siehe basis.css :focus-visible */
    border-color: var(--link);
    box-shadow: var(--focus);
}

input::placeholder {
    color: var(--placeholder);
}

/* Kurze Felder: Jahr, PLZ, Nummern */
input.short {
    max-width: 11rem;
}

input.year {
    max-width: 7rem;
}

input.plz {
    max-width: 8rem;
}

/* Mehrere Felder nebeneinander, umbrechend. Raster mit Unterraster (subgrid): Label, Hinweis, Eingabe und Meldung jedes
   Felds liegen in gemeinsamen Zeilen – die Eingabefelder stehen auf gleicher Höhe, auch wenn nur eines einen Hinweis hat
   oder nur eine Fehlermeldung über zwei Zeilen läuft (Fach-IDs 62, 63, 87). */
.row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr));
    column-gap: 1rem;
    align-items: start;
}

.row > .field,
.row > .field-wrap,
.row > .field-wrap > .field {   /* Ort Schweiz/Ausland: Hülle und Feld reichen das Raster durch */
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 4;
}

.row .field > label,
.row .field > .label {
    grid-row: 1;
}

.row .field > .hint {
    grid-row: 2;
}

.row .field > .control {
    grid-row: 3;
    align-self: end;
}

.row .field > .msg {
    grid-row: 4;
}

/* schmale Felder (Datum von/bis): gleich breite, kürzere Spalten */
.row:has(> .field.narrow) {
    grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));
}

/* Telefon: schmale Vorwahl, breite Nummer – in der Anmeldung davor noch die Art (Mobil/Privat/Geschäft) */
.row.telefon {
    grid-template-columns: 7.5rem minmax(12rem, 1fr);
}

.row.telefon:has(> :nth-child(3)) {
    grid-template-columns: minmax(8rem, 1fr) 7.5rem minmax(12rem, 2fr);
}

/* Vorwahl (Kombinationsfeld): zu schmal für Haken, «×» und Pfeil nebeneinander – der Haken überdeckte das «×»
   (Fach-ID 94). Gültig zeigt hier nur der grüne Rand; Platz rechts nur für «×» und Pfeil. */
.row.telefon .field.is-valid .control:has(.combo)::after {
    display: none;
}

/* Platz für «×» und Pfeil immer frei halten, nicht nur wenn gültig: vor der Wahl lief «+41 Schweiz» unter das «×»
   (Fach-ID 94 Re-Test 13.11.2026). */
.row.telefon .field .combo input.combo-input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
    padding-right: 4.4rem;   /* spezifischer als die Kombinationsfeld-Regeln unten (auch «gültig») */
    text-overflow: clip;     /* sichtbar bleibt «+41»; mit «…» bliebe nur «+…» */
}

@media (max-width: 40rem) {
    .row.telefon,
    .row.telefon:has(> :nth-child(3)) {
        grid-template-columns: 7.5rem minmax(0, 1fr);   /* Art in eigener Zeile, Vorwahl und Nummer nebeneinander */
    }

    .row.telefon > :first-child:nth-last-child(3) {
        grid-column: 1 / -1;
    }
}

/* Von–bis-Jahre mit gemeinsamem Hinweis darunter */
.row.years {
    margin-bottom: 0;
}

/* Haken und Meldung direkt beim schmalen Jahresfeld statt am rechten Rand der Spalte (Fach-ID 64) */
.row.years .field .control {
    width: fit-content;
}

.row.years .field {
    margin-bottom: .2rem;
}

.years-hint {
    margin: 0 0 1.1rem;
}

/* ---- Validierung ----------------------------------------------------------------------------- */
/* Die Meldungszeile ist immer da (min-height), damit die Seite beim Prüfen nicht springt */
.field .msg {
    display: block;
    min-height: 1.4rem;
    font-size: .9rem;
    margin-top: .3rem;
    color: var(--grey);
}

/* ungültig: roter Rand, rote Meldung mit Ausrufezeichen */
.field.is-invalid input,
.field.is-invalid select,
.field.is-invalid textarea {
    border-color: var(--red);
    background: var(--invalid-bg);
}

.field.is-invalid .msg {
    color: var(--red);
}

.field.is-invalid .msg::before {
    content: "";
    display: inline-block;
    width: .9rem;
    height: .9rem;
    margin-right: .35rem;
    vertical-align: -2px;
    border-radius: 50%;
    background: var(--red) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 3.5v5.5M8 11.5v1' stroke='%23fff' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* gültig: grüner Rand, grüner Haken rechts im Feld (Platz dafür über padding-right) */
.field.is-valid input:not([type="checkbox"]):not([type="radio"]),
.field.is-valid select,
.field.is-valid textarea {
    border-color: var(--green);
    padding-right: 2.6rem;
}

.field.is-valid select {
    padding-right: 4.2rem; /* Haken links vom Pfeil */
}

.field.is-valid .control::after {
    content: "";
    position: absolute;
    right: .9rem;
    top: 50%;
    width: 1.1rem;
    height: 1.1rem;
    margin-top: -.55rem;
    background: var(--green);
    clip-path: path("M14.8618 4.93359L8.04736 14.5532L3.30859 11.1064L4.19043 9.89355L7.70093 12.4468L13.6372 4.06641L14.8618 4.93359Z");
    transform: scale(.95);
    pointer-events: none;
}

.field.is-valid select + .control::after,
.field.is-valid .control.select::after {
    right: 2.6rem;
}

.field.is-valid .msg {
    color: var(--green-dark);
}

/* ---- Auswahl: Radio und Checkbox als Karten -------------------------------------------------- */
.choices {
    display: grid;
    gap: .5rem;
}

/* Nebeneinander statt untereinander (wenige kurze Optionen) */
.choices.inline {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem 1.25rem;
}

.choice {
    display: flex;
    gap: .75rem;
    align-items: flex-start;
    padding: .75rem .9rem;
    border: 1px solid var(--grey-mid);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--white);
    transition: border-color var(--speed), background var(--speed);
}

.choice:hover {
    border-color: var(--grey-mid-darker);
}

/* gewählte Karte: dunkler Rand, graue Fläche; Fokus auf dem versteckten Input zeigt den Ring auf der Karte */
.choice:has(input:checked) {
    border-color: var(--black);
    background: var(--grey-very-light);
}

.choice:has(input:focus-visible) {
    box-shadow: var(--focus);
}

.choice input {
    width: 1.25rem;
    height: 1.25rem;
    margin: .15rem 0 0;
    accent-color: var(--red);
    flex: none;
}

.choice span {
    color: var(--black);
    /* lange Fachnamen («Spanische Sprachwissenschaft/Literaturwissenschaft») dürfen die Karte nicht sprengen:
       Flex-Kind darf schmaler als sein Inhalt werden und innerhalb des Wortes umbrechen (Fach-ID 60) */
    min-width: 0;
    overflow-wrap: anywhere;
    hyphens: auto;
}

.choice small {
    display: block;
    color: var(--grey);
    font-size: .9rem;
}

/* ohne Karte, nur Kästchen und Text */
.choice.inline {
    display: inline-flex;
    margin-right: .5rem;
    border: 0;
    padding: .3rem 0;
    background: none;
}

/* nicht wählbar (z. B. durch eine andere Wahl ausgeschlossen, js/sem.js) */
.choice.disabled {
    opacity: .5;
    cursor: default;
}

fieldset > .choice {
    margin-bottom: 1rem;
    max-width: var(--wide);
}

/* einfache Checkbox mit Text, ohne Karte */
.chk {
    display: flex;
    gap: .75rem;
    align-items: flex-start;
    cursor: pointer;
    margin: .5rem 0;
}

.chk input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: .2rem;
    accent-color: var(--red);
    flex: none;
}

/* ---- Durchsuchbare Auswahl (Kombinationsfeld, js/combobox.js) -----------------------------------
 * Das echte <select> bleibt unsichtbar im Formular (Wert, Validierung), davor liegt ein Textfeld mit
 * Vorschlagsliste. */
.combo {
    position: relative;
}

.combo select.combo-native {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    left: 0;
    bottom: 0;
}

/* Selektor mit input…:not(…): sonst gewinnt die allgemeine Feldregel (Innenabstand .9rem) und der Text läuft unter
   «×» und Pfeil (Fach-ID 94 Re-Test 13.11.2026) */
.combo input.combo-input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
    padding-right: 4.4rem; /* Platz für Löschen-Knopf und Pfeil */
    text-overflow: ellipsis;
}

.combo .combo-input::placeholder {
    color: var(--placeholder);
}

.combo::after {
    content: "";
    position: absolute;
    right: 1rem;
    top: 50%;
    width: 18px;
    height: 10px;
    margin-top: -5px;
    pointer-events: none;
    background: var(--icon-chevron) center no-repeat;
}

/* «×» zum Leeren */
.combo .combo-clear {
    position: absolute;
    right: 2.6rem;
    top: 50%;
    width: 1.6rem;
    height: 1.6rem;
    margin-top: -.8rem;
    border: 0;
    border-radius: 50%;
    background: var(--grey-light);
    cursor: pointer;
    color: var(--grey-dark);
    font-size: 1rem;
    line-height: 1;
}

.combo .combo-clear::before {
    content: "×";
}

.combo .combo-clear:hover {
    background: var(--grey-mid);
}

.combo .combo-clear:focus-visible {
    outline: 2px solid transparent; /* siehe basis.css :focus-visible */
    box-shadow: var(--focus);
}

/* Vorschlagsliste unter dem Feld */
.combo-list {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: 18rem;
    overflow-y: auto;
    margin: 0;
    padding: .3rem 0;
    list-style: none;
    background: var(--white);
    border: 1px solid var(--grey-mid-darker);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
}

.combo-list li {
    padding: .55rem .9rem;
    cursor: pointer;
}

.combo-list li.active,
.combo-list li:hover {
    background: var(--grey-very-light);
}

.combo-list li[aria-selected="true"] {
    font-weight: 700;
}

.combo-list li[aria-selected="true"]::before {
    content: "✓ ";
    color: var(--green);
}

.combo-list li.empty {
    color: var(--grey);
    cursor: default;
}

/* Validierungsfarben auch auf dem sichtbaren Textfeld; Haken weiter links wegen Löschen-Knopf und Pfeil */
.field.is-invalid .combo-input {
    border-color: var(--red);
    background: var(--invalid-bg);
}

.field.is-valid .combo-input {
    border-color: var(--green);
}

.field.is-valid .control:has(.combo)::after {
    right: 4.7rem;
}

.field.is-valid .combo input.combo-input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
    padding-right: 6.6rem;
}
