/*
 * CATD Meters - shared styles.
 *
 * Designed to be a visual sibling of the React owner-portal: same tokens
 * (Inter, CATD blues/greens), white rounded-xl cards with a soft shadow that
 * lifts on hover, restrained colour. Plain CSS so it works in the WP theme
 * (front-end readings page, self-registration) and lightly in wp-admin.
 */

:root {
	--font-stack: 'Inter', Roboto, Arial, sans-serif;

	--primary: #0278c0;
	--primary-hover: #015d94;
	--success: #26ad3e;
	--success-hover: #1e8f33;
	--danger: #dc3545;
	--danger-text: #c82333;

	--text-heading: #1b3a4b;
	--text-body: #2c3e50;
	--text-secondary: rgba(44, 62, 80, 0.6);

	--bg: #f4faff;
	--card: #ffffff;
	--border: rgba(0, 43, 73, 0.1);

	--radius-card: 0.75rem;   /* rounded-xl */
	--radius-button: 0.5rem;  /* rounded-lg */
	--shadow-sm: 0 1px 2px rgba(0, 43, 73, 0.06);
	--shadow-md: 0 6px 18px rgba(0, 43, 73, 0.10);
	--shadow-lg: 0 12px 32px rgba(0, 43, 73, 0.16);

	--sidebar-width: 240px;
	--topbar-height: 64px;
	--bottomnav-height: 64px;

	/* Back-compat aliases (older class names referenced these). */
	--color-primary: var(--primary);
	--color-primary-hover: var(--primary-hover);
	--color-success: var(--success);
	--color-success-hover: var(--success-hover);
	--text-body-color: var(--text-body);
	--bg-body: var(--bg);
	--bg-card: var(--card);
}

@keyframes catd-fade-in {
	from { opacity: 0; transform: translateY(4px); }
	to { opacity: 1; transform: translateY(0); }
}

@keyframes catd-shimmer {
	0% { background-position: 200% 0; }
	100% { background-position: -200% 0; }
}

/* ---------- Shell ---------- */

/* The hidden attribute must win over component display rules (e.g. inline-flex). */
[hidden] { display: none !important; }

.catd-app {
	font-family: var(--font-stack);
	color: var(--text-body);
	background: var(--bg);
	min-height: 100vh;
	margin: 0;
}

/* Force Inter on headings inside our screens, in case the active theme's
 * global styles try to apply a serif face to bare h1–h6 elements. */
.catd-app :is(h1, h2, h3, h4, h5, h6),
.catd-auth-page :is(h1, h2, h3, h4, h5, h6) {
	font-family: var(--font-stack);
}

.catd-container {
	max-width: 1080px;
	margin: 0 auto;
	padding: 1.5rem 1rem 4rem;
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

/* Sticky topbar (sibling of the portal's). */
.catd-topbar {
	position: sticky;
	top: 0;
	z-index: 50;
	background: var(--card);
	border-bottom: 1px solid var(--border);
}

.catd-topbar-inner {
	max-width: 1080px;
	margin: 0 auto;
	padding: 0.6rem 1rem;
	display: flex;
	align-items: center;
	gap: 0.75rem 1rem;
	justify-content: space-between;
	flex-wrap: wrap;
}

@media (max-width: 560px) {
	.catd-topbar-right { width: 100%; }
	.catd-select-inline { flex: 1; min-width: 0; }
}

.catd-topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.catd-topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.catd-logo { height: 44px; width: auto; object-fit: contain; }
.catd-topbar-title { font-weight: 700; color: var(--text-heading); font-size: 1.05rem; }

/* ---------- Cards ---------- */

.catd-card {
	background: var(--card);
	border-radius: var(--radius-card);
	box-shadow: var(--shadow-sm);
	padding: 1.25rem;
	transition: box-shadow 0.2s ease;
}

.catd-card-hover:hover { box-shadow: var(--shadow-md); }

.catd-card h2,
.catd-card h3 { color: var(--text-heading); font-weight: 600; margin-top: 0; }

.catd-card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
}

