:root {
	--bg: #f4f5f7;
	--surface: #ffffff;
	--surface-2: #f0f2f5;
	--border: #d9dde3;
	--text: #1c2430;
	--text-dim: #5b6675;
	--accent: #2f6fed;
	--accent-text: #ffffff;
	--ok: #1e8e4e;
	--ok-bg: #e5f5ec;
	--danger: #c23b3b;
	--radius: 14px;
	--shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #12151a;
		--surface: #1b1f27;
		--surface-2: #232833;
		--border: #333a46;
		--text: #e7ebf1;
		--text-dim: #9aa5b4;
		--accent: #4d86ff;
		--accent-text: #0b1017;
		--ok: #46c079;
		--ok-bg: #17351f;
		--danger: #ff6b6b;
		--shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35);
	}
}

* {
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
		Arial, sans-serif;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

.wrap {
	width: 100%;
	max-width: 720px;
	margin: 0 auto;
	padding: 10px 12px;
}

/* ---------- login ---------- */
.login-screen {
	min-height: 100dvh;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px 16px;
}

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 28px 22px;
	width: 100%;
	max-width: 400px;
}

form {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

label {
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--text-dim);
}

input {
	font: inherit;
	font-size: 16px; /* prevents iOS zoom on focus */
	color: var(--text);
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 12px 14px;
	width: 100%;
	min-height: 48px;
}

input:focus {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
	border-color: var(--accent);
}

button {
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	background: var(--accent);
	color: var(--accent-text);
	border: 0;
	border-radius: 10px;
	padding: 12px 16px;
	min-height: 48px;
	transition: filter 0.15s ease, opacity 0.15s ease;
}

button:hover {
	filter: brightness(1.05);
}

button:disabled {
	opacity: 0.55;
	cursor: default;
}

button.ghost {
	background: transparent;
	color: var(--text-dim);
	border: 1px solid var(--border);
}

.msg {
	font-size: 0.9rem;
	min-height: 1.2em;
}

.msg.error {
	color: var(--danger);
}

/* ---------- dashboard ---------- */
.topbar {
	position: sticky;
	top: 0;
	z-index: 5;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}

.topbar .wrap {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding-top: 8px;
	padding-bottom: 8px;
}

.topbar h1 {
	margin: 0;
	font-size: 1.05rem;
}

.who {
	display: flex;
	align-items: center;
	gap: 10px;
	font-size: 0.9rem;
	color: var(--text-dim);
}

.who button {
	min-height: 38px;
	padding: 8px 12px;
	font-size: 0.85rem;
}

/* The whole materials list is tuned for density: small paddings, one variant
   per single line, and the "last count" note tucked directly under the name.
   Adjust the four values below to loosen or tighten it everywhere at once. */
:root {
	--row-pad-y: 6px;    /* top/bottom padding inside each variant row     */
	--row-pad-x: 12px;   /* left/right padding inside cards and rows       */
	--card-gap: 8px;     /* vertical space between material cards          */
	--control-h: 36px;   /* height of the number box and the Save button  */
}

.section-title {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 8px;
	margin: 10px 2px 6px;
}

.section-title h2 {
	margin: 0;
	font-size: 0.9rem;
}

.section-title .hint {
	font-size: 0.72rem;
	color: var(--text-dim);
}

.material {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	box-shadow: var(--shadow);
	margin-bottom: var(--card-gap);
	overflow: hidden;
}

/* Material name: a compact uppercase strip, not a big heading. */
.material > h3 {
	margin: 0;
	padding: 6px var(--row-pad-x);
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--text-dim);
	border-bottom: 1px solid var(--border);
	background: var(--surface-2);
}

/* One variant = one line:  name / (last-count note)  |  number  |  Save
   Column 1 holds the name on row 1 and the note on row 2; the number box
   and the Save button each span both rows so the line stays a single strip. */
.variant {
	display: grid;
	grid-template-columns: 1fr auto auto;
	align-items: center;
	column-gap: 10px;
	row-gap: 1px;
	padding: var(--row-pad-y) var(--row-pad-x);
	border-bottom: 1px solid var(--border);
}

.variant:last-child {
	border-bottom: 0;
}

.variant .v-label {
	grid-column: 1;
	grid-row: 1;
	font-weight: 600;
	font-size: 0.92rem;
	line-height: 1.2;
}

.variant .v-meta {
	grid-column: 1;
	grid-row: 2;
	font-size: 0.72rem;
	line-height: 1.15;
	color: var(--text-dim);
}

