/* ============================================================
   Bistando – globales Stylesheet (Desktop + iPhone)
   Ersetzt auch alle <style>-Blöcke der Unterseiten.
   ============================================================ */

:root {
	color-scheme: light;
	--bg: #f1f5f9;
	--card: #ffffff;
	--text: #172033;
	--muted: #64748b;
	--line: #e2e8f0;
	--field: #f8fafc;
	--brand: #2563eb;
	--brand-dark: #1e3a8a;
	--danger: #dc2626;
	--ok: #16a34a;
	--shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 10px 28px rgba(15, 23, 42, .06);
	--top: env(safe-area-inset-top, 0px);
	--bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #0b1220;
	--card: #131c2e;
	--text: #e6ebf5;
	--muted: #93a1b8;
	--line: #25314a;
	--field: #1a2540;
	--brand: #4f8bff;
	--shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

:root[data-theme="light"] { color-scheme: light; }

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
}

body {
	display: block;
	min-height: 100vh;
	min-height: 100dvh;
	background: var(--bg);
	color: var(--text);
	font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
	line-height: 1.4;
	overflow-x: hidden;
	-webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
	font: inherit;
	color: inherit;
}

button {
	-webkit-tap-highlight-color: transparent;
}

/* ============================================================
   LAYOUT: feste Sidebar, Seite scrollt – Sidebar bleibt stehen
   ============================================================ */

.sidebar {
	position: fixed;
	inset: 0 auto 0 0;
	width: 240px;
	z-index: 2000;
	display: flex;
	flex-direction: column;
	padding: 20px;
	overflow-y: auto;
	background: linear-gradient(180deg, var(--brand-dark), #2563eb);
	color: #fff;
}

/* <content> existiert im fertigen HTML nicht mehr -> Platz über body schaffen */
body:has(.sidebar) { padding-left: 240px; }

.logo {
	margin-bottom: 30px;
	font-size: 22px;
	font-weight: 700;
	text-align: center;
}

.nav { flex: 1; }

.nav a {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 10px;
	padding: 12px 14px;
	border-radius: 12px;
	background: rgba(255, 255, 255, .1);
	color: #fff;
	text-decoration: none;
	transition: background .2s;
}

.nav a.active {
	background: #fff;
	color: var(--brand);
	font-weight: 700;
}

.nav-icon {
	width: 24px;
	min-width: 24px;
	text-align: center;
	font-size: 20px;
	line-height: 1;
}

.logout {
	width: 100%;
	padding: 12px;
	border: none;
	border-radius: 12px;
	background: rgba(255, 255, 255, .15);
	color: #fff;
	font-size: 16px;
	cursor: pointer;
}

@media (hover: hover) {
	.nav a:hover { background: rgba(255, 255, 255, .22); }
	.logout:hover { background: rgba(255, 255, 255, .3); }
}

.mobile-topbar, .sidebar-overlay, .mobile-menu-close { display: none; }

/* ============================================================
   KARTEN / ÜBERSCHRIFTEN
   ============================================================ */

.dash, .history-container, .device-page { padding: 32px; }

.card, .history-card, .device-card, .cardAddDevice {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 20px;
	padding: 26px;
	box-shadow: var(--shadow);
}

.card, .history-card { overflow-x: auto; }

.cardAddDevice {
	width: min(760px, calc(100% - 64px));
	margin: 32px auto;
}

h2 { font-size: 22px; font-weight: 700; margin-bottom: 20px; }

/* ============================================================
   FORMULAR-FELDER
   ============================================================ */

.filter-group input, .filter-group select,
.history-search input, .history-search select,
.form-group input, .form-group select,
.action-input {
	width: 100%;
	min-width: 0;
	height: 44px;
	padding: 0 12px;
	border: 1px solid var(--line);
	border-radius: 12px;
	background: var(--card);
	font-size: 16px; /* verhindert Auto-Zoom auf dem iPhone */
	outline: none;
	-webkit-appearance: none;
	appearance: none;
}

.filter-group select, .history-search select, .form-group select {
	padding-right: 32px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
}

input[type="date"] { text-align: left; }

.filter-group input:focus, .filter-group select:focus,
.history-search input:focus, .history-search select:focus,
.form-group input:focus, .form-group select:focus,
.action-input:focus {
	border-color: var(--brand);
	box-shadow: 0 0 0 3px rgba(37, 99, 235, .2);
}

.filter-group label, .history-search label, .form-group label {
	display: block;
	margin-bottom: 6px;
	font-size: 13px;
	font-weight: 600;
	color: var(--muted);
}

/* ============================================================
   FILTER
   ============================================================ */

.device-filters, .history-search {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
	gap: 14px;
	align-items: end;
	margin-bottom: 22px;
	padding: 18px;
	background: var(--field);
	border: 1px solid var(--line);
	border-radius: 16px;
}

.filter-group { display: flex; flex-direction: column; }
.filter-group.date-filter, .filter-group.price-filter { grid-column: span 2; }
.history-search > div { display: flex; flex-direction: column; }

.range-inputs { display: flex; align-items: center; gap: 8px; }
.range-inputs span { font-size: 13px; color: var(--muted); }

.reset-filter-btn, #resetSearch {
	height: 44px;
	padding: 0 18px;
	border: none;
	border-radius: 12px;
	background: #ffbf19;
	color: #1f2937;
	font-weight: 700;
	cursor: pointer;
}

