:root {
	--bg: #f5f7fb;
	--surface: #ffffff;
	--surface-2: #eef2f8;
	--border: #dde3ec;
	--text: #1b2333;
	--muted: #6b7587;
	--primary: #3b6fe0;
	--primary-strong: #2b54b8;
	--ok: #15a05f;
	--err: #e0524b;
	--shadow: 0 10px 28px rgba(27, 35, 51, 0.10);
	--radius: 14px;
	--sidebar-w: 280px;
}

* { box-sizing: border-box; }

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

.mono {
	font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.86em;
}
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.cur { color: var(--muted); font-size: 0.78em; }

/* Layout: sidebar + content */
.layout {
	display: grid;
	grid-template-columns: var(--sidebar-w) 1fr;
	min-height: 100vh;
}

.sidebar {
	background: var(--surface);
	border-right: 1px solid var(--border);
	padding: 20px 18px;
	display: flex;
	flex-direction: column;
	gap: 24px;
	position: sticky;
	top: 0;
	height: 100vh;
	overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
	width: 40px; height: 40px;
	display: grid; place-items: center;
	background: linear-gradient(135deg, var(--primary), var(--primary-strong));
	border-radius: 11px;
	font-weight: 800;
	box-shadow: var(--shadow);
}
.brand h1 { font-size: 1.05rem; margin: 0; }
.brand p { margin: 0; font-size: 0.78rem; color: var(--muted); }

.nav-label {
	font-size: 0.72rem;
	text-transform: uppercase;
	letter-spacing: 0.6px;
	color: var(--muted);
	margin: 0 0 10px;
}

/* Sidebar footer (sign out) pinned to the bottom */
.sidebar-bottom {
	margin-top: auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding-top: 8px;
}
.sidebar-link {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	text-align: left;
	background: transparent;
	border: 1px solid transparent;
	color: var(--muted);
	padding: 10px 12px;
	border-radius: 10px;
	cursor: pointer;
	font-size: 0.88rem;
	font-weight: 500;
	transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.sidebar-link:hover {
	background: var(--surface-2);
	border-color: var(--border);
	color: var(--text);
}
.sidebar-link-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	border-radius: 8px;
	background: rgba(59, 111, 224, 0.10);
	border: 1px solid rgba(59, 111, 224, 0.22);
	font-size: 0.68rem;
	font-weight: 800;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	color: var(--primary-strong);
	flex-shrink: 0;
}
.sidebar-foot {
	padding-top: 12px;
	border-top: 1px solid var(--border);
}

/* Sign-in page */
.auth-body {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: 24px;
	background:
		radial-gradient(1200px 500px at 50% -10%, rgba(59, 111, 224, 0.10), transparent),
		var(--bg);
}
.auth-card {
	width: 100%;
	max-width: 380px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 28px 26px;
	display: flex;
	flex-direction: column;
	gap: 18px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand h1 { font-size: 1.05rem; margin: 0; }
.auth-brand p { margin: 2px 0 0; font-size: 0.82rem; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field span { font-size: 0.8rem; color: var(--muted); }
.auth-input {
	background: var(--bg);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 10px;
	padding: 11px 13px;
	font-size: 0.94rem;
	outline: none;
	transition: border-color 0.15s;
}
.auth-input:focus { border-color: var(--primary); }
.auth-submit { margin-top: 4px; padding: 11px 16px; }

/* Marketplace list */
.mk-list { display: flex; flex-direction: column; gap: 4px; }
.mk-item {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	text-align: left;
	background: transparent;
	border: 1px solid transparent;
	color: var(--text);
	padding: 10px 12px;
	border-radius: 10px;
	cursor: pointer;
	font-size: 0.9rem;
	transition: background 0.12s, border-color 0.12s;
}
.mk-item:hover { background: var(--surface-2); }
.mk-item.active {
	background: rgba(59, 111, 224, 0.10);
	border-color: rgba(59, 111, 224, 0.35);
	color: var(--primary-strong);
}
.mk-item .flag { font-size: 1.2rem; line-height: 1; }
.mk-item .mk-name { flex: 1; }
.mk-item .mk-code {
	font-size: 0.72rem;
	color: var(--muted);
	font-family: ui-monospace, monospace;
}

/* Upload (toolbar) */
.upload-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-shrink: 0;
}
.file-pick {
	position: relative;
	display: inline-flex;
	cursor: pointer;
}
.file-pick input[type="file"] {
	position: absolute;
	inset: 0;
	opacity: 0;
	cursor: pointer;
}
.file-name {
	max-width: 200px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 0.84rem;
}
.file-name.has-file { color: var(--text); }

.btn {
	border: 1px solid var(--border);
	background: var(--surface-2);
	color: var(--text);
	padding: 9px 16px;
	border-radius: 10px;
	font-size: 0.88rem;
	font-weight: 600;
	cursor: pointer;
	transition: transform 0.05s, border-color 0.15s;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-strong)); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }

