/**
 * mod_termine_melden - media/css/termine-melden.css
 * Version: 3.3.1
 * Datum: 2026-09-28
 * Beschreibung: Gestaltung von Terminliste, Formular, Miniaturansichten und
 *   Dialogen. Bewusst unabhängig vom Template (kein Bootstrap nötig).
 *   Mobil zuerst: auf dem Handy einspaltig, Dialoge im Vollbild.
 *
 * Änderungshistorie:
 * 3.3.0 (2026-09-28): Dialoge als <dialog> mit eigener Gestaltung,
 *   Handy-Vollbild, eigenes Spaltenraster, Grundgestaltung der Formularfelder.
 */

/* =====================================================================
   Grundlagen
   ===================================================================== */
.tm-modul {
    --tm-akzent: #c1440e;
    --tm-akzent-dunkel: #9c360a;
    --tm-dunkel: #22262b;
    --tm-rand: #d9d6d0;
    --tm-grau: #6c6c6c;
    --tm-radius: .5rem;
}
.tm-modul [hidden] {
    display: none !important;
}

/* ---------- Formularfelder: solide Grundgestaltung, falls das Template keine liefert ---------- */
.tm-modul .form-label {
    display: block;
    font-weight: 600;
    margin-bottom: .3rem;
}
.tm-modul .form-control,
.tm-modul .form-select {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 2.75rem;          /* gut treffbar auf dem Handy */
    padding: .5rem .75rem;
    font-size: 1rem;              /* verhindert Auto-Zoom in iOS */
    border: 1px solid var(--tm-rand);
    border-radius: var(--tm-radius);
    background-color: #fff;
}
.tm-modul textarea.form-control {
    min-height: 6rem;
}
.tm-modul .form-text {
    font-size: .875rem;
    color: var(--tm-grau);
    margin-top: .25rem;
}
.tm-modul .mb-3 {
    margin-bottom: 1rem;
}
.tm-modul .tm-card {
    border: 1px solid var(--tm-rand);
    border-radius: .6rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .08);
    background: #fff;
}

