:root {
	--bg: #0b0f17;
	--bg-elevated: #111827;
	--card: #151c2c;
	--card-hover: #1a2236;
	--border: #243047;
	--border-light: #2f3d56;
	--text: #e8edf7;
	--text-muted: #8b95a8;
	--primary: #5b8cff;
	--primary-hover: #4a7aef;
	--primary-soft: rgba(91, 140, 255, 0.12);
	--success: #22c55e;
	--success-soft: rgba(34, 197, 94, 0.12);
	--danger: #ef4444;
	--danger-soft: rgba(239, 68, 68, 0.12);
	--warning: #f59e0b;
	--radius: 12px;
	--radius-sm: 8px;
	--shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
	--sidebar-w: 300px;
	--topbar-h: 60px;
	--font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
	height: 100%;
	margin: 0;
	font-family: var(--font);
	font-size: 14px;
	line-height: 1.5;
	color: var(--text);
	background: var(--bg);
	-webkit-font-smoothing: antialiased;
}

body {
	display: flex;
	flex-direction: column;
	min-height: 100%;
	overflow: hidden;
}

/* ── Topbar ── */
.topbar {
	height: var(--topbar-h);
	padding: 0 20px;
	display: flex;
	align-items: center;
	gap: 16px;
	border-bottom: 1px solid var(--border);
	background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent);
	flex-shrink: 0;
}

.brand {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 180px;
}

.brand strong {
	display: block;
	font-size: 15px;
	font-weight: 700;
	letter-spacing: 0.2px;
}

.brand small {
	display: block;
	font-size: 11px;
	color: var(--text-muted);
	margin-top: 1px;
}

.logo-dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--primary);
	box-shadow: 0 0 0 4px var(--primary-soft);
	flex-shrink: 0;
}

.topbar-center {
	display: flex;
	align-items: center;
	gap: 10px;
	flex: 1;
	min-width: 0;
}

.topbar-actions {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-left: auto;
}

.pill-field {
	display: flex;
	align-items: center;
	gap: 8px;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 6px 12px 6px 14px;
	min-width: 0;
}

.pill-field.compact { max-width: 140px; }

.pill-field span {
	font-size: 11px;
	color: var(--text-muted);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	white-space: nowrap;
}

.pill-field input {
	border: 0;
	background: transparent;
	color: var(--text);
	outline: none;
	font-size: 13px;
	min-width: 120px;
	width: 100%;
}

.user-chip {
	display: flex;
	align-items: center;
	gap: 8px;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 4px 6px 4px 12px;
}

.avatar {
	font-size: 13px;
	font-weight: 600;
}

.toggle-pill {
	display: flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
	user-select: none;
	font-size: 13px;
	color: var(--text-muted);
}

.toggle-pill input { display: none; }

.toggle-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4b5563;
	transition: background 0.2s, box-shadow 0.2s;
}

.toggle-pill input:checked + .toggle-dot {
	background: var(--success);
	box-shadow: 0 0 0 4px var(--success-soft);
}

.toggle-pill input:checked ~ span:last-child { color: var(--success); }

/* ── Layout ── */
.app-layout {
	display: grid;
	grid-template-columns: var(--sidebar-w) 1fr;
	flex: 1;
	min-height: 0;
	overflow: hidden;
}

.sidebar {
	border-right: 1px solid var(--border);
	padding: 16px;
	overflow-y: auto;
	background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent);
}

.content {
	display: flex;
	flex-direction: column;
	min-width: 0;
	min-height: 0;
	flex: 1;
	overflow: hidden;
}

.stage {
	display: grid;
	grid-template-columns: 1fr 380px;
	grid-template-rows: minmax(0, 1fr);
	gap: 16px;
	padding: 16px;
	flex: 1 1 0;
	min-height: 0;
	overflow: hidden;
	align-items: stretch;
}

/* ── Cards ── */
.card {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 14px;
	margin-bottom: 12px;
}

.card-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}

.card-head h3 {
	margin: 0;
	font-size: 13px;
	font-weight: 600;
	color: var(--text);
}

.card-desc {
	margin: 4px 0 0;
	font-size: 12px;
	color: var(--text-muted);
}

.badge {
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.6px;
	padding: 3px 8px;
	border-radius: 999px;
	background: var(--primary-soft);
	color: var(--primary);
	border: 1px solid rgba(91, 140, 255, 0.25);
}

.badge-muted {
	background: rgba(255,255,255,0.04);
	color: var(--text-muted);
	border-color: var(--border);
}

.badge-warning {
	background: rgba(245, 158, 11, 0.12);
	color: #fbbf24;
	border-color: rgba(245, 158, 11, 0.35);
}

.card-warning {
	border-color: rgba(245, 158, 11, 0.35);
}

.card-warning .card-desc strong {
	color: #fbbf24;
	font-weight: 600;
}

/* ── Form fields ── */
.field {
	display: grid;
	grid-template-columns: 72px 1fr;
	align-items: center;
	gap: 8px;
	margin-bottom: 8px;
}

