/**
 * Quill editor restyled to the directory's form tokens.
 *
 * Loaded after `quill.snow.css` on the dashboard and listing-flow screens
 * only. Without JavaScript (or with the CDN blocked) the plain textarea is
 * shown and none of this applies — hence everything is scoped to
 * `[data-wd-richtext-ready="1"]`.
 */

.wd-richtext__source--enhanced {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.wd-richtext[data-wd-richtext-ready="1"] .wd-richtext__editor {
	background: var(--wd-paper);
	color: var(--wd-text);
	font-size: 0.95rem;
	line-height: 1.6;
}

/* Toolbar container */
.wd-richtext .ql-toolbar.ql-snow {
	display: flex !important;
	flex-wrap: wrap !important;
	align-items: center !important;
	justify-content: flex-start !important;
	border: 1px solid var(--wd-border) !important;
	border-bottom: 0 !important;
	border-radius: var(--wd-radius-sm, 6px) var(--wd-radius-sm, 6px) 0 0 !important;
	background: var(--wd-paper, #f6f9fd) !important;
	padding: 6px 12px !important;
	gap: 4px 6px !important;
	min-height: 42px;
	box-sizing: border-box !important;
	position: relative !important;
}

/* Standard format groups */
.wd-richtext .ql-toolbar.ql-snow .ql-formats {
	display: inline-flex !important;
	align-items: center !important;
	margin-right: 8px !important;
	margin-bottom: 0 !important;
	vertical-align: middle !important;
}

/* Container & Editor content */
.wd-richtext .ql-container.ql-snow {
	border: 1px solid var(--wd-border) !important;
	border-radius: 0 0 var(--wd-radius-sm, 6px) var(--wd-radius-sm, 6px) !important;
	background: var(--wd-paper);
}

.wd-richtext .ql-container.ql-snow .ql-editor {
	min-height: 8.5rem;
	padding: 0.85rem 1rem;
	color: var(--wd-text);
	font-size: 0.95rem;
	line-height: 1.6;
}

.wd-richtext .ql-container.ql-snow .ql-editor.ql-blank::before {
	color: var(--wd-text-muted);
	font-style: normal;
}

/* Focus states */
.wd-richtext:focus-within .ql-toolbar.ql-snow,
.wd-richtext:focus-within .ql-container.ql-snow,
.wd-richtext--html-mode:focus-within .wd-richtext__html-editor {
	border-color: var(--wd-primary) !important;
}

.wd-richtext:focus-within .ql-container.ql-snow {
	background: var(--wd-cream);
	box-shadow: var(--wd-focus);
}

/* Standard toolbar stroke & fills */
.wd-richtext .ql-snow .ql-stroke {
	stroke: var(--wd-text-muted);
}

.wd-richtext .ql-snow .ql-fill {
	fill: var(--wd-text-muted);
}

.wd-richtext .ql-snow .ql-picker {
	color: var(--wd-text-muted);
}

.wd-richtext .ql-snow button:hover .ql-stroke,
.wd-richtext .ql-snow button:focus-visible .ql-stroke,
.wd-richtext .ql-snow .ql-picker-label:hover .ql-stroke,
.wd-richtext .ql-snow .ql-picker-item:hover .ql-stroke {
	stroke: var(--wd-primary);
}

.wd-richtext .ql-snow button:focus-visible,
.wd-richtext .ql-snow .ql-picker-label:focus-visible {
	outline: 2px solid var(--wd-primary);
	outline-offset: 1px;
}

/* HTML Source Toggle Group: Pinned smoothly to the right with breathing room */
.wd-richtext .ql-toolbar.ql-snow .wd-richtext__formats-toggle {
	margin-left: auto !important;
	margin-right: 0 !important;
	padding: 0 !important;
	display: inline-flex !important;
	align-items: center !important;
	align-self: center !important;
}

/* HTML Toggle Button: Overrides Quill's default 28px width & float left */
.wd-richtext .ql-toolbar.ql-snow button.wd-richtext__toggle-html,
.ql-snow .ql-toolbar button.wd-richtext__toggle-html {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	float: none !important;
	width: auto !important;
	height: auto !important;
	min-height: 28px !important;
	max-height: 28px !important;
	padding: 0 10px !important;
	margin: 0 !important;
	gap: 6px !important;
	font-family: var(--wd-font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif) !important;
	font-size: 0.75rem !important;
	font-weight: 600 !important;
	letter-spacing: 0.03em !important;
	line-height: 1 !important;
	color: var(--wd-text, #2b3a4d) !important;
	background: var(--wd-cream, #ffffff) !important;
	border: 1px solid var(--wd-border, #dce6f2) !important;
	border-radius: var(--wd-radius-sm, 6px) !important;
	box-shadow: 0 1px 2px rgba(10, 17, 32, 0.04) !important;
	cursor: pointer !important;
	transition: all 0.15s ease !important;
	box-sizing: border-box !important;
	vertical-align: middle !important;
	white-space: nowrap !important;
}

.wd-richtext .ql-toolbar.ql-snow button.wd-richtext__toggle-html:hover,
.ql-snow .ql-toolbar button.wd-richtext__toggle-html:hover {
	color: var(--wd-primary, #0066ff) !important;
	border-color: var(--wd-primary, #0066ff) !important;
	background: var(--wd-surface, #e8f0fb) !important;
	box-shadow: 0 2px 4px rgba(0, 102, 255, 0.08) !important;
}

.wd-richtext .ql-toolbar.ql-snow button.wd-richtext__toggle-html:focus-visible,
.ql-snow .ql-toolbar button.wd-richtext__toggle-html:focus-visible {
	outline: 2px solid var(--wd-primary, #0066ff) !important;
	outline-offset: 2px !important;
}

.wd-richtext .ql-toolbar.ql-snow button.wd-richtext__toggle-html.is-active,
.ql-snow .ql-toolbar button.wd-richtext__toggle-html.is-active {
	color: #ffffff !important;
	background: var(--wd-primary, #0066ff) !important;
	border-color: var(--wd-primary, #0066ff) !important;
	box-shadow: 0 2px 4px rgba(0, 102, 255, 0.22) !important;
}

.wd-richtext .ql-toolbar.ql-snow button.wd-richtext__toggle-html .wd-richtext__toggle-icon {
	display: inline-block !important;
	flex-shrink: 0 !important;
	stroke: currentColor !important;
	vertical-align: middle !important;
	margin: 0 !important;
	padding: 0 !important;
	width: 13px !important;
	height: 13px !important;
}

.wd-richtext .ql-toolbar.ql-snow button.wd-richtext__toggle-html .wd-richtext__toggle-label {
	display: inline-block !important;
	line-height: 1 !important;
	font-weight: 600 !important;
}

/* Dedicated Raw HTML Editor */
.wd-richtext__html-editor {
	width: 100%;
	min-height: 8.5rem;
	padding: 0.85rem 1rem;
	font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
	font-size: 0.875rem;
	line-height: 1.6;
	color: var(--wd-text);
	background: var(--wd-paper);
	border: 1px solid var(--wd-border);
	border-radius: 0 0 var(--wd-radius-sm, 6px) var(--wd-radius-sm, 6px);
	resize: vertical;
	box-sizing: border-box;
}

.wd-richtext--html-mode:focus-within .wd-richtext__html-editor {
	background: var(--wd-cream);
	box-shadow: var(--wd-focus);
	outline: none;
}

.wd-richtext--html-mode .ql-toolbar button:not(.wd-richtext__toggle-html),
.wd-richtext--html-mode .ql-toolbar .ql-picker {
	opacity: 0.35;
	pointer-events: none;
}
