/* Frontend builder & viewer Custom Server */
.csrv-builder {
	--csrv-primary: #2271b1;
	--csrv-border: #e2e8f0;
	font-size: 15px;
	line-height: 1.5;
}

.csrv-columns {
	display: grid;
	grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.4fr);
	gap: 24px;
	align-items: start;
}

@media (max-width: 860px) {
	.csrv-columns {
		grid-template-columns: 1fr;
	}
}

/* Steps hint */
.csrv-steps {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	margin-bottom: 16px;
}

.csrv-step {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	color: #475569;
}

.csrv-step b {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: var(--csrv-primary);
	color: #fff;
	font-size: 12px;
}

/* Palette */
.csrv-palette {
	background: #f8fafc;
	border: 1px solid var(--csrv-border);
	border-radius: 8px;
	padding: 16px;
	display: flex;
	flex-direction: column;
	max-height: 680px;
}

.csrv-palette-scroll {
	overflow-y: auto;
	flex: 1;
	margin-top: 4px;
	padding-right: 4px;
}

/* Search */
.csrv-search-wrap {
	margin-bottom: 10px;
}

.csrv-search {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid #cbd5e1;
	border-radius: 8px;
	font-size: 14px;
	background: #fff;
	box-sizing: border-box;
}

.csrv-search:focus {
	outline: 2px solid var(--csrv-primary);
	outline-offset: -1px;
}

/* Category chips */
.csrv-cat-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 10px;
}

.csrv-chip {
	border: 1px solid #cbd5e1;
	background: #fff;
	color: #334155;
	border-radius: 999px;
	padding: 5px 12px;
	font-size: 12.5px;
	cursor: pointer;
	transition: all 0.12s ease;
}

.csrv-chip:hover {
	border-color: var(--csrv-primary);
	color: var(--csrv-primary);
}

.csrv-chip-active {
	background: var(--csrv-primary);
	border-color: var(--csrv-primary);
	color: #fff;
}

.csrv-chip-count {
	opacity: 0.7;
	font-size: 11px;
}

.csrv-no-results {
	color: #94a3b8;
	text-align: center;
	padding: 24px 8px;
}

.csrv-palette h3,
.csrv-build-area h3 {
	margin-top: 0;
}

.csrv-palette-category h4 {
	margin: 14px 0 6px;
	font-size: 13px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: #64748b;
	position: sticky;
	top: 0;
	background: #f8fafc;
	padding: 4px 0;
	z-index: 1;
}

.csrv-palette-category:first-child h4 {
	margin-top: 2px;
}

.csrv-palette-item[hidden],
.csrv-palette-category[hidden] {
	display: none;
}

.csrv-palette-item {
	display: grid;
	grid-template-columns: 1fr auto;
	grid-template-areas: "name add" "meta add" "price add";
	gap: 0 8px;
	background: #fff;
	border: 1px solid var(--csrv-border);
	border-radius: 6px;
	padding: 8px 10px;
	margin-bottom: 6px;
	cursor: grab;
	transition: box-shadow 0.15s ease;
}