#resetSearch { background: var(--line); color: var(--text); }
.reset-filter-btn:active, #resetSearch:active { transform: scale(.97); }

.filter-toggle { display: none; }

/* ============================================================
   TABELLEN (Desktop)
   ============================================================ */

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
	padding: 12px;
	background: var(--field);
	border-bottom: 1px solid var(--line);
	color: var(--muted);
	font-size: 13px;
	font-weight: 600;
	text-align: left;
	white-space: nowrap;
}

td {
	padding: 12px;
	border-bottom: 1px solid var(--line);
	white-space: nowrap;
}

.device-row, .history-device-row { cursor: pointer; }
.device-row td:first-child, .history-device-row td:first-child { font-weight: 700; }

@media (hover: hover) {
	.device-row:hover, .history-device-row:hover { background: var(--field); }
}

.old-value { color: var(--danger); font-weight: 600; }
.new-value { color: var(--ok); font-weight: 600; }

/* ============================================================
   MODALS (Desktop: zentriert)
   ============================================================ */

.overlay, .history-modal, .qr-modal {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 9999;
	align-items: center;
	justify-content: center;
	padding: 20px;
	background: rgba(15, 23, 42, .55);
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
}

.history-modal.open, .qr-modal.active { display: flex; }

.dashboardmodal, .history-modal-content, .qr-modal-content {
	position: relative;
	width: min(800px, 100%);
	max-height: 90vh;
	max-height: 90dvh;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--card);
	color: var(--text);
	border-radius: 22px;
	box-shadow: 0 25px 70px rgba(0, 0, 0, .3);
}

.history-modal-content { max-width: 1000px; padding: 28px; }
.action-modal { width: min(440px, 100%); }

.modal-header {
	position: sticky;
	top: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 18px 24px;
	background: var(--card);
	border-bottom: 1px solid var(--line);
}

.modal-header h2 { margin: 0; font-size: 20px; }

.close-btn, #closeHistoryModal, .qr-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 50%;
	background: var(--field);
	color: var(--muted);
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
}

#closeHistoryModal { position: sticky; top: 0; float: right; margin: 0 0 8px 12px; z-index: 3; }
.qr-close { position: absolute; top: 14px; right: 14px; }

#modalDeviceName { margin: 0 52px 22px 0; }

/* Dashboard-Modal */
.dashboardmodal .device-details {
	display: grid;
	grid-template-columns: 200px 1fr;
	gap: 12px 20px;
	padding: 24px;
}

.detail-label { color: var(--muted); font-weight: 600; font-size: 14px; }

.detail-value {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding-bottom: 8px;
	border-bottom: 1px solid var(--line);
	word-break: break-word;
}

.edit-btn {
	flex-shrink: 0;
	min-width: 40px;
	height: 36px;
	border: none;
	border-radius: 10px;
	background: var(--field);
	cursor: pointer;
}

