/*
 * Guest villa-state strip (Piste C).
 *
 * A single line at the top of the guest dashboard whose tone reflects the
 * current power state of the villa (green nominal, amber sur-groupe,
 * red panne secteur). Water gets its own line beneath, hidden when nominal.
 *
 * Design tokens: derives its own --gs-villa-state-* palette from the
 * existing --gs-color-* semantic tokens so it stays in sync with the
 * portal theme (light / dark). Never hardcodes a color.
 *
 * Scoped under the portal shell so no other page can drag these styles in.
 */

.mphb-gs-shell .gs-villa-state {
	/* Tone accents, resolved per tone via data-tone above.
	 * Defaults picked to match --gs-color-* semantics :
	 *   ok        → success (green)
	 *   warn      → warning (amber)
	 *   warn-pale → warning (pale amber for RETOUR_SECTEUR_ATTENTE)
	 *   crit      → error (red)
	 *   crit-deep → error (deep red)
	 */
	--gs-villa-state-radius: 12px;
	--gs-villa-state-pad-y: 12px;
	--gs-villa-state-pad-x: 14px;
	--gs-villa-state-bar-w: 3px;
	--gs-villa-state-gap: 8px;

	display: flex;
	flex-direction: column;
	gap: 8px;
	margin: 0 0 var(--gs-space-lg, 16px);
}

