* { box-sizing: border-box; }

html, body, #app { height: 100%; margin: 0; }

body {
    font: 14px/1.45 system-ui, "Segoe UI", sans-serif;
    color: #1b1b1b;
    background: #fafafa;
}

.seite { display: flex; flex-direction: column; height: 100%; min-height: 0; }

/* Kopfzeile: Projekt-Menü, Geschoss, Ansichten, Speichern, Ausgabe, Einstellungen */
.kopf { position: relative; z-index: 50; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; padding: 6px 10px;
        background: #fff; border-bottom: 1px solid #e4e4e7; }
.kopf .fueller { flex: 1; }
.kopf select, .kopf input:not([type=file]), .panel input:not([type=file]):not([type=checkbox]), .panel select {
    font: inherit; padding: 5px 8px; border: 1px solid #d4d4d8; border-radius: 4px; background: #fff; }
.geschosswahl { max-width: 230px; }
.ansichten { display: flex; gap: 4px; }
.menueknopf strong { font-weight: 600; }
.stand { font-size: 12px; color: #52525b; }
.vermerk { color: #a11; font-weight: 600; font-size: 12px; }

.menue { position: relative; }
.menue-hinter { position: fixed; inset: 0; z-index: 40; }
.aufklapp { position: absolute; left: 0; top: calc(100% + 6px); z-index: 60; display: flex; flex-direction: column; gap: 8px;
            width: 300px; max-height: calc(100vh - 70px); overflow-y: auto; padding: 12px;
            background: #fff; border: 1px solid #d4d4d8; border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, .16); }
.aufklapp.breit { width: 340px; }
.aufklapp.rechts { left: auto; right: 0; }
.aufklapp h3 { margin: 6px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #52525b; }
.aufklapp h3:first-child { margin-top: 0; }
.aufklapp h4 { margin: 6px 0 0; font-size: 13px; }
.aufklapp label, .panel > .inhalt > section label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #52525b; }
.aufklapp button { text-align: left; }
.aufklapp details { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid #e4e4e7; padding-top: 8px; }
.aufklapp details[open] > * { margin-bottom: 8px; }
.aufklapp details button, .aufklapp details label { width: 100%; }
.aufklapp summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #52525b; }
.aufklapp .liste { display: flex; flex-direction: column; gap: 4px; }
.versteckt { display: none !important; }

.band { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; margin: 0; }
.band button { flex: none; padding: 0 8px; }
.meldung { margin: 0; padding: 8px; background: #f0fdf4; border-left: 3px solid #15803d; font-size: 12px; }

/* Plan über die ganze Breite; rechts das Panel, zugeklappt nur eine schmale Reiterleiste */
main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr);
       min-width: 0; min-height: 0; padding: 8px; gap: 0; }
main.mit-panel { grid-template-columns: minmax(0, 1fr) 8px var(--panel, 400px); }
.buehne { position: relative; min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; }
.buehne > * { flex: 1; min-height: 0; }
.griff { cursor: col-resize; }
.griff:hover { background: #dbeafe; }
.zugflaeche { position: fixed; inset: 0; z-index: 950; cursor: col-resize; }

.panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fff; border: 1px solid #e4e4e7; border-radius: 6px; }
.panel .reiter { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid #e4e4e7; }
.panel .reiter button { padding: 3px 9px; font-size: 13px; }
.panel .reiter .schliessen { margin-left: auto; }
.panel.zu { margin-left: 8px; border: 0; background: none; }
.panel.zu .reiter { flex-direction: column; flex-wrap: nowrap; padding: 0; border: 0; }
.panel.zu .reiter button { writing-mode: vertical-rl; padding: 9px 3px; }
.panel .inhalt { flex: 1; min-height: 0; overflow-y: auto; }
.panel .inhalt > section { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.editorrahmen { height: 100%; }
.knoepfe { display: flex; flex-wrap: wrap; gap: 6px; }
.zahl { display: inline-block; min-width: 18px; margin-left: 2px; padding: 0 5px; border-radius: 9px; background: #e4e4e7; color: #27272a; font-size: 11px; }
.zahl.warnung { background: #c2410c; color: #fff; }
button.aktiv .zahl { background: #fff; color: #1f4e8c; }
.panel.zu .zahl { margin: 4px 0 0; padding: 4px 0; min-width: 0; }
.klein { margin: 0; font-size: 12px; color: #52525b; }

button {
    font: inherit;
    padding: 5px 12px;
    border: 1px solid #d4d4d8;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
}

button:hover:not(:disabled) { background: #f4f4f5; }
button:disabled { opacity: .5; cursor: default; }
button.aktiv, button.aktiv:hover:not(:disabled) { background: #1f4e8c; border-color: #1f4e8c; color: #fff; }

.geschosse { display: flex; flex-wrap: wrap; gap: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 3px 4px; text-align: right; border-bottom: 1px solid #f0f0f0; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; color: #52525b; }
tfoot td { color: #52525b; }

.meldungen { margin: 0; padding: 0; list-style: none; font-size: 12px; display: flex; flex-direction: column; gap: 6px; }
.meldungen li { padding: 6px 8px; border-left: 3px solid #a1a1aa; background: #f4f4f5; }
.meldungen li.warnung { border-color: #c2410c; background: #fff7ed; }
.meldungen span { display: block; color: #71717a; }

.fehler { margin: 0; padding: 8px; background: #fef2f2; border-left: 3px solid #b91c1c; font-size: 12px; }

.projekte { display: flex; flex-direction: column; gap: 4px; }
.projekte button { display: flex; justify-content: space-between; gap: 8px; text-align: left; }
.projekte small { color: inherit; opacity: .7; white-space: nowrap; }
.leer { margin: auto; color: #71717a; text-align: center; flex: none; }

@media (max-width: 1500px) {
    .vermerk { display: none; }
}

/* Den Knopf für das Panel gibt es nur in der unteren Leiste auf Handy und Tablet im Hochformat */
.ansichten .nur-schmal { display: none; }

/* Tablet quer und kleine Laptops: Das Panel lässt dem Plan mehr als die Hälfte */
@media (max-width: 1200px) {
    main.mit-panel { grid-template-columns: minmax(0, 1fr) 8px min(var(--panel, 400px), 45vw); }
    .kopf .stand { display: none; }
}

/* Handy und Tablet hoch (Grenze auch in aufmassViewer.js): oben nur Projekt, Geschoss, Speichern, Ausgabe und Einstellungen,
   unten am Rand die Ansichten und „Details“, das Panel teilt sich die Höhe mit dem Plan */
@media (max-width: 900px) {
    :root { --unten: calc(58px + env(safe-area-inset-bottom)); }
    .seite { height: 100vh; height: 100dvh; }

    .kopf { flex-wrap: nowrap; gap: 6px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
    .kopf > .menue:first-child { flex: 0 1 auto; min-width: 96px; }
    .kopf .lang { display: none; }
    .menueknopf { display: flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; }
    .menueknopf strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .geschosswahl { flex: 0 1 auto; min-width: 64px; max-width: 120px; }
    .kopf .fueller { flex: 1 1 0; min-width: 0; }
    .kopf > button, .kopf > .menue { flex: none; }
    .aufklapp, .aufklapp.breit { width: min(340px, calc(100vw - 16px)); max-height: calc(100dvh - var(--unten) - 64px); }

    .ansichten { position: fixed; left: 0; right: 0; bottom: 0; z-index: 48; height: var(--unten); gap: 2px;
                 padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid #e4e4e7;
                 box-shadow: 0 -2px 10px rgba(0, 0, 0, .06); }
    .ansichten button { flex: 1 1 0; min-width: 0; padding: 2px; border: 0; border-radius: 8px; font-size: 12px; line-height: 1.2; }
    .ansichten .nur-schmal { display: block; }
    .ansichten .zahl { margin-left: 4px; }

    main, main.mit-panel { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); padding: 6px; }
    /* Offenes Panel unter dem Plan: Der Plan wird kleiner, bleibt aber ganz zu sehen */
    main.mit-panel { grid-template-rows: minmax(0, 1fr) min(48dvh, 460px); row-gap: 6px; }
    .seite:has(.ansichten) main { padding-bottom: calc(var(--unten) + 6px); }
    main .griff { display: none; }

    .panel { border-radius: 10px; box-shadow: 0 -4px 16px rgba(0, 0, 0, .10); }
    .panel.zu { display: none; }
    .panel .reiter { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .panel .reiter::-webkit-scrollbar { display: none; }
    .panel .reiter button { flex: none; }
    .panel .reiter .schliessen { position: sticky; right: 0; box-shadow: -6px 0 6px #fff; }

    .lade.leicht { padding-top: 12px; }
}

/* Finger statt Maus: größere Knöpfe und Felder */
@media (pointer: coarse) {
    button, .kopf select, .panel select, .panel input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]) { min-height: 36px; }
    .ansichten button { min-height: 0; }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    padding: 10px 16px;
    background: #fef3c7;
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; float: right; }

.loading-progress { display: block; width: 6rem; height: 6rem; margin: 30vh auto 1rem; }
.loading-progress circle { fill: none; stroke: #e4e4e7; stroke-width: .5rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child { stroke: #1f4e8c; stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * .8), 500%; }
.loading-progress-text { text-align: center; color: #71717a; }
.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Lädt"); }

.markierungen { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.markierungen li { display: flex; gap: 6px; align-items: flex-start; }
.markierungen li.erledigt { color: #a1a1aa; text-decoration: line-through; }
.markierungen em { display: block; font-style: normal; color: #71717a; text-decoration: none; }
.nr { flex: none; display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 4px;
      border-radius: 10px; color: #fff; font-size: 11px; background: #52525b; }
.nr.kat-mangel { background: #dc2626; }
.nr.kat-uebergabe { background: #2563eb; }
.nr.kat-wartung { background: #d97706; }
.nr.kat-hinweis { background: #0f766e; }
.erledigt .nr { background: #a1a1aa; }
.panel .editorrahmen .editor { border: 0; border-radius: 0; }
.aufklapp h3.mit-knopf { display: flex; align-items: center; justify-content: space-between; }
.aufklapp button.symbol { padding: 0 7px; font-size: 16px; line-height: 1.3; text-transform: none; letter-spacing: 0; }

/* Lade-Anzeigen: Balken unter der Kopfzeile bei jedem Warten auf den Dienst, Kasten über dem Plan beim Öffnen */
.fortschritt { position: relative; flex: none; height: 3px; margin-bottom: -3px; overflow: hidden; pointer-events: none; z-index: 5; }
.fortschritt.an::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 35%; background: #2563eb; border-radius: 2px;
    animation: fortschritt 1.1s ease-in-out infinite; }
@keyframes fortschritt { from { transform: translateX(-100%); } to { transform: translateX(290%); } }

.lade { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .72); cursor: progress; animation: einblenden .15s ease-out; }
.lade .kasten { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; max-width: 360px;
    padding: 14px 18px; background: #fff; border: 1px solid #d4d4d8; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .12); }
.lade strong { font-weight: 600; }
/* Vorschau nach einer Änderung: Plan bleibt gut sichtbar, der Kasten sitzt oben */
.lade.leicht { align-items: flex-start; padding-top: 56px; background: rgba(255, 255, 255, .35); }
.lade.leicht .kasten { padding: 8px 14px; }
.lade small { grid-column: 2; color: #52525b; opacity: 0; animation: einblenden .4s ease-out 4s forwards; }
.kreisel { width: 22px; height: 22px; border: 3px solid #dbeafe; border-top-color: #2563eb; border-radius: 50%;
    animation: kreisel .8s linear infinite; }
@keyframes kreisel { to { transform: rotate(360deg); } }
@keyframes einblenden { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    .kreisel { animation-duration: 2.4s; }
    .fortschritt.an::before { animation: none; width: 100%; opacity: .6; }
}