.modal-footer {
	position: sticky;
	bottom: 0;
	display: flex;
	justify-content: flex-end;
	padding: 16px 24px;
	background: var(--card);
	border-top: 1px solid var(--line);
}

.delete-btn, .confirm-btn, .cancel-btn, .save-btn {
	height: 46px;
	padding: 0 20px;
	border: none;
	border-radius: 12px;
	font-weight: 700;
	cursor: pointer;
}

.delete-btn, .confirm-btn.delete { background: var(--danger); color: #fff; }
.confirm-btn, .save-btn { background: var(--brand); color: #fff; }
.cancel-btn { background: var(--line); color: var(--text); }

.action-input { display: block; margin-top: 16px; }
.action-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* Historie-Modal */
.history-modal .device-details {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 12px;
	margin-bottom: 26px;
}

.history-modal .device-details > div {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 12px 14px;
	background: var(--field);
	border-radius: 12px;
}

.history-modal .device-details strong { font-size: 12px; color: var(--muted); font-weight: 600; }
.history-modal .device-details span { word-break: break-word; }
.history-modal-content hr { border: none; border-top: 1px solid var(--line); margin: 22px 0; }
.history-modal-content h3 { margin: 22px 0 10px; font-size: 17px; }

.history-entry {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px 10px;
	margin-bottom: 8px;
	padding: 12px 14px;
	background: var(--field);
	border-radius: 12px;
	font-size: 14px;
}

.history-entry > span:first-child { min-width: 145px; color: var(--muted); font-size: 13px; }

/* ============================================================
   GERÄTE-DETAILSEITE
   ============================================================ */

.device-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 14px;
	padding-bottom: 22px;
	border-bottom: 1px solid var(--line);
}

.device-title { font-size: 28px; font-weight: 700; line-height: 1.2; }
.device-id { margin-top: 4px; color: var(--muted); font-size: 14px; }

.status-badge {
	flex-shrink: 0;
	padding: 7px 14px;
	border-radius: 999px;
	background: var(--brand);
	color: #fff;
	font-size: 14px;
	font-weight: 600;
}

.device-section { margin-top: 28px; }

.data-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
	gap: 12px;
}

.data-item {
	position: relative;
	min-width: 0;
	padding: 14px 16px;
	background: var(--field);
	border-radius: 14px;
}

.data-item span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 13px; }
.data-item strong { font-size: 15px; word-break: break-word; }

.editable-field { cursor: pointer; padding-right: 44px; user-select: none; transition: transform .08s; }
.editable-field:active { transform: scale(.98); }

.edit-icon {
	position: absolute;
	right: 14px;
	top: 50%;
	margin: 0 !important;
	transform: translateY(-50%);
	font-size: 18px;
	color: var(--brand) !important;
}

#historyLoading { padding: 12px 0; color: var(--muted); }

/* ============================================================
   GERÄT HINZUFÜGEN
   ============================================================ */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
#dynamicFields { display: contents; }
#dynamicFields .form-group { animation: fadeIn .3s ease; }
.save-btn { grid-column: 1 / -1; height: 50px; margin-top: 6px; font-size: 16px; }

@keyframes fadeIn {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: none; }
}

/* QR-Modal */
.qr-modal-content { width: min(420px, 100%); padding: 32px 28px; text-align: center; }

.qr-success-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 54px;
	height: 54px;
	margin: 0 auto 14px;
	border-radius: 50%;
	background: rgba(22, 163, 74, .15);
	color: var(--ok);
	font-size: 28px;
	font-weight: 700;
}

.qr-modal-content h2 { margin: 0; font-size: 22px; }
.qr-description { margin: 8px 0 22px; color: var(--muted); font-size: 14px; }

.qr-code-box {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 232px;
	height: 232px;
	margin: 0 auto 20px;
	background: #fff; /* QR-Code braucht immer weißen Grund */
	border: 1px solid var(--line);
	border-radius: 16px;
}

#qrcode img, #qrcode canvas { display: block; }

