/**
 * Qalam Content Manager - callout boxes (v3.3.0, restyled v3.3.1).
 *
 * Four kinds of helping box an editor can drop into any chapter of any book:
 *   qcm-callout-insight   💡 LIGHTBULB    the "aha" idea behind a passage
 *   qcm-callout-note      📝 HELPING NOTE  a definition, formula or quick summary
 *   qcm-callout-warning   ⚠️ WATCH OUT     a common mistake or false assumption
 *   qcm-callout-practice  🔍 IN PRACTICE   a real-world example or use
 *
 * Markup (what the Studio "Callout" button inserts):
 *   <div class="qcm-callout qcm-callout-insight" role="note">
 *     <p class="qcm-callout-title"><strong>💡 LIGHTBULB: Title</strong></p>
 *     <p>Two to four sentences.</p>
 *   </div>
 *
 * v3.3.1 - the boxes no longer look like part of the book text:
 *   - every box is a coloured card with a solid coloured title band and a sans-serif face,
 *     so it reads as "a note about the book", not as the book itself;
 *   - when the page is wide enough (about 1000px of page, i.e. the full-screen reader on a
 *     laptop or desktop) the boxes move out of the text into a right-hand notes column with
 *     its own tinted background, beside the paragraph they follow. Narrower pages (phones,
 *     the embedded reader, picture-book spreads) keep them in the text as cards.
 *   The column is pure CSS (a container query on the reader page), so the chapter HTML,
 *   reading order, screen readers, search engines and the Urdu toggle are all unchanged.
 *   PHP adds .qcm-has-callouts to a page that has any box (QCM_Reader::has_callouts()).
 *
 * Loaded by the reader (as a dependency of qcm-reader.css), the Studio preview and the
 * Studio visual editor, so the box looks the same while writing and reading.
 */

/* ------------------------------------------------------------------
 * The card (every width)
 * ---------------------------------------------------------------- */
