* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	font-size: 13px;
	height: 100vh;
	overflow: hidden;
	background: #f8f9fa;
}

.header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	height: 50px;
	background: #fff;
	border-bottom: 1px solid #e1e5e9;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 16px;
	z-index: 1000;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.controls {
	display: flex;
	align-items: center;
	gap: 12px;
}

.file-input {
	display: none;
}

.upload-btn,
.paste-btn,
.save-btn,
.reset-btn {
	padding: 6px 12px;
	border: 1px solid #d1d5db;
	border-radius: 4px;
	background: #fff;
	cursor: pointer;
	font-size: 13px;
	transition: all 0.2s;
}

.upload-btn:hover,
.paste-btn:hover,
.save-btn:hover:not(:disabled),
.reset-btn:hover:not(:disabled) {
	background: #f3f4f6;
	border-color: #9ca3af;
}

.save-btn {
	background: #2563eb;
	color: white;
	border-color: #2563eb;
}

.save-btn:hover:not(:disabled) {
	background: #1d4ed8;
}

.save-btn:disabled,
.reset-btn:disabled {
	background: #e5e7eb;
	color: #9ca3af;
	cursor: not-allowed;
	border-color: #e5e7eb;
}

.reset-btn {
	background: #dc2626;
	color: white;
	border-color: #dc2626;
}

.reset-btn:hover:not(:disabled) {
	background: #b91c1c;
	border-color: #b91c1c;
}

.info {
	display: flex;
	gap: 16px;
	font-size: 12px;
	color: #6b7280;
}

.main-content {
	position: fixed;
	top: 50px;
	left: 0;
	right: 0;
	bottom: 0;
	overflow: auto;
}

.table-container {
	height: 100%;
	overflow: auto;
	position: relative;
}

.placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	color: #9ca3af;
	font-size: 16px;
}

.placeholder-link {
	display: inline;
	padding: 0;
	border: none;
	background: none;
	color: #2563eb;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.placeholder-link:hover {
	color: #1d4ed8;
}

.csv-table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	font-size: 13px;
	background: white;
}

.csv-table thead {
	position: sticky;
	top: 0;
	z-index: 100;
}

.csv-table th {
	background: #e5e7eb;
	border: 1px solid #d1d5db;
	border-top: none;
	padding: 6px 8px;
	text-align: left;
	font-weight: 600;
	color: #374151;
	white-space: nowrap;
	min-width: 80px;
	position: relative;
}

.csv-table th:first-child {
	border-left: 1px solid #d1d5db;
}

.csv-table th:last-child {
	border-right: 1px solid #d1d5db;
}

.csv-table td {
	border: 0.25px solid #e5e7eb;
	border-top: none;
	padding: 5px 8px;
	cursor: text;
	position: relative;
	min-width: 80px;
	white-space: nowrap;
	/* Fixed height keeps virtual-scroll row measurements accurate */
	height: 28px;
	max-height: 28px;
	overflow: hidden;
}

.csv-table td:first-child {
	border-left: 1px solid #d1d5db;
}

.csv-table td:last-child {
	border-right: 1px solid #d1d5db;
}

/* Header-to-body separator line */
.csv-table tbody tr:first-child td {
	border-top: 1px solid #d1d5db;
}

/* Stable alternating row colors driven by data-index class (works with virtual scroll) */
.csv-table tbody tr.row-even {
	background: #f9fafb;
}

.csv-table tbody tr.row-odd {
	background: #ffffff;
}

.csv-table tbody tr:hover {
	background: #e3f2fd !important;
}

.csv-table td:hover {
	background: #e3f2fd !important;
}

.csv-table td.editing {
	background: #fff3cd !important;
	padding: 0;
}

.csv-table td.editing input {
	width: 100%;
	height: 100%;
	border: none;
	padding: 5px 8px;
	font-size: 13px;
	font-family: inherit;
	background: transparent;
	outline: 2px solid #2563eb;
	outline-offset: -2px;
}

.csv-table td.edited {
	background: #fef3c7 !important;
	border-left: 2px solid #f59e0b !important;
	position: relative;
}

.csv-table td.edited::after {
	content: '●';
	position: absolute;
	top: 2px;
	right: 4px;
	color: #f59e0b;
	font-size: 8px;
	line-height: 1;
}

.row-number {
	color: #6b7280;
	font-weight: 500;
	text-align: center;
	min-width: 64px !important;
	max-width: 64px !important;
	cursor: default !important;
	user-select: none;
	border: 1px solid #d1d5db !important;
	border-right: 2px solid #d1d5db !important;
}

/* Row number header styling */
.csv-table th.row-number {
	background: #d1d5db !important;
}

/* Row number alternating colors (tied to stable data-index class) */
.csv-table tbody tr.row-even .row-number {
	background: #f3f4f6 !important;
}

