/* ESZI Gebäude- und Industrie-Portal — zentrales Stylesheet.
   Alles Optische wird hier gesteuert. Eingebunden von layout.html
   und von den NFC-Feldansichten. */

/* ==================================================================
   Design-Tokens

   Es gibt zwei Themen. Umgeschaltet wird ueber das Attribut
   data-thema am <html>-Element:

       <html data-thema="dunkel">   oder   <html data-thema="hell">

   Das setzt ein kleines Skript im <head> von layout.html, bevor die
   Seite gezeichnet wird - sonst wuerde es kurz aufblitzen. Die Wahl
   liegt im localStorage unter "eszi:thema"; ohne gespeicherte Wahl
   richtet sich die Seite nach der Systemeinstellung des Geraets.

   Wer die Farbwelt aendern will, aendert diese beiden Bloecke und
   sonst nichts.
   ================================================================== */

/* ---- Gemeinsam: Masse, Formen, Schrift --------------------------- */
:root{
    /* Abstandsskala: nur diese Werte verwenden */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;
    --sp-7: 48px;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;

    /* Farbtoene der Status-Badges. Aus diesen Toenen rechnet sich
       jedes Badge Schrift, Flaeche und Rahmen selbst aus - siehe
       Abschnitt "Badges". Deshalb muss fuer Hell nichts doppelt
       gepflegt werden. */
    --h-neutral: #7d8797;
    --h-cyan: #0091c2;
    --h-magenta: #bf4080;
    --h-violet: #6d28d9;
    --h-orange: #c26500;

    /* Die Kopfleiste bleibt in BEIDEN Themen dunkel - sie ist das
       Markenband der Seite, kein Inhalt. Deshalb stehen ihre Farben
       hier und nicht in den Themenbloecken. */
    --topbar-bg: rgba(24, 27, 33, 0.94);
    --topbar-border: #333944;
    --topbar-text: #c8d0dc;
    --topbar-text-strong: #ffffff;
    --topbar-muted: #8f98a6;
    --topbar-hover: #2d333e;
    --topbar-accent: #e51414;

    /* ESZI-Schriftzug */
    --font-marke: "ESZI Schreibschrift", "Lucida Handwriting", "Segoe Script", cursive;
}

/* Nur der Schriftzug in der Kopfleiste braucht diese Schrift, deshalb
   ist sie auf die tatsaechlich benutzten Zeichen zusammengestrichen
   (92 KB TTF -> 21 KB WOFF). swap: der Text ist sofort lesbar und
   wird nachtraeglich ersetzt, falls die Datei noch laedt. */
@font-face{
    font-family: "ESZI Schreibschrift";
    src: url("fonts/lucida-handwriting-subset.woff") format("woff");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* ---- Dunkel (Standard) ------------------------------------------ */
:root,
:root[data-thema="dunkel"]{
    color-scheme: dark;

    /* Flaechen: neutrale Graustufen statt Blauschwarz.
       Der Hintergrund ist bewusst DUNKLER als die Karten - sonst
       hoeren die Karten auf, wie Karten zu wirken. */
    --bg: #1b1e24;
    --panel: #242830;
    --panel-2: #2a2f38;
    --panel-3: #20242b;
    --sunken: #171a20;
    --border: #383e49;
    --border-soft: #30353f;

    /* leichte Aufhellung fuer Hover und eingelassene Flaechen */
    --tint: rgba(255, 255, 255, 0.035);
    --tint-soft: rgba(255, 255, 255, 0.022);

    /* Schrift */
    --text: #eceff4;
    --text-strong: #ffffff;
    --muted: #a2abba;
    --muted-strong: #c3cbd8;

    /* Marke und Signale
       Rot ist die Marke und die EINE Primaeraktion pro Seite.
       Warnung, Fehler und Erfolg haben eigene Farben, damit Rot
       nicht gleichzeitig "Speichern" und "Achtung" bedeutet. */
    --accent: #d40000;
    --accent-hover: #ee1414;
    --accent-soft: rgba(212, 0, 0, 0.14);
    --accent-line: rgba(212, 0, 0, 0.38);
    --accent-text: #ff9e9e;
    --danger-text: #ff9a9a;

    --success: #34b57e;
    --warning: #d9930d;
    --danger: #e05252;
    --info: #5b9bd5;
    --link: #9ec7ff;

    --btn-bg: #2a2f38;
    --btn-bg-hover: #333945;
    --btn-bg-active: #262b33;
    --btn-border-hover: #4a5262;

    --sticky-bg: rgba(36, 40, 48, 0.96);
    /* Platzhalter muessen lesbar sein - sie sagen, was ins Feld gehoert.
       #7a828f lag genau auf der Grenze (4,5 : 1 auf dem Eingabefeld,
       darunter auf helleren Flaechen). Jetzt 5,8 : 1, und immer noch
       deutlich blasser als echter Text (15 : 1). */
    --platzhalter: #8d95a2;

    --shadow: 0 1px 2px rgba(0,0,0,0.30), 0 8px 24px rgba(0,0,0,0.22);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.28);

    /* Rezept fuer Badges und Meldungen: im Dunkeln wird der Farbton
       zur Schrift hin aufgehellt. */
    --ton-fg-gegen: #ffffff;
    --ton-fg-anteil: 40%;
    --ton-bg-anteil: 15%;
    --ton-bd-anteil: 36%;
}

