/**
 * Westphal Solutions — Markdown tool styles
 *
 * Visually matched to ws-html.css so the two site tools read as siblings:
 * the same top bar, sliding-thumb toggle, button chrome, and two-pane layout
 * with a hairline gutter. Behaviour is unchanged — this only styles the markup
 * produced by the [ws_markdown] shortcode and driven by ws-markdown.js.
 *
 * The shared shell here is intentionally identical to ws-html.css; when you're
 * ready, both can collapse into one ws-tools base file with these two as thin
 * skins on top.
 */

.wsmd {
	--wsmd-mono: 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
	--wsmd-gap: 1px; /* hairline between the two panes */

	border: 1px solid var(--ws-border);
	border-radius: var(--ws-radius);
	background: var(--ws-surface);
	overflow: hidden;
	font-family: var(--ws-font);
	color: var(--ws-text);
}

/* ---------------------------------------------------------------------------
   Top bar: Write/Convert toggle on the left, Copy on the right
   --------------------------------------------------------------------------- */
.wsmd__bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px;
	padding: 10px 12px;
	border-bottom: 1px solid var(--ws-border);
	background: var(--ws-bg);
}

/* ---- Mode toggle (Write / Convert), the sliding-thumb pattern -------------- */
.wsmd__modes {
	position: relative;
	display: flex;
	padding: 3px;
	border: 1px solid var(--ws-border);
	border-radius: var(--ws-radius-pill);
	background: var(--ws-surface);
}

.wsmd__thumb {
	position: absolute;
	top: 3px;
	left: 3px;
	width: calc(50% - 3px);
	height: calc(100% - 6px);
	border-radius: var(--ws-radius-pill);
	background: var(--ws-accent);
	transition: transform 0.28s var(--ws-ease);
}
.wsmd__modes[data-active="convert"] .wsmd__thumb { transform: translateX(100%); }

.wsmd__mode {
	position: relative;
	z-index: 1;
	flex: 1 1 0;
	min-width: 76px;
	padding: 6px 14px;
	border: 0;
	background: transparent;
	font-family: var(--ws-font);
	font-size: 0.8rem;
	font-weight: 700;
	color: var(--ws-muted);
	cursor: pointer;
}
.wsmd__mode[aria-pressed="true"] { color: var(--ws-black); }
.wsmd__mode:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 2px; border-radius: var(--ws-radius-pill); }

/* ---- Copy button ----------------------------------------------------------- */
.wsmd__copy {
	margin-left: auto;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-family: var(--ws-font);
	font-size: 0.85rem;
	font-weight: 700;
	line-height: 1;
	padding: 9px 14px;
	border-radius: var(--ws-radius);
	border: 1px solid var(--ws-border);
	background: var(--ws-surface);
	color: var(--ws-text);
	cursor: pointer;
	transition: transform 0.15s var(--ws-ease),
				background-color 0.2s var(--ws-ease),
				border-color 0.2s var(--ws-ease),
				color 0.2s var(--ws-ease);
}
.wsmd__copy:hover { border-color: var(--ws-accent); }
.wsmd__copy:active { transform: translateY(1px); }
.wsmd__copy:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 2px; }
.wsmd__copy.is-copied {
	background: var(--ws-slate);
	border-color: var(--ws-slate);
	color: var(--ws-white);
}

/* ---------------------------------------------------------------------------
   Formatting toolbar (Write mode only)
   --------------------------------------------------------------------------- */
.wsmd__toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	padding: 8px 12px;
	border-bottom: 1px solid var(--ws-border);
	background: var(--ws-surface);
}
/* Formatting only applies to the Markdown source, so hide it while converting. */
.wsmd[data-mode="convert"] .wsmd__toolbar { display: none; }

.wsmd__tool {
	min-width: 34px;
	height: 34px;
	padding: 0 9px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-family: var(--ws-font);
	font-size: 0.85rem;
	font-weight: 700;
	color: var(--ws-text);
	background: var(--ws-bg);
	border: 1px solid var(--ws-border);
	border-radius: var(--ws-radius);
	cursor: pointer;
	transition: transform 0.15s var(--ws-ease),
				border-color 0.2s var(--ws-ease),
				background-color 0.2s var(--ws-ease);
}
.wsmd__tool:hover { border-color: var(--ws-accent); }
.wsmd__tool:active { transform: translateY(1px); }
.wsmd__tool:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 2px; }
.wsmd__tool em { font-style: italic; }
.wsmd__tool strong { font-weight: 900; }

/* ---------------------------------------------------------------------------
   Panes
   --------------------------------------------------------------------------- */
.wsmd__panes {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--wsmd-gap);
	background: var(--ws-border); /* hairline gutter between panes */
}

