/* --- nebenkosten/public/assets/css/utilities.css ---
   Wiederverwendbare Utility-Klassen zur Vermeidung von Inline-Styles.
   Wird im Layout als letztes Stylesheet geladen.
   ===================================================================== */

/* Höhe des klebenden Seitenkopfs (.slf-header): 8px + 42px Logo + 8px + 1px
   Rahmen. Alles, was darunter kleben oder dorthin springen soll, rechnet mit
   dieser Variablen. */
:root {
    --slf-header-h: 3.7rem;
}

/* Verhindert horizontales Scrollen der gesamten Seite */
body { overflow-x: hidden; }

/* ============================================
   FLEXBOX
   ============================================ */
.flex { display: flex; }
.flex-gap-sm { gap: 0.5rem; }
.flex-gap { gap: 0.75rem; }
.flex-wrap { flex-wrap: wrap; }
.align-end { align-items: flex-end; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }

.flex-row {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    align-items: center;
}
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}
.flex-start {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
}
.flex-col {
    display: flex;
    flex-direction: column;
}
.flex-auto { flex: 1 1 auto; min-width: 0; }
.flex-none { flex: 0 0 auto; }

/* ============================================
   ABSTÄNDE
   ============================================ */
.m-0 { margin: 0; }
.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-1 { margin-bottom: 1rem; }
.mb-2 { margin-bottom: 2rem; }
.mt-sm { margin-top: 0.25rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 2rem; }
.ml-sm { margin-left: 0.5rem; }
.ml-auto { margin-left: auto; }
.p-sm { padding: 0.25rem; }

/* ============================================
   BREITEN
   ============================================ */
.w-full { width: 100%; }
.w-5 { max-width: 5rem; }
.w-6 { max-width: 6rem; }
.w-input-sm { max-width: 5rem; }
.w-input-md { max-width: 10rem; }
.w-input-lg { max-width: 16rem; }
.w-input-xl { max-width: 600px; }
.w-select-full { width: 100%; }
.w-date { max-width: 300px; }
.w-select { width: 200px; }
.min-w-300 { min-width: 300px; }

/* ============================================
   TEXT & DARSTELLUNG
   ============================================ */
.text-right { text-align: right; }
.text-center { text-align: center; }
/* höhere Spezifität als .content th { text-align:left } */
.content th.text-right,
.content td.text-right { text-align: right; }

