/* ---------- Basis ---------- */
:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --border: #e2e5ea;
    --text: #1f2430;
    --text-dim: #6b7280;
    --accent: #3b6ef5;
    --accent-soft: #e8eefe;
    --danger: #d9534f;
    --ok: #34a06c;
    --warn: #e0a326;
    --shadow: 0 2px 8px rgba(20, 30, 60, 0.10);
    --shadow-lg: 0 6px 24px rgba(20, 30, 60, 0.16);
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text);
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

/* button/input/textarea/select-Basisregeln: seit der Tailwind-Migration
   im Base-Layer von css/app.src.css */

.hidden { display: none !important; }

/* ---------- Sidebar ----------
   Seit der Tailwind-Migration: statisches Gerüst als Utilities in
   index.html; die von js/app.js generierten Bausteine (.sb-label, .sum-line,
   .bar, .room-row, .field, .detail-*, …) liegen im Components-Layer von
   css/app.src.css */

/* .btn / .btn-mini / .btn-primary / .btn-danger: seit der Tailwind-Migration
   im Components-Layer von css/app.src.css */

/* ---------- Viewport / Canvas ---------- */
#viewport {
    position: relative;
    flex: 1;
    overflow: hidden;
    background-color: var(--bg);
    background-image: radial-gradient(circle, #d3d7de 1px, transparent 1px);
    touch-action: none;
    cursor: default;
}
#viewport.panning { cursor: grabbing; }
#viewport.pan-ready { cursor: grab; }

#linkLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: visible;
    z-index: 0;
    pointer-events: none;
}

#world {
    position: absolute;
    top: 0; left: 0;
    width: 0; height: 0;
    transform-origin: 0 0;
}

/* Toolbar & Zoom */
#toolbar {
    position: absolute;
    top: 12px; left: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    box-shadow: var(--shadow);
    z-index: 10;
}

.tb-btn {
    padding: 6px 11px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.tb-btn:hover { background: var(--accent-soft); color: var(--accent); }

.tb-hint {
    font-size: 12px;
    color: var(--text-dim);
    padding: 0 10px 0 6px;
    border-left: 1px solid var(--border);
    margin-left: 4px;
}

#zoomControls {
    position: absolute;
    bottom: 14px; right: 14px;
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    box-shadow: var(--shadow);
    z-index: 10;
}
#zoomLevel {
    font-size: 12px;
    color: var(--text-dim);
    min-width: 48px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Leerer Zustand */
.empty-hint {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-dim);
    pointer-events: none;
    z-index: 5;
}
.empty-hint h2 { color: var(--text); margin-bottom: 12px; }
.empty-hint p { margin: 6px 0; font-size: 14px; }