.catd-section-title { margin: 0 0 0.85rem; font-size: 0.95rem; font-weight: 700; color: var(--text-heading); }
.catd-subtitle { margin: 1.25rem 0 0.5rem; color: var(--text-heading); font-weight: 600; }

.catd-card-label {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--text-heading);
}

.catd-icon { width: 1.15rem; height: 1.15rem; color: var(--primary); flex: none; }
.catd-muted { color: var(--text-secondary); }

/* ---------- Hero (latest reading) ---------- */

.catd-hero {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 1rem;
}

.catd-hero-meta { min-width: 0; }
.catd-hero-name { font-size: 1.05rem; font-weight: 700; color: var(--text-heading); margin: 0; }
.catd-hero-sub { font-size: 0.85rem; color: var(--text-secondary); margin: 0.15rem 0 0; }

.catd-hero-figure { text-align: right; }
.catd-hero-label { font-size: 0.78rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }
.catd-hero-value { font-size: 2.4rem; line-height: 1.05; font-weight: 700; color: var(--text-heading); }
.catd-hero-unit { font-size: 1rem; font-weight: 500; color: var(--text-secondary); margin-left: 0.25rem; }
.catd-hero-date { font-size: 0.82rem; color: var(--text-secondary); margin-top: 0.15rem; }

.catd-badge {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	margin-top: 0.5rem;
	padding: 0.25rem 0.6rem;
	border-radius: 999px;
	font-size: 0.8rem;
	font-weight: 600;
	background: rgba(2, 120, 192, 0.08);
	color: var(--primary);
}

/* ---------- Stat cards ---------- */

.catd-stats {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 1rem;
}

@media (max-width: 720px) {
	.catd-stats { grid-template-columns: 1fr; }
}

.catd-stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text-heading); }
.catd-stat-unit { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); margin-left: 0.2rem; }
.catd-stat-label { font-size: 0.82rem; color: var(--text-secondary); margin-top: 0.15rem; }

/* ---------- Segmented toggle (sibling of the portal's) ---------- */

.catd-toggle {
	display: inline-flex;
	background: var(--border);
	border-radius: var(--radius-button);
	padding: 0.2rem;
	gap: 0.2rem;
}

.catd-toggle-btn {
	border: 0;
	background: transparent;
	padding: 0.3rem 0.85rem;
	border-radius: calc(var(--radius-button) - 0.15rem);
	font: inherit;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--text-secondary);
	cursor: pointer;
}

.catd-toggle-btn.is-active { background: var(--card); color: var(--text-heading); box-shadow: var(--shadow-sm); }

/* ---------- Forms ---------- */

.catd-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-heading); margin-bottom: 0.35rem; }

.catd-input,
.catd-select {
	width: 100%;
	box-sizing: border-box;
	padding: 0.5rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: var(--radius-button);
	font-family: var(--font-stack);
	font-size: 0.92rem;
	color: var(--text-body);
	background: #fff;
}

.catd-input:focus,
.catd-select:focus {
	outline: none;
	border-color: var(--primary);
	box-shadow: 0 0 0 2px rgba(2, 120, 192, 0.15);
}

.catd-select-inline { width: auto; min-width: 200px; max-width: 320px; }
.catd-date { width: auto; }

.catd-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	border: none;
	border-radius: var(--radius-button);
	padding: 0.5rem 1rem;
	font-family: var(--font-stack);
	font-weight: 600;
	font-size: 0.9rem;
	color: #fff;
	cursor: pointer;
	text-decoration: none;
	transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.catd-btn-primary { background: var(--primary); }
.catd-btn-primary:hover { background: var(--primary-hover); }
.catd-btn-success { background: var(--success); }
.catd-btn-success:hover { background: var(--success-hover); }

