/* Thingo web UI stylesheet.  One design system for every page fragment; no inline
   styles in the templates.  Server-generated markup (selects, the account picker,
   image galleries, delete links) is styled here by element and existing class. */

:root {
	--bg: #f4f6f8;
	--surface: #ffffff;
	--text: #1f2937;
	--muted: #6b7280;
	--border: #dfe3e8;
	--row-alt: #f8fafc;
	--accent: #1d6fb8;
	--accent-dark: #155a96;
	--accent-soft: #e8f1fa;
	--ok: #0f6e45;
	--ok-bg: #e9f7ef;
	--err: #b42318;
	--err-bg: #fdecea;
	--warn: #8a5a00;
	--warn-bg: #fff6e0;
	--radius: 8px;
	--shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);
	--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--font-head: Comfortaa, var(--font);
	--font-mono: ui-monospace, "Lucida Console", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: var(--font);
	line-height: 1.45;
}

h1, h2, h3, h4 {
	font-family: var(--font-head);
	font-weight: 600;
	line-height: 1.2;
	margin: 0 0 .6em;
	color: var(--text);
}
h1 { font-size: 1.9rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; margin-top: 1.4em; }
p { margin: 0 0 .9em; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); text-decoration: underline; }
img { max-width: 100%; }
sup { font-size: .6em; }

/* ---------- page frame ---------- */

.site-header {
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	box-shadow: var(--shadow);
}
.site-header .bar {
	max-width: 1100px;
	margin: 0 auto;
	padding: 10px 20px;
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px 24px;
}
.brand { display: flex; align-items: center; }
.brand img { height: 44px; width: auto; display: block; border-radius: 8px; }
.site-nav {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 2px;
	flex: 1 1 auto;
}
.site-nav a {
	display: inline-block;
	padding: 8px 10px;
	border-radius: 6px;
	color: var(--text);
	font-weight: 500;
}
.site-nav a:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; }
.site-nav .sep { flex: 1 1 auto; }

/* the account picker is a server-generated <form class="acct-picker"> */
.acct-picker {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	font-size: .95rem;
}
.acct-picker label { font-weight: 600; color: var(--muted); white-space: nowrap; }
.acct-picker select { width: auto; max-width: 260px; padding: 6px 28px 6px 8px; }

main.page {
	max-width: 1100px;
	margin: 0 auto;
	padding: 24px 20px 40px;
}

.site-footer {
	max-width: 1100px;
	margin: 0 auto;
	padding: 16px 20px 32px;
	color: var(--muted);
	font-size: .8rem;
	border-top: 1px solid var(--border);
}
.site-footer p { margin: 0 0 .4em; }
.site-footer a { margin-right: 16px; }

/* ---------- surfaces ---------- */

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 20px 24px;
	margin-bottom: 20px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.card.narrow .f-entry { grid-template-columns: 130px minmax(0, 1fr); }

.page-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 8px 16px;
	margin-bottom: 14px;
}
.page-head h1, .page-head h2 { margin: 0; }
.page-head .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.intro { color: var(--muted); max-width: 70ch; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 20px; }
.cards .card { margin: 0; display: flex; flex-direction: column; }
.cards .card .cta { margin-top: auto; padding-top: 12px; }

/* ---------- alerts (the server fills %%error%% and %%message%%; empty ones vanish) ---------- */

