/* Victron Gateway */
:root {
	--bg: #0b1a2e;
	--surface: #11233c;
	--surface-2: #172d4b;
	--border: #233d60;
	--text: #e8eef7;
	--muted: #8fa2bd;
	--primary: #3d8bfd;
	--primary-strong: #1f6fd1;
	--on-primary: #ffffff;
	--solar: #f5a524;
	--battery: #22c55e;
	--danger: #f05252;
	--ac: #38bdf8;
	--dc: #a78bfa;
	--shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .18);
	--radius: 14px;
	--font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
	color-scheme: dark;
}
:root[data-theme="light"] {
	--bg: #f2f5fa;
	--surface: #ffffff;
	--surface-2: #eef3fa;
	--border: #dbe3ef;
	--text: #0f1e33;
	--muted: #5b6b82;
	--primary: #1f6fd1;
	--primary-strong: #1559ad;
	--solar: #d98b06;
	--battery: #16a34a;
	--danger: #dc2626;
	--ac: #0284c7;
	--dc: #7c3aed;
	--shadow: 0 1px 2px rgba(15, 30, 51, .06), 0 8px 24px rgba(15, 30, 51, .06);
	color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.5 var(--font);
	min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.mono { font-family: var(--mono); font-size: .9em; }
[hidden] { display: none !important; }

/* ---- top bar / nav ------------------------------------------------------- */
.topbar {
	position: sticky; top: 0; z-index: 10;
	display: flex; align-items: center; gap: 24px;
	padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
	background: color-mix(in srgb, var(--bg) 85%, transparent);
	backdrop-filter: blur(12px);
	border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-mark rect { fill: var(--primary-strong); }
.brand-mark path { fill: #fff; }
.brand-mark.big { width: 56px; height: 56px; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.topnav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topnav a.active { color: var(--text); background: var(--surface-2); }
.topbar-actions { display: flex; gap: 4px; margin-left: auto; }
.topbar-actions form { margin: 0; }
.icon-btn {
	display: grid; place-items: center; width: 38px; height: 38px;
	background: none; border: 0; border-radius: 10px; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

.bottomnav { display: none; }

.main { max-width: 1360px; margin: 0 auto; padding: 24px 16px 48px; }

@media (max-width: 760px) {
	.topnav { display: none; }
	.topbar { gap: 12px; }
	.has-nav .main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
	.bottomnav {
		position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
		display: grid; grid-template-columns: repeat(4, 1fr);
		padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
		background: color-mix(in srgb, var(--surface) 92%, transparent);
		backdrop-filter: blur(12px);
		border-top: 1px solid var(--border);
	}
	.bottomnav a {
		display: flex; flex-direction: column; align-items: center; gap: 2px;
		padding: 6px 0; color: var(--muted); font-size: .72rem; font-weight: 500; border-radius: 10px;
	}
	.bottomnav a:hover { text-decoration: none; }
	.bottomnav a.active { color: var(--primary); }
	.bottomnav svg { width: 22px; height: 22px; fill: currentColor; }
	h1 { font-size: 1.35rem; }
}

/* ---- generic ---------------------------------------------------------------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-block; font-size: .85rem; margin-bottom: 6px; }
.card {
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
	padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 16px; }
.grid-2 > .card + .card { margin-top: 0; }
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 6px;
	padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
	background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: var(--primary); }
.btn.primary { background: var(--primary-strong); border-color: var(--primary-strong); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.badge {
	display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
	font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.badge.ok { color: var(--battery); background: color-mix(in srgb, var(--battery) 14%, transparent); }
.badge.ok::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 2s infinite; }
.badge.off { color: var(--muted); }
.badge.premium { color: var(--solar); background: color-mix(in srgb, var(--solar) 16%, transparent); }
@keyframes pulse { 50% { opacity: .35; } }
.alert {
	padding: 10px 14px; border-radius: 10px; margin-bottom: 16px;
	background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 500;
}
.alert.ok { background: color-mix(in srgb, var(--battery) 14%, transparent); color: var(--battery); }
.empty { text-align: center; padding: 48px 16px; max-width: 420px; margin: 0 auto; }
.empty svg { width: 48px; height: 48px; fill: var(--muted); opacity: .6; }
.empty h2 { margin: 8px 0; }

/* ---- forms ------------------------------------------------------------------ */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: .9rem; font-weight: 500; }
input[type=text], input[type=password], input[type=email], select {
	width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
	background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.rename summary { list-style: none; }
.rename summary::-webkit-details-marker { display: none; }
.rename[open] summary { display: none; }
.rename[open] .inline-form { margin-top: 0; }

/* ---- login ------------------------------------------------------------------ */
.login-wrap { min-height: calc(100vh - 72px); display: grid; place-items: center; }
.login-card {
	width: 100%; max-width: 400px; padding: 32px 28px; border-radius: 20px;
	background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { margin-top: 12px; }
.login-brand p { margin: 4px 0 0; }

/* ---- dashboard ---------------------------------------------------------------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
	padding: 14px 16px; display: grid; gap: 2px; box-shadow: var(--shadow);
}
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.solar .stat-value { color: var(--solar); }
.stat.battery .stat-value { color: var(--battery); }
@media (max-width: 480px) {
	.dev-rows { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
	.summary { gap: 8px; }
	.stat { padding: 10px 12px; }
	.stat-value { font-size: 1.15rem; }
}

.group + .group { margin-top: 28px; }
.group-title { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.cards { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr)); gap: 16px; }
.dev {
	position: relative; display: grid; gap: 12px; color: var(--text);
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
	padding: 16px 18px; box-shadow: var(--shadow); overflow: hidden;
	transition: transform .15s ease, border-color .15s ease;
}
.dev:hover { text-decoration: none; transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.dev::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.dev { -webkit-touch-callout: none; }
.sorting, .sorting * { user-select: none; -webkit-user-select: none; cursor: grabbing; }
.dev.dragging { z-index: 5; transition: none; opacity: 1; border-color: var(--accent); box-shadow: 0 14px 36px rgba(0, 0, 0, .35); }
.reorder-hint { margin-top: 14px; }
.dev.offline { opacity: .6; }
.dev-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.dev-name { font-weight: 600; }
.dev-type { font-size: .8rem; color: var(--muted); }
.dev-main { display: flex; align-items: baseline; gap: 6px; }
.dev-main .v { font-size: 2.2rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--accent); }
.dev-main .u { color: var(--muted); font-weight: 600; }
.dev-main .l { margin-left: auto; font-size: .8rem; color: var(--muted); }
.dev-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin: 0; }
.dev-rows div { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; }
.dev-rows dt { color: var(--muted); }
.dev-rows dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.dev-foot { font-size: .75rem; color: var(--muted); display: flex; justify-content: space-between; }
.socbar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.socbar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s ease; }

.accent-solar, .dev.accent-solar { --accent: var(--solar); }
.accent-battery, .dev.accent-battery { --accent: var(--battery); }
.accent-ac, .dev.accent-ac { --accent: var(--ac); }
.accent-dc, .dev.accent-dc { --accent: var(--dc); }

/* ---- device page ---------------------------------------------------------------- */
.device-hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.device-hero .dev-main .v { font-size: 3rem; }
.hero-side { display: grid; gap: 4px; text-align: right; }
.fields { margin: 0; display: grid; }
.fields > div:not(.cells) { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.fields > div:last-child { border-bottom: 0; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.cells { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; align-items: end; height: 110px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cells > span { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; height: 100%; font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cells i { width: 100%; background: var(--battery); border-radius: 4px 4px 0 0; min-height: 4px; }

/* ---- yield chart ------------------------------------------------------------------ */
.yc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.tabs button {
	border: 0; background: none; color: var(--muted); font: inherit; font-size: .85rem; font-weight: 600;
	padding: 5px 12px; border-radius: 8px; cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.yc-nav { display: flex; align-items: center; gap: 4px; }
.yc-nav button {
	width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
	background: none; color: var(--text); cursor: pointer; font-size: 1rem;
}
.yc-nav button:disabled { opacity: .35; cursor: default; }
.yc-title { min-width: 120px; text-align: center; font-weight: 600; font-size: .9rem; }
.yc-total { font-size: 1.6rem; font-weight: 700; color: var(--solar); font-variant-numeric: tabular-nums; }
.yc-total small { font-size: .85rem; color: var(--muted); font-weight: 500; margin-left: 6px; }
.yc-svg { width: 100%; height: 220px; display: block; margin-top: 8px; }
.yc-svg .bar { fill: var(--solar); }
.yc-svg .bar:hover { fill: color-mix(in srgb, var(--solar) 75%, var(--text)); }
.yc-svg .grid { stroke: var(--border); stroke-width: 1; }
.yc-svg text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.yc-tip { min-height: 1.4em; font-size: .85rem; color: var(--muted); text-align: center; }

/* ---- lists ---------------------------------------------------------------------- */
.list { display: grid; gap: 12px; }
.list .card + .card { margin-top: 0; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row-title { font-weight: 600; }
.right { text-align: right; display: grid; gap: 4px; justify-items: end; }
.gw-msg { margin: 12px 0 0; }

/* ---- export menu ------------------------------------------------------------------ */
.export { position: relative; }
.export summary { list-style: none; }
.export summary::-webkit-details-marker { display: none; }
.export-menu {
	position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; min-width: 280px; max-width: calc(100vw - 32px);
	display: grid; padding: 6px; border-radius: 12px;
	background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.export-menu a { padding: 9px 12px; border-radius: 8px; color: var(--text); font-size: .9rem; }
.export-menu a:hover { background: var(--surface-2); text-decoration: none; }
@media (max-width: 560px) {
	.export-menu { right: auto; left: 0; }
}

/* ---- language switch on the login page ------------------------------------------- */
.login-wrap { align-content: center; gap: 20px; }
.lang-switch { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; max-width: 400px; }
.lang-switch a { color: var(--muted); font-size: .85rem; }
.lang-switch a.active { color: var(--text); font-weight: 600; }
.test-mail { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); justify-items: start; }
.test-mail p { margin: 0; }
.form label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.form label.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---- notifications (alert rules) ---------------------------------------------------- */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rules { display: grid; }
.rule { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.rule:first-child { padding-top: 0; }
.rule:last-child { border-bottom: 0; }
.rule-side { display: grid; gap: 8px; justify-items: end; }
.rule-actions { display: flex; gap: 6px; }
.badge.warn { color: var(--solar); background: color-mix(in srgb, var(--solar) 16%, transparent); }
.badge.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 16%, transparent); }
.card-subtitle { font-size: .9rem; font-weight: 600; margin: 20px 0 4px; color: var(--muted); }
.text-danger { color: var(--danger); }
.text-ok { color: var(--battery); }
