/*
    nb-markdown-editor.

    The editor deliberately renders into the light DOM rather than a shadow root, for two reasons:
    contenteditable and the Selection API have long-standing rough edges across shadow boundaries,
    and — more importantly — rendering here means the prose is styled by the same global stylesheet
    and the same data-theme that will style it once published. What the author sees while typing is
    what the reader gets, without a second set of styles kept in sync by hand.

    Because there is no shadow root, every rule below must stay scoped under nb-markdown-editor.
*/

nb-markdown-editor {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
	width: 100%;
	border-radius: 0.75rem;
	background: var(--background-white);
	box-shadow: var(--input-glass-shadow);
	color: var(--global-font-color);
	font-family: var(--global-font-family);
}

nb-markdown-editor[disabled] {
	opacity: 0.5;
	pointer-events: none;
}

/*
    The form value carrier. It cannot be display:none or hidden: jQuery Validate ignores :hidden
    controls (so asp-validation-for would never fire), and native constraint validation cannot focus
    an unfocusable control, which makes a required field fail to submit with only a console warning.
    A 1px, transparent, still-focusable control satisfies both without ever being seen.
*/
nb-markdown-editor > textarea {
	position: absolute;
	bottom: 0;
	left: 0;
	width: 1px;
	height: 1px;
	padding: 0;
	border: 0;
	opacity: 0;
	resize: none;
	pointer-events: none;
}

/*#region Toolbar */

nb-md-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	padding: 0.4rem 0.5rem;
	border-bottom: 1px solid var(--soft-border-color);
}

nb-md-toolbar nb-md-separator {
	width: 1px;
	height: 1.25rem;
	margin: 0 0.35rem;
	background: var(--soft-border-color);
}

nb-md-toolbar button {
	display: grid;
	place-items: center;
	min-width: 2rem;
	height: 2rem;
	padding: 0.25rem 0.5rem;
    color: var(--light-global-font-color);
	border: none;
	border-radius: 0.4rem;
    background: var(--blue-gray);
    box-shadow: var(--outline-button-shadow);
	font-family: inherit;
	font-size: var(--font-size-small);
	font-weight: 600;
	cursor: pointer;
	transition: background 0.12s ease-out, color 0.12s ease-out;
}

nb-md-toolbar button:hover:not(:disabled) {
	background: var(--hover-gray);
	color: var(--global-font-color);
}

/* Reflects the mark or block under the cursor, so the toolbar reads as state rather than as a
   set of one-shot actions. */
nb-md-toolbar button[data-active="true"] {
	background: var(--primary-green);
	color: var(--colored-button-font-color);
}

nb-md-toolbar button:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

nb-md-toolbar button svg {
	width: 1rem;
	height: 1rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	pointer-events: none;
}

/*#endregion*/

/*#region Editing surface */

nb-md-surface {
	display: block;
	min-height: var(--nb-md-min-height, 10rem);
	max-height: var(--nb-md-max-height, 30rem);
	overflow-y: auto;
	padding: 0.9rem 1rem;
    background: var(--blue-gray);
    box-shadow: var(--outline-button-shadow);
    border-radius: 1.5rem;
}

nb-md-surface .ProseMirror {
	outline: none;
	min-height: inherit;
	font-size: var(--font-size-normal);
	line-height: 1.6;
}

/* Tiptap's placeholder decoration. Rendered on the first empty block only. */
nb-md-surface .ProseMirror p.is-editor-empty:first-child::before {
	content: attr(data-placeholder);
	float: left;
	height: 0;
	color: var(--light-text);
	pointer-events: none;
}

nb-md-surface .ProseMirror > *:first-child {
	margin-top: 0;
}

nb-md-surface .ProseMirror > *:last-child {
	margin-bottom: 0;
}

nb-md-surface .ProseMirror p {
	margin: 0 0 0.75rem;
}

nb-md-surface .ProseMirror h1,
nb-md-surface .ProseMirror h2,
nb-md-surface .ProseMirror h3 {
	margin: 1.25rem 0 0.6rem;
	font-weight: 650;
	line-height: 1.3;
}

nb-md-surface .ProseMirror h1 { font-size: var(--font-size-xlarge); }
nb-md-surface .ProseMirror h2 { font-size: var(--font-size-large); }
nb-md-surface .ProseMirror h3 { font-size: var(--font-size-medium); }

nb-md-surface .ProseMirror ul,
nb-md-surface .ProseMirror ol {
	margin: 0 0 0.75rem;
	padding-left: 1.4rem;
}

nb-md-surface .ProseMirror li {
	margin-bottom: 0.2rem;
}

nb-md-surface .ProseMirror li > p {
	margin: 0;
}

nb-md-surface .ProseMirror blockquote {
	margin: 0 0 0.75rem;
	padding-left: 0.9rem;
	border-left: 3px solid var(--primary-green);
	color: var(--light-global-font-color);
}

nb-md-surface .ProseMirror a {
	color: var(--link-blue);
	text-decoration: underline;
	cursor: pointer;
}

/*#endregion*/

/*#region Selection bubble

    Hand-positioned rather than pulled from a positioning library: the only case it has to handle is
    a small bar above the selection, clamped to the viewport, which is far less code than the
    dependency would have added to the bundle.
*/

nb-md-bubble {
	position: absolute;
	z-index: 20;
	display: none;
	align-items: center;
	gap: 0.15rem;
	padding: 0.25rem;
	border-radius: 0.5rem;
	background: var(--background-white);
	box-shadow: var(--continer-outer-shadow);
    border: 1px solid var(--border-color);
	/* Positioned from JS; the transform centres it on the selection. */
	transform: translate(-50%, -100%);
}

nb-md-bubble[data-visible="true"] {
	display: flex;
}

nb-md-bubble button {
	display: grid;
	place-items: center;
	min-width: 1.75rem;
	height: 1.75rem;
	padding: 0 0.35rem;
	border: none;
	border-radius: 0.35rem;
	background: transparent;
	color: var(--global-font-color);
	font-family: inherit;
	font-size: var(--font-size-small);
	font-weight: 600;
	cursor: pointer;
}

nb-md-bubble button:hover {
	background: var(--hover-gray);
}

nb-md-bubble button[data-active="true"] {
	background: var(--primary-green);
	color: var(--colored-button-font-color);
}

nb-md-bubble button svg {
	width: 0.95rem;
	height: 0.95rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	pointer-events: none;
}

/*#endregion*/

/* Set by the component when the hidden textarea fails constraint validation on submit, and cleared
   once it passes again. :user-invalid cannot be used here — it only matches after the user has
   interacted with the control itself, and nobody ever focuses a 1px transparent textarea. */
nb-markdown-editor[data-invalid] {
	box-shadow: 0 0 0 1px var(--danger-red);
}