.field span {
	font-size: 12px;
	color: var(--text-muted);
}

.field.inline {
	display: inline-grid;
	grid-template-columns: auto 1fr;
	margin-bottom: 0;
}

.field-grid {
	display: grid;
	gap: 4px;
}

input, select, .select {
	width: 100%;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 8px 10px;
	color: var(--text);
	font-size: 13px;
	font-family: inherit;
	outline: none;
	transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
	border-color: var(--primary);
	box-shadow: 0 0 0 3px var(--primary-soft);
}

input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

input[type="datetime-local"] {
	min-width: 0;
	max-width: 100%;
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
	filter: invert(0.7);
	cursor: pointer;
}

.input-suffix {
	display: flex;
	align-items: center;
	gap: 6px;
}

.input-suffix input { flex: 1; }

.input-suffix em {
	font-style: normal;
	font-size: 12px;
	color: var(--text-muted);
	white-space: nowrap;
}

.input-suffix.compact input { width: 72px; }

.input-group {
	display: flex;
	gap: 6px;
}

.input-group input { flex: 1; }

.check-row {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 8px 0 12px;
	font-size: 12px;
	color: var(--text-muted);
	cursor: pointer;
}

.check-row input { width: auto; accent-color: var(--primary); }

.hint {
	margin: 8px 0 0;
	font-size: 11px;
	color: var(--text-muted);
	word-break: break-all;
}

.hint.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* ── Buttons ── */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 8px 14px;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--bg-elevated);
	color: var(--text);
	font-size: 13px;
	font-family: inherit;
	font-weight: 500;
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s, transform 0.1s;
	white-space: nowrap;
}

.btn:hover {
	background: var(--card-hover);
	border-color: var(--border-light);
}

.btn:active { transform: scale(0.98); }

.btn-primary {
	background: linear-gradient(180deg, rgba(91,140,255,0.25), rgba(91,140,255,0.12));
	border-color: rgba(91, 140, 255, 0.45);
	color: #dbeafe;
}

.btn-primary:hover {
	background: linear-gradient(180deg, rgba(91,140,255,0.35), rgba(91,140,255,0.18));
	border-color: var(--primary);
}

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

.btn-ghost:hover {
	background: rgba(255,255,255,0.04);
	color: var(--text);
}

.btn-sm { padding: 6px 10px; font-size: 12px; }

.btn-block { width: 100%; }

.btn-row {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 4px;
}

/* ── Map ── */
.map-wrap {
	position: relative;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	overflow: hidden;
	min-height: 0;
	height: 100%;
	background: #0a0e16;
}

#map {
	width: 100%;
	height: 100%;
	min-height: 0;
}

.map-badge {
	position: absolute;
	top: 12px;
	left: 12px;
	z-index: 2;
	font-size: 11px;
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(11, 15, 23, 0.82);
	border: 1px solid var(--border);
	color: var(--text-muted);
	backdrop-filter: blur(8px);
	pointer-events: none;
}

.map-placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	min-height: 0;
	color: var(--text-muted);
	text-align: center;
	padding: 24px;
	line-height: 1.7;
}

.map-auth-banner {
	position: absolute;
	inset: 12px;
	z-index: 10;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 20px 24px;
	border-radius: var(--radius-sm);
	background: rgba(11, 15, 23, 0.92);
	border: 1px solid rgba(245, 158, 11, 0.45);
	color: var(--text);
	pointer-events: none;
	line-height: 1.6;
}

.map-auth-banner strong {
	color: #fbbf24;
	font-size: 15px;
	margin-bottom: 8px;
}

.map-auth-banner p {
	margin: 6px 0;
	font-size: 13px;
	color: var(--text-muted);
	max-width: 420px;
}

.map-auth-hint code {
	color: #93c5fd;
	font-family: ui-monospace, Consolas, monospace;
}

/* ── Device panel ── */
.device-panel {
	display: flex;
	flex-direction: column;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--card);
	overflow: hidden;
	min-height: 0;
	height: 100%;
}

.panel-head {
	padding: 12px 14px;
	border-bottom: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.panel-head h3 {
	margin: 0;
	font-size: 13px;
	font-weight: 600;
}

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

.chip {
	font-size: 11px;
	padding: 3px 8px;
	border-radius: 999px;
	background: var(--primary-soft);
	color: var(--primary);
	border: 1px solid rgba(91, 140, 255, 0.2);
}

.chip-muted {
	background: rgba(255,255,255,0.04);
	color: var(--text-muted);
	border-color: var(--border);
}

.chip em {
	font-style: normal;
	font-weight: 600;
}

.table-wrap {
	flex: 1;
	overflow: auto;
	min-height: 0;
}

#tbl {
	width: 100%;
	border-collapse: collapse;
}