.qr-device-info { margin-bottom: 20px; padding: 10px 14px; background: var(--field); border-radius: 12px; }
.qr-device-info span { display: block; margin-bottom: 2px; font-size: 12px; color: var(--muted); }
.qr-device-info strong { word-break: break-all; }

.qr-actions { display: flex; gap: 10px; }
.qr-actions button { flex: 1; height: 46px; border-radius: 12px; font-weight: 700; cursor: pointer; }
.qr-print-btn { border: none; background: var(--brand); color: #fff; }
.qr-close-btn { border: 1px solid var(--line); background: var(--card); color: var(--text); }

/* ============================================================
   LOGIN
   ============================================================ */

body.login {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
	min-height: 100dvh;
	overflow: hidden;
	color-scheme: light;
	color: #172033;
	background: linear-gradient(135deg, #eef2ff, #f8fafc);
}

.video-bg {
	position: fixed;
	inset: 0;
	overflow: hidden;
	background: url(https://cdn.biexcellence.com/git/dev/fragBob/apps/general/img/login-bg.png) center / cover no-repeat;
}

.video-background {
	width: 100%;
	height: 100%;
	object-fit: cover;
	mix-blend-mode: multiply;
}

.loginBody {
	position: fixed;
	inset: 0;
	z-index: 10;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: var(--top) 16px var(--bottom);
	text-align: center;
}

.logintitel {
	font-size: clamp(3rem, 14vw, 8rem);
	font-weight: 800;
	line-height: 1.05;
	color: #2f4d9e;
	text-shadow: 0 4px 10px rgba(0, 0, 0, .15), 0 10px 25px rgba(37, 99, 235, .25);
}

.loginsubtitle {
	margin: 4px 0 32px;
	font-size: clamp(.8rem, 3.6vw, 1.5rem);
	letter-spacing: 2px;
	text-transform: uppercase;
	color: #64748b;
}

form.loginForm.loginForm { width: min(340px, 90vw); margin: auto; opacity: .97; }

.loginForm .w-25 {
	padding: 30px;
	border-radius: 20px;
	background: rgba(255, 255, 255, .92);
	box-shadow: 0 10px 30px rgba(0, 0, 0, .1), 0 0 40px rgba(37, 99, 235, .1);
	-webkit-backdrop-filter: blur(10px);
	backdrop-filter: blur(10px);
}

.loginForm input.form-control {
	width: 100%;
	height: 46px;
	margin-bottom: 14px;
	padding: 0 12px;
	border: 1px solid #d1d5db;
	border-radius: 10px;
	background: #fff;
	color: #172033;
	font-size: 16px;
	outline: none;
}

.loginForm input.form-control:focus {
	border-color: #3b82f6;
	box-shadow: 0 0 0 3px rgba(59, 130, 246, .2);
}

.loginForm .loginBtn {
	width: 100%;
	height: 46px;
	border: none;
	border-radius: 10px;
	background: #3b82f6;
	color: #fff;
	font-weight: 700;
	cursor: pointer;
}

.loginForm .loginBtn:active { background: #2563eb; }

.robot {
	position: fixed;
	z-index: 1;
	width: clamp(90px, 22vw, 180px);
	left: -200px;
	top: 50px;
	pointer-events: none;
	transition: left 12s linear, top 12s linear, transform 2s ease;
}

/* ============================================================
   MOBILE KARTEN (werden vom Skript aus den Tabellen erzeugt)
   ============================================================ */

.mobile-table-cards { display: none; }

.mobile-device-card {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 18px;
	padding: 16px;
	box-shadow: var(--shadow);
	cursor: pointer;
	transition: transform .15s;
}

.mobile-device-card:active { transform: scale(.985); }

.mobile-device-card-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}

.mobile-device-card-title { font-size: 17px; font-weight: 700; line-height: 1.25; }
.mobile-device-card-category { margin-top: 3px; font-size: 13px; color: var(--muted); }

.mobile-device-card-status {
	flex-shrink: 0;
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(37, 99, 235, .12);
	color: var(--brand);
	font-size: 12px;
	font-weight: 700;
}

.mobile-device-card-status[data-s="aktiv"] { background: rgba(22, 163, 74, .15); color: var(--ok); }
.mobile-device-card-status[data-s="defekt"] { background: rgba(220, 38, 38, .14); color: var(--danger); }
.mobile-device-card-status[data-s="außer betrieb"] { background: var(--line); color: var(--muted); }

.mobile-device-card-data { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.mobile-device-card-field { min-width: 0; }
.mobile-device-card-label { display: block; margin-bottom: 1px; font-size: 12px; color: var(--muted); }

.mobile-device-card-value {
	display: block;
	font-size: 14px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.mobile-device-card-arrow { margin-top: 8px; text-align: right; font-size: 20px; color: var(--muted); }

/* ============================================================
   BIS 900px: Menü wird zur Schublade
   ============================================================ */

@media (max-width: 900px) {
	body:has(.sidebar) {
		padding-left: 0;
		padding-top: calc(56px + var(--top));
	}

	.mobile-topbar {
		position: fixed;
		inset: 0 0 auto 0;
		z-index: 3000;
		display: flex;
		align-items: center;
		height: calc(56px + var(--top));
		padding: var(--top) 12px 0;
		background: linear-gradient(135deg, var(--brand-dark), #2563eb);
		color: #fff;
		box-shadow: 0 2px 14px rgba(0, 0, 0, .18);
	}

	.mobile-logo { flex: 1; margin-right: 44px; text-align: center; font-size: 19px; font-weight: 700; }

	.menu-toggle, .mobile-menu-close {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		border: none;
		border-radius: 12px;
		background: rgba(255, 255, 255, .14);
		color: #fff;
		font-size: 24px;
		cursor: pointer;
	}

	.sidebar {
		width: min(300px, 86vw);
		padding: calc(16px + var(--top)) 16px calc(16px + var(--bottom));
		z-index: 4000;
		transform: translateX(-105%);
		transition: transform .28s ease;
	}

	.sidebar.open { transform: none; box-shadow: 10px 0 35px rgba(0, 0, 0, .3); }

	.sidebar-header { display: flex; align-items: center; margin-bottom: 24px; }
	.sidebar-header .logo { flex: 1; margin: 0; text-align: left; }

	.nav a { min-height: 52px; font-size: 16px; border-radius: 14px; }
	.nav a:active { transform: scale(.97); }

	.sidebar-overlay {
		display: block;
		position: fixed;
		inset: 0;
		z-index: 3500;
		background: rgba(0, 0, 0, .45);
		opacity: 0;
		pointer-events: none;
		transition: opacity .25s;
	}

	.sidebar-overlay.show { opacity: 1; pointer-events: auto; }
	body.menu-open { overflow: hidden; }

	.history-modal .device-details { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   BIS 700px: iPhone-Ansicht
   ============================================================ */

@media (max-width: 700px) {
	.dash, .history-container, .device-page {
		padding: 14px calc(14px + env(safe-area-inset-right, 0px)) calc(24px + var(--bottom)) calc(14px + env(safe-area-inset-left, 0px));
	}

	.card, .history-card, .device-card, .cardAddDevice { padding: 16px; border-radius: 20px; }
	.card, .history-card { overflow: visible; }
	.cardAddDevice { width: auto; margin: 14px; }

	h2 { font-size: 21px; margin-bottom: 14px; }

	/* Tabellen -> Karten */
	.mobile-card-table { display: none !important; }
	.mobile-table-cards { display: flex; flex-direction: column; gap: 12px; }

	/* Filter einklappbar */
	.filter-toggle {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 48px;
		margin-bottom: 12px;
		padding: 0 16px;
		border: 1px solid var(--line);
		border-radius: 14px;
		background: var(--field);
		font-weight: 600;
		cursor: pointer;
	}

	.filter-toggle::after { content: "▾"; color: var(--muted); transition: transform .2s; }
	.filter-toggle.on::after { transform: rotate(180deg); }

        
    .device-filters,
    .history-search {
        display: none;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        padding: 12px;
        width: 100%;
        min-width: 0;
    }

    .device-filters.open,
    .history-search.open {
        display: grid;
    }

    .device-filters .filter-group,
    .history-search > div {
        width: 100%;
        min-width: 0;
    }

    .device-filters input,
    .device-filters select,
    .history-search input,
    .history-search select {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: 40px;
        padding: 0 10px;
        font-size: 16px;
    }

    .filter-group.date-filter,
    .filter-group.price-filter {
        grid-column: auto;
    }

    .range-inputs {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 6px;
        width: 100%;
        min-width: 0;
    }

    .range-inputs input {
        width: 100%;
        min-width: 0;
        padding: 0 5px;
        font-size: 14px;
    }

    .range-inputs span {
        font-size: 12px;
    }

    .device-filters .reset-filter-btn,
    #resetSearch {
        width: 100%;
        height: 42px;
        margin-top: 4px;
    }

	.device-filters .reset-filter-btn, #resetSearch { width: 100%; height: 48px; }

	/* Modals -> Bottom-Sheet */
	.overlay, .history-modal, .qr-modal { align-items: flex-end; padding: 0; }

	.dashboardmodal, .history-modal-content, .qr-modal-content {
		width: 100%;
		max-width: none;
		max-height: 92dvh;
		border-radius: 24px 24px 0 0;
		animation: sheetUp .28s ease;
	}

	.history-modal-content { padding: 20px 16px calc(24px + var(--bottom)); }
	.qr-modal-content { padding-bottom: calc(24px + var(--bottom)); }
	.modal-footer { padding-bottom: calc(16px + var(--bottom)); }
	.modal-footer .delete-btn { width: 100%; }

	.dashboardmodal .device-details { grid-template-columns: 1fr; gap: 0; padding: 16px 20px; }
	.detail-label { margin-top: 12px; font-size: 12px; }
	.detail-value { padding-bottom: 8px; }

	.history-modal .device-details { grid-template-columns: 1fr 1fr; gap: 8px; }
	.history-entry > span:first-child { min-width: 100%; }

	.action-buttons button { flex: 1; }

	/* Gerätedetails */
	.device-header { align-items: flex-start; }
	.device-title { font-size: 23px; }
	.data-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
	.data-item { padding: 12px 14px; }
	.editable-field { padding-right: 34px; }
	.edit-icon { right: 10px; }

	/* Änderungsverlauf als kompakte Zeilen */
	.history-table thead { display: none; }
	.history-table, .history-table tbody { display: block; }

	.history-table tr {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 2px 12px;
		padding: 12px 0;
		border-bottom: 1px solid var(--line);
	}

	.history-table td { display: block; padding: 0; border: 0; white-space: normal; word-break: break-word; }
	.history-table td:nth-child(1) { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
	.history-table td:nth-child(2) { grid-column: 1 / -1; font-weight: 700; }

	/* Formular */
	.form-grid { grid-template-columns: 1fr; gap: 14px; }

	/* Login */
	form.loginForm.loginForm { padding: 18px; }
	.loginForm .w-25 { padding: 16px; }
}

@media (max-width: 380px) {
	.mobile-device-card-data { grid-template-columns: 1fr; }
	.data-grid { grid-template-columns: 1fr; }
}

@keyframes sheetUp {
	from { transform: translateY(40px); opacity: 0; }
	to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
	* { animation: none !important; transition: none !important; }
}

/* ============================================================
   EINSTELLUNGEN
   ============================================================ */

.settings-card {
	max-width: 560px;
	margin: 32px;
	padding: 26px;
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 20px;
	box-shadow: var(--shadow);
}

.setting-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 48px; }
.setting-item label { font-weight: 600; }

#darkModeToggle {
	position: relative;
	flex-shrink: 0;
	width: 52px;
	height: 32px;
	border: none;
	border-radius: 999px;
	background: var(--line);
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background .2s;
}

#darkModeToggle::after {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
	transition: transform .2s;
}

#darkModeToggle:checked { background: var(--ok); }
#darkModeToggle:checked::after { transform: translateX(20px); }

@media (max-width: 700px) { .settings-card { margin: 14px; padding: 18px; } }

/* ============================================================
   STATISTIKEN
   ============================================================ */

.stats-page { padding: 32px; }

.stats-kpis {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
	gap: 14px;
	margin-bottom: 14px;
}

.kpi, .stat-card {
	min-width: 0;
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 18px;
	box-shadow: var(--shadow);
}

.kpi { padding: 18px; }

.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--brand)); }
.kpi.ok { --dot: var(--ok); }
.kpi.bad { --dot: var(--danger); }
.kpi.warn { --dot: #f59e0b; }

.kpi-value {
	margin-top: 8px;
	font-size: clamp(24px, 2.4vw, 32px);
	font-weight: 700;
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
	overflow-wrap: anywhere;
}

.kpi-sub { margin-top: 6px; font-size: 12.5px; color: var(--muted); }

.stats-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
	gap: 14px;
}

.stat-card { padding: 20px; }

.stat-card h3 {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	min-height: 30px;
	margin-bottom: 16px;
	font-size: 16px;
	font-weight: 700;
}

.stat-empty, .stat-more { color: var(--muted); font-size: 14px; }
.stat-more { padding-top: 10px; }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut { position: relative; flex-shrink: 0; width: 150px; height: 150px; }
.donut svg { display: block; width: 100%; height: 100%; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center strong { font-size: 28px; line-height: 1; }
.donut-center span { margin-top: 4px; font-size: 12px; color: var(--muted); }

.legend { flex: 1; min-width: 150px; list-style: none; }
.legend li { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; }
.legend b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* Balken */
.bar-row { display: grid; grid-template-columns: minmax(70px, 120px) 1fr auto; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 14px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: 999px; background: var(--field); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--brand); animation: grow .7s ease; }
.bar-val { min-width: 28px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

@keyframes grow { from { width: 0; } }

/* Säulen */
.cols { display: flex; align-items: stretch; gap: 10px; height: 190px; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; }
.col-val { font-size: 12px; font-weight: 600; color: var(--muted); }
.col-bar { width: 100%; max-width: 44px; border-radius: 8px 8px 3px 3px; background: var(--brand); }
.col-label { font-size: 12px; color: var(--muted); }

/* Kürzlich geändert */
.seg { display: inline-flex; padding: 3px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; }
.seg button { height: 28px; padding: 0 10px; border: none; border-radius: 8px; background: none; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }

.recent-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.recent-main { min-width: 0; display: flex; flex-direction: column; }
.recent-main strong, .recent-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-main small { color: var(--muted); font-size: 12.5px; }
.recent-time { flex-shrink: 0; font-size: 12.5px; color: var(--muted); }

@media (max-width: 700px) {
	.stats-page { padding: 14px calc(14px + env(safe-area-inset-right, 0px)) calc(24px + var(--bottom)) calc(14px + env(safe-area-inset-left, 0px)); }
	.stats-kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
	.kpi { padding: 14px; }
	.stat-card { padding: 16px; }
	.seg button { height: 32px; }
}

.recent-main small { white-space: normal; overflow-wrap: anywhere; }

/* ============================================================
   WERT-ÄNDERN-FENSTER (Geräteseite) + HINWEIS
   ============================================================ */

.action-body { padding: 22px 24px 24px; }
.modal-sub { margin-bottom: 14px; color: var(--muted); font-size: 14px; }
.action-body .action-input { margin-top: 0; }

select.action-input {
	padding-right: 32px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
}

.field-error { margin-top: 10px; color: var(--danger); font-size: 14px; font-weight: 600; }
.field-error[hidden] { display: none; }

.cancel-btn:disabled, .confirm-btn:disabled { opacity: .6; cursor: default; }

.toast {
	position: fixed;
	left: 50%;
	bottom: calc(24px + var(--bottom));
	z-index: 10000;
	max-width: calc(100% - 32px);
	padding: 12px 18px;
	border-radius: 999px;
	background: var(--text);
	color: var(--bg);
	font-size: 14px;
	font-weight: 600;
	text-align: center;
	opacity: 0;
	transform: translate(-50%, 16px);
	pointer-events: none;
	transition: opacity .25s, transform .25s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes flash { from { background: rgba(22, 163, 74, .3); } }
.flash { animation: flash 1.4s ease; }

@media (max-width: 700px) {
	.action-body { padding: 18px 20px calc(22px + var(--bottom)); }
}