/* Eigenes Spaltenraster: Handy einspaltig, ab 576px nebeneinander */
.tm-reihe {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
@media (min-width: 576px) {
    .tm-reihe {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}
.tm-spalte {
    min-width: 0;
}

/* Honeypot: aus dem sichtbaren Bereich schieben */
.tm-hp {
    position: absolute !important;
    left: -10000px !important;
    top: auto !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}

/* ---------- Miniaturansichten ---------- */
.tm-vorschau {
    margin: 0;
}
.tm-vorschau img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(240px, 100%);
    max-height: 240px;
    object-fit: contain;
    border-radius: var(--tm-radius);
    border: 1px solid rgba(0, 0, 0, .15);
    background: #f4f4f4;
}
.tm-vorschau figcaption {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}
.tm-vorschau-aktuell.tm-entfernt img {
    opacity: .35;
    filter: grayscale(1);
}

/* =====================================================================
   Terminliste
   ===================================================================== */
.tm-karten {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}
.tm-karte {
    flex: 1 1 30%;
    min-width: 220px;
    min-height: 150px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
    text-align: center;
    border-radius: 4px;
    background-color: #555;
    background-size: cover;
    background-position: center;
}
.tm-karte-datum {
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.tm-karte-titel {
    margin: 10px 0 0;
    font-size: 16px;
}
.tm-karte-titel a {
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.tm-modul .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tm-tabelle {
    width: 100%;
    border-collapse: collapse;
}
.tm-tabelle th,
.tm-tabelle td {
    padding: .55rem .5rem;
    border-bottom: 1px solid var(--tm-rand);
    text-align: left;
    vertical-align: top;
}
.tm-tabelle td:first-child {
    white-space: nowrap;
}
.tm-zeile {
    cursor: pointer;
}
.tm-zeile:hover,
.tm-zeile:focus {
    background-color: rgba(0, 0, 0, .04);
    outline: none;
}
.tm-zeile:focus-visible {
    box-shadow: inset 3px 0 0 var(--tm-akzent);
}
.tm-zeile[hidden] {
    display: none;
}
.tm-info {
    display: inline-block;
    margin-left: 6px;
    color: #007bff;
    vertical-align: middle;
    line-height: 1;
}
.tm-info svg {
    display: block;
}
@media (max-width: 575.98px) {
    .tm-karte {
        min-width: 100%;
        min-height: 130px;
    }
    .tm-tabelle {
        font-size: .9rem;
    }
}

/* =====================================================================
   Dialoge (natives <dialog>, liegt im "Top Layer" über allem)
   ===================================================================== */
html.tm-dialog-offen,
html.tm-dialog-offen body {
    overflow: hidden !important;          /* Seite dahinter scrollt nicht mit */
}

dialog.tm-dialog {
    box-sizing: border-box;
    padding: 0;
    margin: auto;
    border: 0;
    border-radius: 12px;
    width: min(1000px, 96vw);
    max-width: 96vw;
    max-height: 92vh;
    color: #222;
    background: #fff;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
    overflow: hidden;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
}
dialog.tm-dialog[open] {
    display: flex;
    flex-direction: column;
}
dialog.tm-dialog::backdrop {
    background: rgba(15, 18, 22, .75);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}
/* Fallback für Browser ohne showModal() */
dialog.tm-dialog--ohne-top-layer {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
}

/* Kopf, Inhalt, Fuß */
.tm-dialog__kopf {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    background: var(--tm-dunkel, #22262b);
    color: #fff;
    border-bottom: 4px solid var(--tm-akzent, #c1440e);
    flex: 0 0 auto;
}
.tm-dialog__titel {
    flex: 1 1 auto;
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.3;
    color: #fff;
    overflow-wrap: anywhere;
}
.tm-dialog__x {
    flex: 0 0 auto;
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
}
.tm-dialog__x:hover,
.tm-dialog__x:focus-visible {
    background: rgba(255, 255, 255, .25);
}
.tm-dialog__inhalt {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
}
.tm-dialog__fuss {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: .75rem 1rem;
    padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e6e3de;
    background: #faf9f7;
}
.tm-dialog__fehler {
    flex: 0 0 auto;
    margin: 0;
    padding: .6rem 1rem;
    background: #fff3cd;
    color: #664d03;
    border-top: 1px solid #ffe69c;
}
.tm-dialog__fehler[hidden],
.tm-pdf-nav[hidden],
.tm-laden[hidden] {
    display: none !important;
}

/* Knöpfe im Dialog (eigene Gestaltung, unabhängig vom Template) */
.tm-knopf {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: .5rem 1.1rem;
    border: 1px solid #c9c5bf;
    border-radius: var(--tm-radius, .5rem);
    background: #fff;
    color: #222;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
}
.tm-knopf:hover {
    background: #f1efec;
}
.tm-knopf:focus-visible {
    outline: 3px solid rgba(193, 68, 14, .45);
    outline-offset: 1px;
}
.tm-knopf:disabled {
    opacity: .45;
    cursor: default;
}
.tm-knopf--primaer {
    background: var(--tm-akzent, #c1440e);
    border-color: var(--tm-akzent, #c1440e);
    color: #fff;
}
.tm-knopf--primaer:hover {
    background: var(--tm-akzent-dunkel, #9c360a);
}
.tm-knopf--klein {
    min-height: 2.5rem;
    min-width: 2.5rem;
    padding: .35rem .7rem;
    font-size: .9rem;
}
.tm-knopf.ist-aktiv {
    background: var(--tm-dunkel, #22262b);
    border-color: var(--tm-dunkel, #22262b);
    color: #fff;
}

/* ---------- Zuschnitt-Dialog ---------- */
dialog.tm-dialog--zuschnitt {
    height: min(92vh, 900px);
}
.tm-werkzeuge {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .9rem;
    padding: .6rem 1rem;
    border-bottom: 1px solid #e6e3de;
    background: #faf9f7;
}
.tm-gruppe {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}
.tm-pdf-nav {
    display: flex;
    align-items: center;
    gap: .4rem;
}
.tm-pdf-seite {
    min-width: 7.5em;
    text-align: center;
    font-size: .9rem;
    white-space: nowrap;
}
.tm-zuschnitt-flaeche {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;                 /* wichtig für flex: Fläche darf schrumpfen */
    background: #1b1b1b;
    overflow: hidden;
}
/* Cropper.js verlangt max-width:100% am Bild */
.tm-zuschnitt-flaeche > img {
    display: block;
    max-width: 100%;
}
.tm-laden {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    color: #fff;
    background: rgba(0, 0, 0, .55);
}
.tm-spinner {
    width: 1.6rem;
    height: 1.6rem;
    border: 3px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tm-drehen .8s linear infinite;
}
@keyframes tm-drehen {
    to { transform: rotate(360deg); }
}

/* ---------- Detail-Dialog der Terminliste ---------- */
dialog.tm-dialog--detail {
    width: min(720px, 96vw);
}
.tm-detail-bild {
    display: block;
    width: 100%;
    height: auto;
    max-height: 60vh;
    object-fit: contain;
    border-radius: 6px;
    margin-bottom: 1rem;
    background: #f4f4f4;
}
.tm-detail-liste {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: .35rem 1rem;
    margin: 0;
}
.tm-detail-liste dt {
    font-weight: 700;
}
.tm-detail-liste dd {
    margin: 0;
    overflow-wrap: anywhere;
}

/* =====================================================================
   Handy: Dialoge im Vollbild, Werkzeugleiste wischbar
   ===================================================================== */
@media (max-width: 767.98px) {
    dialog.tm-dialog,
    dialog.tm-dialog--zuschnitt,
    dialog.tm-dialog--detail {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;             /* Fallback */
        height: 100dvh;            /* berücksichtigt die Adressleiste */
        max-height: 100vh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
    }
    .tm-dialog__kopf {
        padding-top: calc(.6rem + env(safe-area-inset-top, 0px));
    }
    .tm-werkzeuge {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: .5rem .75rem;
    }
    .tm-werkzeuge::-webkit-scrollbar {
        display: none;
    }
    .tm-gruppe {
        flex-wrap: nowrap;
    }
    .tm-dialog__fuss .tm-knopf {
        flex: 1 1 0;               /* große Knöpfe über die volle Breite */
        min-height: 3rem;
    }
    .tm-detail-liste {
        grid-template-columns: 1fr;
        gap: 0;
    }
    .tm-detail-liste dd {
        margin-bottom: .6rem;
    }
}
