/* ============================================================
   Riegenverwaltung – App Styles (portiert aus dem Altprojekt)
   ============================================================ */

:root {
    --app-primary: #0d6efd;
    --app-sidebar-width: 260px;
    --app-sidebar-bg: #1e293b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f5f6fa;
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--app-sidebar-width);
    height: 100vh;
    background: var(--app-sidebar-bg);
    color: #fff;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-header h5 { margin: 0; font-weight: 600; }
.sidebar-header small { opacity: 0.6; }

/* Riegen-Umschalter im Kopf */
.sidebar .tenant-switch .btn {
    width: 100%;
    text-align: left;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar .tenant-switch .btn:hover { background: rgba(255, 255, 255, 0.14); }
.sidebar .tenant-switch .btn .tenant-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .tenant-switch .dropdown-menu { width: 100%; }
.sidebar .tenant-switch .dropdown-item { white-space: normal; overflow-wrap: anywhere; }   /* lange Riegennamen umbrechen statt überlaufen */
.sidebar .tenant-switch .dropdown-item small { display: block; }
.sidebar .tenant-switch .dropdown-item.active { background: var(--app-primary); }

.sidebar .nav-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.sidebar .nav-scroll::-webkit-scrollbar { width: 6px; }
.sidebar .nav-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar .nav-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
.sidebar .nav-scroll::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); }