.variant .v-input {
	grid-column: 2;
	grid-row: 1 / span 2;
}

.variant .v-input input {
	display: block;
	width: 72px;
	min-height: var(--control-h);
	padding: 2px 6px;
	text-align: center;
	font-weight: 600;
	font-size: 16px;
}

.variant .v-actions {
	grid-column: 3;
	grid-row: 1 / span 2;
	display: flex;
	align-items: center;
	gap: 6px;
}

.variant .v-actions button {
	min-height: var(--control-h);
	padding: 4px 12px;
}

.variant.saved {
	background: var(--ok-bg);
}

.variant .saved-flag {
	color: var(--ok);
	font-size: 0.75rem;
	font-weight: 600;
	opacity: 0;
	transition: opacity 0.2s ease;
}

.variant.saved .saved-flag {
	opacity: 1;
}

.state {
	text-align: center;
	color: var(--text-dim);
	padding: 20px 0;
}

/* ---------- number inputs: no spinner arrows ----------
   Hides the up/down steppers that desktop browsers add to <input type=number>.
   Phones don't show them, so this only changes the desktop view. */
input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

/* ---------- hamburger nav ----------
   The button is injected into .topbar .wrap by nav.js; the drawer + overlay
   are appended to <body>. Open state is `body.nav-open`. */
.hamburger {
	display: inline-flex;
	flex-direction: column;
	justify-content: center;
	gap: 4px;
	flex: 0 0 auto;
	width: 40px;
	min-height: 40px;
	padding: 0 9px;
	background: transparent;
	border: 1px solid var(--border);
	border-radius: 10px;
}

.hamburger span {
	display: block;
	width: 100%;
	height: 2px;
	border-radius: 2px;
	background: var(--text);
}

.topbar .wrap > .hamburger {
	margin-right: 4px;
}

.nav-overlay {
	position: fixed;
	inset: 0;
	z-index: 20;
	background: rgba(0, 0, 0, 0.4);
}

.nav-drawer {
	position: fixed;
	top: 0;
	left: 0;
	bottom: 0;
	z-index: 21;
	width: 264px;
	max-width: 80vw;
	padding: 8px 0;
	overflow-y: auto;
	background: var(--surface);
	border-right: 1px solid var(--border);
	box-shadow: var(--shadow);
	transform: translateX(-100%);
	transition: transform 0.18s ease;
}

body.nav-open .nav-drawer {
	transform: none;
}

.nav-drawer a {
	display: block;
	padding: 12px 18px;
	color: var(--text);
	text-decoration: none;
	font-weight: 600;
	font-size: 0.95rem;
}

.nav-drawer a:hover {
	background: var(--surface-2);
}

.nav-drawer a.active {
	color: var(--accent);
	box-shadow: inset 3px 0 0 var(--accent);
}

.nav-drawer-head,
.nav-drawer .nav-section {
	padding: 10px 18px 6px;
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--text-dim);
}

.nav-drawer .nav-section {
	margin-top: 6px;
	border-top: 1px solid var(--border);
}

/* ---------- tools list ----------
   Reuses the .material / .variant card styles from the tracker. */
.tool-serial {
	font-variant-numeric: tabular-nums;
}

/* ---------- export page ----------
   A small form of checkboxes over a preview that reuses the admin tables. */
.export-form {
	max-width: none;
	padding: 14px 16px;
	margin-bottom: 14px;
	gap: 10px;
}

.export-form .checks {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 16px;
	margin: 0;
	padding: 0;
	border: 0;
}

.export-form legend {
	width: 100%;
	padding: 0;
	margin-bottom: 2px;
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--text-dim);
}

.export-form .check {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 0.92rem;
	font-weight: 500;
	color: var(--text);
}

.export-form .check input {
	width: 18px;
	height: 18px;
	min-height: 0;
	padding: 0;
}

.export-actions {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-top: 4px;
}

.export-actions .msg {
	color: var(--text-dim);
	font-size: 0.82rem;
}

.export-actions button {
	min-height: 40px;
	padding: 8px 16px;
}

.export-buttons {
	display: flex;
	gap: 8px;
	flex: 0 0 auto;
}

/* The PDF shown on the page when a new tab was blocked. */
.pdf-viewer {
	margin-bottom: 14px;
}

.pdf-viewer .section-title button {
	min-height: 30px;
	padding: 3px 10px;
	font-size: 0.8rem;
}

.pdf-pages canvas {
	display: block;
	max-width: 100%;
	margin-bottom: 10px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: #fff;
	box-shadow: var(--shadow);
}

