/* TFMKit Leads GIS — component contract.
 *
 * Tokens are the converter surface's (DESIGN_MEMORY.md), not the cleaner's
 * indigo mockup palette. Utilities come from uno.css; component classes live
 * here. Where a class sets its own `display`, a matching `.x.hidden` rule is
 * required — an inline or class-level `display` beats the utility `.hidden`.
 */

/* --- Fonts (vendored, same files every TFMKit app uses) ------------------ */
@font-face {
	font-family: 'Inter';
	font-style: normal;
	font-weight: 100 900;
	font-display: swap;
	src: url('/fonts/inter-latin.woff2') format('woff2');
}
@font-face {
	font-family: 'Cal Sans';
	font-style: normal;
	font-weight: 600;
	font-display: swap;
	src: url('/fonts/calsans-latin.woff2') format('woff2');
}
@font-face {
	font-family: 'JetBrains Mono';
	font-style: normal;
	font-weight: 100 800;
	font-display: swap;
	src: url('/fonts/jetbrainsmono-latin.woff2') format('woff2');
}
@font-face {
	font-family: 'Plus Jakarta Sans';
	font-style: normal;
	font-weight: 200 800;
	font-display: swap;
	src: url('/fonts/plusjakartasans-latin.woff2') format('woff2');
}

/* --- Tokens -------------------------------------------------------------- */
:root {
	--bg-primary: #ffffff;
	--bg-secondary: #f8fafc;
	--bg-tertiary: #f1f5f9;
	--bg-elevated: #ffffff;

	--text-primary: #0f172a;
	--text-secondary: #475569;
	--text-tertiary: #64748b;
	--text-muted: #94a3b8;
	--text-inverted: #ffffff;

	--border-primary: #e2e8f0;
	--border-secondary: #cbd5e1;

	--accent-primary: #6366f1;
	--accent-primary-hover: #4f46e5;
	--accent-light: #eef2ff;

	--success: #10b981;
	--warning: #f59e0b;
	--error: #ef4444;

	--card-bg: #ffffff;
	--card-border: #e2e8f0;
	--input-bg: #ffffff;
	--input-border: #d1d5db;

	--btn-primary-bg: #18181b;
	--btn-primary-text: #ffffff;
	--btn-primary-hover: #27272a;

	--ring-color: rgba(99, 102, 241, 0.5);

	--radius-2xl: 16px;
	--radius-xl: 12px;
	--radius-md: 8px;
	--radius-pill: 9999px;

	--font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
	--font-display: 'Cal Sans', 'Inter', system-ui, sans-serif;
	--font-mono: 'JetBrains Mono', ui-monospace, monospace;

	--ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
	--dur-fast: 150ms;
	--dur-base: 200ms;

	color-scheme: light;
}