.sidebar .nav-section {
    display: block;
    padding: 0 1.2rem;
    margin-top: 1rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.45;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.7);
    padding: 0.6rem 1.2rem;
    border-radius: 0.375rem;
    margin: 0.1rem 0.5rem;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    white-space: nowrap;
}
.sidebar .nav-link:hover,
.sidebar .nav-link.active { color: #fff; background: rgba(255, 255, 255, 0.1); }
.sidebar .nav-link i { width: 1.5rem; text-align: center; margin-right: 0.5rem; flex-shrink: 0; }

/* Aufklappbarer Menüpunkt (Datenverwaltung → Import, später Sicherung) */
.sidebar button.nav-link { background: none; border: 0; text-align: left; }
.sidebar .nav-link .nav-caret { width: auto; margin-right: 0; margin-left: auto; font-size: 0.7rem; transition: transform 0.2s ease; }
.sidebar .nav-link[aria-expanded="true"] .nav-caret { transform: rotate(180deg); }
.sidebar .nav-sub .nav-link { padding-left: 2.4rem; }

.sidebar .sidebar-bottom { flex-shrink: 0; }
.sidebar .sidebar-user {
    padding: 1rem 1.2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.sidebar .sidebar-user .who { min-width: 0; }
.sidebar .sidebar-user .who small { display: block; opacity: 0.6; }
.sidebar .sidebar-user .who a { color: #fff; text-decoration: none; font-size: 0.9rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .sidebar-user .who a:hover { text-decoration: underline; }
.sidebar .sidebar-collapse-btn {
    width: 100%;
    border: 0;
    border-radius: 0;
    padding: 0.5rem;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
}
.sidebar .sidebar-collapse-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }

/* Eingeklappt: Sidebar komplett raus, Inhalt rückt nach (Desktop + Mobile gleich) */
html.sidebar-collapsed .sidebar { transform: translateX(-100%); }
html.sidebar-collapsed .main-content { margin-left: 0; padding-top: 3.5rem; }
html.sidebar-collapsed .sidebar-toggle-btn { display: flex !important; }

/* ---------- Hauptbereich ---------- */
.main-content {
    margin-left: var(--app-sidebar-width);
    padding: 1.5rem;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

/* Burger-Button: nur sichtbar auf Mobile oder wenn eingeklappt */
.sidebar-toggle-btn {
    display: none !important;
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 1001;
    align-items: center;
    justify-content: center;
}
.sidebar.show ~ .sidebar-toggle-btn { display: none !important; }

/* Overlay + Sidebar als Overlay (Mobile / eingeklappt) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}
.sidebar-overlay.show { display: block; }
.sidebar.show { transform: translateX(0) !important; }

@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; padding-top: 3.5rem; }
    .sidebar-toggle-btn { display: flex !important; }
}

/* ---------- Seiten ohne Login (Altprojekt-Design: Verlauf + zentrierte Karte) ---------- */
.auth-body {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    border-radius: 1rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.auth-icon { font-size: 2.5rem; line-height: 1; }
.auth-icon-primary { color: #0d6efd; }
.auth-icon-success { color: #198754; }
.auth-icon-dark    { color: #1e293b; }

/* 6-stelliger Code: gross, monospace, Ziffern auseinander – wirkt wie sechs Felder */
.code-input {
    font-size: 1.8rem;
    text-align: center;
    letter-spacing: 0.5rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-input::placeholder { letter-spacing: 0.5rem; opacity: 0.35; }

.secret-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.95rem;
    letter-spacing: 0.15rem;
    word-break: break-all;
    background: #f8f9fa;
    padding: 0.5rem;
    border-radius: 0.375rem;
    border: 1px solid #dee2e6;
}

/* ---------- Inline-Editing (Kontaktliste + Detailseite) ---------- */
[data-edit] { cursor: pointer; position: relative; }
[data-edit]:hover { background: #e8f0fe; box-shadow: inset 0 0 0 1px #9ec5fe; }
.edit-block { display: inline-block; min-width: 8rem; padding: .25rem .4rem; border-radius: .3rem; }
.contact-table td.editing { padding: .2rem .3rem; background: #fff; box-shadow: none; }
.contact-table td.editing .form-control,
.contact-table td.editing .form-select { min-width: 9rem; }
.contact-table tr.row-saved td { background: #d1e7dd; transition: background .2s; }
.cell-error { white-space: normal; max-width: 16rem; }
.rel-badge { background: #cfe2ff; color: #084298; font-weight: 500; }
.rel-badge.rel-foreign { background: #e9ecef; color: #6c757d; }

.inline-popover {
    position: fixed;
    z-index: 1050;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: .5rem;
    padding: .6rem;
    max-height: 360px;
    overflow-y: auto;
}
.popover-list { max-height: 240px; overflow-y: auto; }
.history-list { max-height: 24rem; overflow-y: auto; }   /* Verlauf: begrenzt, scrollt intern */
.popover-item {
    display: flex; align-items: center; width: 100%;
    padding: .3rem .4rem; border: 0; background: none; text-align: left; border-radius: .3rem; gap: .4rem;
}
.popover-item:hover { background: #f1f3f5; }
.popover-add { cursor: pointer; color: #198754; }
.popover-add::before { content: '+'; font-weight: 700; margin-right: .3rem; }

.save-indicator { position: fixed; bottom: 1rem; right: 1rem; z-index: 9999; animation: fadeIn .3s ease; margin: 0; }

/* Mehrfachauswahl der Kontaktliste: Häkchen-Spalte + Aktionsleiste (templates/contacts/index.php) */
.select-col { width: 2.2rem; text-align: center; }
.select-col .form-check-input { margin: 0; cursor: pointer; }
.bulk-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
    margin-bottom: .75rem; padding: .5rem .75rem;
    background: #e8f0fe; border: 1px solid #9ec5fe; border-radius: .5rem;
}
.bulk-panel { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; width: 100%; padding-top: .5rem; border-top: 1px solid #9ec5fe; }

/* ---------- Utilities (CSP erlaubt keine Inline-Styles) ---------- */
/* DIE eine begrenzte Inhaltsbreite (Design-Standard, Entscheid Sandro 2026-08-24):
   einfache Formulare/Schmalinhalte nutzen w-form-wide, alles andere volle Breite. */
.w-form-wide  { max-width: 48rem; }
.col-role     { width: 24rem; }
.col-fit      { width: 1%; white-space: nowrap; }   /* Spalte schrumpft auf den Inhalt (z.B. Letzter Login) */
.col-target   { width: 22rem; }
.col-decision { width: 18rem; }
.import-table td { white-space: normal; vertical-align: top; }
.cursor-default { cursor: default; }

/* ---------- Bausteine (aus dem Altprojekt, für Baustein 3 ff.) ---------- */
.table-container {
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    overflow-x: auto;
    width: 100%;
}
.table-container table { margin-bottom: 0; width: max-content; min-width: 100%; }
.table-container th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}
.table-container td { vertical-align: middle; font-size: 0.85rem; white-space: nowrap; padding: 0.4rem 0.5rem; }

/* Aktivitäten-Log: Aktions-Spalte umbrechen und in der Breite begrenzen – lange Details
   (Spalten-Listen, Diffs) strecken sonst die ganze Tabelle in eine Zeile. Die Breite sitzt auf dem
   inneren Block, weil max-width auf <td> nicht zuverlässig greift; der Selektor muss
   .table-container td (white-space: nowrap) an Spezifität schlagen. */
.table-container td.audit-action { white-space: normal; vertical-align: top; }
.audit-action .audit-action-content { max-width: 46rem; overflow-wrap: anywhere; }

/* M365-Sync: Protokoll-Zeilen als Liste mit Symbol statt Roh-Text (<pre>) */
.sync-log { list-style: none; padding-left: 0; margin: 0.25rem 0 0; }
.sync-log li { display: flex; gap: 0.4rem; align-items: baseline; padding: 0.1rem 0; overflow-wrap: anywhere; }
.sync-log li > i { flex-shrink: 0; }

.card { border: 0; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.card-header { background: #fff; font-weight: 600; }

.stat-card { background: #fff; border-radius: 0.5rem; padding: 1.2rem; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.stat-card .stat-number { font-size: 1.8rem; font-weight: 700; color: var(--app-primary); }

.search-box { position: relative; }
.search-box input { padding-left: 2.5rem; border-radius: 2rem; border: 1px solid #dee2e6; }
.search-box i { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: #6c757d; }

.filter-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }

.group-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 1rem;
    font-size: 0.7rem;
    font-weight: 500;
    margin: 1px;
    color: #fff;
    line-height: 1.3;
}

/* Gruppen-Zelle der Kontaktliste: feste Breite, max. zwei Badges + «+X» (templates/contacts/_row.php) */
.contact-table td.cell-groups { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }
.group-more { background: #6c757d; }

/* Reihenfolge per Drag & Drop (Gruppen, Zusatzfelder, Kontaktlisten-Spalten) */
.drag-col { width: 2rem; }
.check-col { width: 6rem; text-align: center; }
.drag-handle { cursor: grab; }
tr.dragging { opacity: 0.5; }
tr.dragging .drag-handle { cursor: grabbing; }
tbody[data-reorder-url] tr.row-saved td { background: #d1e7dd; transition: background 0.2s; }

/* Bild-Zuschneider (Einstellungen → Favicon) und Logo */
.crop-canvas { display: block; border: 1px solid #dee2e6; border-radius: 0.375rem; background: #f8f9fa; cursor: grab; touch-action: none; }
.crop-canvas:active { cursor: grabbing; }
.crop-stage { max-width: 240px; }
.crop-zoom { width: 192px; }
.settings-logo-preview { max-height: 48px; max-width: 160px; }
.auth-logo { max-height: 90px; max-width: 100%; margin-bottom: 0.75rem; }

/* Gruppen-Chips der Kontaktliste (wie im Alt-Tool): Badge-Optik, klickbar; aktiv = kräftig mit Ring */
button.group-chip {
    border: 0;
    cursor: pointer;
    opacity: 0.55;
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
}
button.group-chip:hover { opacity: 0.85; }
button.group-chip.active { opacity: 1; box-shadow: 0 0 0 2px rgba(33, 37, 41, 0.35); font-weight: 600; }

/* SharePoint-Ordner-Auswahl (Anbindungen): scrollbare Liste im Formular */
.sp-browser { max-height: 320px; overflow-y: auto; }
.sp-browse-list .list-group-item { border-left: 0; border-right: 0; }

/* Dashboard-Kacheln: klickbar mit dezentem Hover, grosses Icon rechts */
.dash-tile { transition: box-shadow 0.15s ease, transform 0.15s ease; }
a.dash-tile:hover { box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.12); transform: translateY(-2px); }
.dash-tile-icon { font-size: 2.2rem; color: #dee2e6; }

/* Fortschrittsbalken des M365-Syncs (natives <progress> – kein Inline-Style nötig, CSP) */
.sync-progress { display: block; width: 100%; height: 1.1rem; }

/* Nav-Badge (ausstehende Syncs) – gelbe Pille rechts im Menüeintrag */
.nav-badge {
    margin-left: auto;
    background: #ffc107;
    color: #212529;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.05rem 0.45rem;
    line-height: 1.3;
}

/* Farbpunkt der Gruppe in der Übersicht (Farbe setzt app.js über data-color, CSP-konform) */
.color-dot { display: inline-block; width: 0.85rem; height: 0.85rem; border-radius: 50%; vertical-align: -0.1rem; background: #adb5bd; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Mitgliederportal (Modul App\Portal): Kopfleiste im Sidebar-Farbton, ruhiger Hintergrund ---------- */
.portal-body { background: #f3f5f9; min-height: 100vh; }
.portal-navbar { background: #1e293b; }
.portal-logo { max-height: 32px; }
.portal-main { max-width: 64rem; }
.portal-level-col { width: 7.5rem; }
.portal-main .form-control-plaintext { padding-top: 0.25rem; padding-bottom: 0.25rem; min-height: 0; }

/* Änderungsanträge (Akkordeon pro Mitglied): EIN Raster für alle Kopfzeilen und Tabellen, damit die
   Blöcke untereinander bündig sind – Kopf: Name | Status | Datum; Tabelle: feste Spaltenbreiten. */
.rq-head { display: grid; grid-template-columns: minmax(0, 1fr) 8rem 9.5rem; align-items: center; column-gap: 0.75rem; width: 100%; padding-right: 0.5rem; }
.rq-head .rq-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rq-head .rq-by { display: block; font-weight: 400; }
.rq-head .rq-status { text-align: center; }
.rq-head .rq-date { text-align: right; }
.rq-table { table-layout: fixed; }
.rq-table td, .rq-table th { overflow-wrap: anywhere; }
.rq-table .rq-col-check { width: 3rem; }
.rq-table .rq-col-field { width: 22%; }
.rq-table .rq-col-date { width: 9.5rem; }
.rq-table .rq-col-status { width: 12rem; }
@media (max-width: 768px) {
    .rq-head { grid-template-columns: minmax(0, 1fr) 6rem; }
    .rq-head .rq-date { display: none; }
}

/* Portalnachrichten: Verlauf als Sprechblasen – Mitglied rechts (blau), Riege links (grau) */
.pm-log { display: flex; flex-direction: column; gap: 0.6rem; }
.pm-msg { max-width: 85%; padding: 0.5rem 0.75rem; border-radius: 0.75rem; }
.pm-member { align-self: flex-end; background: #e7f0fd; border-bottom-right-radius: 0.2rem; }
.pm-tenant { align-self: flex-start; background: #f1f3f5; border-bottom-left-radius: 0.2rem; }
.pm-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.pm-closed .card-header { background: #f8f9fa; }
/* Konversationen im Portal: farbiger Rand nach Status, damit jede Karte als eigene Konversation lesbar ist */
.pm-thread { border-left: 4px solid #adb5bd; }
.pm-thread.pm-open { border-left-color: #ffc107; }
.pm-thread.pm-answered { border-left-color: #198754; }
.pm-thread.pm-closed { border-left-color: #adb5bd; opacity: 0.9; }
.pm-thread .card-header .btn.collapsed .bi-chevron-down { transform: none; }
.pm-thread .card-header .btn .bi-chevron-down { transition: transform 0.2s; transform: rotate(180deg); }
.pm-new { border-left: 4px solid #0d6efd; }
/* Portal: klar getrennte Abschnitte (Mitgliederdaten | Nachrichten) */
.portal-section { margin-top: 3rem; padding-top: 1.5rem; border-top: 2px solid #dee2e6; }
/* Badge am aufklappbaren Menüpunkt (Untermenü «Mitgliederportal»): Zahl vor dem Pfeil */
.sidebar button.nav-link .nav-badge { order: 1; margin-left: auto; }
.sidebar button.nav-link .nav-caret { order: 2; margin-left: 0.5rem; }
/* Anmeldeseite mit Microsoft-Knopf: Trennlinie «oder mit Passwort» */
.auth-divider { display: flex; align-items: center; gap: 0.75rem; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; border-top: 1px solid #dee2e6; }