#tbl th {
	position: sticky;
	top: 0;
	z-index: 1;
	background: var(--bg-elevated);
	text-align: left;
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.4px;
	color: var(--text-muted);
	padding: 10px 12px;
	border-bottom: 1px solid var(--border);
	white-space: nowrap;
}

#tbl td {
	padding: 10px 12px;
	font-size: 12px;
	border-bottom: 1px solid rgba(36, 48, 71, 0.6);
	vertical-align: middle;
}

#tbl tbody tr {
	cursor: pointer;
	transition: background 0.12s;
}

#tbl tbody tr:hover { background: rgba(91, 140, 255, 0.06); }

#tbl tbody tr:active { background: rgba(91, 140, 255, 0.1); }

/* ── Power config ── */
.power-config {
	margin: 0 16px 16px;
	flex: 0 0 auto;
	max-height: min(42vh, 360px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 0;
}

.power-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px;
	flex-shrink: 0;
}

.version-tag {
	font-size: 11px;
	font-family: ui-monospace, Consolas, monospace;
	color: var(--text-muted);
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(255,255,255,0.04);
	border: 1px solid var(--border);
}

.power-table-wrap {
	margin-top: 4px;
	flex: 1 1 auto;
	min-height: 0;
	overflow: auto;
}

.power-config-table {
	width: 100%;
	border-collapse: collapse;
}

.power-config-table th,
.power-config-table td {
	padding: 10px 12px;
	border-bottom: 1px solid rgba(36, 48, 71, 0.6);
	font-size: 12px;
	text-align: left;
	vertical-align: middle;
}

.power-config-table th {
	background: var(--bg-elevated);
	font-size: 11px;
	font-weight: 600;
	color: var(--text-muted);
	text-transform: uppercase;
	letter-spacing: 0.4px;
}

.power-config-table td:first-child {
	color: var(--text-muted);
	font-weight: 500;
	min-width: 140px;
}

.power-config-table input,
.power-config-table select {
	padding: 6px 8px;
	font-size: 12px;
}

.cell-check { text-align: center; }
.cell-check input { width: auto; accent-color: var(--primary); }

.mode-dot {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	margin-right: 6px;
	vertical-align: middle;
}

.mode-dot.save { background: var(--success); }
.mode-dot.balanced { background: var(--primary); }
.mode-dot.high { background: var(--warning); }

/* ── Alerts ── */
.alert {
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	font-size: 13px;
	margin-top: 10px;
}

.alert-error {
	color: #fca5a5;
	background: var(--danger-soft);
	border: 1px solid rgba(239, 68, 68, 0.25);
}

.alert-success,
.success {
	color: #86efac;
	background: var(--success-soft);
	border: 1px solid rgba(34, 197, 94, 0.25);
}

.error {
	color: #fca5a5;
	background: var(--danger-soft);
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	border: 1px solid rgba(239, 68, 68, 0.25);
}

/* ── Modal ── */
.modal {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 1000;
	place-items: center;
}

.modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.65);
	backdrop-filter: blur(4px);
}

.modal-card {
	position: relative;
	width: 400px;
	max-width: calc(100vw - 32px);
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 16px;
	padding: 28px;
	box-shadow: var(--shadow);
}

.modal-brand {
	display: flex;
	align-items: center;
	gap: 14px;
	margin-bottom: 24px;
}

.modal-brand h2 {
	margin: 0;
	font-size: 18px;
	font-weight: 700;
}

.modal-brand p {
	margin: 2px 0 0;
	font-size: 13px;
	color: var(--text-muted);
}

.modal-form .field {
	grid-template-columns: 64px 1fr;
	margin-bottom: 14px;
}

.form-actions { margin-top: 8px; }

.status-badge {
	display: inline-block;
	font-size: 11px;
	font-weight: 600;
	padding: 2px 8px;
	border-radius: 999px;
}

.status-badge.online {
	color: #86efac;
	background: var(--success-soft);
	border: 1px solid rgba(34, 197, 94, 0.25);
}

.status-badge.offline {
	color: var(--text-muted);
	background: rgba(255,255,255,0.04);
	border: 1px solid var(--border);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
	background: var(--border);
	border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Responsive ── */
@media (max-width: 1200px) {
	.stage {
		grid-template-columns: 1fr;
		grid-template-rows: minmax(240px, 1fr) minmax(180px, auto);
	}

	.device-panel {
		max-height: 280px;
		height: auto;
	}
}

@media (max-width: 900px) {
	body { overflow: auto; }

	.app-layout {
		grid-template-columns: 1fr;
		overflow: visible;
	}

	.sidebar {
		border-right: 0;
		border-bottom: 1px solid var(--border);
		max-height: none;
	}

	.topbar {
		flex-wrap: wrap;
		height: auto;
		padding: 12px 16px;
		gap: 10px;
	}

	.topbar-center { order: 3; width: 100%; }

	.pill-field { flex: 1; }

	.content { overflow: visible; }

	.stage { padding: 12px; }

	.power-config { margin: 0 12px 12px; }

	.power-meta { width: 100%; }
}
