/* Invoice Builder — 3-panel: Palette | Canvas | Settings */
/* Mirrors email-builder.css architecture and design tokens */

/* ─── Layout ──────────────────────────────────────────────────────────── */

.kramar-ib-builder {
	display: grid;
	grid-template-columns: 240px 1fr 320px;
	min-height: calc(100vh - 92px);
}

/* ─── Palette (Left Panel) ────────────────────────────────────────────── */

.kramar-ib-palette {
	background: var(--kramar-eb-surface, #fff);
	border-right: 1px solid var(--kramar-eb-border, #e4e4e7);
	position: sticky;
	top: 92px;
	max-height: calc(100vh - 92px);
	overflow-y: auto;
}

.kramar-ib-palette__header {
	padding: 16px;
	border-bottom: 1px solid var(--kramar-eb-border-light, #f0f0f1);
}

.kramar-ib-palette__header h3 {
	margin: 0;
	font-size: 13px;
	font-weight: 600;
	color: var(--kramar-eb-text, #1e1e1e);
}

.kramar-ib-palette__body {
	padding: 8px 12px 16px;
}

/* Palette groups */
.kramar-ib-palette-group {
	margin-bottom: 4px;
}

.kramar-ib-palette-group__label {
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--kramar-eb-text-light, #a7aaad);
	padding: 10px 4px 4px;
	margin: 0;
}

/* Palette items */
.kramar-ib-palette-item {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 7px 8px;
	font-size: 13px;
	color: var(--kramar-eb-text, #1e1e1e);
	border-radius: var(--kramar-eb-radius-sm, 3px);
	cursor: pointer;
	transition: background var(--kramar-eb-transition, 150ms ease);
	user-select: none;
}

.kramar-ib-palette-item:hover {
	background: var(--kramar-eb-surface-alt, #f6f7f7);
}

.kramar-ib-palette-icon {
	font-size: 16px;
	width: 16px;
	height: 16px;
	color: var(--kramar-eb-text-muted, #787c82);
	flex-shrink: 0;
}

.kramar-ib-palette-label {
	flex: 1;
}

/* ─── Canvas (Center Panel) ───────────────────────────────────────────── */

.kramar-ib-canvas {
	background: #c8cacf;
	padding: 24px;
	display: flex;
	justify-content: center;
	align-items: flex-start;
	overflow: auto;
}

/* True A4 page (210mm × 297mm @ 96dpi ≈ 794 × 1123px) so the canvas is a
   faithful WYSIWYG of the final PDF — content that overflows one page is
   visible immediately. Margins match Block_Renderer's preview/PDF margins. */
.kramar-ib-canvas__document {
	width: 794px;
	min-height: 1123px;
	box-sizing: border-box;
	background: #fff;
	box-shadow: 0 1px 12px rgba(0, 0, 0, 0.18);
	padding: 57px 68px 76px;
	font-family: 'Helvetica', 'Arial', sans-serif;
	font-size: 12px;
	color: #333;
	line-height: 1.4;
	flex-shrink: 0;
}

.kramar-ib-canvas-banner {
	margin: 0 0 16px;
	padding: 8px 12px;
	background: #fef3c7;
	border: 1px solid #fde68a;
	border-radius: 4px;
	font-size: 12px;
	color: #92400e;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.kramar-ib-block__placeholder {
	padding: 10px 12px;
	border: 1px dashed #d1d5db;
	border-radius: 4px;
	background: #fafbfc;
	color: #9ca3af;
	font-size: 12px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.kramar-ib-canvas__empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: 300px;
	color: #a7aaad;
	text-align: center;
	gap: 8px;
}

.kramar-ib-canvas__empty .dashicons {
	font-size: 40px;
	width: 40px;
	height: 40px;
	color: #d1d5db;
}

/* ─── Block Cards on Canvas ───────────────────────────────────────────── */

/* Zero padding/margin/border: blocks carry their own spacing via inline
   styles (matching the PDF). Selection uses an overlay outline so it never
   shifts the layout. */
.kramar-ib-block {
	position: relative;
	padding: 0;
	margin: 0;
	border: 0;
	cursor: pointer;
}

.kramar-ib-block::after {
	content: "";
	position: absolute;
	inset: -4px;
	border-radius: 4px;
	pointer-events: none;
	transition: box-shadow 120ms ease, background 120ms ease;
}

.kramar-ib-block:hover::after {
	box-shadow: 0 0 0 1.5px #c7d2fe;
	background: rgba(37, 99, 235, 0.03);
}

.kramar-ib-block--selected::after {
	box-shadow: 0 0 0 2px #2563eb;
	background: rgba(37, 99, 235, 0.05);
}

/* Block actions bar */
.kramar-ib-block__actions {
	position: absolute;
	top: -1px;
	right: -1px;
	display: none;
	align-items: center;
	gap: 2px;
	padding: 2px 4px;
	background: #fff;
	border: 1px solid #d1d5db;
	border-radius: 0 6px 0 6px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
	z-index: 2;
}

.kramar-ib-block:hover .kramar-ib-block__actions,
.kramar-ib-block--selected .kramar-ib-block__actions {
	display: flex;
}

.kramar-ib-block__handle {
	cursor: grab;
	color: #9ca3af;
	font-size: 16px !important;
	width: 20px !important;
	height: 20px !important;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 3px;
	transition: color 150ms, background 150ms;
}

.kramar-ib-block__handle:hover {
	color: #374151;
	background: #f3f4f6;
}

.kramar-ib-block__handle:active {
	cursor: grabbing;
}

.kramar-ib-block__delete {
	cursor: pointer;
	color: #9ca3af;
	font-size: 16px !important;
	width: 20px !important;
	height: 20px !important;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 3px;
	transition: color 150ms, background 150ms;
}

.kramar-ib-block__delete:hover {
	color: #dc2626;
	background: #fef2f2;
}

.kramar-ib-block__required {
	font-size: 10px;
	font-weight: 600;
	display: inline-flex;
	align-items: center;
	padding: 2px 7px;
	border-radius: 999px;
	background: #fef3c7;
	color: #92400e;
	white-space: nowrap;
	text-transform: uppercase;
	letter-spacing: 0.02em;
}

/* Block content */
.kramar-ib-block__content {
	pointer-events: none;
}

/* Block hint — hidden on the A4 canvas to keep WYSIWYG spacing exact. */
.kramar-ib-block__hint {
	display: none !important;
}

/* Drop placeholder */
.kramar-ib-drop-placeholder {
	height: 3px;
	background: #2563eb;
	border-radius: 2px;
	margin: 4px 0;
	animation: kramarIbFadeIn 0.15s ease;
}

/* Canvas footer — mirrors the PDF/preview footer (server-rendered HTML). */
.kramar-ib-canvas-footer {
	margin-top: 36px;
	padding-top: 6px;
	border-top: 1px solid #ddd;
	text-align: center;
	font-size: 8.5px;
	color: #999;
	line-height: 1.6;
	pointer-events: none;
}

/* ─── Settings (Right Panel) ──────────────────────────────────────────── */

.kramar-ib-settings {
	background: var(--kramar-eb-surface, #fff);
	border-left: 1px solid var(--kramar-eb-border, #e4e4e7);
	position: sticky;
	top: 92px;
	max-height: calc(100vh - 92px);
	overflow-y: auto;
}

.kramar-ib-settings__header {
	padding: 16px;
	border-bottom: 1px solid var(--kramar-eb-border-light, #f0f0f1);
}

.kramar-ib-settings__header h3 {
	margin: 0;
	font-size: 13px;
	font-weight: 600;
	color: var(--kramar-eb-text, #1e1e1e);
}

.kramar-ib-settings__body {
	padding: 16px;
}

.kramar-ib-settings__empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: 200px;
	text-align: center;
}

/* Settings form fields */
.kramar-ib-settings-form {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.kramar-ib-field {
	margin-bottom: 10px;
}

.kramar-ib-field__label {
	display: block;
	font-size: 12px;
	font-weight: 500;
	color: #374151;
	margin-bottom: 4px;
}

.kramar-ib-field__input,
.kramar-ib-field__textarea,
.kramar-ib-field__select {
	width: 100%;
	padding: 7px 10px;
	border: 1px solid #d1d5db;
	border-radius: 4px;
	font-size: 13px;
	box-sizing: border-box;
	transition: border-color 150ms;
	font-family: inherit;
}

.kramar-ib-field__input:focus,
.kramar-ib-field__textarea:focus,
.kramar-ib-field__select:focus {
	outline: none;
	border-color: #2563eb;
	box-shadow: 0 0 0 1px #2563eb;
}

.kramar-ib-field__textarea {
	resize: vertical;
	min-height: 60px;
}

.kramar-ib-field--toggle {
	padding: 4px 0;
}

.kramar-ib-field__toggle-label {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	cursor: pointer;
	color: #374151;
}

.kramar-ib-field__hint {
	font-size: 11px;
	color: #9ca3af;
	margin: 0 0 10px;
	line-height: 1.4;
}

.kramar-ib-required-notice {
	margin-top: 16px;
	padding: 10px 12px;
	background: #fef3c7;
	border-radius: 4px;
	font-size: 11px;
	color: #92400e;
	line-height: 1.4;
}

/* ─── Toolbar tweaks ──────────────────────────────────────────────────── */

.kramar-ib-toolbar__preview {
	margin-right: 4px;
}

/* ─── Toast Notices ───────────────────────────────────────────────────── */

.kramar-ib-toast {
	position: fixed;
	top: 46px;
	right: 20px;
	padding: 10px 18px;
	border-radius: 4px;
	font-size: 13px;
	font-weight: 500;
	z-index: 100001;
	animation: kramarIbFadeIn 0.2s ease;
}

.kramar-ib-toast--success {
	background: #dcfce7;
	color: #166534;
	border: 1px solid #bbf7d0;
}

.kramar-ib-toast--error {
	background: #fef2f2;
	color: #991b1b;
	border: 1px solid #fecaca;
}

/* ─── Animations ──────────────────────────────────────────────────────── */

@keyframes kramarIbFadeIn {
	from { opacity: 0; transform: translateY(-8px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive: A4 preview fit-to-width ────────────────────────────── */

/* The A4 document is 794px + 48px canvas padding = needs ~842px of canvas
   width. When the grid's center column is narrower the doc overflows and
   justify-content:center clips BOTH sides. Container-query scaling fits
   the doc to whatever width the canvas actually gets, regardless of WP
   sidebar state or viewport. */
.kramar-ib-canvas {
	container-type: inline-size;
	container-name: ib-canvas;
}

/* Canvas narrower than 842px (doc 794 + 48px padding): scale the A4
   page to fit. Measured canvas widths with current grids:
     1440→678  1280→518  1024→622 (2-col grid)
   Scale = (canvasWidth - 48px padding) / 794. */
/* zoom (unlike transform: scale) affects layout size, so the flex
   container centers the visually-smaller element correctly and the
   canvas scrollbar disappears. Supported in all major browsers. */
@container ib-canvas (max-width: 660px) and (min-width: 501px) {
	.kramar-ib-canvas__document {
		/* Canvas 501-660 → avail 453-612 → factor 0.57-0.77. Use 0.70. */
		zoom: 0.70;
	}
}

@container ib-canvas (max-width: 500px) and (min-width: 401px) {
	.kramar-ib-canvas__document {
		/* Canvas 401-500 → avail 353-452 → factor 0.44-0.57. Use 0.50. */
		zoom: 0.50;
	}
}

@container ib-canvas (max-width: 400px) {
	.kramar-ib-canvas__document {
		/* Canvas ≤400 → avail ≤352 → factor ≤0.44. Use 0.38. */
		zoom: 0.38;
	}
}

/* ─── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
	.kramar-ib-builder {
		grid-template-columns: 200px 1fr 280px;
	}
}

/* At ≤1024px the 3-column grid leaves only ~342px for the canvas.
   Switch to 2 columns: palette + canvas side-by-side, settings below. */
@media (max-width: 1024px) {
	.kramar-ib-builder {
		grid-template-columns: 200px 1fr;
	}

	.kramar-ib-settings {
		position: static;
		max-height: none;
	}
}

@media (max-width: 900px) {
	.kramar-ib-builder {
		grid-template-columns: 1fr;
	}

	.kramar-ib-palette,
	.kramar-ib-settings {
		position: static;
		max-height: none;
	}
}

/* =========================================================================
   Dark Mode (.dark-mode on <body>)
   ========================================================================= */

/* Builder panels */
.dark-mode .kramar-ib-palette,
.dark-mode .kramar-ib-settings {
	background: #1d2327;
	border-color: #3c434a;
}
.dark-mode .kramar-ib-palette__header,
.dark-mode .kramar-ib-settings__header {
	border-bottom-color: #3c434a;
}
.dark-mode .kramar-ib-palette__header h3,
.dark-mode .kramar-ib-settings__header h3 {
	color: #f0f0f1;
}
.dark-mode .kramar-ib-palette-group__label {
	color: #a7aaad;
}
.dark-mode .kramar-ib-palette-item {
	color: #f0f0f1;
}
.dark-mode .kramar-ib-palette-item:hover {
	background: #2c3338;
}
.dark-mode .kramar-ib-canvas {
	background: #23282d;
}
/* A4 document paper stays white intentionally — it's a PDF preview */
.dark-mode .kramar-ib-canvas__empty {
	color: #a7aaad;
}
.dark-mode .kramar-ib-field__label {
	color: #a7aaad;
}
.dark-mode .kramar-ib-field__input,
.dark-mode .kramar-ib-field__textarea,
.dark-mode .kramar-ib-field__select {
	background: #2c3338;
	border-color: #3c434a;
	color: #f0f0f1;
}
.dark-mode .kramar-ib-field__toggle-label {
	color: #f0f0f1;
}
.dark-mode .kramar-ib-field__hint {
	color: #787c82;
}
.dark-mode .kramar-ib-block__actions {
	background: #2c3338;
	border-color: #3c434a;
}
.dark-mode .kramar-ib-toast--success {
	background: #0d2818;
	color: #6ee7b7;
	border-color: #065f46;
}
.dark-mode .kramar-ib-toast--error {
	background: #2c1b1b;
	color: #fca5a5;
	border-color: #991b1b;
}