.csrv-palette-item:hover {
	box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

.csrv-item-name { grid-area: name; font-weight: 600; }
.csrv-item-meta { grid-area: meta; font-size: 12px; color: #64748b; }
.csrv-item-price { grid-area: price; font-size: 13px; color: var(--csrv-primary); font-weight: 600; }

.csrv-add-btn {
	grid-area: add;
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	align-self: center;
	width: 34px !important;
	height: 34px !important;
	padding: 0 !important;
	min-width: 34px !important;
	min-height: 34px !important;
	border-radius: 50%;
	border: 1px solid var(--csrv-primary);
	background: #fff;
	color: var(--csrv-primary);
	font-size: 22px !important;
	font-weight: 700;
	line-height: 1 !important;
	text-indent: 0 !important;
	box-shadow: none !important;
	appearance: none;
	-webkit-appearance: none;
	cursor: pointer;
}

.csrv-add-btn:hover {
	background: var(--csrv-primary);
	color: #fff;
}

/* Build area */
.csrv-build-area {
	border: 1px solid var(--csrv-border);
	border-radius: 8px;
	padding: 16px;
}

.csrv-config-name-wrap {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 10px;
}

.csrv-config-name-wrap label {
	font-size: 13px;
	font-weight: 600;
	color: #334155;
}

.csrv-config-name {
	width: 100%;
	padding: 9px 11px;
	border: 1px solid #cbd5e1;
	border-radius: 8px;
	font-size: 14px;
	box-sizing: border-box;
}

.csrv-config-name:focus {
	outline: 2px solid var(--csrv-primary);
	outline-offset: -1px;
}

.csrv-dropzone {
	min-height: 160px;
	border: 2px dashed #cbd5e1;
	border-radius: 8px;
	padding: 10px;
	transition: border-color 0.15s ease, background 0.15s ease;
}

.csrv-dropzone-over {
	border-color: var(--csrv-primary);
	background: #eff6ff;
}

.csrv-empty-hint {
	color: #94a3b8;
	text-align: center;
	margin: 48px 8px;
}

.csrv-selected-row {
	display: grid;
	grid-template-columns: auto 1fr auto auto auto;
	align-items: center;
	gap: 10px;
	background: #fff;
	border: 1px solid var(--csrv-border);
	border-radius: 6px;
	padding: 8px 10px;
	margin-bottom: 6px;
}

.csrv-selected-cat {
	font-size: 11px;
	background: #eef2ff;
	color: #4338ca;
	border-radius: 999px;
	padding: 2px 8px;
	white-space: nowrap;
}

.csrv-selected-name { font-weight: 600; }
.csrv-selected-price { font-weight: 600; color: var(--csrv-primary); white-space: nowrap; }

.csrv-qty-controls {
	display: inline-flex !important;
	align-items: center;
	gap: 6px;
	padding: 3px 6px;
	border: 1px solid #cbd5e1;
	border-radius: 999px;
	background: #f8fafc;
}

.csrv-qty-controls button {
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	width: 30px !important;
	height: 30px !important;
	min-width: 30px !important;
	min-height: 30px !important;
	padding: 0 !important;
	border-radius: 50%;
	border: 1px solid #94a3b8;
	background: #fff;
	color: #0f172a;
	font-size: 20px !important;
	font-weight: 700;
	cursor: pointer;
	line-height: 1 !important;
	text-indent: 0 !important;
	box-shadow: none !important;
	appearance: none;
	-webkit-appearance: none;
}

.csrv-qty-controls button:hover {
	background: #e2e8f0;
}

.csrv-qty {
	min-width: 26px;
	text-align: center;
	font-weight: 700;
}

.csrv-remove-btn {
	border: none;
	background: none;
	color: #dc2626;
	font-size: 18px;
	cursor: pointer;
	line-height: 1;
}

@media (max-width: 740px) {
	.csrv-selected-row {
		grid-template-columns: auto 1fr auto;
		grid-template-areas:
			"cat name remove"
			"qty qty price";
		row-gap: 8px;
	}

	.csrv-selected-cat {
		grid-area: cat;
	}

	.csrv-selected-name {
		grid-area: name;
	}

	.csrv-remove-btn {
		grid-area: remove;
		justify-self: end;
	}

	.csrv-qty-controls {
		grid-area: qty;
		justify-self: start;
	}

	.csrv-selected-price {
		grid-area: price;
		justify-self: end;
	}
}

/* Errors */
.csrv-errors {
	margin-top: 12px;
	background: #fef2f2;
	border: 1px solid #fca5a5;
	border-radius: 6px;
	padding: 10px 14px;
	color: #991b1b;
}

.csrv-errors ul {
	margin: 6px 0 0 18px;
}

/* Total & actions */
.csrv-total-bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: 14px;
	padding: 12px 14px;
	background: #f1f5f9;
	border-radius: 6px;
	font-size: 17px;
}

.csrv-total-bar strong {
	color: var(--csrv-primary);
	font-size: 20px;
}

.csrv-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 14px;
}

.csrv-btn {
	display: inline-block;
	border-radius: 6px;
	padding: 9px 18px;
	font-size: 14px;
	cursor: pointer;
	text-decoration: none;
	border: 1px solid transparent;
}

.csrv-btn-primary {
	background: var(--csrv-primary);
	color: #fff;
}

.csrv-btn-primary:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.csrv-btn-secondary {
	background: #fff;
	border-color: #cbd5e1;
	color: #334155;
}

.csrv-btn:hover:not(:disabled) {
	filter: brightness(0.95);
}

/* Modal */
.csrv-modal {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 99999;
	padding: 16px;
}

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

.csrv-modal-box {
	position: relative;
	background: #fff;
	border-radius: 10px;
	max-width: 640px;
	width: 100%;
	max-height: 85vh;
	overflow-y: auto;
	padding: 24px;
}

.csrv-modal-close {
	position: absolute;
	top: 8px;
	right: 12px;
	border: none;
	background: none;
	font-size: 26px;
	cursor: pointer;
	color: #64748b;
}

.csrv-share-box {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 14px;
}

.csrv-share-box input {
	flex: 1 1 240px;
	padding: 8px 10px;
	border: 1px solid var(--csrv-border);
	border-radius: 6px;
	font-size: 13px;
}

/* Summary table (preview, viewer, print) */
.csrv-summary-table {
	width: 100%;
	border-collapse: collapse;
	margin-top: 10px;
}

.csrv-summary-table th,
.csrv-summary-table td {
	border: 1px solid var(--csrv-border);
	padding: 8px 10px;
	text-align: left;
}

.csrv-summary-table tfoot th {
	background: #f1f5f9;
}

.csrv-price-date {
	color: #64748b;
	font-size: 13px;
}

/* Viewer */
.csrv-viewer-card {
	border: 1px solid var(--csrv-border);
	border-radius: 8px;
	padding: 20px;
}