.drop-overlay {
    position: absolute;
    inset: 12px;
    border: 3px dashed var(--accent);
    border-radius: 16px;
    background: rgba(59, 110, 245, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    z-index: 30;
    pointer-events: none;
}

/* ---------- Räume ---------- */
.room {
    position: absolute;
    border: 2px solid;
    border-radius: 8px;
    z-index: 1;
    /* Innenfläche lässt Klicks durch (Pan & Item-Zugriff), nur Kopf & Griff reagieren */
    pointer-events: none;
}
.room-header, .room-resize { pointer-events: auto; }
.room.selected {
    box-shadow: 0 0 0 3px rgba(59, 110, 245, 0.35);
    z-index: 2;
}

.room-header {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 6px 10px;
    border-radius: 6px 6px 0 0;
    cursor: grab;
    display: flex;
    align-items: baseline;
    gap: 10px;
    user-select: none;
}
.room-header:active { cursor: grabbing; }

.room-name {
    border: none;
    background: transparent;
    font-weight: 700;
    font-size: 14px;
    min-width: 40px;
    flex: 1;
    padding: 1px 4px;
    border-radius: 4px;
    cursor: text;
}
.room-name:focus { outline: 2px solid rgba(255,255,255,0.9); background: rgba(255,255,255,0.5); }

.room-add {
    flex: none;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    color: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.room-add:hover { background: #fff; color: var(--accent); }
.room-del:hover { background: #fff; color: var(--danger); }

.room-budget-tag {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    opacity: 0.9;
}
.room-budget-tag.over { color: #b00020; font-weight: 700; opacity: 1; }

.room-meta {
    position: absolute;
    bottom: 4px; left: 10px;
    font-size: 11px;
    opacity: 0.75;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}
.room-meta .chip {
    width: 11px; height: 11px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.25);
    display: inline-block;
}

.room-resize {
    position: absolute;
    right: -6px; bottom: -6px;
    width: 16px; height: 16px;
    cursor: nwse-resize;
    border-radius: 4px;
}
.room-resize::after {
    content: "";
    position: absolute;
    right: 4px; bottom: 4px;
    width: 8px; height: 8px;
    border-right: 2px solid rgba(0,0,0,0.4);
    border-bottom: 2px solid rgba(0,0,0,0.4);
}

/* ---------- Mehrfachauswahl & Gruppen ---------- */
.selection-bar {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 5px 6px 5px 14px;
    box-shadow: var(--shadow-lg);
    z-index: 15;
    font-size: 13px;
    font-weight: 600;
}

.marquee {
    position: absolute;
    border: 1.5px dashed var(--accent);
    background: rgba(59, 110, 245, 0.08);
    border-radius: 4px;
    z-index: 14;
    pointer-events: none;
}

.group { position: absolute; }

.group.free-frame {
    border: 2px dashed #9aa7c4;
    border-radius: 12px;
    pointer-events: none;
    z-index: 2;
}
.group.free-frame.selected { border-color: var(--accent); }

.group-header {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 30px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px 0 10px;
    pointer-events: auto;
    cursor: grab;
    background: rgba(154, 167, 196, 0.18);
    border-radius: 10px 10px 0 0;
    user-select: none;
}
.group-header:active { cursor: grabbing; }
.group.free-frame.selected .group-header { background: var(--accent-soft); }

.group-name {
    border: none;
    background: transparent;
    font-weight: 700;
    font-size: 12px;
    flex: 1;
    min-width: 30px;
    padding: 1px 4px;
    border-radius: 4px;
    cursor: text;
}
.group-name:hover { background: rgba(255,255,255,0.6); }
.group-name:focus { outline: 2px solid var(--accent); background: #fff; }

.group-total {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.group-btn {
    border: none;
    background: transparent;
    border-radius: 5px;
    font-size: 13px;
    line-height: 1;
    padding: 3px 6px;
    color: var(--text-dim);
}
.group-btn:hover { background: #fff; color: var(--accent); }

/* Tabellen-Ansicht der Gruppe */
.group.table-card {
    width: 320px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 3;
}
.group.table-card.selected {
    outline: 2px solid var(--accent);
    box-shadow: var(--shadow-lg);
    z-index: 4;
}
.group.table-card .group-header {
    position: static;
    height: 34px;
    background: var(--accent-soft);
    border-radius: var(--radius) var(--radius) 0 0;
}

.group-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-top: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
}
.group-row:hover { background: var(--bg); }
.group-row.selected { background: var(--accent-soft); }

.row-num {
    color: var(--text-dim);
    font-size: 11px;
    width: 17px;
    text-align: right;
    flex: none;
}
.row-thumb {
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--text-dim);
}
.row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}
.row-price { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Leistungs-Karten (kind: service): Bild/Icon links, Inhalt rechts */
.item.kind-service {
    border-left: 3px solid #8b5cf6;
    display: flex;
    align-items: stretch;
}
.item.kind-service .zone-thumb {
    flex: none;
    width: 64px;
    min-height: 64px;
    border-radius: 7px 0 0 7px;
    border-right: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0e9fd;
}
.item.kind-service .zone-thumb img.item-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
}
.item.kind-service .zone-thumb.thumb-icon {
    font-size: 24px;
    color: #6d3fc4;
}
.item.kind-service .item-body {
    flex: 1;
    min-width: 0;
}
.item.kind-service .item-price-row { flex-wrap: wrap; }
.kind-tag {
    font-size: 10px;
    font-weight: 700;
    color: #6d3fc4;
    background: #f0e9fd;
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.group-splits {
    padding: 5px 10px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.group-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-top: 2px solid var(--border);
    font-weight: 700;
    font-size: 13px;
    background: var(--bg);
    border-radius: 0 0 var(--radius) var(--radius);
}

/* ---------- Items ---------- */
.item {
    position: absolute;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 3;
    cursor: grab;
    user-select: none;
}
.item:active { cursor: grabbing; }
.item.selected {
    outline: 2px solid var(--accent);
    box-shadow: var(--shadow-lg);
    z-index: 4;
}
.item.dragging { opacity: 0.85; box-shadow: var(--shadow-lg); z-index: 5; }

.item img.item-img {
    display: block;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    pointer-events: none;
}

/* Karten-Zonen: oben Thumbnail, unten Daten (per Klick "scharf schalten") */
.zone-thumb, .item-body.zone-data { position: relative; }

.zone-thumb.thumb-placeholder {
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: var(--bg);
    color: var(--text-dim);
    font-size: 11px;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
}

.item .armed {
    box-shadow: inset 0 0 0 2px var(--accent);
    background: var(--accent-soft);
}
.item .armed::after {
    content: attr(data-hint);
    position: absolute;
    top: 3px;
    right: 3px;
    background: var(--accent);
    color: #fff;
    font-size: 9px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 1;
}

.item-body { padding: 8px 10px; }

.item-name {
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    padding: 2px 3px;
    border-radius: 4px;
    cursor: text;
    /* zweizeilig: umbrechen und nach 2 Zeilen abschneiden */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: normal;
    word-break: break-word;
    min-height: 1.3em;
}
.item-name:hover { background: var(--bg); }
.item-name:focus {
    outline: 2px solid var(--accent);
    background: #fff;
    /* beim Bearbeiten voll ausklappen */
    display: block;
    -webkit-line-clamp: unset;
    max-height: 6.5em;
    overflow: auto;
}
.item-name:empty::before {
    content: attr(data-placeholder);
    color: #b6bcc6;
}

.item-desc {
    font-size: 12px;
    line-height: 1.35;
    color: var(--text-dim);
    padding: 1px 3px;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item-price-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.item-qty {
    width: 38px;
    border: 1px solid transparent;
    background: transparent;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    padding: 2px 3px;
    border-radius: 4px;
    cursor: text;
    text-align: center;
}
.item-qty:hover { background: var(--bg); }
.item-qty:focus { outline: 2px solid var(--accent); background: #fff; }

.qty-x {
    font-size: 11px;
    color: var(--text-dim);
}

.item-total {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.item-price {
    width: 90px;
    border: 1px solid transparent;
    background: transparent;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    padding: 2px 3px;
    border-radius: 4px;
    cursor: text;
}
.item-price:hover { background: var(--bg); }
.item-price:focus { outline: 2px solid var(--accent); background: #fff; }
.item-price::placeholder { color: #b6bcc6; }

.item-link {
    margin-left: auto;
    text-decoration: none;
    font-size: 13px;
    opacity: 0.7;
}
.item-link:hover { opacity: 1; }

.item-loading {
    font-size: 11px;
    color: var(--text-dim);
    padding: 0 3px;
}

.item-room-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 5px;
    padding: 1px 3px;
}
.item-room-tag .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.item-del {
    position: absolute;
    top: -9px; right: -9px;
    width: 21px; height: 21px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}
.item:hover .item-del, .item.selected .item-del { display: flex; }
.item-del:hover { color: var(--danger); border-color: var(--danger); }

/* Notizen */
.item.note {
    background: #fff8c5;
    border-color: #e6d97a;
}
.item.note .item-note {
    width: 100%;
    border: none;
    background: transparent;
    resize: none;
    font-size: 13px;
    font-family: inherit;
    padding: 10px 12px;
    min-height: 70px;
    cursor: text;
}
.item.note .item-note:focus { outline: none; }

/* ---------- Stockwerk-Leiste ---------- */
#floorBar {
    position: absolute;
    top: 56px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    box-shadow: var(--shadow);
    z-index: 10;
    max-width: 70%;
    overflow-x: auto;
}

.floor-tab {
    border: 1px solid transparent;
    background: transparent;
    border-radius: 7px;
    padding: 5px 11px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.floor-tab:hover { background: var(--bg); color: var(--text); }
.floor-tab.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}
.floor-tab .floor-del {
    font-weight: 700;
    opacity: 0.6;
    padding: 0 2px;
}
.floor-tab .floor-del:hover { opacity: 1; color: var(--danger); }
.floor-add { font-weight: 700; }

/* ---------- Projekt-Galerie & Konto-Bereich ----------
   Seit der Tailwind-Migration: Utilities in index.html (Galerie-Hülle)
   und js/app.js (renderGallery/renderAccountArea) */


/* Auth-/Passwort-Modal: seit der Tailwind-Migration Utilities in index.html */

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(20px);
    background: #26304a;
    color: #fff;
    font-size: 13px;
    padding: 10px 18px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 300;
    max-width: 80vw;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- Kontextmenü ---------- */
#contextMenu {
    position: absolute;
    min-width: 190px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 4px;
    z-index: 40;
    display: flex;
    flex-direction: column;
}
#contextMenu .cm-item {
    text-align: left;
    border: none;
    background: transparent;
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}
#contextMenu .cm-item:hover { background: var(--accent-soft); color: var(--accent); }
#contextMenu .cm-item.danger:hover { background: #fdecec; color: var(--danger); }
#contextMenu .cm-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 6px;
}

/* ---------- PDF- / Druck-Export ---------- */
#printReport { display: none; }

@media print {
    @page { margin: 14mm; }
    html, body { overflow: visible; height: auto; }
    #app { display: none !important; }
    #printReport { display: block !important; }
}

#printReport {
    color: #1f2430;
    font-size: 10pt;
    line-height: 1.4;
}
#printReport h1 {
    font-size: 18pt;
    margin: 0 0 2mm;
}
#printReport .pr-date {
    color: #6b7280;
    font-size: 9pt;
    margin-bottom: 8mm;
}
#printReport h2 {
    font-size: 13pt;
    margin: 0 0 2mm;
    display: flex;
    align-items: center;
    gap: 2.5mm;
    border-bottom: 1.5px solid #d5d9e0;
    padding-bottom: 1.5mm;
    break-after: avoid;
}
#printReport .pr-room-sum {
    margin-left: auto;
    font-size: 11pt;
    font-variant-numeric: tabular-nums;
}
#printReport h3 {
    font-size: 10.5pt;
    margin: 4mm 0 2mm;
    break-after: avoid;
}
#printReport .pr-dot {
    display: inline-block;
    width: 3.2mm;
    height: 3.2mm;
    border-radius: 50%;
    flex: none;
    margin-right: 1mm;
}
#printReport .pr-meta {
    color: #6b7280;
    font-size: 9pt;
    margin-bottom: 2mm;
}
#printReport .pr-room {
    margin-bottom: 9mm;
}
#printReport .pr-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4mm;
    margin-bottom: 2mm;
}
#printReport .pr-card {
    border: 1px solid #d5d9e0;
    border-radius: 2.5mm;
    overflow: hidden;
    break-inside: avoid;
    background: #fff;
}
#printReport .pr-card img {
    display: block;
    width: 100%;
    height: 32mm;
    object-fit: cover;
}
#printReport .pr-noimg {
    height: 16mm;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f5f7;
    font-size: 14pt;
}
#printReport .pr-card-body {
    padding: 2mm 2.5mm;
}
#printReport .pr-title {
    font-weight: 600;
    font-size: 9pt;
}
#printReport .pr-kind {
    display: inline-block;
    color: #6d3fc4;
    background: #f0e9fd;
    font-size: 7.5pt;
    font-weight: 700;
    padding: 0 1.5mm;
    border-radius: 1mm;
    margin-top: 1mm;
}
#printReport .pr-price {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-top: 1mm;
}
#printReport .pr-dim {
    color: #6b7280;
    font-size: 9pt;
    font-weight: 400;
}
#printReport .pr-budget { break-inside: avoid; }
#printReport .pr-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}
#printReport .pr-table th,
#printReport .pr-table td {
    border: 1px solid #d5d9e0;
    padding: 1.8mm 2.5mm;
    text-align: right;
}
#printReport .pr-table th:first-child,
#printReport .pr-table td:first-child {
    text-align: left;
}
#printReport .pr-table thead th {
    background: #f4f5f7;
    font-size: 9pt;
}
#printReport .pr-table tfoot td {
    background: #f4f5f7;
    font-weight: 700;
    border-top: 2px solid #9aa2b0;
}
#printReport .pr-over { color: #d9534f; font-weight: 700; }

/* Scrollbars dezent */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb { background: #cfd4dc; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #b8bec9; }