.error, .message, .warning, .form-note {
	border-radius: var(--radius);
	padding: 10px 14px;
	margin: 0 0 14px;
	font-size: .95rem;
	border: 1px solid transparent;
}
.error { background: var(--err-bg); color: var(--err); border-color: #f3c2bd; font-weight: 600; }
.message { background: var(--ok-bg); color: var(--ok); border-color: #bfe6d0; }
.warning { background: var(--warn-bg); color: var(--warn); border-color: #f0d9a3; }
.form-note { background: var(--accent-soft); color: var(--accent-dark); border-color: #c9ddf0; }
.error:empty, .message:empty, .warning:empty { display: none; }
.notice-danger {
	background: var(--err-bg);
	border: 1px solid #f3c2bd;
	border-radius: var(--radius);
	padding: 14px 18px;
	margin-bottom: 18px;
}
.notice-danger p { margin: 0 0 .5em; }
.notice-danger strong { color: var(--err); }

/* ---------- forms ---------- */

.f-entry {
	display: grid;
	grid-template-columns: 180px minmax(0, 1fr);
	gap: 6px 18px;
	align-items: start;
	padding: 9px 0;
	border-bottom: 1px solid var(--border);
}
.f-entry:last-of-type { border-bottom: 0; }
.f-label {
	font-weight: 600;
	font-size: .92rem;
	color: var(--muted);
	padding-top: 8px;
}
.f-label label { font-weight: inherit; font-size: inherit; }
.f-input { min-width: 0; padding-top: 6px; }
.f-input.plain { padding-top: 8px; }
.f-extra { grid-column: 2; font-size: .9rem; }
.f-group { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.f-group input[type="number"], .f-group input[type="text"], .f-group input[type="date"] { width: auto; }
.f-group .x { color: var(--muted); }
.hint { display: block; color: var(--muted); font-size: .85rem; margin-top: 4px; }

label { font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], textarea, select {
	font: inherit;
	color: var(--text);
	background: var(--surface);
	border: 1px solid #c5cbd3;
	border-radius: 6px;
	padding: 8px 10px;
	width: 100%;
	max-width: 560px;
}
input[type="number"] { max-width: 110px; }
input[type="date"] { max-width: 200px; }
textarea { min-height: 80px; resize: vertical; }
select {
	appearance: none;
	padding-right: 30px;
	background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b7280' stroke-width='1.6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 10px center;
}
input:focus, textarea:focus, select:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px rgba(29, 111, 184, .2);
}
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--muted); }
input[type="checkbox"] { width: 18px; height: 18px; vertical-align: middle; margin-right: 8px; accent-color: var(--accent); }
input[type="file"] { font: inherit; }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: normal; }
.check input[type="checkbox"] { margin-top: 3px; flex: 0 0 auto; }

.form-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	margin-top: 18px;
	padding-top: 14px;
	border-top: 1px solid var(--border);
}
.form-actions .spacer { flex: 1 1 auto; }

input[type="submit"], button, .btn {
	font: inherit;
	font-weight: 600;
	font-size: .95rem;
	color: #fff;
	background: var(--accent);
	border: 1px solid var(--accent);
	border-radius: 6px;
	padding: 9px 16px;
	min-height: 40px;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	text-decoration: none;
	line-height: 1.2;
}
input[type="submit"]:hover, button:hover, .btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; text-decoration: none; }
.btn-secondary, input[type="submit"].btn-secondary, button.btn-secondary {
	background: var(--surface);
	color: var(--accent-dark);
	border-color: #b9c6d4;
}
.btn-secondary:hover { background: var(--accent-soft); }
.btn-danger, input[type="submit"].btn-danger, button.btn-danger { background: var(--err); border-color: var(--err); }
.btn-danger:hover { background: #8f1c13; border-color: #8f1c13; }
/* server-generated delete links sit in a .danger-zone: render them as quiet red links */
.danger-zone { margin-top: 10px; font-size: .9rem; }
.danger-zone a { color: var(--err); }
.toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px;
	margin-bottom: 14px;
}
.toolbar form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.toolbar input[type="text"], .toolbar input[type="search"] { width: 260px; max-width: 100%; }
.toolbar .spacer { flex: 1 1 auto; }

/* a titled sub-section inside a card (e.g. a Thing's estate details) */
.section {
	margin-top: 22px;
	padding-top: 18px;
	border-top: 2px solid var(--border);
}
.section > h3 { font-size: 1.3rem; margin: 0 0 8px; }
h3.section-break { margin-top: 22px; padding-top: 18px; border-top: 2px solid var(--border); font-size: 1.3rem; }

/* ---------- key/value display (info pages) ---------- */

.kv { margin: 0; }
.kv .f-label, .kv .f-input { padding-top: 6px; }
.mono { font-family: var(--font-mono); font-size: .9rem; white-space: pre-wrap; }
.small { font-size: .85rem; color: var(--muted); }
.footer { font-size: .85rem; color: var(--muted); }   /* legacy class used inside list rows */
.preformatted { font-family: var(--font-mono); white-space: pre-wrap; }

/* ---------- lists as tables ---------- */