.dark {
	--bg-primary: #09090b;
	--bg-secondary: #101013;
	--bg-tertiary: #18181b;
	--bg-elevated: #1c1c20;

	--text-primary: #fafafa;
	--text-secondary: #a1a1aa;
	/* #94a3b8 is 2.6:1 on white — decorative fills only. Anything read uses
	   --text-tertiary, which clears 4.5:1 on both surfaces. */
	--text-tertiary: #8b8b95;
	--text-muted: #52525b;
	--text-inverted: #09090b;

	--border-primary: #27272a;
	--border-secondary: #3f3f46;

	--accent-primary: #818cf8;
	--accent-primary-hover: #a5b4fc;
	--accent-light: rgba(99, 102, 241, 0.15);

	--card-bg: #101013;
	--card-border: #27272a;
	--input-bg: #101013;
	--input-border: #3f3f46;

	--btn-primary-bg: #fafafa;
	--btn-primary-text: #09090b;
	--btn-primary-hover: #e4e4e7;

	--ring-color: rgba(129, 140, 248, 0.5);

	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

html,
body {
	height: 100%;
	margin: 0;
}

body {
	font-family: var(--font-sans);
	background: var(--bg-secondary);
	color: var(--text-primary);
	-webkit-font-smoothing: antialiased;
}

/* --- Focus: visible, managed, never removed without replacement ---------- */
:focus-visible {
	outline: 2px solid var(--accent-primary);
	outline-offset: 2px;
}

/* --- Layout -------------------------------------------------------------- */
.app-shell {
	display: flex;
	flex-direction: column;
	height: 100vh;
	overflow: hidden;
	background: var(--bg-primary);
}

.workspace {
	display: flex;
	flex: 1;
	min-height: 0;
	overflow: hidden;
}

.stage {
	position: relative;
	flex: 1;
	min-width: 0;
	background: var(--bg-tertiary);
}

.wordmark-strip {
	display: flex;
	align-items: center;
	gap: 12px;
	height: 44px;
	padding: 0 16px;
	border-bottom: 1px solid var(--border-primary);
	background: var(--bg-primary);
}

.wordmark-strip .logo {
	width: 24px;
	height: 24px;
	flex: 0 0 24px;
}

.wordmark {
	font-family: var(--font-display);
	font-size: 15px;
	font-weight: 600;
	letter-spacing: -0.01em;
}
.wordmark em {
	font-style: normal;
	background: linear-gradient(to right, #0ea5e9, #2563eb, #7c3aed);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
}

.eyebrow {
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--text-tertiary);
}

.divider {
	height: 1px;
	background: var(--border-primary);
	border: 0;
	margin: 0;
}

/* --- Surfaces ------------------------------------------------------------ */
.card {
	background: var(--card-bg);
	border: 1px solid var(--card-border);
	border-radius: var(--radius-2xl);
}
.card-subtle {
	background: var(--bg-secondary);
	border: 1px solid var(--border-primary);
	border-radius: var(--radius-xl);
}

.panel {
	display: flex;
	flex-direction: column;
	gap: 14px;
	padding: 14px;
}
.panel.hidden {
	display: none;
}

/* --- Buttons: ranked by importance, never coloured by meaning ------------ */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-height: 32px;
	padding: 0 14px;
	border-radius: var(--radius-pill);
	border: 1px solid transparent;
	font-family: inherit;
	font-size: 12.5px;
	font-weight: 600;
	cursor: pointer;
	transition:
		background var(--dur-fast) var(--ease-smooth),
		border-color var(--dur-fast) var(--ease-smooth);
}
.btn:disabled {
	cursor: not-allowed;
	background: var(--bg-tertiary);
	color: var(--text-muted);
	border-color: var(--border-primary);
	box-shadow: none;
}
.btn-primary {
	background: var(--btn-primary-bg);
	color: var(--btn-primary-text);
}
.btn-primary:hover:not(:disabled) {
	background: var(--btn-primary-hover);
}
.btn-secondary {
	background: var(--bg-primary);
	color: var(--text-secondary);
	border-color: var(--border-secondary);
}
.btn-secondary:hover:not(:disabled) {
	background: var(--bg-tertiary);
}
.btn-ghost {
	background: transparent;
	color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
	background: var(--bg-tertiary);
}
.btn-sm {
	min-height: 26px;
	padding: 0 10px;
	font-size: 11.5px;
}

/* --- Form controls: real labels, never placeholder-as-label -------------- */
.field {
	display: flex;
	flex-direction: column;
	gap: 5px;
}
.field.hidden {
	display: none;
}
.field > label {
	font-size: 11px;
	font-weight: 600;
	color: var(--text-secondary);
}
.input {
	min-height: 32px;
	padding: 0 10px;
	background: var(--input-bg);
	color: var(--text-primary);
	border: 1px solid var(--input-border);
	border-radius: var(--radius-md);
	font-family: inherit;
	font-size: 12.5px;
	width: 100%;
}
.input::placeholder {
	color: var(--text-muted);
}
.input:focus {
	border-color: var(--accent-primary);
	outline: none;
	box-shadow: 0 0 0 2px var(--ring-color);
}
/* Numeric inputs are figures — mono, tabular, so columns line up. */
.input-num {
	font-family: var(--font-mono);
	font-variant-numeric: tabular-nums;
}

