/* Base Board – dunkles Theme passend zur BlueMap */
:root {
	--bb-bg: #16181d;
	--bb-surface: rgba(28, 31, 38, 0.94);
	--bb-surface-2: #252932;
	--bb-surface-3: #2f3440;
	--bb-border: #363b47;
	--bb-text: #e7e9ee;
	--bb-muted: #9aa2b1;
	--bb-accent: #3e8bff;
	--bb-accent-2: #2f6fd6;
	--bb-danger: #e5484d;
	--bb-ok: #46a758;
	--bb-warn: #ffb224;
	--bb-radius: 10px;
	--bb-top: 56px;
	--bb-sidebar: 330px;
	--bb-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
	--bb-font: "Quicksand", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	color-scheme: dark;
}

html, body {
	margin: 0;
	height: 100%;
	overflow: hidden;
	background: var(--bb-bg);
	font-family: var(--bb-font);
}

/* BlueMaps eigene Steuerleiste ersetzen wir durch unsere */
#app .control-bar { display: none !important; }
#app #zoom-buttons { top: auto !important; left: auto !important; right: 14px !important; bottom: 44px !important; }
.bb-editing #map-container .bm-marker-popup { display: none !important; }

#bb-root {
	position: fixed;
	inset: 0;
	z-index: 20000;
	pointer-events: none;
	color: var(--bb-text);
	font-size: 14px;
	line-height: 1.45;
}
#bb-root > * { pointer-events: auto; }
#bb-root [hidden] { display: none !important; }
#bb-root button, #bb-root input, #bb-root textarea, #bb-root select { font: inherit; color: inherit; }
#bb-root a { color: #8fb8ff; }