.qcm-callout {
	--qcm-co-accent: var(--qk2-pri,#4A7C59);   /* left rule and border */
	--qcm-co-band: var(--qk2-pri,#4A7C59);     /* title band background */
	--qcm-co-band-ink: #ffffff; /* title band text */
	--qcm-co-bg: #dcefe5;       /* card background */
	--qcm-co-ink: #23302b;      /* card body text */
	position: relative;
	box-sizing: border-box;
	margin: 1.8em 0;
	padding: 0 1.1em 0.95em;
	overflow: hidden;
	border: 1px solid color-mix(in srgb, var(--qcm-co-accent) 40%, transparent);
	border-inline-start: 5px solid var(--qcm-co-accent);
	border-radius: 10px;
	background: var(--qcm-co-bg);
	color: var(--qcm-co-ink);
	box-shadow: 0 2px 0 color-mix(in srgb, var(--qcm-co-accent) 14%, transparent), 0 6px 18px rgba(40, 30, 20, 0.08);
	font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	font-size: 0.9em;
	line-height: 1.6;
	break-inside: avoid;
	page-break-inside: avoid;
}

/* Title band: a solid coloured strip across the top of the card. */
.qcm-callout .qcm-callout-title,
.qcm-page-content .qcm-callout .qcm-callout-title {
	margin: 0 -1.1em 0.75em;
	padding: 0.55em 1.1em 0.5em;
	background: var(--qcm-co-band);
	color: var(--qcm-co-band-ink);
	font-family: inherit;
	font-size: 0.86em;
	letter-spacing: 0.035em;
	line-height: 1.4;
}
.qcm-callout .qcm-callout-title strong { font-weight: 700; color: inherit; }

.qcm-callout p { margin: 0 0 0.6em; color: inherit; }
.qcm-callout > :last-child { margin-bottom: 0; }
.qcm-callout ul,
.qcm-callout ol { margin: 0.2em 0 0.6em; padding-inline-start: 1.3em; }
.qcm-callout li { margin: 0.2em 0; color: inherit; }
.qcm-callout strong { color: inherit; }
.qcm-callout a { color: var(--qcm-co-band); }

/* Kinds - light theme (also the Studio editor). Band colours keep white text at AA contrast. */
.qcm-callout-insight {
	--qcm-co-accent: #c27a36;
	--qcm-co-band: #8a531f;
	--qcm-co-bg: #fbe8c8;
	--qcm-co-ink: #3d2a17;
}
.qcm-callout-note {
	--qcm-co-accent: #2c7a5f;
	--qcm-co-band: var(--qk2-pri,#4A7C59);
	--qcm-co-bg: #d9eee3;
	--qcm-co-ink: #1f3129;
}
.qcm-callout-warning {
	--qcm-co-accent: #c64a35;
	--qcm-co-band: #9a3322;
	--qcm-co-bg: #fbded6;
	--qcm-co-ink: #3f1c15;
}
.qcm-callout-practice {
	--qcm-co-accent: #3a78a8;
	--qcm-co-band: #24557a;
	--qcm-co-bg: #dbe8f5;
	--qcm-co-ink: #182b3b;
}

/* Reader theme: Sepia - richer tints so the card still stands off the yellowed page. */
.qcm-theme-sepia .qcm-callout-insight  { --qcm-co-bg: #f3d6a6; }
.qcm-theme-sepia .qcm-callout-note     { --qcm-co-bg: #d3e2c6; }
.qcm-theme-sepia .qcm-callout-warning  { --qcm-co-bg: #f1cdbd; }
.qcm-theme-sepia .qcm-callout-practice { --qcm-co-bg: #cfdde3; }

/* Reader theme: Dark - light bands with dark text, deep tinted cards. */
.qcm-theme-dark .qcm-callout { --qcm-co-band-ink: var(--qk2-ink,#1E293B); --qcm-co-ink: #ece8e0; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
.qcm-theme-dark .qcm-callout-insight  { --qcm-co-accent: #d9965a; --qcm-co-band: #f0b985; --qcm-co-bg: #3a2c1e; }
.qcm-theme-dark .qcm-callout-note     { --qcm-co-accent: #5fae92; --qcm-co-band: #8fd0b7; --qcm-co-bg: #1d3329; }
.qcm-theme-dark .qcm-callout-warning  { --qcm-co-accent: #e27560; --qcm-co-band: #f3a393; --qcm-co-bg: #3a221d; }
.qcm-theme-dark .qcm-callout-practice { --qcm-co-accent: #6aa6d6; --qcm-co-band: #a2c9ea; --qcm-co-bg: #1c2b3a; }

/* Older browsers without color-mix(): a plain hairline border and soft shadow. */
@supports not (border-color: color-mix(in srgb, red 10%, transparent)) {
	.qcm-callout { border-color: rgba(0, 0, 0, 0.14); border-inline-start-color: var(--qcm-co-accent); box-shadow: 0 6px 18px rgba(40, 30, 20, 0.08); }
}

/* Small phones: a little less padding so the reading column keeps its width. */
@media (max-width: 480px) {
	.qcm-callout { padding: 0 0.9em 0.85em; margin: 1.5em 0; }
	.qcm-callout .qcm-callout-title,
	.qcm-page-content .qcm-callout .qcm-callout-title { margin: 0 -0.9em 0.7em; padding: 0.5em 0.9em 0.45em; }
}

/* ------------------------------------------------------------------
 * The right-hand notes column (wide reader pages only)
 * ---------------------------------------------------------------- */

/* Each reader page measures its own width, so the embedded 900px reader and phones
   keep the in-text cards while the full-width reader gets the column. */
.qcm-reader .qcm-page { container: qcm-page / inline-size; }

@container qcm-page (min-width: 1000px) {
	.qcm-page-inner.qcm-has-callouts:not(.qcm-has-art) {
		--qcm-side-w: clamp(16rem, 27cqi, 22rem);
		--qcm-side-gap: 3rem;
		--qcm-side-reserve: calc(var(--qcm-side-w) + var(--qcm-side-gap));
		max-width: 1200px;
		padding-left: 2.75rem;
		padding-right: 2.25rem;
	}

	/* Book text keeps a comfortable measure on the left; title and extras line up with it. */
	.qcm-has-callouts:not(.qcm-has-art) .qcm-page-text > h2,
	.qcm-has-callouts:not(.qcm-has-art) .qcm-page-extras { margin-right: var(--qcm-side-reserve); }

	.qcm-has-callouts:not(.qcm-has-art) .qcm-page-content {
		position: relative;
		z-index: 0;
		display: flow-root; /* contains the floated notes, so the column never spills off the page */
		padding-right: var(--qcm-side-reserve);
	}

	/* The column itself: a tinted strip with a rule, running the full height of the text. */
	.qcm-has-callouts:not(.qcm-has-art) .qcm-page-content::before {
		content: "";
		position: absolute;
		z-index: -1;
		top: -0.6rem;
		bottom: -0.6rem;
		right: -1rem;
		width: calc(var(--qcm-side-w) + var(--qcm-side-gap) / 2 + 1rem);
		border-left: 1px solid rgba(91, 58, 41, 0.2);
		border-radius: 0 10px 10px 0;
		background: rgba(91, 58, 41, 0.045);
		pointer-events: none;
	}
	.qcm-theme-sepia .qcm-has-callouts:not(.qcm-has-art) .qcm-page-content::before { background: rgba(91, 58, 41, 0.07); border-left-color: rgba(91, 58, 41, 0.26); }
	.qcm-theme-dark .qcm-has-callouts:not(.qcm-has-art) .qcm-page-content::before { background: rgba(255, 255, 255, 0.035); border-left-color: rgba(255, 255, 255, 0.14); }

	/* A box moves out of the text into the column, next to the passage it follows.
	   Physical "right" on purpose: the column stays on the right in the Urdu (RTL) view too. */
	.qcm-has-callouts:not(.qcm-has-art) .qcm-page-content .qcm-callout {
		float: right;
		clear: right;
		width: var(--qcm-side-w);
		margin: 0.3em calc(-1 * var(--qcm-side-reserve)) 1.4em 0;
		font-size: 0.84em;
		line-height: 1.55;
	}
	/* Keep the first box level with the first line of text. */
	.qcm-has-callouts:not(.qcm-has-art) .qcm-page-content .qcm-callout:first-child { margin-top: 0; }
}

@media print {
	.qcm-callout { background: none; box-shadow: none; border-color: #999; border-inline-start-color: #333; color: #000; }
	.qcm-callout .qcm-callout-title { background: none; color: #000; border-bottom: 1px solid #999; }
}