.catd-btn-outline { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.catd-btn-outline:hover { color: var(--danger-text); border-color: rgba(220, 53, 69, 0.4); }

.catd-btn-ghost {
	background: transparent;
	color: var(--primary);
	border: 0;
	padding: 0.35rem 0;
	font-weight: 600;
	font-size: 0.85rem;
	cursor: pointer;
}
.catd-btn-ghost:hover { text-decoration: underline; }

/* ---------- Readings table ---------- */

.catd-rtable { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.catd-rtable th {
	text-align: left;
	padding: 0.55rem 0.7rem;
	color: var(--text-secondary);
	font-weight: 600;
	font-size: 0.78rem;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	border-bottom: 1px solid var(--border);
}
.catd-rtable td { padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); color: var(--text-body); }
.catd-rtable tr:last-child td { border-bottom: 0; }
.catd-rtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.catd-rtable .latest td { background: rgba(2, 120, 192, 0.04); font-weight: 600; color: var(--text-heading); }

/* ---------- Map ---------- */

#catd-map { width: 100%; height: 60vh; min-height: 22rem; max-height: 75vh; border-radius: var(--radius-button); z-index: 0; }

/* Citiri: scrollable card capped to the same height as the map. */
.catd-rtable-wrap { max-height: 75vh; overflow-y: auto; }

/* ---------- Banners / states ---------- */

.catd-alert {
	border-left: 3px solid;
	padding: 0.75rem 0.9rem;
	border-radius: 0 var(--radius-button) var(--radius-button) 0;
	font-size: 0.9rem;
	margin: 0.5rem 0;
}
.catd-alert-error { background: rgba(220, 53, 69, 0.06); border-color: var(--danger-text); color: var(--danger-text); }
.catd-alert-success { background: rgba(38, 173, 62, 0.06); border-color: var(--success-hover); color: var(--success-hover); }
.catd-alert-info { background: rgba(2, 120, 192, 0.06); border-color: var(--primary); color: var(--text-body); }

.catd-empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-secondary); }
.catd-empty .catd-icon { width: 2.2rem; height: 2.2rem; margin: 0 auto 0.6rem; opacity: 0.5; color: var(--text-secondary); }

.catd-skeleton {
	background: linear-gradient(90deg, #eef4fa 25%, #f7fbff 50%, #eef4fa 75%);
	background-size: 200% 100%;
	animation: catd-shimmer 1.2s infinite;
	border-radius: 6px;
}

.catd-fade-in { animation: catd-fade-in 0.3s ease-out; }

/* ---------- Auth / registration card ---------- */

.catd-auth-card {
	max-width: 420px;
	margin: 2.5rem auto;
	background: var(--card);
	border-radius: var(--radius-card);
	box-shadow: var(--shadow-sm);
	padding: 2rem;
	font-family: var(--font-stack);
	color: var(--text-body);
}

.catd-auth-title { color: var(--text-heading); font-size: 1.25rem; font-weight: 600; margin: 0 0 0.25rem; }
.catd-auth-help { font-size: 0.9rem; color: var(--text-secondary); margin: 0 0 1.25rem; }
.catd-auth-card .catd-input { margin-bottom: 1rem; }
.catd-auth-card .catd-btn { width: 100%; justify-content: center; }

/* =====================================================================
 * App shell (readings page): a single fixed topbar + full-width card grid.
 * ===================================================================== */

.catd-appbar {
	position: fixed;
	top: 0; left: 0; right: 0;
	z-index: 55;
	min-height: var(--topbar-height);
	background: var(--card);
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	gap: 0.6rem 1rem;
	flex-wrap: wrap;
	padding: 0.55rem 1rem;
}

.catd-appbar-logo { height: 38px; width: auto; object-fit: contain; flex: none; }
.catd-appbar-title { font-size: 1.05rem; font-weight: 700; color: var(--text-heading); margin: 0; flex: 1; min-width: 0; }
.catd-appbar-title small { display: block; font-size: 0.72rem; font-weight: 500; color: var(--text-secondary); }

/* Meter selector styled like the portal's location selector. */
.catd-meterselect {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.4rem 0.6rem;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius-button);
	box-shadow: var(--shadow-sm);
}
.catd-meterselect svg { width: 1rem; height: 1rem; color: var(--text-heading); flex: none; }
.catd-meterselect select {
	border: 0; background: transparent; font-family: var(--font-stack);
	font-size: 0.85rem; font-weight: 600; color: var(--text-heading);
	max-width: 48vw; outline: none;
}