/* ---- Hell -------------------------------------------------------- */
:root[data-thema="hell"]{
    color-scheme: light;

    --bg: #eff1f4;
    --panel: #ffffff;
    --panel-2: #f7f8fa;
    --panel-3: #f6f7f9;
    --sunken: #ffffff;
    --border: #d4d9e0;
    --border-soft: #e4e7ec;

    --tint: rgba(16, 24, 40, 0.035);
    --tint-soft: rgba(16, 24, 40, 0.022);

    --text: #1c2028;
    --text-strong: #0d1017;
    --muted: #5d6b80;
    --muted-strong: #475467;

    /* Reines #d40000 flimmert auf Weiss, deshalb einen Hauch dunkler. */
    --accent: #c40000;
    --accent-hover: #a30000;
    --accent-soft: rgba(196, 0, 0, 0.08);
    --accent-line: rgba(196, 0, 0, 0.28);
    --accent-text: #a30000;
    --danger-text: #9f1f15;

    --success: #067647;
    --warning: #b54708;
    --danger: #b42318;
    --info: #175cd3;
    --link: #175cd3;

    --btn-bg: #ffffff;
    --btn-bg-hover: #f2f4f7;
    --btn-bg-active: #eaecf0;
    --btn-border-hover: #b3bac6;

    --sticky-bg: rgba(255, 255, 255, 0.96);
    /* Vorher #98a2b3: 2,6 : 1 auf Weiss - "z. B. 24 V DC" war kaum zu
       erkennen. Jetzt 5,0 : 1, gegen 16 : 1 fuer echten Text. */
    --platzhalter: #5b6578;

    --shadow: 0 1px 2px rgba(16,24,40,0.06), 0 10px 24px rgba(16,24,40,0.07);
    --shadow-sm: 0 1px 2px rgba(16,24,40,0.07);

    /* Im Hellen wird der Farbton zur Schrift hin abgedunkelt. */
    --ton-fg-gegen: #000000;
    --ton-fg-anteil: 12%;
    --ton-bg-anteil: 10%;
    --ton-bd-anteil: 32%;
    /* Neutrales Grau fuer Badges: im hellen Thema dunkler, sonst
       reicht der Kontrast der kleinen Schrift nicht (3,8:1). */
    --h-neutral: #667085;
}

*{
    box-sizing: border-box;
}

html, body{
    overflow-x: hidden;
}