.csv-table tbody tr.row-odd .row-number {
	background: #e5e7eb !important;
}

/* Virtual-scroll spacer rows — zero visual footprint.
   max-height: none overrides the base td rule so the inline height style wins.
   Do NOT set height here — the inline style on each spacer td controls it. */
.csv-table tbody tr.vs-spacer td {
	border: none !important;
	padding: 0 !important;
	max-height: none !important;
	overflow: visible;
	background: none !important;
}

/* Progress overlay */
.progress-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.7);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 2000;
	backdrop-filter: blur(2px);
}

.progress-overlay.hidden {
	display: none;
}

.progress-container {
	background: white;
	padding: 24px;
	border-radius: 8px;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
	min-width: 320px;
	max-width: 400px;
}

.progress-info {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 12px;
}

.progress-info span:first-child {
	font-weight: 500;
	color: #374151;
}

.progress-info span:last-child {
	font-weight: 600;
	color: #2563eb;
	font-size: 14px;
}

.progress-bar {
	width: 100%;
	height: 8px;
	background: #e5e7eb;
	border-radius: 4px;
	overflow: hidden;
	margin-bottom: 8px;
}

.progress-fill {
	height: 100%;
	background: linear-gradient(90deg, #2563eb, #3b82f6);
	border-radius: 4px;
	width: 0%;
	transition: width 0.3s ease;
	position: relative;
}

.progress-fill::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: linear-gradient(
		90deg,
		transparent,
		rgba(255, 255, 255, 0.3),
		transparent
	);
	animation: shimmer 2s infinite;
}

@keyframes shimmer {
	0% {
		transform: translateX(-100%);
	}
	100% {
		transform: translateX(100%);
	}
}

.progress-details {
	font-size: 12px;
	color: #6b7280;
	text-align: center;
	min-height: 16px;
}

/* Loading states for buttons */
.upload-btn.loading,
.save-btn.loading {
	position: relative;
	color: transparent;
	pointer-events: none;
}

.upload-btn.loading::after,
.save-btn.loading::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 16px;
	height: 16px;
	border: 2px solid #e5e7eb;
	border-top: 2px solid currentColor;
	border-radius: 50%;
	animation: spin 1s linear infinite;
}

.save-btn.loading::after {
	border-color: rgba(255, 255, 255, 0.3);
	border-top-color: white;
}

@keyframes spin {
	to {
		transform: translate(-50%, -50%) rotate(360deg);
	}
}

/* Scrollbar styling */
.table-container::-webkit-scrollbar {
	width: 8px;
	height: 8px;
}

.table-container::-webkit-scrollbar-track {
	background: #f1f1f1;
}

.table-container::-webkit-scrollbar-thumb {
	background: #c1c1c1;
	border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
	background: #a1a1a1;
}

/* Drag-and-drop overlay */
body.drag-over::after {
	content: 'Drop CSV file to open';
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 22px;
	font-weight: 600;
	color: #2563eb;
	background: rgba(37, 99, 235, 0.08);
	border: 3px dashed #2563eb;
	z-index: 4000;
	pointer-events: none;
}

/* Paste CSV modal */
.paste-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 2000;
	backdrop-filter: blur(2px);
	padding: 16px;
}

.paste-overlay.hidden {
	display: none;
}

.paste-container {
	background: white;
	padding: 20px 24px;
	border-radius: 8px;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
	width: 100%;
	max-width: 640px;
	max-height: calc(100vh - 32px);
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.paste-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.paste-header h2 {
	font-size: 16px;
	font-weight: 600;
	color: #374151;
}

.paste-close-btn {
	border: none;
	background: transparent;
	font-size: 22px;
	line-height: 1;
	color: #6b7280;
	cursor: pointer;
	padding: 0 4px;
}

.paste-close-btn:hover {
	color: #111827;
}

.paste-hint {
	font-size: 13px;
	color: #6b7280;
}

.paste-textarea {
	width: 100%;
	min-height: 220px;
	max-height: 50vh;
	resize: vertical;
	padding: 10px 12px;
	border: 1px solid #d1d5db;
	border-radius: 4px;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 13px;
	line-height: 1.4;
	color: #111827;
	outline: none;
}

.paste-textarea:focus {
	border-color: #2563eb;
	box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.paste-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.paste-cancel-btn,
.paste-load-btn {
	padding: 6px 12px;
	border: 1px solid #d1d5db;
	border-radius: 4px;
	background: #fff;
	cursor: pointer;
	font-size: 13px;
}

.paste-cancel-btn:hover {
	background: #f3f4f6;
	border-color: #9ca3af;
}

.paste-load-btn {
	background: #2563eb;
	color: white;
	border-color: #2563eb;
}

.paste-load-btn:hover {
	background: #1d4ed8;
}