.upload-result { width: 100%; }
.upload-result:empty { display: none; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 0.82rem; border: 1px solid var(--border); }
.alert-ok { background: rgba(21, 160, 95, 0.10); border-color: rgba(21, 160, 95, 0.40); color: #0f7a47; }
.alert-err { background: rgba(224, 82, 75, 0.10); border-color: rgba(224, 82, 75, 0.40); color: #b3382f; }

/* Content */
.content { padding: 24px 28px 56px; min-width: 0; }
.content-head {
	margin-bottom: 18px;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 10px;
}
.content-toolbar {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
}
.filter-toggle {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 0.85rem;
	color: var(--muted);
	cursor: pointer;
	user-select: none;
	white-space: nowrap;
}
.filter-toggle input { accent-color: var(--primary); width: 15px; height: 15px; cursor: pointer; }
.filter-toggle:hover { color: var(--text); }
.missing-badge {
	color: #b45309;
	background: rgba(217, 119, 6, 0.10);
	border: 1px solid rgba(217, 119, 6, 0.30);
	border-radius: 999px;
	padding: 2px 11px;
	font-size: 0.78rem;
	cursor: pointer;
	transition: background 0.12s, border-color 0.12s;
}
.missing-badge:hover { background: rgba(217, 119, 6, 0.18); border-color: rgba(217, 119, 6, 0.5); }
.missing-badge.active { background: rgba(217, 119, 6, 0.24); border-color: rgba(217, 119, 6, 0.65); }
.search {
	flex: 1 1 280px;
	min-width: 200px;
	max-width: 460px;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 10px;
	padding: 11px 15px;
	font-size: 0.92rem;
	outline: none;
	transition: border-color 0.15s;
}
.search:focus { border-color: var(--primary); }

.items-meta { margin-bottom: 10px; font-size: 0.8rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.items-meta .items-export { margin-left: auto; }

.table-wrap {
	overflow-x: auto;
	border-radius: 12px;
	border: 1px solid var(--border);
	background: var(--surface);
}
.data-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.88rem;
	table-layout: fixed;
	min-width: 1120px;
}
/* Stable column widths so sorting / paging never reflows the layout */
.data-table th.img-col, .data-table td.img-cell { width: 52px; }
.data-table th:nth-child(2), .data-table td:nth-child(2) { width: 130px; }
.data-table th:nth-child(3), .data-table td:nth-child(3) { width: 120px; }
.data-table th:nth-child(4), .data-table td:nth-child(4) { width: 220px; }
.data-table th:nth-child(5), .data-table td:nth-child(5),
.data-table th:nth-child(7), .data-table td:nth-child(7) { width: 132px; }
.data-table th:nth-child(6), .data-table td:nth-child(6),
.data-table th:nth-child(8), .data-table td:nth-child(8) { width: 110px; }
.data-table th:nth-child(9), .data-table td:nth-child(9) { width: 130px; }
.data-table th.actions-col, .data-table td.actions-cell { width: 92px; }
.data-table td { overflow: hidden; text-overflow: ellipsis; }
.data-table td.mono { word-break: break-all; }
.data-table thead th {
	text-align: left;
	font-weight: 600;
	font-size: 0.72rem;
	text-transform: uppercase;
	letter-spacing: 0.4px;
	color: var(--muted);
	padding: 12px 14px;
	background: var(--surface-2);
	border-bottom: 1px solid var(--border);
	white-space: nowrap;
	position: sticky;
	top: 0;
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .num { text-align: right; white-space: nowrap; }
.threshold { color: var(--muted); }
.title {
	max-width: 220px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Small product thumbnails */
.img-col { width: 48px; }
.img-cell { width: 48px; }
.thumb {
	width: 36px;
	height: 36px;
	object-fit: contain;
	border-radius: 6px;
	background: var(--surface-2);
	display: block;
}

/* Sortable column headers */
.sort-link {
	color: inherit;
	text-decoration: none;
	cursor: pointer;
	white-space: nowrap;
	display: inline-flex;
	align-items: center;
	gap: 6px;
}
.sort-link:hover { color: var(--text); }
.sort-link.active { color: var(--primary); }
/* Reserve a fixed slot for the arrow so toggling direction never shifts layout */
.sort-arrow {
	display: inline-block;
	width: 1em;
	text-align: center;
	font-size: 0.9em;
	color: var(--muted);
	opacity: 0.5;
}
.sort-link.active .sort-arrow { color: var(--primary); opacity: 1; }
.data-table .num .sort-link { justify-content: flex-end; }

/* Inline edit */
.actions-col { width: 1%; }
.actions-cell { white-space: nowrap; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; border-radius: 8px; }
.edit-row { background: rgba(59, 111, 224, 0.06); }
.edit-input {
	width: 100%;
	min-width: 90px;
	background: var(--bg);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 8px;
	padding: 6px 9px;
	font-size: 0.85rem;
	outline: none;
}
.edit-input:focus { border-color: var(--primary); }
.edit-num { width: 92px; min-width: 80px; text-align: right; }
.edit-actions { display: flex; gap: 6px; }

/* Detail / edit modal */
.data-row:hover { background: var(--surface-2); }
.modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.6);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	z-index: 50;
}
.modal {
	position: relative;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	width: 100%;
	max-width: 620px;
	max-height: 88vh;
	overflow-y: auto;
	padding: 22px;
}
.modal-close {
	position: absolute;
	top: 10px;
	right: 12px;
	background: transparent;
	border: none;
	color: var(--muted);
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-body { display: flex; gap: 20px; }
.modal-img {
	flex: 0 0 200px;
	display: flex;
	align-items: flex-start;
	justify-content: center;
}
.modal-img img {
	width: 100%;
	max-width: 200px;
	border-radius: 10px;
	background: var(--surface-2);
}
.modal-noimg {
	width: 200px;
	height: 200px;
	display: grid;
	place-items: center;
	border: 1px dashed var(--border);
	border-radius: 10px;
}
.modal-info { flex: 1; min-width: 0; }
.modal-title { margin: 0 0 14px; font-size: 1.05rem; }
.modal-title a { color: var(--text); text-decoration: none; }
.modal-title a:hover { color: var(--primary); text-decoration: underline; }
.modal-dl {
	display: grid;
	grid-template-columns: max-content 1fr;
	gap: 8px 16px;
	margin: 0 0 16px;
	font-size: 0.88rem;
}
.modal-dl dt { color: var(--muted); }
.modal-dl dd { margin: 0; word-break: break-word; }
.modal-dl dd .edit-input { width: 100%; }
.modal-actions { display: flex; gap: 8px; }

@media (max-width: 560px) {
	.modal-body { flex-direction: column; }
	.modal-img, .modal-img img, .modal-noimg { flex-basis: auto; max-width: 100%; width: 100%; }
}

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }
.pager-info { font-size: 0.84rem; color: var(--muted); }
.pager-jump {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 0.84rem;
	color: var(--muted);
}
.page-input {
	width: 58px;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 8px;
	padding: 5px 8px;
	font-size: 0.84rem;
	text-align: center;
	outline: none;
}
.page-input:focus { border-color: var(--primary); }

/* Hide the native number spinners — they look out of place */
.page-input::-webkit-outer-spin-button,
.page-input::-webkit-inner-spin-button,
.edit-num::-webkit-outer-spin-button,
.edit-num::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}
.page-input,
.edit-num {
	-moz-appearance: textfield;
	appearance: textfield;
}

.empty { text-align: center; padding: 48px 16px; }
.empty p { margin: 4px 0; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* htmx indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.spinner {
	width: 13px; height: 13px;
	border: 2px solid rgba(255,255,255,0.55);
	border-top-color: #fff;
	border-radius: 50%;
	animation: spin 0.6s linear infinite;
	vertical-align: -2px;
	margin-right: 6px;
}
.btn-ghost .spinner {
	border-color: rgba(0,0,0,0.12);
	border-top-color: var(--text);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Exchange rates modal */
.rates-modal { max-width: 420px; padding: 22px 22px 18px; }
.rates-header { margin-bottom: 16px; }
.rates-title {
	margin: 0;
	font-size: 1.05rem;
	font-weight: 700;
	letter-spacing: -0.01em;
}
.rates-subtitle {
	margin: 6px 0 0;
	font-size: 0.82rem;
	color: var(--muted);
	line-height: 1.45;
}
.rates-form { display: flex; flex-direction: column; gap: 14px; }
.rates-grid {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 12px;
}
.rates-grid-head,
.rates-grid-row {
	display: grid;
	grid-template-columns: 56px 1fr;
	align-items: center;
	gap: 12px;
}
.rates-grid-head {
	padding: 0 2px 2px;
	font-size: 0.68rem;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--muted);
	font-weight: 600;
}
.rates-grid-row { cursor: pointer; }
.rate-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 48px;
	padding: 6px 10px;
	border-radius: 8px;
	background: var(--surface);
	border: 1px solid var(--border);
	font-size: 0.78rem;
	font-weight: 700;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	color: var(--primary-strong);
}
.rate-field {
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 0;
}
.rate-input {
	flex: 1;
	min-width: 0;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 9px;
	padding: 8px 10px;
	font-size: 0.88rem;
	text-align: right;
	outline: none;
	transition: border-color 0.15s, box-shadow 0.15s;
}
.rate-input:hover { border-color: #c8d2e0; }
.rate-input:focus {
	border-color: var(--primary);
	box-shadow: 0 0 0 3px rgba(59, 111, 224, 0.14);
}
.rate-suffix {
	font-size: 0.72rem;
	font-weight: 600;
	flex-shrink: 0;
}
.rates-actions { margin-top: 0; justify-content: flex-end; }
.rates-result:empty { display: none; }
.rates-toast {
	padding: 9px 11px;
	font-size: 0.82rem;
	border-radius: 9px;
}

.rate-input::-webkit-outer-spin-button,
.rate-input::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}
.rate-input {
	-moz-appearance: textfield;
	appearance: textfield;
}

.notify-status {
	display: inline-block;
	font-size: 0.78rem;
	font-weight: 600;
	padding: 2px 8px;
	border-radius: 999px;
}
.notify-on {
	color: #0f7a47;
	background: rgba(21, 160, 95, 0.12);
}
.notify-off {
	color: var(--muted);
	background: var(--surface-2);
	border: 1px solid var(--border);
}

@media (max-width: 760px) {
	.layout { grid-template-columns: 1fr; }
	.sidebar { position: static; height: auto; }
	.mk-list { flex-direction: row; flex-wrap: wrap; }
	.mk-item { width: auto; }
	.mk-item .mk-name { display: none; }
	.sidebar-bottom { margin-top: 16px; }
}