body{
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body.explorer-open{
    overflow: hidden;
}

h1, h2, h3{
    line-height: 1.25;
    letter-spacing: -0.01em;
}

h2{
    font-size: 1.12rem;
}

a{
    color: var(--text);
    text-decoration: none;
}

a:hover{
    color: var(--text-strong);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Fliesstext-Links bekommen eine eigene Farbe, damit man sieht,
   was klickbar ist. Buttons und Explorer sind ausgenommen. */
.portal-section-body a:not(.btn),
.card p a:not(.btn),
td a:not(.btn){
    color: var(--link);
}

:focus-visible{
    outline: 2px solid var(--link);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- */
/* Topbar                                                            */
/* ---------------------------------------------------------------- */
.topbar{
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--topbar-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--topbar-border);
    color: var(--topbar-text);
}

/* Alles in der Kopfleiste erbt die hellen Schriftfarben, damit im
   hellen Thema nicht dunkel auf dunkel steht. */
.topbar a{
    color: var(--topbar-text);
}

.topbar a:hover{
    color: var(--topbar-text-strong);
}

.topbar .muted{
    color: var(--topbar-muted);
}

.topbar-inner{
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-4);
}

.brand-wrap{
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-width: 0;
}

.brand{
    font-size: 1.02rem;
    font-weight: 650;
    letter-spacing: 0;
    min-width: 0;
    color: var(--topbar-text-strong);
}

.brand-zeile{
    display: flex;
    align-items: baseline;
    gap: 0.5em;
    min-width: 0;
}

/* Der Schriftzug ESZI. Die Schrift laeuft duenn und klein, deshalb
   deutlich groesser gesetzt als der Rest der Zeile. */
.brand-zeile > span:first-child{
    font-family: var(--font-marke);
    font-weight: 400;
    font-size: 1.65em;
    line-height: 1;
    letter-spacing: 0.02em;
    color: var(--topbar-accent);
    flex: 0 0 auto;
}

.brand-text{
    min-width: 0;
    white-space: nowrap;
}

/* Wird die Leiste eng, bleibt nur das Zeichen stehen - besser als
   ein zweizeiliger Titel. */
@media (max-width: 1280px){
    .brand-text{
        display: none;
    }
}

.top-links{
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
}

/* Umschalter Hell/Dunkel. Steht bewusst vor den Navigationslinks,
   damit er auch auf der Anmeldeseite erreichbar ist. */
.thema-schalter{
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: 36px;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--topbar-border);
    background: transparent;
    color: var(--topbar-text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.thema-schalter:hover{
    background: var(--topbar-hover);
    border-color: var(--topbar-text-strong);
    color: var(--topbar-text-strong);
}

.thema-zeichen{
    font-size: 1rem;
    line-height: 1;
}

@media (max-width: 560px){
    /* Am Handy reicht das Zeichen, der Platz wird knapp. */
    .thema-wort{
        display: none;
    }
}

/* Navigation in der Topbar ist kein Button-Feld: flacher, ruhiger */
.top-links .btn{
    background: transparent;
    border-color: transparent;
    color: var(--topbar-text);
    min-height: 36px;
    padding: var(--sp-2) var(--sp-3);
    font-weight: 500;
}

.top-links .btn:hover{
    background: var(--topbar-hover);
    border-color: var(--topbar-border);
    color: var(--topbar-text-strong);
    transform: none;
    text-decoration: none;
}

.top-links .btn-primary{
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

/* ---------------------------------------------------------------- */
/* Grundgeruest                                                      */
/* ---------------------------------------------------------------- */
/* Der Inhalt nutzt die volle Fensterbreite. Frueher war hier bei
   1960px Schluss und der Inhalt darin nochmal bei 1360px - auf einem
   grossen Monitor blieb dadurch fast die Haelfte ungenutzt. */
.shell{
    max-width: none;
    margin: 0 auto;
    padding: var(--sp-5) var(--sp-5) var(--sp-7);
}

.shell.with-explorer{
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: var(--sp-5);
    align-items: start;
}

.content-area{
    min-width: 0;
    grid-column: 2;
}

/* Hielt frueher den Rest der Zeile frei. Wird nicht mehr gebraucht,
   bleibt aber im Markup stehen, damit kein Template anzufassen ist. */
.shell-gutter{
    display: none;
}

.container{
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0 0 var(--sp-7);
    min-width: 0;
}

/* Breite hilft Rastern und Tabellen. Lesetext und Beschriftung-Wert-
   Paare brauchen dagegen eine Grenze, sonst wandert das Auge beim
   Zeilenwechsel ins Leere und Wert und Beschriftung reissen auseinander. */
.kv{
    max-width: 780px;
}

.page-subtitle,
.portal-section-body p,
.field-hint,
.todo-card-textblock{
    max-width: 92ch;
}

.field input,
.field select{
    max-width: 680px;
}

.field textarea{
    max-width: 1000px;
}

.page-title{
    margin: 0 0 var(--sp-2);
    font-size: 1.65rem;
    font-weight: 650;
}

.page-subtitle{
    margin: 0 0 var(--sp-5);
    color: var(--muted);
    font-size: 0.95rem;
}

/* ---------------------------------------------------------------- */
/* Karten                                                            */
/* ---------------------------------------------------------------- */
.card{
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-5);
    min-width: 0;
}

.card + .card{
    margin-top: var(--sp-4);
}

/* Abstand ZWISCHEN den Bloecken einer Seite kommt ab hier zentral und
   nicht mehr aus einzelnen style="margin-top"-Angaben in den Templates.
   Das schliesst auch die Luecke, die entstand, wenn direkt hinter einer
   Karte ein Raster stand: das Raster ist keine Karte, also griff die
   Regel darunter nicht und der Block klebte oben an.

   "~" statt "+": das Plus verlangt, dass zwei Bloecke im Quelltext
   unmittelbar nebeneinanderstehen. Ein <style> oder <script> dazwischen
   - unsichtbar, aber ein eigenes Element - reichte, und der Abstand
   fiel auf null. Genau so klebte auf jeder Einheit-Seite "Zaehler /
   Zuordnung" an den "Mieterzugaengen". Die Tilde fragt nur, ob vorher
   schon ein Block stand.

   Die Knopfleiste und das Dashboard-Raster gehoeren mit in die Liste:
   stand eine Karte direkt unter einer Leiste ohne eigenen Abstand, oder
   unter dem Dashboard-Raster, fehlte er ebenfalls ganz. */
.container > :is(.card, .grid-2, .grid-3, .table-wrap, .todo-list, .btn-row, .dashboard-grid)
    ~ :is(.card, .grid-2, .grid-3, .table-wrap, .todo-list, .btn-row, .dashboard-grid){
    margin-top: var(--sp-4);
}

/* Eine Knopfleiste auf Seitenebene haelt nach unten immer 16 px -
   gleich, was darunter folgt. Die Regel oben greift nur, wenn der
   naechste Block eine bekannte Klasse traegt; unter manchen Leisten steht
   aber ein eigener Wrapper (das Heartbeat-Raster, die Stoerungsliste,
   das Live-Raster, ein Formular). Frueher hat jede dieser Leisten ihre
   18 px per style="margin-bottom" selbst mitgebracht. Der Container ist
   ein Blockelement, die beiden Abstaende fallen also zusammen - wo die
   Regel oben auch greift, bleibt es bei 16 px, nicht 32. */
.container > .btn-row{
    margin-bottom: var(--sp-4);
}

/* Dasselbe eine Ebene tiefer: viele Bearbeiten-Seiten stecken ihre
   Karten in ein einziges <form>, das dann der eigentliche Seiteninhalt
   ist. Die Regel oben erreicht diese Karten nicht, sie brachten ihren
   Abstand deshalb jede fuer sich per style="margin-top" mit - mal 18,
   mal 20 px. */
.container > form > :is(.card, .grid-2, .grid-3, .table-wrap, .btn-row)
    ~ :is(.card, .grid-2, .grid-3, .table-wrap, .btn-row){
    margin-top: var(--sp-4);
}

/* Seiten ohne Untertitel. Ueblich ist Titel - Untertitel - Inhalt, mit
   24 px vor dem Inhalt. Fehlt der Untertitel, blieben nur die 8 px, die
   sonst zwischen Titel und Untertitel stehen, und die erste Karte hing
   am Titel. */
.container > .page-title + :not(.page-subtitle, style, script){
    margin-top: var(--sp-5);
}

/* Untereinander gestapelte Karten brauchen Abstand nach oben,
   NEBENEINANDER liegende nicht: im Raster hat das die zweite Karte
   sonst um 16px nach unten geschoben - genau das sah verschoben aus.
   Auch hier "~" statt "+", aus demselben Grund wie oben. */
.grid-2 > .card ~ .card,
.grid-2 > details.portal-section ~ details.portal-section,
.grid-3 > .card ~ .card,
.grid-3 > details.portal-section ~ details.portal-section,
.todo-card-grid > .card ~ .card,
.mieter-karten > .card ~ .card,
.mieter-post > .card ~ .card,
.detail-grid-wrap > .card ~ .card,
.detail-grid-2 > .card ~ .card{
    margin-top: 0;
}

.card .card{
    background: var(--panel-3);
    box-shadow: none;
}

/* ---------------------------------------------------------------- */
/* Buttons                                                           */
/* Eine rote Primaeraktion pro Seite. Alles andere ist neutral.       */
/* Loeschen ist ein Umriss-Button, kein Fuellton.                     */
/* ---------------------------------------------------------------- */
.btn{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: 40px;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--btn-bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.94rem;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover{
    background: var(--btn-bg-hover);
    border-color: var(--btn-border-hover);
    color: var(--text-strong);
    text-decoration: none;
}

.btn:active{
    background: var(--btn-bg-active);
}

.btn-primary{
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover{
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.btn-danger{
    background: transparent;
    border-color: color-mix(in srgb, var(--danger) 45%, transparent);
    color: var(--danger-text);
}

.btn-danger:hover{
    background: color-mix(in srgb, var(--danger) 14%, transparent);
    border-color: color-mix(in srgb, var(--danger) 70%, transparent);
    color: var(--danger-text);
}

.btn-ghost{
    background: transparent;
    border-color: transparent;
    color: var(--muted-strong);
}

.btn-ghost:hover{
    background: var(--panel-2);
    border-color: var(--border-soft);
}

/* Ein <summary class="btn"> soll kein Dreieck zeigen */
summary.btn{
    list-style: none;
}

summary.btn::-webkit-details-marker{
    display: none;
}

.btn-sm{
    min-height: 32px;
    padding: var(--sp-1) var(--sp-3);
    font-size: 0.87rem;
}

/* Aktionen in Tabellenzellen duerfen die Zeile nicht sprengen */
td .btn{
    min-height: 32px;
    padding: var(--sp-1) var(--sp-3);
    font-size: 0.87rem;
}

td .btn-row{
    gap: var(--sp-2);
}

.btn-row{
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
    align-items: stretch;
}

.btn-row form{
    margin: 0;
}

/* Aktionsleiste: Primaeres links, Gefaehrliches rechts abgesetzt */
.action-bar{
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
}

.action-bar .spacer{
    flex: 1 1 auto;
}

.action-bar form{
    margin: 0;
}

/* Aufklappmenue fuer selten gebrauchte Aktionen */
details.menu{
    position: relative;
}

details.menu > summary{
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: 40px;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    font-size: 0.94rem;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
}

details.menu > summary::-webkit-details-marker{
    display: none;
}

details.menu > summary:hover{
    background: var(--btn-bg-hover);
    border-color: var(--btn-border-hover);
}

.menu-panel{
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 20;
    min-width: 230px;
    display: grid;
    gap: 2px;
    padding: var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel-2);
    box-shadow: var(--shadow);
}

.menu-panel a,
.menu-panel button{
    display: block;
    width: 100%;
    text-align: left;
    padding: var(--sp-2) var(--sp-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 0.94rem;
    cursor: pointer;
}

.menu-panel a:hover,
.menu-panel button:hover{
    background: var(--panel);
    color: var(--text-strong);
    text-decoration: none;
}

.menu-panel form{
    margin: 0;
}

.action-sep{
    width: 1px;
    align-self: stretch;
    min-height: 28px;
    background: var(--border);
    margin: 0 var(--sp-1);
}

/* ---------------------------------------------------------------- */
/* Formulare                                                         */
/* ---------------------------------------------------------------- */
.grid-2{
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-4);
}

.grid-3{
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--sp-4);
}

.field{
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.field label{
    color: var(--muted-strong);
    font-size: 0.88rem;
    font-weight: 600;
}

/* Grundform fuer alle Eingabefelder, die keine eigene Gestaltung haben.
   Ohne diese Regel zeichnet der Browser im dunklen Thema seine eigenen
   Felder (#3b3b3b, Platzhalter #757575 = Kontrast 2,4:1). :where() hat
   keine Spezifitaet - jede Regel einer Seite gewinnt weiterhin. */
:where(input:not([type=checkbox], [type=radio], [type=range], [type=color], [type=file], [type=submit], [type=button], [type=reset], [type=image]), select, textarea){
    background-color: var(--sunken);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

:where(input, textarea)::placeholder{
    color: var(--platzhalter);
    opacity: 1;
}

.field input,
.field select,
.field textarea{
    width: 100%;
    padding: 10px var(--sp-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--sunken);
    color: var(--text);
    outline: none;
    font-family: inherit;
    font-size: 16px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder,
.field textarea::placeholder{
    color: var(--platzhalter);
}

.field input:hover,
.field select:hover,
.field textarea:hover{
    border-color: var(--btn-border-hover);
}

.field input:focus,
.field select:focus,
.field textarea:focus{
    border-color: var(--link);
    box-shadow: 0 0 0 3px rgba(158, 199, 255, 0.16);
}

.field textarea{
    min-height: 110px;
    resize: vertical;
    line-height: 1.55;
}

.field-hint{
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0;
}

.check-row{
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    cursor: pointer;
    color: var(--muted-strong);
    font-size: 0.94rem;
    font-weight: 600;
    line-height: 1.35;
    margin: 0;
    width: auto;
}

/* Auswahlknoepfe verhalten sich wie Haken - dieselbe Zeile, dieselbe
   Groesse. Ohne diese Regel zieht ".field input { width: 100% }" sie
   auf volle Breite, und die Beschriftung landet am rechten Rand, weit
   weg von dem, wozu sie gehoert. */
.check-row input[type="checkbox"],
.check-row input[type="radio"]{
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    flex: 0 0 18px;
    accent-color: var(--accent);
    box-shadow: none;
}

.check-row span{
    color: var(--muted-strong);
}

.field .check-row input[type="checkbox"],
.field .check-row input[type="radio"]{
    border: none;
    background: transparent;
    outline: none;
}

/* Formularabschnitt mit Ueberschrift */
.form-section{
    scroll-margin-top: 90px;
}

.form-section + .form-section{
    margin-top: var(--sp-6);
    padding-top: var(--sp-5);
    border-top: 1px solid var(--border-soft);
}

.form-section > h2{
    margin: 0 0 var(--sp-4);
    font-size: 1.02rem;
    color: var(--text-strong);
}

/* Sprungleiste ueber langen Formularen */
.section-nav{
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
}

.section-nav a{
    padding: 6px var(--sp-3);
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel-3);
    color: var(--muted-strong);
    font-size: 0.88rem;
    font-weight: 600;
}

.section-nav a:hover{
    background: var(--panel-2);
    color: var(--text-strong);
    text-decoration: none;
}

/* Speichern bleibt immer erreichbar */
.form-actions{
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-3);
    margin: var(--sp-5) calc(-1 * var(--sp-5)) calc(-1 * var(--sp-5));
    padding: var(--sp-3) var(--sp-5);
    background: var(--sticky-bg);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
}

.form-actions .spacer{
    flex: 1 1 auto;
}

.dirty-hint{
    color: var(--warning);
    font-size: 0.88rem;
    font-weight: 600;
}

/* ---------------------------------------------------------------- */
/* Werteliste: macht <p><strong>Label:</strong> Wert</p> lesbar,      */
/* ohne dass ein einziges Template angefasst werden muss.            */
/* ---------------------------------------------------------------- */
.portal-section-body p{
    margin: 0 0 var(--sp-2);
}

/* Hängender Einzug: die erste Zeile zieht das Label nach links,
   alle Folgezeilen und alles nach einem <br> bleiben in der
   Wertespalte stehen statt an den linken Rand zu rutschen. */
.portal-section-body p:has(> strong:first-child){
    padding-left: 198px;
    text-indent: -198px;
}

.portal-section-body p > strong:first-child{
    display: inline-block;
    min-width: 186px;
    padding-right: var(--sp-3);
    color: var(--muted);
    font-weight: 550;
    text-indent: 0;
    vertical-align: top;
}

/* In zweispaltigen Bereichen ist weniger Platz */
.portal-section-body .grid-2 p:has(> strong:first-child),
.portal-section-body .todo-card-grid p:has(> strong:first-child){
    padding-left: 160px;
    text-indent: -160px;
}

.portal-section-body .grid-2 p > strong:first-child,
.portal-section-body .todo-card-grid p > strong:first-child{
    min-width: 148px;
}

.kv{
    display: grid;
    grid-template-columns: 186px minmax(0, 1fr);
    gap: var(--sp-2) var(--sp-3);
    align-items: baseline;
}

.kv dt{
    color: var(--muted);
    font-weight: 550;
    margin: 0;
}

.kv dd{
    margin: 0;
    color: var(--text);
    min-width: 0;
    word-break: break-word;
}

/* ---------------------------------------------------------------- */
/* Tabellen                                                          */
/* ---------------------------------------------------------------- */
.table-wrap{
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
}

table{
    width: 100%;
    border-collapse: collapse;
}

th, td{
    text-align: left;
    padding: 10px var(--sp-3);
    border-bottom: 1px solid var(--border-soft);
    vertical-align: top;
}

thead th,
tr:first-child th{
    background: var(--panel-3);
}

th{
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

td{
    color: var(--text);
    font-size: 0.94rem;
}

tbody tr:hover td,
tr:hover td{
    background: var(--tint-soft);
}

tr:last-child td{
    border-bottom: 0;
}

/* ---------------------------------------------------------------- */
/* Badges                                                            */
/* ---------------------------------------------------------------- */
.badge{
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 650;
    border: 1px solid var(--border);
    background: var(--panel-3);
    white-space: nowrap;
}

/* Jedes Badge rechnet Schrift, Flaeche und Rahmen aus EINEM Farbton
   aus. Das Rezept (--ton-*) steht im Themenblock oben, deshalb sitzen
   die Badges in Hell und Dunkel ohne doppelte Pflege richtig. */
.badge-aktiv,
.badge-inaktiv,
.badge-stoerung,
.badge-wartung,
.badge-status-neu,
.badge-status-offen,
.badge-status-in-bearbeitung,
.badge-status-wartet-fremdfirma,
.badge-status-wartet-ersatzteil,
.badge-status-erledigt,
.badge-status-verworfen,
.badge-prio-niedrig,
.badge-prio-mittel,
.badge-prio-hoch,
.badge-prio-kritisch{
    color: color-mix(in srgb, var(--ton), var(--ton-fg-gegen) var(--ton-fg-anteil));
    background: color-mix(in srgb, var(--ton) var(--ton-bg-anteil), transparent);
    border-color: color-mix(in srgb, var(--ton) var(--ton-bd-anteil), transparent);
}

.badge-aktiv{ --ton: var(--success); }
.badge-inaktiv{ --ton: var(--h-neutral); }
.badge-stoerung{ --ton: var(--danger); }
.badge-wartung{ --ton: var(--warning); }
.badge-status-neu{ --ton: var(--info); }
.badge-status-offen{ --ton: var(--warning); }
.badge-status-in-bearbeitung{ --ton: var(--h-cyan); }
.badge-status-wartet-fremdfirma{ --ton: var(--h-magenta); }
.badge-status-wartet-ersatzteil{ --ton: var(--h-violet); }
.badge-status-erledigt{ --ton: var(--success); }
.badge-status-verworfen{ --ton: var(--h-neutral); }
.badge-prio-niedrig{ --ton: var(--h-neutral); }
.badge-prio-mittel{ --ton: var(--warning); }
.badge-prio-hoch{ --ton: var(--h-orange); }
.badge-prio-kritisch{ --ton: var(--danger); }

.badge-status-standard,
.badge-prio-standard{ color: var(--muted-strong); }

.ticket-badge{
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent-line);
    background: var(--accent-soft);
    color: var(--accent-text);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 650;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- */
/* To-do-Karten                                                      */
/* ---------------------------------------------------------------- */
.todo-title{
    font-weight: 650;
    color: var(--text-strong);
    margin-bottom: var(--sp-1);
}

.todo-subline{
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.todo-detail{
    background: var(--panel-3);
    border-left: 3px solid var(--border);
}

.todo-detail.todo-detail-status-neu{ border-left-color: #5b9bd5; }
.todo-detail.todo-detail-status-offen{ border-left-color: #d9930d; }
.todo-detail.todo-detail-status-in-bearbeitung{ border-left-color: #0091c2; }
.todo-detail.todo-detail-status-wartet-fremdfirma{ border-left-color: #bf4080; }
.todo-detail.todo-detail-status-wartet-ersatzteil{ border-left-color: #6d28d9; }
.todo-detail.todo-detail-status-erledigt{ border-left-color: #34b57e; }
.todo-detail.todo-detail-status-verworfen{ border-left-color: #788294; }

.todo-list{
    display: grid;
    gap: var(--sp-3);
}

.todo-card{
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.todo-card > summary{
    list-style: none;
}

.todo-card > summary::-webkit-details-marker{
    display: none;
}

.todo-card-head{
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: transparent;
    cursor: pointer;
}

.todo-card[open] .todo-card-head{
    border-bottom: 1px solid var(--border-soft);
}

.todo-card-head:hover{
    background: var(--tint-soft);
}

.todo-card-head-main{
    min-width: 0;
    display: grid;
    gap: var(--sp-2);
    flex: 1 1 auto;
}

.todo-card-summary-note{
    color: var(--muted);
    font-size: 0.88rem;
}

.todo-card-toggle{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--muted-strong);
    font-size: 1rem;
    font-weight: 700;
    flex: 0 0 auto;
    transition: transform 0.18s ease;
}

.todo-card[open] .todo-card-toggle{
    transform: rotate(90deg);
}

.todo-card-badges{
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    align-items: center;
}

.todo-card-actions{
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    min-width: 170px;
}

.todo-card-body{
    padding: var(--sp-4);
    display: grid;
    gap: var(--sp-4);
}

.todo-card-grid{
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--sp-3);
}

.todo-card-field{
    padding: var(--sp-3);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    border: 1px solid var(--border-soft);
}

.todo-card-label{
    display: block;
    margin-bottom: var(--sp-1);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.todo-card-value{
    color: var(--text);
    line-height: 1.55;
    word-break: break-word;
}

.todo-card-textblock{
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    border-left: 3px solid var(--accent-line);
}

.todo-card-textblock strong{
    color: var(--muted-strong);
}

.todo-attachments{
    display: grid;
    gap: var(--sp-3);
}

.todo-attachment-list{
    display: grid;
    gap: var(--sp-3);
}

.todo-attachment-item{
    padding: var(--sp-3);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    border: 1px solid var(--border-soft);
}

.todo-attachment-preview{
    display: block;
    width: 100%;
    max-width: 280px;
    max-height: 180px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    margin-bottom: var(--sp-2);
}

.todo-attachment-name{
    font-weight: 650;
    color: var(--text-strong);
    word-break: break-word;
}

.todo-attachment-meta{
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: var(--sp-1);
    line-height: 1.5;
}

/* Platzhalter fuer eine hochgeladene Datei, die auf der Platte fehlt.
   Ehrlicher als das kaputte Bildsymbol des Browsers. */
.bild-fehlt{
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
    background: var(--panel-3);
    color: var(--muted);
    font-size: 0.8rem;
    text-align: center;
    padding: var(--sp-2);
}

/* ---------------------------------------------------------------- */
/* Meldungen                                                         */
/* ---------------------------------------------------------------- */
.flash{
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-sm);
    margin-bottom: var(--sp-3);
    border: 1px solid var(--border);
    border-left-width: 3px;
    font-size: 0.94rem;
}

.flash.error{
    --ton: var(--danger);
    background: color-mix(in srgb, var(--ton) 10%, transparent);
    border-color: color-mix(in srgb, var(--ton) 30%, transparent);
    border-left-color: var(--ton);
    color: color-mix(in srgb, var(--ton), var(--ton-fg-gegen) var(--ton-fg-anteil));
}

.flash.success{
    --ton: var(--success);
    background: color-mix(in srgb, var(--ton) 10%, transparent);
    border-color: color-mix(in srgb, var(--ton) 30%, transparent);
    border-left-color: var(--ton);
    color: color-mix(in srgb, var(--ton), var(--ton-fg-gegen) var(--ton-fg-anteil));
}

.flash.info{
    --ton: var(--info);
    background: color-mix(in srgb, var(--ton) 10%, transparent);
    border-color: color-mix(in srgb, var(--ton) 30%, transparent);
    border-left-color: var(--ton);
    color: color-mix(in srgb, var(--ton), var(--ton-fg-gegen) var(--ton-fg-anteil));
}

.flash.warning{
    --ton: var(--warning);
    background: color-mix(in srgb, var(--ton) 10%, transparent);
    border-color: color-mix(in srgb, var(--ton) 30%, transparent);
    border-left-color: var(--ton);
    color: color-mix(in srgb, var(--ton), var(--ton-fg-gegen) var(--ton-fg-anteil));
}

.auth-wrap{
    max-width: 460px;
    margin: var(--sp-7) auto;
}

.muted{
    color: var(--muted);
}

/* ---------------------------------------------------------------- */
/* Klappbare Abschnitte                                              */
/* ---------------------------------------------------------------- */
details.portal-section{
    padding: 0;
    overflow: hidden;
    scroll-margin-top: 80px;
}

details.portal-section + details.portal-section{
    margin-top: var(--sp-4);
}

.portal-section-summary{
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}

.portal-section-summary:hover{
    background: var(--tint-soft);
}

.portal-section-summary::-webkit-details-marker{
    display: none;
}

.portal-section-summary h2{
    margin: 0;
    min-width: 0;
    font-size: 1.02rem;
}

.portal-section-summary-text{
    display: flex;
    align-items: baseline;
    gap: var(--sp-3);
    min-width: 0;
    flex: 1 1 auto;
}

.portal-section-summary-note{
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
}

.portal-section-caret{
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 1rem;
    transition: transform 0.18s ease;
}

details.portal-section[open] .portal-section-caret{
    transform: rotate(90deg);
}

details.portal-section[open] .portal-section-summary{
    border-bottom: 1px solid var(--border-soft);
}

.portal-section-body{
    padding: var(--sp-5);
    min-width: 0;
}

.portal-section-body > :first-child{
    margin-top: 0;
}

/* ---------------------------------------------------------------- */
/* Explorer                                                          */
/* ---------------------------------------------------------------- */
.explorer-toggle{
    display: none;
    min-height: 40px;
    min-width: 40px;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--topbar-border);
    background: var(--topbar-hover);
    color: var(--topbar-text-strong);
    font-weight: 700;
    cursor: pointer;
}

.explorer-backdrop{
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 12, 0.6);
    z-index: 34;
}

.explorer{
    align-self: stretch;
    min-width: 0;
    overflow: visible;
}

.explorer-panel{
    position: static;
    top: auto;
    max-height: none;
    overflow: visible;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-4);
}

.explorer-head{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-3);
}

.explorer-title{
    margin: 0;
    font-size: 0.8rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.explorer-close{
    display: none;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    border-radius: var(--radius-sm);
    min-width: 34px;
    min-height: 34px;
    cursor: pointer;
}

.explorer-search{
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--sunken);
    color: var(--text);
    font-family: inherit;
    font-size: 0.94rem;
    margin-bottom: var(--sp-3);
}

.explorer-search:focus{
    outline: none;
    border-color: var(--link);
    box-shadow: 0 0 0 3px rgba(158, 199, 255, 0.16);
}

.explorer-links{
    display: grid;
    gap: var(--sp-1);
    margin-bottom: var(--sp-4);
}

.explorer-link,
.explorer-item-link,
.explorer-building-link{
    display: block;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: background 0.15s ease, color 0.15s ease;
}

.explorer-link:hover,
.explorer-item-link:hover,
.explorer-building-link:hover{
    text-decoration: none;
}

.explorer-link{
    background: transparent;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.94rem;
    color: var(--muted-strong);
}

.explorer-link:hover,
.explorer-item-link:hover{
    background: var(--panel-2);
    color: var(--text-strong);
}

.explorer-link.active,
.explorer-item-link.active{
    background: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--accent-text);
    font-weight: 650;
}

.explorer-tree{
    display: grid;
    gap: var(--sp-2);
}

.explorer-group{
    --explorer-building-color: var(--accent);
    --explorer-building-hover: var(--accent-hover);
    --explorer-section-color: var(--muted);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    overflow: hidden;
}

.explorer-group > summary{
    list-style: none;
    cursor: pointer;
    padding: 0;
}

.explorer-group > summary::-webkit-details-marker{
    display: none;
}

.explorer-summary-row{
    display: flex;
    align-items: stretch;
}

/* Die Gebaeudefarbe wird zum Streifen links statt zur Vollflaeche.
   Damit bleibt die Seitenleiste ruhig und die Farbe trotzdem lesbar. */
.explorer-building-link{
    position: relative;
    flex: 1 1 auto;
    font-weight: 650;
    font-size: 0.95rem;
    background: transparent;
    color: var(--text-strong);
    border-radius: 0;
    border-left: 3px solid var(--explorer-building-color);
    padding: var(--sp-3);
}

.explorer-building-link small{
    display: block;
    color: var(--muted);
    font-weight: 400;
    font-size: 0.84rem;
    margin-top: 2px;
}

.explorer-building-link:hover{
    background: var(--panel-2);
    color: var(--text-strong);
}

/* Woran gerade gearbeitet wird, muss man auf einen Blick sehen - sonst
   traegt man Daten im falschen Gebaeude ein. Deshalb nicht nur eine
   Toenung wie beim Ueberfahren, sondern ein breiter farbiger Balken,
   ein Akzentgrund und das Woertchen "Hier". */
.explorer-building-link.active{
    background: var(--accent-soft);
    color: var(--accent-text);
    border-left-width: 6px;
    padding-left: calc(var(--sp-3) - 3px);
    font-weight: 700;
}

.explorer-building-link.active small{
    color: var(--accent-text);
    opacity: 0.85;
}

.explorer-hier{
    display: inline-block;
    margin-right: 8px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    vertical-align: 1px;
}

/* Der ganze Ast bekommt eine Kante, damit er sich auch im aufgeklappten
   Zustand vom Rest abhebt. */
.explorer-group.ist-aktiv{
    border-radius: var(--radius-sm);
    box-shadow: inset 0 0 0 1px var(--accent-line);
    background: color-mix(in srgb, var(--accent), transparent 96%);
}

.explorer-caret{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.18s ease, color 0.15s ease;
}

.explorer-group[open] .explorer-caret{
    transform: rotate(90deg);
}

.explorer-caret:hover{
    color: var(--text-strong);
}

.explorer-sections{
    padding: 0 var(--sp-2) var(--sp-2);
    display: grid;
    gap: var(--sp-2);
}

.explorer-section-title{
    margin: 0 0 var(--sp-1);
    padding: var(--sp-1) var(--sp-2);
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.explorer-category > summary{
    cursor: pointer;
    list-style: none;
}

.explorer-category > summary::-webkit-details-marker{
    display: none;
}

.explorer-category > summary:hover{
    color: var(--text-strong);
}

.explorer-items{
    display: grid;
    gap: 2px;
}

.explorer-subgroups{
    display: grid;
    gap: var(--sp-1);
    padding: 0 var(--sp-1);
}

.explorer-subgroup{
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: var(--tint-soft);
    overflow: hidden;
}

.explorer-subgroup > summary{
    list-style: none;
    cursor: pointer;
    padding: 0;
}

.explorer-subgroup > summary::-webkit-details-marker{
    display: none;
}

.explorer-subgroup-summary{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    color: var(--text);
    font-weight: 600;
    font-size: 0.92rem;
}

.explorer-subgroup-summary:hover{
    background: var(--panel-2);
}

.explorer-subgroup-label{
    min-width: 0;
}

.explorer-subgroup-count{
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 600;
}

.explorer-subgroup-caret{
    color: var(--muted);
    transition: transform 0.18s ease;
    flex: 0 0 auto;
}

.explorer-subgroup[open] .explorer-subgroup-caret{
    transform: rotate(90deg);
}

.explorer-data-warning{
    display: block;
    margin-top: 2px;
    color: var(--warning);
    font-size: 0.76rem;
    font-weight: normal;
}

.explorer-item-link.active .explorer-data-warning{ color: inherit; }

.explorer-subgroup-items{
    display: grid;
    gap: 2px;
    padding: var(--sp-1) var(--sp-2) var(--sp-2) var(--sp-3);
    border-top: 1px solid var(--border-soft);
}

.explorer-item-link{
    font-size: 0.92rem;
    color: var(--muted-strong);
}

.explorer-empty{
    color: var(--muted);
    font-size: 0.88rem;
    padding: 0 var(--sp-2);
}

.room-floor-group{
    margin-top: 0;
    margin-bottom: var(--sp-3);
    background: var(--panel-3);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 0;
    overflow: hidden;
}

.room-floor-group > summary{
    list-style: none;
    cursor: pointer;
    padding: 0;
}

.room-floor-group > summary::-webkit-details-marker{
    display: none;
}

.room-floor-group-summary{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
}

.room-floor-group-summary:hover{
    background: var(--tint-soft);
}

.room-floor-group-title{
    color: var(--text-strong);
    font-size: 0.96rem;
    font-weight: 650;
}

.room-floor-group-count{
    color: var(--muted);
    font-size: 0.88rem;
}

.room-floor-group-caret{
    color: var(--muted);
    transition: transform 0.18s ease;
    flex: 0 0 auto;
}

.room-floor-group[open] .room-floor-group-caret{
    transform: rotate(90deg);
}

.room-floor-group-body{
    padding: 0 var(--sp-4) var(--sp-4);
}

/* ---------------------------------------------------------------- */
/* Umbrueche                                                         */
/* ---------------------------------------------------------------- */
@media (max-width: 1100px){
    .shell.with-explorer{
        grid-template-columns: 1fr;
    }

    .explorer-toggle{
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .explorer-backdrop.show{
        display: block;
    }

    .explorer{
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(92vw, 360px);
        z-index: 35;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        max-width: 100%;
    }

    .explorer.show{
        transform: translateX(0);
    }

    .explorer-panel{
        position: static;
        top: auto;
        max-height: none;
        height: 100%;
        border-radius: 0 var(--radius) var(--radius) 0;
        overflow-y: auto;
    }

    .explorer-close{
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .content-area{
        grid-column: auto;
    }

    .shell-gutter{
        display: none;
    }
}

@media (max-width: 800px){
    .grid-2{
        grid-template-columns: 1fr;
    }

    .kv{
        grid-template-columns: 150px minmax(0, 1fr);
    }

    .portal-section-summary{
        padding: var(--sp-3) var(--sp-4);
    }

    .portal-section-summary-note{
        font-size: 0.85rem;
        white-space: normal;
    }

    .portal-section-body{
        padding: var(--sp-4);
    }

    .topbar-inner{
        flex-direction: column;
        align-items: stretch;
        padding: var(--sp-3);
    }

    .page-title{
        font-size: 1.4rem;
    }

    .shell{
        padding: var(--sp-4) var(--sp-3) var(--sp-6);
    }

    .container{
        padding-bottom: var(--sp-6);
    }

    .card{
        padding: var(--sp-4);
    }

    .form-actions{
        margin: var(--sp-4) calc(-1 * var(--sp-4)) calc(-1 * var(--sp-4));
        padding: var(--sp-3) var(--sp-4);
    }

    .brand-wrap{
        width: 100%;
        justify-content: space-between;
        align-items: center;
    }

    .top-links{
        width: 100%;
        justify-content: flex-start;
        gap: var(--sp-1);
    }

    .top-links .muted{
        width: 100%;
        display: block;
        margin-bottom: 2px;
        font-size: 0.86rem;
    }

    .btn-row{
        flex-direction: column;
    }

    .btn-row .btn,
    .btn-row > a,
    .btn-row > button,
    .btn-row > form,
    .btn-row > form .btn,
    .btn-row > form button{
        width: 100%;
    }

    td .btn-row{
        flex-direction: row;
    }

    td .btn-row .btn,
    td .btn-row > form,
    td .btn-row > form .btn{
        width: auto;
    }

    .action-bar .action-sep,
    .action-bar .spacer{
        display: none;
    }

    th, td{
        padding: var(--sp-2) var(--sp-3);
        font-size: 0.92rem;
    }

    th{
        white-space: normal;
    }

    .todo-card-head{
        align-items: flex-start;
    }

    .todo-card-actions{
        min-width: 0;
        justify-content: stretch;
    }
}

@media (max-width: 560px){
    .portal-section-summary{
        padding: var(--sp-3);
    }

    .portal-section-summary h2{
        font-size: 0.98rem;
    }

    .portal-section-summary-note{
        display: none;
    }

    .portal-section-body{
        padding: var(--sp-3);
    }

    /* Label und Wert untereinander, sonst wird es zu eng */
    .portal-section-body p:has(> strong:first-child),
    .portal-section-body .grid-2 p:has(> strong:first-child),
    .portal-section-body .todo-card-grid p:has(> strong:first-child){
        padding-left: 0;
        text-indent: 0;
    }

    .portal-section-body p > strong:first-child{
        display: block;
        min-width: 0;
        padding-right: 0;
        font-size: 0.85rem;
    }

    .kv{
        grid-template-columns: 1fr;
        gap: var(--sp-1);
    }

    .kv dd{
        margin-bottom: var(--sp-2);
    }

    .top-links .btn{
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    .page-title{
        font-size: 1.25rem;
    }

    .page-subtitle{
        font-size: 0.92rem;
    }

    .card{
        padding: var(--sp-3);
    }

    .explorer{
        width: 100vw;
    }

    .explorer-panel{
        border-radius: 0;
        padding: var(--sp-3);
    }

    .btn,
    .explorer-toggle{
        min-height: 44px;
    }

    th, td{
        padding: var(--sp-2);
        font-size: 0.9rem;
    }

    table{
        min-width: 620px;
    }
}

@media print{
    .topbar, .explorer, .explorer-backdrop, .btn-row, .action-bar, .form-actions{
        display: none !important;
    }

    body{
        background: #fff;
        color: #000;
    }

    .card{
        border-color: #ccc;
        box-shadow: none;
    }
}

@media (prefers-reduced-motion: reduce){
    *{
        transition: none !important;
        animation: none !important;
    }
}