.bb-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Buttons */
.bb-btn {
	display: inline-flex; align-items: center; gap: 6px;
	min-height: 34px; padding: 0 12px;
	border: 1px solid var(--bb-border); border-radius: 8px;
	background: var(--bb-surface-2); color: var(--bb-text);
	cursor: pointer; white-space: nowrap; text-decoration: none;
	transition: background .15s, border-color .15s;
	font-weight: 600;
}
.bb-btn:hover { background: var(--bb-surface-3); }
.bb-btn:focus-visible, .bb-seg button:focus-visible, .bb-item:focus-visible, .bb-color:focus-visible { outline: 2px solid var(--bb-accent); outline-offset: 2px; }
.bb-btn:disabled { opacity: .45; cursor: default; }
.bb-btn.bb-primary { background: var(--bb-accent); border-color: var(--bb-accent); color: #fff; }
.bb-btn.bb-primary:hover { background: var(--bb-accent-2); }
.bb-btn.bb-danger { color: #ff8f92; }
.bb-btn.bb-danger:hover { background: rgba(229, 72, 77, .18); border-color: var(--bb-danger); }
.bb-btn.bb-ghost { background: transparent; border-color: transparent; }
.bb-btn.bb-ghost:hover { background: var(--bb-surface-3); }
.bb-btn.bb-on { background: rgba(62, 139, 255, .2); border-color: var(--bb-accent); }
.bb-btn.bb-edit-on { background: rgba(255, 178, 36, .18); border-color: var(--bb-warn); color: #ffd27a; }
.bb-icon-btn { padding: 0; width: 34px; justify-content: center; }
.bb-btn.bb-busy { position: relative; color: transparent !important; }
.bb-btn.bb-busy::after { content: ""; position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px; border: 2px solid #fff; border-right-color: transparent; border-radius: 50%; animation: bb-spin .7s linear infinite; }

.bb-seg { display: inline-flex; background: var(--bb-surface-2); border: 1px solid var(--bb-border); border-radius: 8px; padding: 2px; gap: 2px; }
.bb-seg button { border: 0; background: transparent; padding: 0 12px; min-height: 28px; border-radius: 6px; cursor: pointer; font-weight: 700; color: var(--bb-muted); }
.bb-seg button:hover { color: var(--bb-text); }
.bb-seg button.bb-on { background: var(--bb-accent); color: #fff; }
.bb-viewseg button { min-width: 44px; }

/* ---------- Topbar */
.bb-topbar {
	position: absolute; top: 0; left: 0; right: 0; height: var(--bb-top);
	display: flex; align-items: center; justify-content: space-between; gap: 10px;
	padding: 0 12px; box-sizing: border-box;
	background: linear-gradient(to bottom, rgba(20, 22, 27, .96), rgba(20, 22, 27, .88));
	border-bottom: 1px solid var(--bb-border);
	backdrop-filter: blur(6px);
}
.bb-top-left, .bb-top-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bb-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .2px; margin-right: 4px; white-space: nowrap; }
.bb-logo { width: 22px; height: 22px; border-radius: 5px; background:
	linear-gradient(135deg, #5aa0ff 0 50%, #2f6fd6 50% 100%);
	box-shadow: inset 0 0 0 2px rgba(255,255,255,.15); }

/* ---------- Status-Banner */
.bb-status {
	position: absolute; top: calc(var(--bb-top) + 8px); left: 50%; transform: translateX(-50%);
	max-width: min(720px, calc(100% - 24px)); box-sizing: border-box;
	padding: 10px 14px; border-radius: var(--bb-radius);
	background: rgba(60, 42, 8, .95); border: 1px solid var(--bb-warn); color: #ffe2a8;
	box-shadow: var(--bb-shadow); z-index: 5;
}

/* ---------- Sidebar */
.bb-sidebar {
	position: absolute; top: var(--bb-top); left: 0; bottom: 0; width: var(--bb-sidebar);
	display: flex; flex-direction: column; box-sizing: border-box;
	background: var(--bb-surface); border-right: 1px solid var(--bb-border);
	transform: translateX(-100%); transition: transform .22s ease; z-index: 3;
}
.bb-sidebar.bb-open { transform: none; }
.bb-sb-head { padding: 12px; display: grid; gap: 10px; border-bottom: 1px solid var(--bb-border); }
.bb-sb-title { display: flex; align-items: center; gap: 8px; }
.bb-tabs { flex: 1; }
.bb-tabs button { flex: 1; }
.bb-sb-close { display: none; }
.bb-search { display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 36px; background: var(--bb-bg); border: 1px solid var(--bb-border); border-radius: 8px; color: var(--bb-muted); }
.bb-search input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; color: var(--bb-text); }
.bb-sb-tools { padding: 10px 12px; display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--bb-border); }
.bb-sb-tools .bb-hint { margin: 0; }
.bb-list { flex: 1; overflow-y: auto; padding: 6px; }
.bb-item {
	display: flex; align-items: center; gap: 10px; width: 100%; box-sizing: border-box;
	padding: 8px; border: 1px solid transparent; border-radius: 8px; background: transparent;
	text-align: left; cursor: pointer;
}
.bb-item:hover { background: var(--bb-surface-2); }
.bb-item.bb-sel { background: rgba(62, 139, 255, .14); border-color: rgba(62, 139, 255, .5); }
.bb-item.bb-dim { opacity: .55; }
.bb-item-area { cursor: default; padding: 4px 4px 4px 8px; }
.bb-item-click { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; cursor: pointer; padding: 4px 0; }
.bb-item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.bb-item-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-item-sub { color: var(--bb-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-item-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: none; background: var(--bb-surface-3); }
.bb-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.12); }
.bb-dot-lg { width: 16px; height: 16px; }
.bb-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.bb-swatch-lg { width: 18px; height: 18px; }
.bb-empty { color: var(--bb-muted); padding: 12px; margin: 0; }
.bb-hint { color: var(--bb-muted); font-size: 12px; }
.bb-muted { color: var(--bb-muted); }
.bb-error { color: #ff8f92; margin: 8px 0 0; }

/* ---------- Detail-Panel */
.bb-panel {
	position: absolute; top: calc(var(--bb-top) + 10px); right: 10px;
	max-height: calc(100% - var(--bb-top) - 50px);
	width: min(430px, calc(100% - 20px)); box-sizing: border-box;
	overflow-y: auto; overscroll-behavior: contain;
	padding: 14px 16px 18px; border-radius: 14px;
	background: var(--bb-surface); border: 1px solid var(--bb-border); box-shadow: var(--bb-shadow);
	z-index: 4;
}
.bb-panel-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.bb-panel-head > .bb-dot, .bb-panel-head > .bb-swatch { margin-top: 6px; }
.bb-panel-title { flex: 1; min-width: 0; }
.bb-panel-title h2 { margin: 0; font-size: 19px; line-height: 1.25; overflow-wrap: anywhere; }
.bb-panel-sub { color: var(--bb-muted); font-size: 12px; margin-top: 2px; }
.bb-panel-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.bb-section { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--bb-muted); margin: 18px 0 8px; }

.bb-notes { overflow-wrap: anywhere; }
.bb-notes p { margin: 0 0 8px; }
.bb-notes ul, .bb-notes ol { margin: 0 0 8px; padding-left: 20px; }
.bb-notes h4 { margin: 10px 0 6px; font-size: 15px; }
.bb-notes code { background: var(--bb-surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.bb-form { display: grid; gap: 12px; }
.bb-field { display: grid; gap: 5px; }
.bb-label { font-size: 12px; font-weight: 700; color: var(--bb-muted); text-transform: uppercase; letter-spacing: .5px; }
.bb-form input[type=text], .bb-form input[type=number], .bb-form textarea, .bb-adder input, .bb-modal input[type=password] {
	width: 100%; box-sizing: border-box; padding: 8px 10px;
	background: var(--bb-bg); border: 1px solid var(--bb-border); border-radius: 8px; color: var(--bb-text);
}
.bb-form textarea { resize: vertical; min-height: 70px; }
.bb-form input:focus, .bb-form textarea:focus, .bb-adder input:focus, .bb-modal input:focus { outline: none; border-color: var(--bb-accent); }
.bb-coords { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bb-coords label { display: grid; gap: 3px; font-size: 12px; color: var(--bb-muted); }
.bb-form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.bb-range-val { text-transform: none; color: var(--bb-text); margin-left: 4px; }
.bb-form input[type=range] { width: 100%; accent-color: var(--bb-accent); }

.bb-colors { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.bb-color { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); padding: 0; }
.bb-color.bb-on { border-color: #fff; box-shadow: 0 0 0 2px var(--bb-accent); }
.bb-color-custom-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--bb-muted); cursor: pointer; }
.bb-color-custom { width: 30px; height: 28px; padding: 0; border: 1px solid var(--bb-border); border-radius: 6px; background: none; cursor: pointer; }

.bb-adder-wrap { display: grid; gap: 8px; margin-bottom: 10px; }
.bb-adder { display: flex; gap: 8px; }
.bb-adder input { flex: 1; min-width: 0; }
.bb-adder-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Masonry (Pinterest-Stil) */
.bb-masonry { column-width: 130px; column-gap: 8px; }
.bb-tile { break-inside: avoid; margin: 0 0 8px; position: relative; border-radius: 10px; overflow: hidden; background: var(--bb-surface-3); }
.bb-tile img { display: block; width: 100%; height: auto; cursor: zoom-in; transition: transform .2s; }
.bb-tile:hover img { transform: scale(1.02); }
.bb-tile[draggable=true] { cursor: grab; }
.bb-tile.bb-dragging { opacity: .4; }
.bb-tile.bb-drop-before { box-shadow: 0 -3px 0 0 var(--bb-accent); }
.bb-tile.bb-drop-after { box-shadow: 0 3px 0 0 var(--bb-accent); }
.bb-tile-tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.bb-tile:hover .bb-tile-tools, .bb-tile:focus-within .bb-tile-tools { opacity: 1; }
@media (hover: none) { .bb-tile-tools { opacity: 1; } }
.bb-tile-btn { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; padding: 0; }
.bb-tile-btn:disabled { opacity: .35; }
.bb-tile-btn .bb-icon { width: 15px; height: 15px; }
.bb-tile-del:hover { background: var(--bb-danger); }

/* ---------- Lightbox */
.bb-lightbox { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; }
.bb-lb-backdrop { position: absolute; inset: 0; background: rgba(5, 6, 8, .92); }
.bb-lb-img { position: relative; max-width: calc(100% - 120px); max-height: calc(100% - 110px); object-fit: contain; border-radius: 8px; box-shadow: var(--bb-shadow); }
.bb-lb-nav, .bb-lb-close { position: absolute; border: 0; border-radius: 50%; width: 46px; height: 46px; display: grid; place-items: center; background: rgba(255,255,255,.1); color: #fff; cursor: pointer; }
.bb-lb-nav:hover, .bb-lb-close:hover { background: rgba(255,255,255,.22); }
.bb-lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.bb-lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.bb-lb-close { top: 14px; right: 14px; }
.bb-lb-bar { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; padding: 6px 14px; border-radius: 20px; background: rgba(0,0,0,.6); white-space: nowrap; }

/* ---------- Pins & Ziehpunkte auf der Karte */
#map-container .bb-pin-host, #map-container .bb-handle-host { position: relative; }
#map-container .bb-pin {
	position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
	display: flex; flex-direction: column; align-items: center;
	border: 0; background: none; padding: 0; cursor: pointer; pointer-events: auto;
	font-family: var(--bb-font); color: #fff;
}
#map-container .bb-pin-icon { width: 34px; height: 34px; fill: var(--pin); stroke: rgba(0,0,0,.55); stroke-width: 1.2; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); order: 2; }
#map-container .bb-pin-label {
	order: 1; margin-bottom: 2px; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; white-space: nowrap;
	background: rgba(15, 17, 21, .85); border: 1px solid rgba(255,255,255,.12); max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}
#map-container .bb-pin:hover .bb-pin-icon, #map-container .bb-pin-selected .bb-pin-icon { transform: scale(1.18); transform-origin: bottom center; }
#map-container .bb-pin-selected .bb-pin-label { background: var(--bb-accent); }
.bb-far #map-container .bb-pin-label { display: none; }
.bb-far #map-container .bb-pin-selected .bb-pin-label, .bb-far #map-container .bb-pin:hover .bb-pin-label { display: block; }

#map-container .bb-handle {
	position: absolute; left: 0; top: 0; width: 14px; height: 14px; transform: translate(-50%, -50%);
	border-radius: 50%; background: #fff; border: 3px solid var(--bb-accent); box-sizing: border-box;
	pointer-events: auto; cursor: grab; touch-action: none; box-shadow: 0 1px 4px rgba(0,0,0,.6);
}
#map-container .bb-handle:active { cursor: grabbing; }
#map-container .bb-handle-first { border-color: var(--bb-ok); width: 18px; height: 18px; cursor: pointer; }
#map-container .bb-handle-mid { width: 11px; height: 11px; border-width: 2px; background: rgba(255,255,255,.55); }
.bb-drawing #map-container canvas { cursor: crosshair; }

/* ---------- Legende, Zeichenleiste, Chip, Footer */
.bb-legend {
	position: absolute; left: 12px; bottom: 36px; z-index: 2; max-width: 240px;
	background: var(--bb-surface); border: 1px solid var(--bb-border); border-radius: var(--bb-radius); box-shadow: var(--bb-shadow);
	transition: left .22s ease;
}
.bb-sidebar-open .bb-legend { left: calc(var(--bb-sidebar) + 12px); }
.bb-legend-head { display: flex; justify-content: space-between; align-items: center; width: 100%; border: 0; background: none; padding: 8px 12px; font-weight: 700; cursor: pointer; }
.bb-legend-toggle { color: var(--bb-muted); font-size: 16px; }
.bb-legend ul { list-style: none; margin: 0; padding: 0 6px 8px; max-height: 220px; overflow-y: auto; }
.bb-legend li button { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; text-align: left; }
.bb-legend li button:hover { background: var(--bb-surface-2); }
.bb-legend li span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bb-drawbar {
	position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 6;
	display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center;
	max-width: calc(100% - 24px); box-sizing: border-box;
	padding: 10px 12px; border-radius: 12px;
	background: var(--bb-surface); border: 1px solid var(--bb-accent); box-shadow: var(--bb-shadow);
}
.bb-drawbar-text { font-weight: 600; }
.bb-drawbar-btns { display: flex; gap: 8px; }

.bb-chip {
	position: absolute; z-index: 7; display: grid; gap: 6px; padding: 10px;
	background: var(--bb-surface); border: 1px solid var(--bb-border); border-radius: 12px; box-shadow: var(--bb-shadow);
	min-width: 200px;
}
.bb-chip-coords { color: var(--bb-muted); font-size: 12px; text-align: center; }

.bb-footer {
	position: absolute; right: 10px; bottom: 8px; z-index: 1;
	font-size: 11px; color: var(--bb-muted); background: rgba(20,22,27,.75); padding: 3px 8px; border-radius: 6px;
}
.bb-footer a { color: var(--bb-muted) !important; }

/* ---------- Modal, Toasts */
.bb-modal-backdrop { position: absolute; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.bb-modal { width: min(420px, 100%); box-sizing: border-box; background: var(--bb-surface-2); border: 1px solid var(--bb-border); border-radius: 14px; padding: 20px; box-shadow: var(--bb-shadow); }
.bb-modal h2 { margin: 0 0 6px; font-size: 19px; }
.bb-modal form { display: grid; gap: 10px; }
.bb-snaps { list-style: none; padding: 0; margin: 0 0 8px; max-height: 180px; overflow-y: auto; display: grid; gap: 4px; }

.bb-toasts { position: absolute; left: 50%; top: calc(var(--bb-top) + 12px); transform: translateX(-50%); display: grid; gap: 6px; z-index: 60; pointer-events: none !important; }
.bb-toast { padding: 9px 14px; border-radius: 9px; background: var(--bb-surface-2); border: 1px solid var(--bb-border); box-shadow: var(--bb-shadow); display: flex; gap: 8px; align-items: center; transition: opacity .4s; max-width: 90vw; }
.bb-toast-ok { border-color: var(--bb-ok); }
.bb-toast-error { border-color: var(--bb-danger); color: #ffb3b5; }
.bb-toast-out { opacity: 0; }
.bb-spinner { width: 14px; height: 14px; border: 2px solid var(--bb-accent); border-right-color: transparent; border-radius: 50%; animation: bb-spin .7s linear infinite; }
@keyframes bb-spin { to { transform: rotate(360deg); } }

/* ---------- Handy & schmale Fenster */
@media (max-width: 900px) {
	.bb-sidebar { width: min(88vw, 360px); box-shadow: var(--bb-shadow); z-index: 8; }
	.bb-sb-close { display: inline-flex; }
	.bb-sidebar-open .bb-legend { left: 12px; }
	.bb-panel {
		top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 72%;
		border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: 24px;
	}
	.bb-mapseg { display: none; }
}
@media (min-width: 901px) {
	.bb-menu-btn { display: none; }
	.bb-mapseg-mobile { display: none !important; }
}
.bb-mapseg-mobile button { flex: 1; }
@media (max-width: 640px) {
	:root { --bb-top: 52px; }
	.bb-topbar { padding: 0 8px; gap: 6px; }
	.bb-top-left, .bb-top-right { gap: 6px; }
	.bb-brand span:last-child, .bb-hide-xs { display: none; }
	.bb-lb-img { max-width: 100%; max-height: calc(100% - 140px); border-radius: 0; }
	.bb-lb-prev, .bb-lb-next { top: auto; bottom: 60px; transform: none; }
	.bb-footer { font-size: 10px; right: 4px; bottom: 4px; }
	.bb-legend { bottom: 40px; max-width: 180px; }
	.bb-drawbar { bottom: 40px; }
}
