/* ==================================================================
   Fehlermeldungen (validation.js) und wiederhergestellte Eingaben
   (drafts.js)

   Der Dialog steht immer in der Mitte - auf dem Handy fast so breit
   wie der Bildschirm, mit eigener Scrollflaeche fuer die Liste, damit
   Titel und Knopf sichtbar bleiben.
   ================================================================== */

html.fc-open {
    overflow: hidden;
}

.fc-dialog {
    width: min(580px, calc(100vw - 32px));
    max-width: none;
    max-height: min(86vh, calc(100dvh - 32px));
    margin: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    overflow: visible;
}

.fc-dialog::backdrop {
    background: rgba(3, 5, 3, 0.74);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

/* Ohne showModal (sehr alte Browser): fest in der Mitte */
.fc-dialog.fc-fallback {
    position: fixed;
    inset: 0;
    z-index: 2000;
    height: fit-content;
    box-shadow: 0 0 0 100vmax rgba(3, 5, 3, 0.74);
}

.fc-panel {
    display: flex;
    flex-direction: column;
    max-height: inherit;
    overflow: hidden;
    border: 1px solid var(--error-line);
    border-top: 3px solid var(--error);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.fc-dialog[open] .fc-panel {
    animation: fc-in 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.fc-dialog[open]::backdrop {
    animation: fc-fade 200ms ease;
}

@keyframes fc-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes fc-fade {
    from {
        opacity: 0;
    }
}

/* --- Kopf ----------------------------------------------------------- */

.fc-head {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    align-items: start;
    padding: 20px 20px 16px 22px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(226, 115, 95, 0.12), rgba(226, 115, 95, 0) 85%);
}

.fc-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--error-line);
    border-radius: var(--radius);
    background: var(--error-bg);
    color: var(--error);
}

.fc-icon svg {
    width: 24px;
    height: 24px;
}

.fc-dialog svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.fc-heading {
    min-width: 0;
    padding-top: 1px;
}

.fc-title {
    margin: 0;
    font-size: 19px;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.fc-lead {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13.5px;
    line-height: 1.45;
}

button.fc-close {
    width: 38px;
    min-height: 38px;
    height: 38px;
    padding: 0;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
}

button.fc-close:hover {
    border-color: var(--border-strong);
    background: var(--surface-soft);
    color: var(--text);
}

.fc-close svg {
    width: 18px;
    height: 18px;
}

/* --- Liste der Fehler ------------------------------------------------ */

.fc-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 16px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    list-style: none;
}

.fc-item {
    padding: 14px 16px 14px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--error);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
}

.fc-item-head {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 10px;
}

.fc-number {
    display: inline-grid;
    flex: none;
    place-items: center;
    min-width: 22px;
    height: 22px;
    margin-top: 1px;
    padding: 0 5px;
    border-radius: var(--radius-sm);
    background: var(--error);
    color: #1c0a06;
    font-size: 12px;
    font-weight: 800;
}

.fc-single .fc-number {
    display: none;
}

.fc-names {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 10px;
    align-items: baseline;
    min-width: 0;
}

.fc-field {
    font-size: 15.5px;
    line-height: 1.35;
}

.fc-where {
    color: var(--faint);
    font-size: 12.5px;
}

.fc-row {
    display: grid;
    grid-template-columns: 104px 1fr;
    gap: 10px;
    align-items: start;
}

.fc-row + .fc-row {
    margin-top: 8px;
}

.fc-tag {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    justify-self: start;
    padding: 2px 8px 2px 6px;
    border: 1px solid;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1.6;
    text-transform: uppercase;
    white-space: nowrap;
}

.fc-tag svg {
    width: 12px;
    height: 12px;
    stroke-width: 2.8;
}

.fc-what .fc-tag {
    border-color: var(--error-line);
    background: var(--error-bg);
    color: var(--error);
}

.fc-how .fc-tag {
    border-color: var(--accent-line);
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.fc-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
}

.fc-what .fc-text {
    color: var(--text);
    font-weight: 500;
}

.fc-how .fc-text {
    color: #cdd5ce;
}

/* --- Fuss ------------------------------------------------------------ */

.fc-foot {
    display: flex;
    justify-content: flex-end;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border);
    background: var(--panel);
}

button.fc-fix {
    min-width: 200px;
    min-height: 44px;
}

/* --- Meldung direkt am Feld ------------------------------------------ */

.fielderror.fc-inline {
    display: block;
    margin-top: 6px;
    padding: 7px 10px;
    border-left: 3px solid var(--error);
    border-radius: var(--radius-sm);
    background: var(--error-bg);
    color: #e9c3ba;
    font-size: 12.5px;
    line-height: 1.45;
}

.fc-inline strong {
    color: var(--error);
    font-weight: 600;
}

td .fc-inline {
    min-width: 160px;
    white-space: normal;
}

/* Einzeilige Formulare (Neue Übung, Seite springen): Die Meldung steht in einer eigenen Zeile darunter. */
form:has(> .fc-inline) {
    flex-wrap: wrap;
}

form > .fc-inline {
    flex: 1 0 100%;
}

.radiorow.fc-invalid-group > label,
.fc-invalid-group .choice-card,
.fc-invalid-group .daytype-option {
    border-color: var(--error-line);
}

input[type="checkbox"].invalid {
    outline: 2px solid var(--error);
    outline-offset: 2px;
}

/* Kurz aufleuchten, wenn der Dialog zu einem Feld springt */
.fc-pulse {
    animation: fc-pulse 1.6s ease-out;
}

@keyframes fc-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(226, 115, 95, 0);
    }
    12% {
        box-shadow: 0 0 0 4px rgba(226, 115, 95, 0.6);
    }
    100% {
        box-shadow: 0 0 0 14px rgba(226, 115, 95, 0);
    }
}

/* --- Wiederhergestellte Eingaben (drafts.js) ------------------------- */

.draft-notice {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
    margin: 0 0 18px;
    padding: 10px 12px 10px 14px;
    border: 1px solid var(--accent-line);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13.5px;
}

.draft-notice svg {
    flex: none;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: var(--accent-strong);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.draft-notice p {
    flex: 1 1 220px;
    margin: 0;
}

.draft-notice button {
    min-height: 34px;
    padding: 5px 12px;
    font-size: 13px;
}

/* Satz-Zeilen als Karten (responsive.css): Die Meldung bekommt die ganze Breite der Karte. */
@media (max-width: 680px) {
    .settable td:has(.fc-inline) {
        grid-column: 1 / -1;
    }

    td .fc-inline {
        min-width: 0;
    }
}

/* --- Handy ----------------------------------------------------------- */

@media (max-width: 560px) {
    .fc-dialog {
        width: calc(100vw - 20px);
        max-height: calc(100dvh - 20px);
    }

    .fc-head {
        gap: 12px;
        padding: 16px 12px 14px 16px;
    }

    .fc-icon {
        width: 38px;
        height: 38px;
    }

    .fc-icon svg {
        width: 21px;
        height: 21px;
    }

    .fc-title {
        font-size: 17px;
    }

    .fc-lead {
        font-size: 13px;
    }

    .fc-list {
        gap: 10px;
        padding: 12px;
    }

    .fc-item {
        padding: 12px;
    }

    .fc-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .fc-row + .fc-row {
        margin-top: 10px;
    }

    .fc-foot {
        padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    }

    button.fc-fix {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fc-dialog[open] .fc-panel,
    .fc-dialog[open]::backdrop,
    .fc-pulse {
        animation: none;
    }
}