.csrv-recalc-result {
	margin-top: 16px;
	background: #f0fdf4;
	border: 1px solid #86efac;
	border-radius: 6px;
	padding: 12px 14px;
}

/* Print: builder menyembunyikan semuanya kecuali print area;
   viewer mencetak kartunya sendiri. */
.csrv-print-area { display: none; }

.csrv-print-doc {
	max-width: 198mm;
	margin: 0 auto;
	padding: 0;
	font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
	color: #111827;
	max-height: 277mm;
	overflow: hidden;
	break-inside: avoid;
	page-break-inside: avoid;
	background: #ffffff;
	border: 1px solid #e5e7eb;
	border-radius: 12px;
	box-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

.csrv-print-topline {
	height: 5px;
	background: linear-gradient(90deg, #0f172a 0%, #1d4ed8 45%, #0ea5e9 100%);
	border-top-left-radius: 12px;
	border-top-right-radius: 12px;
}

.csrv-print-head {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	padding: 14px 16px 10px;
	border-bottom: 1px solid #e5e7eb;
	margin-bottom: 0;
}

.csrv-print-brand {
	display: flex;
	align-items: center;
	gap: 10px;
}

.csrv-print-brand-text h2 {
	margin: 0;
	font-size: 15px;
	font-weight: 700;
	color: #0f172a;
}

.csrv-print-brand-text p {
	margin: 2px 0 0;
	font-size: 11px;
	color: #64748b;
}

.csrv-print-logo {
	max-height: 36px;
	width: auto;
	max-width: 150px;
	display: block;
}

.csrv-print-logo-text {
	font-size: 18px;
	font-weight: 700;
	letter-spacing: 0.02em;
}

.csrv-print-meta-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(86px, auto));
	gap: 6px;
}

.csrv-print-meta-card {
	border: 1px solid #dbeafe;
	background: #f8fbff;
	border-radius: 8px;
	padding: 6px 8px;
	text-align: left;
}

.csrv-print-meta-card span {
	display: block;
	font-size: 9px;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: #64748b;
	margin-bottom: 3px;
}

.csrv-print-meta-card strong {
	display: block;
	font-size: 11px;
	color: #0f172a;
	font-weight: 600;
	line-height: 1.2;
}

.csrv-print-kicker {
	padding: 10px 16px;
	background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
	border-bottom: 1px solid #e5e7eb;
}

.csrv-print-kicker h1 {
	margin: 0;
	font-size: 16px;
	font-weight: 700;
}

.csrv-print-kicker p {
	margin: 4px 0 0;
	font-size: 11px;
	color: #64748b;
}

.csrv-print-body {
	padding: 10px 16px 12px;
}

.csrv-print-section-title {
	margin: 0 0 6px;
	font-size: 12px;
	font-weight: 700;
	color: #0f172a;
}

.csrv-print-table-wrap {
	border: 1px solid #dbe2ea;
	border-radius: 8px;
	overflow: hidden;
}

.csrv-print-body .csrv-summary-table {
	margin-top: 0;
	border-collapse: separate;
	border-spacing: 0;
	width: 100%;
	break-inside: avoid;
	page-break-inside: avoid;
}

.csrv-print-body .csrv-summary-table th {
	background: #f8fafc;
	border: none;
	border-bottom: 1px solid #dbe2ea;
	font-size: 9.5px;
	font-weight: 700;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	color: #475569;
	padding: 6px;
}

.csrv-print-body .csrv-summary-table th,
.csrv-print-body .csrv-summary-table td {
	font-size: 10px;
	padding: 5px 6px;
	line-height: 1.2;
}

.csrv-print-body .csrv-summary-table td {
	border: none;
	border-bottom: 1px solid #edf2f7;
}

.csrv-print-body .csrv-summary-table tbody tr:last-child td {
	border-bottom: none;
}

.csrv-print-total {
	display: flex;
	justify-content: flex-end;
	gap: 14px;
	margin-top: 8px;
	font-size: 12px;
	font-weight: 700;
	background: #f8fafc;
	border: 1px solid #dbe2ea;
	border-radius: 8px;
	padding: 7px 10px;
}

.csrv-print-note {
	margin-top: 8px;
	font-size: 10px;
	color: #374151;
}

.csrv-print-footer {
	margin-top: 6px;
	padding-top: 6px;
	border-top: 1px dashed #cbd5e1;
	font-size: 9px;
	color: #64748b;
	text-align: right;
}

.csrv-print-doc a,
.csrv-print-doc a:visited {
	color: inherit !important;
	text-decoration: none !important;
}

@media print {
	@page {
		size: A4 portrait;
		margin: 10mm 6mm;
	}

	body.csrv-printing > * {
		display: none !important;
	}

	body.csrv-printing #csrv-global-print-area {
		display: block;
		position: static;
		width: 198mm;
		max-width: 198mm;
		margin: 0 auto;
		padding: 0;
		background: transparent;
	}

	body.csrv-printing #csrv-global-print-area a[href]:after {
		content: '' !important;
	}

	.csrv-viewer .csrv-no-print { display: none !important; }
}