.wsmd__pane {
	display: flex;
	flex-direction: column;
	min-width: 0;
	background: var(--ws-surface);
}

.wsmd__label {
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--ws-muted);
	padding: 9px 12px;
	border-bottom: 1px solid var(--ws-border);
}

/* ---- Editable fields: source textarea + rich contenteditable --------------- */
.wsmd__field {
	flex: 1 1 auto;
	width: 100%;
	min-height: 320px;
	border: 0;
	padding: 14px 16px;
	font-size: 0.95rem;
	line-height: 1.6;
	color: var(--ws-text);
	background: var(--ws-bg);
}
.wsmd__field:focus { outline: 0; box-shadow: inset 0 0 0 2px var(--ws-accent); }

/* The Markdown source + the converted output read as code. */
textarea.wsmd__field,
.wsmd__source {
	resize: vertical;
	font-family: var(--wsmd-mono);
	font-size: 0.9rem;
	tab-size: 2;
	white-space: pre-wrap;
	overflow: auto;
}

.wsmd__source { background: var(--ws-surface); color: var(--ws-muted); }

/* Rich paste area placeholder. */
.wsmd__rich { overflow: auto; }
.wsmd__rich:empty::before {
	content: attr(data-placeholder);
	color: var(--ws-muted);
}

/* ---- Show / hide fields per mode (mirrors ws-markdown.js) ------------------ */
.wsmd[data-mode="write"]   [data-wsmd-rich],
.wsmd[data-mode="write"]   [data-wsmd-source]  { display: none; }
.wsmd[data-mode="convert"] [data-wsmd-md],
.wsmd[data-mode="convert"] [data-wsmd-preview] { display: none; }

/* ---------------------------------------------------------------------------
   Rendered preview typography
   --------------------------------------------------------------------------- */
.wsmd__preview {
	flex: 1 1 auto;
	min-height: 320px;
	padding: 14px 18px;
	overflow: auto;
	line-height: var(--ws-lh-body);
	color: var(--ws-text);
	background: var(--ws-surface);
}
.wsmd__preview > :first-child { margin-top: 0; }
.wsmd__preview > :last-child { margin-bottom: 0; }
.wsmd__preview h1,
.wsmd__preview h2,
.wsmd__preview h3,
.wsmd__preview h4 { color: var(--ws-heading); line-height: var(--ws-lh-head); margin: 1.1em 0 0.4em; }
.wsmd__preview h1 { font-size: 1.8rem; font-weight: 900; }
.wsmd__preview h2 { font-size: 1.5rem; font-weight: 900; }
.wsmd__preview h3 { font-size: 1.25rem; font-weight: 700; }
.wsmd__preview h4 { font-size: 1.05rem; font-weight: 700; }
.wsmd__preview p { margin: 0 0 0.9em; }
.wsmd__preview ul,
.wsmd__preview ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.wsmd__preview li { margin: 0.2em 0; }
.wsmd__preview a { color: var(--ws-text); text-decoration: underline; text-decoration-color: var(--ws-accent); }
.wsmd__preview blockquote {
	margin: 0 0 0.9em;
	padding: 0.2em 0 0.2em 1em;
	border-left: 4px solid var(--ws-accent);
	color: var(--ws-muted);
}
.wsmd__preview code {
	font-family: var(--wsmd-mono);
	font-size: 0.88em;
	padding: 0.1em 0.35em;
	border-radius: var(--ws-radius-sm);
	background: var(--ws-light-grey);
	color: var(--ws-black);
}
[data-theme="dark"] .wsmd__preview code { background: var(--ws-charcoal); color: var(--ws-light-grey); }
.wsmd__preview pre {
	margin: 0 0 0.9em;
	padding: 12px 14px;
	overflow: auto;
	border-radius: var(--ws-radius);
	background: var(--ws-charcoal);
	color: var(--ws-light-grey);
	border-left: 4px solid var(--ws-accent);
}
.wsmd__preview pre code { background: none; color: inherit; padding: 0; }

/* ---------------------------------------------------------------------------
   Footnote line under the tool
   --------------------------------------------------------------------------- */
.wsmd__note {
	margin: 0;
	padding: 10px 14px;
	font-size: 0.8rem;
	color: var(--ws-muted);
	border-top: 1px solid var(--ws-border);
	background: var(--ws-bg);
}

/* ---------------------------------------------------------------------------
   Responsive: stack the two panes below 720px
   --------------------------------------------------------------------------- */
@media (max-width: 720px) {
	.wsmd__panes { grid-template-columns: 1fr; }
	.wsmd__field,
	.wsmd__preview { min-height: 240px; }
}