.table-wrap { overflow-x: auto; }
table.list {
	width: 100%;
	border-collapse: collapse;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font-size: .95rem;
}
table.list th, table.list td {
	padding: 10px 12px;
	text-align: left;
	vertical-align: top;
	border-bottom: 1px solid var(--border);
	overflow-wrap: anywhere;
}
table.list th {
	font-size: .8rem;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--muted);
	background: var(--row-alt);
	white-space: nowrap;
}
table.list tbody tr:nth-child(even) td { background: var(--row-alt); }
table.list tbody tr:hover td { background: var(--accent-soft); }
table.list tr:last-child td { border-bottom: 0; }
table.list .num, table.list .center { text-align: center; white-space: nowrap; }
table.list .sel { width: 44px; text-align: center; }
table.list .sel input[type="checkbox"] { margin: 0; }
table.list .thumb { width: 96px; }
table.list .thumb img { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: #fff; }
table.list .primary { font-weight: 600; overflow-wrap: normal; }
table.list .sub { display: block; font-weight: normal; font-size: .82rem; color: var(--muted); margin-top: 2px; }
.list-foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	margin-top: 14px;
}
.list-foot .count { color: var(--muted); font-size: .9rem; }
.list-foot .spacer { flex: 1 1 auto; }
.list-foot select { width: auto; max-width: 320px; }
.summary { color: var(--muted); font-size: .95rem; margin: 10px 0 0; }

/* ---------- status page ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.st-list { margin: 0; }
.st-entry { display: grid; grid-template-columns: 140px 1fr; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.st-entry:last-child { border-bottom: 0; }
.st-label { font-weight: 600; color: var(--muted); font-size: .9rem; }
.st-value { font-family: var(--font-mono); font-size: .92rem; overflow-wrap: anywhere; }

/* ---------- image galleries (markup generated by the server) ---------- */

.th-gallery { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 4px; }
.th-gallery-item { flex: 0 1 200px; text-align: center; }
.th-gallery-item img { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; transition: transform .15s; background: #fff; }
.th-gallery-item img:hover { transform: scale(1.03); box-shadow: var(--shadow); }
.th-gallery-caption { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.th-thumb-gallery {
	display: flex;
	flex-wrap: nowrap;
	overflow-x: auto;
	gap: 8px;
	margin-bottom: 10px;
	padding: 8px;
	background: var(--row-alt);
	border: 1px solid var(--border);
	border-radius: 6px;
}
.th-thumb-item { flex: 0 0 auto; }
.th-thumb-item a { display: block; border: 2px solid var(--border); border-radius: 6px; overflow: hidden; }
.th-thumb-item a:hover { border-color: var(--accent); }
.th-thumb-item img { display: block; width: 88px; height: 88px; object-fit: cover; }

/* ---------- lightbox (full-size image overlay on the Thing page) ---------- */

.lightbox {
	position: fixed;
	inset: 0;
	background: rgba(17, 24, 39, .88);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 24px;
	cursor: zoom-out;
	z-index: 100;
}
.lightbox[hidden] { display: none; }
.lightbox img {
	max-width: 100%;
	max-height: calc(100vh - 80px);
	width: auto;
	height: auto;
	border-radius: 6px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
	background: #fff;
}
.lightbox-caption { color: #e5e7eb; font-size: .9rem; }
.th-gallery-item img { cursor: zoom-in; }

/* ---------- misc ---------- */

.cf-turnstile { margin-top: 6px; }
.center { text-align: center; }
.hidden { display: none; }
.play-badge img { max-width: 180px; }

/* ---------- small screens ---------- */

@media (max-width: 720px) {
	main.page { padding: 16px 12px 32px; }
	.card { padding: 16px; }
	.f-entry { grid-template-columns: 1fr; gap: 4px; }
	.f-label { padding-top: 0; }
	.f-extra { grid-column: 1; }
	.acct-picker { width: 100%; }
	.acct-picker select { max-width: none; flex: 1 1 auto; }
	input[type="submit"], button, .btn { width: 100%; }
	.form-actions .spacer { display: none; }
	.toolbar input[type="text"] { width: 100%; }
	/* data tables keep their columns and scroll sideways inside .table-wrap */
	table.list { min-width: 680px; }
}