/* --- Chips / selection: the active option inverts ----------------------- */
.chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 26px;
	padding: 0 10px;
	border-radius: var(--radius-pill);
	border: 1px solid var(--border-primary);
	background: var(--bg-primary);
	color: var(--text-secondary);
	font-size: 11.5px;
	font-weight: 500;
	cursor: pointer;
}
.chip:hover {
	border-color: var(--border-secondary);
}
.chip.active {
	background: var(--text-primary);
	color: var(--bg-primary);
	border-color: var(--text-primary);
}

.tabs {
	display: inline-flex;
	gap: 2px;
	padding: 2px;
	border-radius: var(--radius-pill);
	background: var(--bg-tertiary);
}
.tabs.hidden {
	display: none;
}
.tabs button {
	border: 0;
	background: transparent;
	color: var(--text-secondary);
	font-family: inherit;
	font-size: 11.5px;
	font-weight: 600;
	padding: 5px 12px;
	border-radius: var(--radius-pill);
	cursor: pointer;
}
.tabs button[aria-selected='true'] {
	background: var(--bg-primary);
	color: var(--text-primary);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* --- Status -------------------------------------------------------------- */
.status {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 6px 10px;
	border-radius: var(--radius-md);
	background: var(--bg-tertiary);
	color: var(--text-secondary);
	font-size: 11.5px;
}
.status.hidden {
	display: none;
}
.status-ok {
	color: var(--success);
	background: color-mix(in oklab, var(--success) 12%, transparent);
}
.status-warn {
	color: var(--warning);
	background: color-mix(in oklab, var(--warning) 12%, transparent);
}
.status-error {
	color: var(--error);
	background: color-mix(in oklab, var(--error) 12%, transparent);
}

/* --- Figures: the counts are the product, so they get the mono face ------ */
.metric {
	font-family: var(--font-mono);
	font-variant-numeric: tabular-nums;
	font-size: 20px;
	font-weight: 600;
	letter-spacing: -0.02em;
}
.metric-lg {
	font-size: 30px;
}
.metric-label {
	font-size: 10.5px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--text-tertiary);
}
.metric-hero {
	color: var(--accent-primary);
}

/* --- Table: text left, figures right, light separators ------------------- */
.table {
	width: 100%;
	border-collapse: collapse;
	font-size: 12px;
}
.table th {
	text-align: left;
	font-size: 10.5px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-tertiary);
	padding: 6px 8px;
	border-bottom: 1px solid var(--border-primary);
	position: sticky;
	top: 0;
	background: var(--bg-primary);
}
.table td {
	padding: 6px 8px;
	border-bottom: 1px solid var(--border-primary);
	color: var(--text-secondary);
}
.table td.num,
.table th.num {
	text-align: right;
	font-family: var(--font-mono);
	font-variant-numeric: tabular-nums;
}
.table tbody tr:hover td {
	background: var(--bg-secondary);
}
/* A redacted row is visibly incomplete rather than silently blank. */
.table td.redacted {
	color: var(--text-muted);
	font-style: italic;
}

/* --- Bar meter for the category breakdown ------------------------------- */
.meter {
	height: 6px;
	border-radius: var(--radius-pill);
	background: var(--bg-tertiary);
	overflow: hidden;
}
.meter > span {
	display: block;
	height: 100%;
	background: var(--accent-primary);
	border-radius: var(--radius-pill);
}