.report-floor {
	margin-bottom: 18px;
}

.report-floor h3 {
	margin: 0 2px 6px;
	font-size: 0.95rem;
}

.report-floor .report-sub {
	margin: 8px 2px 4px;
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--text-dim);
}

.report-floor .admin-table td {
	white-space: normal;
}

/* ---------- admin panel ----------
   Deliberately dense: small type, tight rows, one <table> per section. */
.admin {
	max-width: 900px;
}

.admin-sec {
	margin-bottom: 16px;
}

.admin-sec-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin: 0 2px 4px;
}

.admin-sec-head h3 {
	margin: 0;
	font-size: 0.78rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--text-dim);
}

.admin-sec-head .count {
	font-weight: 400;
	opacity: 0.6;
}

.admin-add {
	min-height: 30px;
	padding: 3px 10px;
	font-size: 0.8rem;
	border-radius: 8px;
}

.admin-table-wrap {
	overflow-x: auto;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	box-shadow: var(--shadow);
}

.admin-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.8rem;
}

.admin-table th {
	padding: 5px 10px;
	text-align: left;
	font-size: 0.66rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	white-space: nowrap;
	color: var(--text-dim);
	background: var(--surface-2);
	border-bottom: 1px solid var(--border);
}

.admin-table td {
	padding: 4px 10px;
	max-width: 220px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	border-bottom: 1px solid var(--border);
}

.admin-table tbody tr:last-child td {
	border-bottom: 0;
}

.admin-table th.num,
.admin-table td.num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.admin-table td.empty {
	padding: 10px;
	text-align: center;
	color: var(--text-dim);
}

.admin-table tr.editable {
	cursor: pointer;
}

.admin-table tbody tr.editable:hover {
	background: var(--surface-2);
}

.admin-table tbody tr.editable:focus {
	outline: 2px solid var(--accent);
	outline-offset: -2px;
}

.admin-table tr.serial-subrow td {
	padding-left: 22px;
	color: var(--text-dim);
	font-size: 0.74rem;
}

/* ---------- modal ---------- */
.modal-backdrop {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: rgba(0, 0, 0, 0.45);
}

.modal-backdrop[hidden] {
	display: none;
}

.modal {
	width: min(440px, 100%);
	max-height: 88vh;
	overflow-y: auto;
	padding: 16px 16px 14px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	box-shadow: var(--shadow);
}

.modal h3 {
	margin: 0 0 12px;
	font-size: 0.95rem;
}

#modal-form {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.field {
	display: flex;
	flex-direction: column;
	gap: 3px;
}

.field-label {
	font-size: 0.76rem;
	font-weight: 600;
	color: var(--text-dim);
}

.field-hint {
	font-size: 0.7rem;
	color: var(--text-dim);
}

.field input,
.field select {
	min-height: 40px;
}

.field-check {
	flex-direction: row;
	align-items: center;
	gap: 8px;
}

.field-check input {
	width: 18px;
	height: 18px;
	min-height: 0;
}

.field-check .field-label {
	font-size: 0.9rem;
	color: var(--text);
}

.modal-msg {
	min-height: 1em;
	font-size: 0.8rem;
	color: var(--danger);
}

.modal-msg.ok {
	color: var(--ok);
}

.modal-actions {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-top: 4px;
}

.modal-right {
	display: flex;
	gap: 8px;
}

.modal-actions button {
	min-height: 38px;
	padding: 6px 14px;
	font-size: 0.85rem;
}

.modal-actions .danger {
	background: var(--danger);
	color: #fff;
}

/* serial sub-editor inside the tool modal */
.serial-editor .serial-list {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.serial-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 4px 8px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 8px;
	font-variant-numeric: tabular-nums;
}

.serial-row select {
	min-height: 26px;
	font-size: 0.78rem;
}

.serial-row .x {
	min-height: 24px;
	padding: 0 8px;
	font-size: 0.8rem;
	color: var(--danger);
	background: transparent;
	border: 1px solid var(--border);
	border-radius: 6px;
}

.serial-empty {
	padding: 2px 0;
	font-size: 0.76rem;
	color: var(--text-dim);
}

.serial-add {
	display: flex;
	gap: 6px;
	margin-top: 6px;
}

.serial-add input {
	flex: 1;
	min-height: 36px;
}

.serial-add select {
	min-height: 36px;
	font-size: 0.82rem;
}

.serial-add button {
	min-height: 36px;
	padding: 4px 12px;
	font-size: 0.82rem;
}
