:root {
	--bg: #f5f8f7;
	--surface: #ffffff;
	--surface-2: #f0f3f2;
	--border: #e3e9e7;
	--text: #1f2933;
	--text-muted: #6b7684;
	--accent: #0f9d8c;
	--accent-dark: #0b7d70;
	--accent-soft: #e6f5f2;
	--danger: #d64545;
	--danger-soft: #fdeaea;
	--success: #1f9d55;
	--radius: 12px;
	--radius-sm: 8px;
	--shadow: 0 1px 2px rgba(16, 24, 32, 0.04), 0 8px 24px rgba(16, 24, 32, 0.06);
	--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* A class-level `display` beats the UA stylesheet's [hidden] rule, so make the
   hidden attribute authoritative — several panels rely on it. */
[hidden] { display: none !important; }

html, body {
	height: 100%;
}

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

a { color: var(--accent-dark); }

h1, h2, h3 { margin: 0 0 8px; font-weight: 700; }

.muted { color: var(--text-muted); }

/* --- buttons & inputs --- */

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	border: none;
	border-radius: var(--radius-sm);
	padding: 10px 18px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	background: var(--accent);
	color: #ffffff;
	transition: background 0.15s ease;
	text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn.btn-secondary:hover { background: var(--border); }
.btn.btn-danger { background: var(--danger); }
.btn.btn-danger:hover { background: #b93a3a; }
.btn.btn-block { width: 100%; }
.btn.btn-sm { padding: 6px 12px; font-size: 13px; }

label {
	display: block;
	font-size: 13px;
	font-weight: 600;
	margin-bottom: 6px;
	color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
select,
textarea {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font-family: var(--font);
	font-size: 14px;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}
.field { margin-bottom: 16px; }

.alert {
	border-radius: var(--radius-sm);
	padding: 10px 14px;
	font-size: 13px;
	margin-bottom: 16px;
}
.alert-error { background: var(--danger-soft); color: #a12f2f; }
.alert-success { background: var(--accent-soft); color: var(--accent-dark); }

/* --- auth pages --- */

.auth-page {
	min-height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
}
.auth-card {
	width: 100%;
	max-width: 380px;
	background: var(--surface);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 32px;
}
.auth-logo {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 800;
	font-size: 20px;
	color: var(--accent-dark);
	margin-bottom: 24px;
}
.auth-logo .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.auth-card h1 { font-size: 20px; }
.auth-card .subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.auth-foot { margin-top: 20px; font-size: 13px; color: var(--text-muted); text-align: center; }
.altcha-wrap { margin-bottom: 16px; }
.code-input {
	font-size: 24px;
	letter-spacing: 8px;
	text-align: center;
	font-weight: 700;
}

/* --- app shell --- */

.app-shell {
	height: 100vh;
	display: flex;
	flex-direction: column;
}
.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 20px;
	height: 56px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	flex-shrink: 0;
}
.topbar-logo {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 800;
	font-size: 17px;
	color: var(--accent-dark);
	text-decoration: none;
}
.topbar-logo .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.topbar-nav { display: flex; align-items: center; gap: 4px; }
.topbar-nav a {
	color: var(--text-muted);
	text-decoration: none;
	font-size: 14px;
	font-weight: 600;
	padding: 8px 12px;
	border-radius: var(--radius-sm);
}
.topbar-nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar-nav a.active { background: var(--accent-soft); color: var(--accent-dark); }

.app-body {
	flex: 1;
	display: flex;
	min-height: 0;
}

#map { flex: 1; min-width: 0; background: #e9edec; }

.sidebar {
	width: 360px;
	flex-shrink: 0;
	background: var(--surface);
	border-left: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	min-height: 0;
}
.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-header .hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.filters { display: flex; gap: 8px; margin-top: 10px; }
.filters select { font-size: 13px; padding: 8px 10px; }

.asset-list { flex: 1; overflow-y: auto; }
.asset-row {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--border);
	cursor: pointer;
}
.asset-row:hover { background: var(--surface-2); }
.asset-row.selected { background: var(--accent-soft); }
.asset-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.asset-row .name { font-weight: 600; font-size: 14px; }
.asset-row .meta { font-size: 12px; color: var(--text-muted); }
.status-badge {
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	padding: 2px 8px;
	border-radius: 999px;
	margin-left: auto;
}
.status-active { background: #e6f5ec; color: var(--success); }
.status-maintenance { background: #fdf3e0; color: #b3740c; }
.status-retired { background: var(--surface-2); color: var(--text-muted); }

.empty-state { padding: 32px 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* --- side panel (add/edit asset) --- */

.panel-overlay {
	position: fixed;
	inset: 0;
	background: rgba(20, 30, 28, 0.25);
	display: none;
	z-index: 50;
}
.panel-overlay.open { display: block; }
.side-panel {
	position: fixed;
	top: 0;
	bottom: 0;
	right: -420px;
	width: 400px;
	max-width: 92vw;
	/* top+bottom (not height:100%) so this stays pinned to the real visible
	   viewport on mobile browsers, where height:100% on a fixed element can
	   overshoot the dynamic address-bar area and push the footer off-screen. */
	background: var(--surface);
	box-shadow: -8px 0 30px rgba(16, 24, 32, 0.12);
	transition: right 0.2s ease;
	z-index: 51;
	display: flex;
	flex-direction: column;
}
.side-panel.open { right: 0; }
.panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 18px 20px;
	border-bottom: 1px solid var(--border);
	flex-shrink: 0;
}
.panel-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; }
/* The <form> sits between .side-panel and .panel-body/.panel-footer, so it has
   to be a flex container too — otherwise .panel-body's flex:1 + overflow have
   no bounded height to work against and the footer buttons fall off-screen. */
.side-panel form {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
}
.panel-body { padding: 20px; overflow-y: auto; flex: 1; min-height: 0; }
.panel-footer {
	padding: 16px 20px;
	border-top: 1px solid var(--border);
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	flex-shrink: 0;
}

.meta-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.meta-row { display: flex; gap: 8px; align-items: center; }
.meta-row input { flex: 1; }
.meta-row button { flex-shrink: 0; }

.maplibregl-popup-content { font-family: var(--font); font-size: 13px; padding: 8px 10px; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* --- settings --- */

.settings-shell {
	flex: 1;
	min-height: 0;
	display: flex;
	background: var(--bg);
}

.settings-nav {
	width: 252px;
	flex-shrink: 0;
	border-right: 1px solid var(--border);
	background: var(--surface);
	padding: 24px 16px;
	overflow-y: auto;
}
.settings-nav-label {
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.07em;
	color: var(--text-muted);
	padding: 0 12px;
	margin-bottom: 12px;
}
.settings-nav a {
	display: block;
	padding: 11px 14px;
	border-radius: var(--radius-sm);
	text-decoration: none;
	color: var(--text);
	margin-bottom: 4px;
	transition: background 0.12s ease;
}
.settings-nav a:hover { background: var(--surface-2); }
.settings-nav a.active { background: var(--accent-soft); }
.settings-nav-title { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; }
.settings-nav-sub {
	display: block;
	font-size: 12px;
	color: var(--text-muted);
	margin-top: 3px;
	line-height: 1.4;
}
.settings-nav a.active .settings-nav-title { color: var(--accent-dark); }
.settings-nav a.active .settings-nav-sub { color: var(--accent-dark); opacity: 0.75; }

.settings-content {
	flex: 1;
	min-width: 0;
	overflow-y: auto;
	padding: 32px 32px 64px;
}
.section-head { max-width: 680px; margin-bottom: 22px; }
.section-head h1 { font-size: 20px; margin-bottom: 6px; }
.section-head p { margin: 0; font-size: 13px; line-height: 1.6; color: var(--text-muted); }

.panel {
	max-width: 680px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	margin-bottom: 18px;
	overflow: hidden;
}
.panel-title-row {
	padding: 14px 20px;
	border-bottom: 1px solid var(--border);
	background: var(--surface-2);
}
.panel-title-row h2 {
	margin: 0;
	font-size: 12px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-muted);
}

.record-list { list-style: none; margin: 0; padding: 0; }
.record { border-bottom: 1px solid var(--border); }
.record:last-child { border-bottom: none; }
.record-view { display: flex; align-items: center; gap: 12px; padding: 14px 20px; }
.record-main { flex: 1; min-width: 0; }
.record-title { font-size: 14px; font-weight: 600; }
.record-sub {
	font-size: 12px;
	color: var(--text-muted);
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	margin-top: 2px;
}
.record-empty { padding: 20px; font-size: 13px; color: var(--text-muted); }

.record-edit {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	align-items: flex-end;
	padding: 16px 20px;
	background: var(--surface-2);
	border-left: 2px solid var(--accent);
}
.record-edit .field { margin-bottom: 0; flex: 1; min-width: 150px; }
.record-edit-actions { display: flex; gap: 8px; }
.record-note {
	flex-basis: 100%;
	margin: 0;
	font-size: 12px;
	color: var(--text-muted);
}
.record-note code {
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 4px;
	padding: 1px 5px;
}

.record-form {
	display: flex;
	gap: 12px;
	align-items: flex-end;
	flex-wrap: wrap;
	padding: 18px 20px;
}
.record-form .field { margin-bottom: 0; flex: 1; min-width: 160px; }
.record-form .field-type, .record-edit .field-type { flex: 0 0 140px; min-width: 140px; }
.record-form .field-color, .record-edit .field-color { flex: 0 0 64px; min-width: 64px; }

/* Keep every control on these rows the same height so labels and the submit
   button line up on one baseline. */
.record-form input, .record-form select, .record-form .btn,
.record-edit input, .record-edit select, .record-edit .btn {
	height: 40px;
}
.record-form input[type="color"], .record-edit input[type="color"] {
	width: 100%;
	padding: 4px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	cursor: pointer;
}
.record-form .btn, .record-edit .btn { flex-shrink: 0; }

/* Choices: chip entry, one hidden input per chip (no comma parsing). */
.field-choices { flex-basis: 100%; }
.chips {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	min-height: 40px;
	padding: 5px 8px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
}
.chips:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	background: var(--accent-soft);
	color: var(--accent-dark);
	border-radius: 999px;
	padding: 3px 4px 3px 10px;
	font-size: 13px;
	font-weight: 600;
}
.chip-remove {
	border: none;
	background: transparent;
	color: var(--accent-dark);
	cursor: pointer;
	font-size: 15px;
	line-height: 1;
	padding: 0 4px;
	border-radius: 999px;
	opacity: 0.65;
}
.chip-remove:hover { opacity: 1; background: rgba(11, 125, 112, 0.12); }
.chips .chip-input {
	flex: 1;
	min-width: 140px;
	border: none;
	outline: none;
	box-shadow: none;
	padding: 4px 2px;
	height: auto;
	background: transparent;
}
.chips .chip-input:focus { border: none; box-shadow: none; }

/* Which categories a field applies to */
.field-scope { flex-basis: 100%; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checkbox {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	font-size: 13px;
	font-weight: 500;
	margin-bottom: 0;
	cursor: pointer;
}
.checkbox input[type="checkbox"] { width: auto; height: auto; margin: 0; cursor: pointer; }
.field-hint { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; }

.scope-tag {
	font-size: 11px;
	font-weight: 600;
	color: var(--text-muted);
	background: var(--surface-2);
	border-radius: 999px;
	padding: 2px 8px;
	margin-left: 8px;
	vertical-align: 1px;
}
.scope-tag.scope-all { background: transparent; color: var(--text-muted); padding-left: 0; }

.swatch { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.type-badge {
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	padding: 3px 8px;
	border-radius: 6px;
	background: var(--surface-2);
	color: var(--text-muted);
	flex-shrink: 0;
	min-width: 64px;
	text-align: center;
}
.type-text { background: var(--accent-soft); color: var(--accent-dark); }
.type-number { background: #eaf0fd; color: #2f6fed; }
.type-date { background: #fdf3e0; color: #b3740c; }
.type-select { background: #f1ebfd; color: #6d43c8; }

.btn.btn-ghost { background: transparent; color: var(--text-muted); padding: 6px 10px; }
.btn.btn-ghost:hover { background: var(--danger-soft); color: var(--danger); }

.shared-fields-head {
	font-size: 12px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
	margin-bottom: 10px;
	border-top: 1px solid var(--border);
	padding-top: 14px;
}

.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
.inline-form .field { margin-bottom: 0; flex: 1; min-width: 120px; }

/* Settings page also holds the account card */
.settings-page { max-width: 640px; margin: 32px auto; padding: 0 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }

/* --- assets table page --- */

.assets-page {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	padding: 20px 24px;
	overflow: hidden;
}
.assets-toolbar {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 16px;
	flex-wrap: wrap;
}
.assets-toolbar input[type="search"] { max-width: 280px; }
.assets-toolbar select { max-width: 180px; }
.assets-count { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

.assets-table-wrap {
	flex: 1;
	min-height: 0;
	overflow: auto;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}
.assets-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.assets-table th {
	position: sticky;
	top: 0;
	background: var(--surface-2);
	text-align: left;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--text-muted);
	padding: 10px 16px;
	cursor: pointer;
	white-space: nowrap;
	user-select: none;
	border-bottom: 1px solid var(--border);
}
.assets-table th:hover { color: var(--text); }
.assets-table th.sort-asc::after { content: " \25B2"; font-size: 10px; }
.assets-table th.sort-desc::after { content: " \25BC"; font-size: 10px; }
.assets-table td {
	padding: 12px 16px;
	border-bottom: 1px solid var(--border);
	vertical-align: middle;
}
.assets-table tbody tr { cursor: pointer; }
.assets-table tbody tr:hover { background: var(--surface-2); }
.assets-table tbody tr:last-child td { border-bottom: none; }
.assets-table td.truncate {
	max-width: 260px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

@media (max-width: 860px) {
	.app-body { flex-direction: column; }
	.sidebar { width: 100%; height: 45%; border-left: none; border-top: 1px solid var(--border); }
	#map { height: 55%; }
	.topbar-nav a span { display: none; }
}