/* --- Map ---------------------------------------------------------------- */
.map-canvas {
	position: absolute;
	inset: 0;
	/* The empty style is transparent, so this blueprint grid is the no-basemap
	   surface — the same grid paper the fallback uses. */
	background-color: var(--bg-tertiary);
	background-image: linear-gradient(var(--border-primary) 1px, transparent 1px),
		linear-gradient(90deg, var(--border-primary) 1px, transparent 1px);
	background-size: 32px 32px;
}
.map-canvas.hidden {
	display: none;
}
.map-fallback {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	text-align: center;
	padding: 32px;
	color: var(--text-tertiary);
	background-image: linear-gradient(var(--border-primary) 1px, transparent 1px),
		linear-gradient(90deg, var(--border-primary) 1px, transparent 1px);
	background-size: 32px 32px;
}
.map-fallback.hidden {
	display: none;
}

.attribution {
	position: absolute;
	right: 8px;
	bottom: 8px;
	padding: 3px 8px;
	border-radius: var(--radius-md);
	background: color-mix(in oklab, var(--bg-primary) 85%, transparent);
	border: 1px solid var(--border-primary);
	font-size: 10.5px;
	color: var(--text-tertiary);
}

/* --- Map chrome: MapLibre's own furniture themed to the app --------------- */
.map-hud {
	position: absolute;
	left: 50%;
	bottom: 10px;
	transform: translateX(-50%);
	z-index: 5;
	padding: 3px 9px;
	border-radius: var(--radius-md);
	border: 1px solid var(--border-primary);
	background: var(--bg-primary);
	background: color-mix(in oklab, var(--bg-primary) 85%, transparent);
	backdrop-filter: blur(8px);
	font-family: var(--font-mono);
	font-size: 10px;
	font-variant-numeric: tabular-nums;
	letter-spacing: 0.04em;
	color: var(--text-secondary);
	pointer-events: none;
}

.stage .maplibregl-ctrl-group {
	background: var(--bg-primary);
	border: 1px solid var(--border-primary);
	border-radius: var(--radius-md);
	box-shadow: none;
	overflow: hidden;
}
.stage .maplibregl-ctrl-group button {
	background: transparent;
}
.stage .maplibregl-ctrl-group button:hover {
	background: var(--bg-tertiary);
}
.stage .maplibregl-ctrl-group button + button {
	border-top: 1px solid var(--border-primary);
}
/* The control glyphs are dark-on-transparent SVGs — flip them only in dark. */
.dark .stage .maplibregl-ctrl-group button .maplibregl-ctrl-icon {
	filter: invert(0.85);
}

.stage .maplibregl-ctrl-scale {
	background: transparent;
	border-color: var(--text-muted);
	color: var(--text-secondary);
	font-family: var(--font-mono);
	font-size: 9.5px;
}

.stage .maplibregl-ctrl-attrib {
	background: color-mix(in oklab, var(--bg-primary) 85%, transparent);
	border-radius: var(--radius-md) 0 0 0;
}
.stage .maplibregl-ctrl-attrib,
.stage .maplibregl-ctrl-attrib a {
	color: var(--text-tertiary);
}
.dark .stage .maplibregl-ctrl-attrib-button {
	filter: invert(0.85);
}

.stage .maplibregl-popup-content {
	background: var(--bg-elevated);
	color: var(--text-primary);
	border: 1px solid var(--border-primary);
	border-radius: var(--radius-md);
	padding: 7px 12px;
	font-family: var(--font-sans);
	font-size: 12px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.stage .maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
	border-top-color: var(--bg-elevated);
}
.stage .maplibregl-popup-anchor-top .maplibregl-popup-tip {
	border-bottom-color: var(--bg-elevated);
}
.stage .maplibregl-popup-anchor-left .maplibregl-popup-tip {
	border-right-color: var(--bg-elevated);
}
.stage .maplibregl-popup-anchor-right .maplibregl-popup-tip {
	border-left-color: var(--bg-elevated);
}

/* --- Scrolling rails ---------------------------------------------------- */
.scroll {
	overflow-y: auto;
	scrollbar-width: thin;
}
.scroll::-webkit-scrollbar {
	width: 8px;
}
.scroll::-webkit-scrollbar-thumb {
	background: var(--border-secondary);
	border-radius: var(--radius-pill);
}

/* --- Motion: honour the preference -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
	}
}