.text-gray { color: #333; }
.text-muted { color: var(--muted); }
.text-success { color: green; font-weight: bold; }
.text-error { color: #a00; }
.font-bold { font-weight: bold; }
.nowrap { white-space: nowrap; }

.heading-md { font-size: 1.3rem; }
.section-title { font-size: 1.3rem; }
.section-title-lg { font-size: 1.4rem; }

.bg-highlight { background: rgba(255, 255, 0, 0.06); }
.bg-gray { background: #eee; }

.list-reset {
    margin: 0;
    padding-left: 1.2rem;
}

.d-block { display: block; }
.d-inline { display: inline; }
.d-inline-block { display: inline-block; }
.d-none { display: none; }   /* für JS-Toggle */

/* Hinweistexte */
.form-hint { font-size: 0.78rem; color: #888; margin: 4px 0 0; }
.help-text { margin-left: 0.5rem; font-size: 0.85rem; color: #666; }
.text-help { margin: 0.25rem 0 0; font-size: 0.85rem; color: #666; }
.text-info-muted { margin-bottom: 1rem; font-size: 0.9rem; color: #888; }

/* ============================================
   FORMULAR-LAYOUTS
   ============================================ */
.form-grid {
    display: grid;
    grid-template-columns: minmax(0, 150px) minmax(0, 1fr);
    gap: 0.5rem 0.75rem;
}
.form-grid-labels {
    display: grid;
    grid-template-columns: minmax(0, 140px) minmax(0, 1fr);
    gap: 0.4rem 0.8rem;
    align-items: center;
}
fieldset.mb-1 { margin-bottom: 1rem; }

.inline-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
}
.flex-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.edit-form-box {
    padding: 1rem;
    background: #f9f9f9;
    border: 1px solid #ddd;
}

/* Wie .filter-bar, aber ohne Hintergrund */
.upload-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: nowrap;
    margin-bottom: 0.5rem;
}
.upload-row > div { flex: 0 0 auto; }
@media (max-width: 768px) {
    .upload-row { flex-wrap: wrap; }
    .upload-row > div { flex: 1 1 100%; }
}

/* Mehrere .admin-card nebeneinander, stapeln sich unter 28rem */
.form-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(28rem, 100%), 1fr));
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}
.form-cards > * {
    min-width: 0;
    margin-bottom: 0;
}
/* In halbbreiten Spalten keine klebende Aktionsspalte */
.form-cards .col-actions {
    position: static;
    width: auto;
    box-shadow: none;
}

/* ============================================
   VORSCHAU-BOXEN
   ============================================ */
.description-box {
    border: 1px solid #ccc;
    border-radius: 0.5rem;
    padding: 0.5rem;
    min-height: 3rem;
    background: #fafafa;
}
.description-preview {
    max-width: 16rem;
    max-height: 4.5rem;
    overflow: auto;
    border: 1px solid #ddd;
    padding: 0.25rem;
    background: #fafafa;
}
.content-preview {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: #666;
    min-height: 2em;
    max-height: 4em;
    overflow: hidden;
}

/* ============================================
   TABELLEN
   ============================================ */

/* Scroll-Wrapper – jede .admin-table gehört hinein */
.table-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
    padding: 0 1rem;
}

/* Kompakte Tabelle ohne min-width (einfache Listen) */
.admin-table.compact { min-width: 0; }

/* Zeilenzustände */
.row-active { background: rgba(255, 255, 0, 0.06); }
.row-highlight { background: rgba(183, 111, 94, 0.08); }
.row-selected { background: #e8f4fc !important; }
.row-disabled { opacity: 0.6; }

/* Spaltenbreiten */
.col-checkbox { width: 40px; }
.col-year { width: 6rem; }
.col-status { width: 12rem; }
.col-actions { width: 10rem; }

/* Lange Texte in Zellen – Klasse auf einen Block INNERHALB der Zelle setzen,
   auf der Zelle selbst bleibt max-width bei table-layout:auto wirkungslos. */
.cell-text,
.cell-preview {
    white-space: normal;
    overflow-wrap: anywhere;
}
.cell-text { max-width: 18rem; }
/* Nur umbrechen, ohne Breitendeckel (Zellen sind sonst nowrap) */
.cell-wrap {
    white-space: normal;
    overflow-wrap: anywhere;
}
.cell-preview {
    max-width: 32rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 768px) {
    .cell-text { max-width: 11rem; }
    .cell-preview { max-width: 13rem; }

    .admin-table { font-size: 0.8rem; }
    .admin-table th,
    .admin-table td {
        padding: 0.4rem 0.3rem;
        white-space: nowrap;
    }

    /* Erste Spalte klebt beim Querscrollen. Steht dort nur eine ID/Nummer/
       ein Jahr: .no-sticky-first auf die Tabelle. Zellen mit colspan
       (Summen-/Hinweiszeilen) sind ausgenommen, sonst verdecken sie die
       Nachbarzellen. */
    .admin-table:not(.no-sticky-first) th:first-child:not([colspan]),
    .admin-table:not(.no-sticky-first) td:first-child:not([colspan]) {
        position: sticky;
        left: 0;
        background: #fff;
        z-index: 1;
    }

    /* Langer Freitext in Spalte 1: Breite kappen, Rest per Ellipsis.
       table-layout:fixed ist Pflicht, sonst greift die Breite nicht. */
    .admin-table.clamp-sticky-first { table-layout: fixed; }
    .admin-table.clamp-sticky-first th:first-child:not([colspan]),
    .admin-table.clamp-sticky-first td:first-child:not([colspan]) {
        width: 40vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 640px) {
    .admin-table { font-size: 0.75rem; }
    .admin-table th,
    .admin-table td { padding: 0.35rem 0.25rem; }

    .admin-table button,
    .admin-table .btn {
        font-size: 0.7rem;
        padding: 0.25rem 0.4rem;
        min-height: 30px;
        white-space: nowrap;
    }
    .admin-table td:first-child {
        white-space: normal;
        min-width: 100px;
    }
    .admin-table td.actions { white-space: nowrap; }
    .admin-table td.actions button {
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
        min-height: 36px;
    }
}

/* ============================================
   SICHTBARKEIT MOBIL
   ============================================ */
.show-mobile { display: none !important; }

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
}

/* ============================================
   MOBILE: KARTEN, FORMULARE, BUTTONS
   ============================================ */
@media (max-width: 768px) {
    /* Touch-Ziele (iOS-Empfehlung) */
    button,
    .btn,
    input[type="submit"] {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }
}

@media (max-width: 640px) {
    .admin-card { padding: 0.75rem !important; }
    .admin-container { padding: 0.5rem 0 !important; }

    .form-grid { grid-template-columns: 1fr !important; }
    .form-grid input[type="text"],
    .form-grid input[type="email"],
    .form-grid input[type="tel"],
    .form-grid input[type="number"],
    .form-grid input[type="date"],
    .form-grid input[type="datetime-local"],
    .form-grid textarea,
    .form-grid select {
        max-width: 100% !important;
        width: 100% !important;
    }

    .actions button,
    .actions .btn { width: 100%; }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .form-actions button,
    .form-actions .btn {
        width: 100%;
        text-align: center;
    }

    .flex-wrap-mobile {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .flex-wrap-mobile > * {
        width: 100% !important;
        max-width: 100% !important;
    }

    .text-sm-center { text-align: center; }
    .mb-sm-2 { margin-bottom: 0.5rem; }
}

/* ============================================
   AUF DEM HANDY EINKLAPPBARER BEREICH
   ============================================
   Natives <details>. Am Rechner bleibt die Zusammenfassung ausgeblendet,
   unter 768px wird sie zur antippbaren Zeile. Zuklappen per Skript in der
   View – CSS kann ein <details> nicht schließen. */
.collapse-mobile > summary { display: none; }

@media (max-width: 768px) {
    .collapse-mobile > summary {
        display: block;
        cursor: pointer;
        padding: 0.6rem 0.75rem;
        margin-bottom: 0.75rem;
        background: var(--paper);
        border-radius: 0.5rem;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
        font-weight: 600;
    }
    .collapse-mobile__aktuell {
        display: block;
        font-weight: 400;
        font-size: 0.9em;
        color: #666;
    }
}

/* ============================================
   REGISTERLEISTE, SCROLLEND UND KLEBEND
   ============================================
   Baut auf .tabs/.tab (backoffice.css) auf. Muss außerhalb von .admin-card
   stehen – deren overflow-x macht das Kleben sonst wirkungslos. */
.tabs--scroll {
    position: sticky;
    top: var(--slf-header-h);
    z-index: 500;                 /* unter Header (1000) und Modal */
    background: var(--bg);
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.tabs--scroll .tab {
    flex: 0 0 auto;
    white-space: nowrap;
}

/* Sprungziel unterhalb des klebenden Kopfs */
.scroll-target {
    scroll-margin-top: calc(var(--slf-header-h) + 0.25rem);
}