.mphb-gs-shell .gs-villa-state__row {
	position: relative;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: var(--gs-villa-state-pad-y) var(--gs-villa-state-pad-x) var(--gs-villa-state-pad-y) calc(var(--gs-villa-state-pad-x) + var(--gs-villa-state-bar-w));
	background: var(--gs-color-surface, #fff);
	border: 1px solid var(--gs-color-border, #e5e7eb);
	border-radius: var(--gs-villa-state-radius);
	overflow: hidden;
	transition: background-color 0.2s ease, border-color 0.2s ease;
}

.mphb-gs-shell .gs-villa-state__row::before {
	content: "";
	position: absolute;
	inset: 0 auto 0 0;
	width: var(--gs-villa-state-bar-w);
	background: var(--gs-villa-state-accent, var(--gs-color-success, #22c55e));
}

.mphb-gs-shell .gs-villa-state__dot {
	flex: 0 0 10px;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--gs-villa-state-accent, var(--gs-color-success, #22c55e));
	box-shadow: 0 0 0 4px var(--gs-villa-state-accent-halo, rgba(34, 197, 94, 0.18));
}

.mphb-gs-shell .gs-villa-state__subtitle {
	margin: 0;
	flex: 1 1 auto;
	min-width: 0;
	font-size: 13px;
	line-height: 1.4;
	font-weight: 500;
	color: var(--gs-color-text, #0f172a);
}

.mphb-gs-shell .gs-villa-state__row[hidden] {
	display: none;
}

/* ============================================================
 * Tones — per data-tone on .gs-villa-state__row
 * Each tone sets --gs-villa-state-accent + halo.
 * ============================================================ */

.mphb-gs-shell .gs-villa-state__row[data-tone="ok"] {
	--gs-villa-state-accent: var(--gs-color-success, #22c55e);
	--gs-villa-state-accent-halo: color-mix(in srgb, var(--gs-color-success, #22c55e) 20%, transparent);
	background: color-mix(in srgb, var(--gs-color-success, #22c55e) 6%, var(--gs-color-surface, #fff));
	border-color: color-mix(in srgb, var(--gs-color-success, #22c55e) 25%, var(--gs-color-border, #e5e7eb));
}

.mphb-gs-shell .gs-villa-state__row[data-tone="warn"] {
	--gs-villa-state-accent: var(--gs-color-warning, #f59e0b);
	--gs-villa-state-accent-halo: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 22%, transparent);
	background: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 8%, var(--gs-color-surface, #fff));
	border-color: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 35%, var(--gs-color-border, #e5e7eb));
}

.mphb-gs-shell .gs-villa-state__row[data-tone="warn-pale"] {
	--gs-villa-state-accent: var(--gs-color-warning, #f59e0b);
	--gs-villa-state-accent-halo: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 12%, transparent);
	background: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 4%, var(--gs-color-surface, #fff));
	border-color: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 22%, var(--gs-color-border, #e5e7eb));
}

.mphb-gs-shell .gs-villa-state__row[data-tone="crit"] {
	--gs-villa-state-accent: var(--gs-color-error, #ef4444);
	--gs-villa-state-accent-halo: color-mix(in srgb, var(--gs-color-error, #ef4444) 22%, transparent);
	background: color-mix(in srgb, var(--gs-color-error, #ef4444) 8%, var(--gs-color-surface, #fff));
	border-color: color-mix(in srgb, var(--gs-color-error, #ef4444) 35%, var(--gs-color-border, #e5e7eb));
}

.mphb-gs-shell .gs-villa-state__row[data-tone="crit-deep"] {
	--gs-villa-state-accent: var(--gs-color-error, #ef4444);
	--gs-villa-state-accent-halo: color-mix(in srgb, var(--gs-color-error, #ef4444) 30%, transparent);
	background: color-mix(in srgb, var(--gs-color-error, #ef4444) 14%, var(--gs-color-surface, #fff));
	border-color: color-mix(in srgb, var(--gs-color-error, #ef4444) 48%, var(--gs-color-border, #e5e7eb));
}

.mphb-gs-shell .gs-villa-state__row[data-tone="crit"] .gs-villa-state__dot,
.mphb-gs-shell .gs-villa-state__row[data-tone="crit-deep"] .gs-villa-state__dot {
	animation: gs-villa-state-pulse 1.8s ease-in-out infinite;
}

@keyframes gs-villa-state-pulse {
	0%, 100% { box-shadow: 0 0 0 4px var(--gs-villa-state-accent-halo); }
	50%      { box-shadow: 0 0 0 8px transparent; }
}

/* ============================================================
 * Dark theme — the shell exposes --gs-color-surface / --gs-color-text
 * with dark values under [data-theme="dark"] and via prefers-color-scheme
 * on [data-theme="auto"]. The tokens above therefore already flip.
 * The tone backgrounds use color-mix() with the surface token so they
 * darken automatically — no extra rules needed. This block just widens
 * the accent halos slightly on dark for readability.
 * ============================================================ */

.mphb-gs-shell[data-theme="dark"] .gs-villa-state__row[data-tone="ok"] {
	background: color-mix(in srgb, var(--gs-color-success, #22c55e) 12%, var(--gs-color-surface, #14212b));
}
.mphb-gs-shell[data-theme="dark"] .gs-villa-state__row[data-tone="warn"] {
	background: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 14%, var(--gs-color-surface, #14212b));
}
.mphb-gs-shell[data-theme="dark"] .gs-villa-state__row[data-tone="warn-pale"] {
	background: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 8%, var(--gs-color-surface, #14212b));
}
.mphb-gs-shell[data-theme="dark"] .gs-villa-state__row[data-tone="crit"] {
	background: color-mix(in srgb, var(--gs-color-error, #ef4444) 14%, var(--gs-color-surface, #14212b));
}
.mphb-gs-shell[data-theme="dark"] .gs-villa-state__row[data-tone="crit-deep"] {
	background: color-mix(in srgb, var(--gs-color-error, #ef4444) 22%, var(--gs-color-surface, #14212b));
}

@media (prefers-color-scheme: dark) {
	.mphb-gs-shell[data-theme="auto"] .gs-villa-state__row[data-tone="ok"] {
		background: color-mix(in srgb, var(--gs-color-success, #22c55e) 12%, var(--gs-color-surface, #14212b));
	}
	.mphb-gs-shell[data-theme="auto"] .gs-villa-state__row[data-tone="warn"] {
		background: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 14%, var(--gs-color-surface, #14212b));
	}
	.mphb-gs-shell[data-theme="auto"] .gs-villa-state__row[data-tone="warn-pale"] {
		background: color-mix(in srgb, var(--gs-color-warning, #f59e0b) 8%, var(--gs-color-surface, #14212b));
	}
	.mphb-gs-shell[data-theme="auto"] .gs-villa-state__row[data-tone="crit"] {
		background: color-mix(in srgb, var(--gs-color-error, #ef4444) 14%, var(--gs-color-surface, #14212b));
	}
	.mphb-gs-shell[data-theme="auto"] .gs-villa-state__row[data-tone="crit-deep"] {
		background: color-mix(in srgb, var(--gs-color-error, #ef4444) 22%, var(--gs-color-surface, #14212b));
	}
}

/* ============================================================
 * Responsive — wrap banner text on narrow screens so safety
 * instructions remain legible; align status dot to first line.
 * ============================================================ */

@media (max-width: 640px) {
	.mphb-gs-shell .gs-villa-state__subtitle {
		font-size: 12px;
		white-space: normal;
		overflow-wrap: anywhere;
	}
	.mphb-gs-shell .gs-villa-state__row {
		align-items: start;
		gap: 8px;
		padding-left: calc(var(--gs-villa-state-pad-x) * 0.6 + var(--gs-villa-state-bar-w));
		padding-right: calc(var(--gs-villa-state-pad-x) * 0.6);
	}
	.mphb-gs-shell .gs-villa-state__dot {
		margin-top: 3px;
	}
}

/* ============================================================
 * Reduced motion — silence the pulse.
 * ============================================================ */

@media (prefers-reduced-motion: reduce) {
	.mphb-gs-shell .gs-villa-state__row[data-tone="crit"] .gs-villa-state__dot,
	.mphb-gs-shell .gs-villa-state__row[data-tone="crit-deep"] .gs-villa-state__dot {
		animation: none;
	}
}

/* ============================================================
 * RTL — flip the accent bar to the right edge.
 * ============================================================ */

.mphb-gs-shell[dir="rtl"] .gs-villa-state__row,
[dir="rtl"] .mphb-gs-shell .gs-villa-state__row {
	padding: var(--gs-villa-state-pad-y) calc(var(--gs-villa-state-pad-x) + var(--gs-villa-state-bar-w)) var(--gs-villa-state-pad-y) var(--gs-villa-state-pad-x);
}
.mphb-gs-shell[dir="rtl"] .gs-villa-state__row::before,
[dir="rtl"] .mphb-gs-shell .gs-villa-state__row::before {
	inset: 0 0 0 auto;
}

@media (max-width: 640px) {
	.mphb-gs-shell[dir="rtl"] .gs-villa-state__row,
	[dir="rtl"] .mphb-gs-shell .gs-villa-state__row {
		padding-left: calc(var(--gs-villa-state-pad-x) * 0.6);
		padding-right: calc(var(--gs-villa-state-pad-x) * 0.6 + var(--gs-villa-state-bar-w));
	}
}