.catd-meterselect-label {
	font-size: 0.78rem;
	font-weight: 600;
	color: var(--text-secondary);
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

/* Logged-in association identity, shown next to the logout button. */
.catd-appbar-user {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	max-width: 28vw;
	font-size: 0.82rem;
	font-weight: 600;
	color: var(--text-heading);
}
.catd-appbar-user svg { width: 1rem; height: 1rem; color: var(--text-secondary); flex: none; }
.catd-appbar-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.catd-btn-logout {
	background: transparent;
	color: var(--danger);
	border: 1px solid var(--danger);
}
.catd-btn-logout svg { width: 1rem; height: 1rem; }
.catd-btn-logout:hover { background: var(--danger); color: #fff; }

.catd-main { padding: calc(var(--topbar-height) + 1.5rem) 1rem 2.5rem; }

.catd-content {
	display: grid;
	grid-template-columns: repeat(12, 1fr);
	gap: 1rem;
	align-items: start;
}

.catd-span-4 { grid-column: span 4; }
.catd-span-5 { grid-column: span 5; }
.catd-span-6 { grid-column: span 6; }
.catd-span-7 { grid-column: span 7; }
.catd-span-8 { grid-column: span 8; }
.catd-span-12 { grid-column: span 12; }

@media (max-width: 960px) {
	.catd-content > * { grid-column: span 12 !important; }
}

@media (min-width: 1024px) {
	.catd-meterselect select { max-width: 320px; }
	.catd-main { padding: calc(var(--topbar-height) + 1.5rem) 1.5rem 2.5rem; }
}

/* =====================================================================
 * Auth screen (registration / self-service) - frosted card over a photo.
 * ===================================================================== */

.catd-auth-page {
	font-family: var(--font-stack);
	color: var(--text-body);
	min-height: 100vh;
	margin: 0;
	position: relative;
}

.catd-auth-bg { position: fixed; inset: 0; background-size: cover; background-position: center; }
.catd-auth-overlay {
	position: fixed; inset: 0;
	background: linear-gradient(to bottom, rgba(244, 250, 255, 0.97), rgba(244, 250, 255, 0.66), rgba(244, 250, 255, 0.93));
	backdrop-filter: blur(2px);
}

.catd-auth-wrap {
	position: relative;
	z-index: 1;
	max-width: 460px;
	margin: 0 auto;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 2rem 1rem;
}

.catd-auth-logo { height: 72px; object-fit: contain; margin: 0 auto 0.75rem; display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1)); }
.catd-auth-brand { text-align: center; font-weight: 600; color: var(--text-heading); margin: 0 0 1.25rem; font-size: 1.05rem; }

.catd-auth-page .catd-auth-card {
	margin: 0;
	width: 100%;
	max-width: 420px;
	box-shadow: var(--shadow-lg);
	border: 1px solid var(--border);
	background: rgba(255, 255, 255, 0.96);
}

.catd-auth-foot { text-align: center; color: var(--text-secondary); font-size: 0.8rem; margin-top: 1.5rem; width: 100%; }
.catd-auth-foot strong { color: var(--text-body); font-weight: 600; }
.catd-auth-foot .dot { display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--text-secondary); margin: 0 0.5rem; vertical-align: middle; }

/* ---------- Admin (wp-admin) ---------- */

.catd-wrap .catd-card { max-width: 1100px; margin-bottom: 1.25rem; }
.catd-tabs { margin-bottom: 1rem; }

.catd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .catd-grid { grid-template-columns: 1fr; } }

.catd-inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.catd-inline-form input[type="text"],
.catd-inline-form input[type="email"] { min-width: 220px; }
