/**
 * References Dropdown Block Styles
 *
 * Accordion dropdown for displaying references and citations.
 * Features accessible toggle with smooth animations.
 *
 * @package TMW_Core_Child
 * @since 1.0.0
 * @version 1.0.0
 */

/* Container */
.references-dropdown__container {
	background: var(--color-bg);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-card);
	overflow: hidden;
	transition: box-shadow var(--transition-base);
}

/* Single post template only: constrain to the post content width.
 *
 * templates/single.html places this block outside .wp-block-post-content, so
 * without a cap it fills the full .container width (~1065px) while the post
 * content above it is capped at --max-width-content-lg (900px) by
 * .flexible-content-wrapper.width-standard - leaving the accordion visibly
 * wider than the article it belongs to.
 *
 * Deliberately scoped to .single-post rather than applied to the block
 * globally, so the block can still fill a wider container if it is ever placed
 * in one elsewhere. Harmless on in-content instances, which the constrained
 * post-content layout already holds at this width. */
.single-post .references-dropdown__container {
	max-width: var(--max-width-content-lg);
	margin-inline: auto;
}

/* XL screens: .width-standard scales 900px -> 1260px at this breakpoint (see
 * 3mw-core responsive.css, "Content Width Presets - Proportional Scaling"), so
 * the cap above has to scale with it or the accordion stays at 900px while the
 * article widens - measured at a 2000px viewport: post content 1260px vs
 * accordion 900px, 180px narrower on each side.
 *
 * The literal 1260px matches the parent theme's value rather than deriving it,
 * because --max-width-content-lg is generated from Theme Settings and is not
 * itself breakpoint-aware; the parent hardcodes these scaled presets the same
 * way. Both conditions are required to match the parent rule: the media query
 * AND the body class, which is toggled by
 * Theme Settings -> Design System -> Enable XL Breakpoint.
 *
 * Both classes sit on <body>, so they chain on one compound selector. */
@media (width >= 1920px) {
	body.single-post.has-xl-breakpoint .references-dropdown__container {
		max-width: 1260px;
	}
}

.references-dropdown__container:hover,
.references-dropdown__container:has(:focus-visible) {
	box-shadow: var(--shadow-sm);
}

/* Header Button */
.references-dropdown__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: var(--space-md) var(--space-lg);
	background: transparent;
	border: none;
	cursor: pointer;
	text-align: left;
	transition: background-color var(--transition-base);
}

.references-dropdown__header:hover {
	background-color: var(--color-white);
}

/* Focus visible state for keyboard navigation */

/* Note: Uses inset outline because container has overflow:hidden which clips outward outlines */
.references-dropdown__container button:focus {
	outline: 3px solid transparent;
}

.references-dropdown__container button:focus-visible {
	outline: 3px solid var(--color-primary);
	outline-offset: -3px; /* Inset outline to avoid being clipped by overflow:hidden */
	box-shadow: var(--shadow-focus);
}

/* Header Content (Icon + Title) */
.references-dropdown__header-content {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
}

/* Document Icon */
.references-dropdown__icon {
	width: 30px;
	height: auto;
	margin-right: var(--space-xs);
	flex-shrink: 0;
}

/* Title */
.references-dropdown__title {
	font-family: var(--font-family-heading);
	font-size: var(--font-size-h5);
	color: var(--color-heading);
	line-height: var(--line-height-heading);
}

/* Toggle Icons Container */
.references-dropdown__toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	flex-shrink: 0;
	color: var(--color-heading);
}

/* Toggle Icons */
.references-dropdown__toggle-icon {
	width: 24px;
	height: 24px;
	transition: color var(--transition-base), transform var(--transition-base);
}

.references-dropdown__header:hover .references-dropdown__toggle-icon {
	color: var(--color-primary);
}

/* Plus icon visible when closed, close icon hidden */
.references-dropdown__toggle-icon--plus {
	display: block;
}

.references-dropdown__toggle-icon--close {
	display: none;
}

/* When expanded: hide plus, show close */
.references-dropdown__header[aria-expanded="true"] .references-dropdown__toggle-icon--plus {
	display: none;
}

.references-dropdown__header[aria-expanded="true"] .references-dropdown__toggle-icon--close {
	display: block;
}

/* When expanded: white background for header and content */
.references-dropdown__container:has(.references-dropdown__header[aria-expanded="true"]) {
	background: var(--color-white);
}

.references-dropdown__header[aria-expanded="true"] {
	background: var(--color-white);
}

/* Panel */
.references-dropdown__panel {
	overflow: hidden;
	transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
	max-height: 0;
	opacity: 0;
}

.references-dropdown__panel:not([hidden]) {
	max-height: none;
	opacity: 1;
}

/* Content Area */
.references-dropdown__content {
	max-width: 1028px;
	padding: var(--space-sm) var(--space-lg) var(--space-md);
}

/* Single post template only: the parent __container is already capped at the
 * post content width, so this inner cap is redundant - and being narrower than
 * the container it would inset the text unevenly against the header above it. */
.single-post .references-dropdown__content {
	max-width: none;
}

.references-dropdown__content ol li {
	position: relative;
	margin-bottom: var(--space-md);
}

/* Numbering comes from the global ordered-list counter on li::before, never from
 * ::marker. Suppress the native marker here rather than relying on the global
 * `ol li { list-style: none }` rule: that rule is scoped to `ol:not([class])` /
 * `ol.wp-block-list`, and the WYSIWYG markup rendered inside the block editor
 * preview iframe doesn't always match either selector. When it doesn't, the live
 * marker renders in addition to the counter and reads as a stray dot beneath
 * each number. */
.references-dropdown__content :is(ol, ul) li {
	list-style: none;
}

.references-dropdown__content li::before {
	position: absolute;
	font-weight: var(--font-weight-semibold);
	color: var(--color-primary);
}

/* Links within references */
.references-dropdown__content a {
	word-break: break-all;
	overflow-wrap: anywhere;
}

.references-dropdown__content a:hover,
.references-dropdown__content a:focus {
	color: var(--color-primary);
	text-decoration: underline;
}

/* Unordered List Styling (fallback) */
.references-dropdown__content ul {
	margin: var(--space-lg) 0 0;
	padding-left: var(--space-xl);
}

.references-dropdown__content ul li {
	margin-bottom: var(--space-md);
	font-size: var(--font-size-small);
	line-height: var(--line-height-relaxed);
}

/* Paragraph styling */
.references-dropdown__content p {
	margin-bottom: var(--space-sm);
	font-size: var(--font-size-small);
	line-height: var(--line-height-relaxed);
}

.references-dropdown__content p:last-child {
	margin-bottom: 0;
}

/* Mobile Styles */
@media (width <= 768px) {
	.references-dropdown__panel:not([hidden]) {
		max-height: none; /* Remove height constraint on mobile - no animation needed */
	}

	.references-dropdown__content {
		padding-left: var(--space-md);
		padding-right: var(--space-md);
		overflow-wrap: anywhere;
		word-break: break-word;
	}

	.references-dropdown__header {
		padding: var(--space-sm) var(--space-md);
	}
}

/* Small Mobile Styles */
@media (width <= 480px) {
	.references-dropdown__icon {
		width: 20px;
		height: 25px;
	}

	.references-dropdown__toggle-icon {
		width: 20px;
		height: 20px;
	}
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
	.references-dropdown__panel {
		transition: none;
	}

	.references-dropdown__toggle-icon {
		transition: none;
	}
}

/* Block Editor Styles */
.editor-styles-wrapper .references-dropdown {
	margin-top: 0;
	margin-bottom: 0;
}

/* Alignment Variations - width controlled by parent .container class */

/* ========================================
 * DARK BACKGROUND CONTEXT
 * Panel has explicit light background, so content
 * should use dark text regardless of ancestor context.
 * Note: revert doesn't work with inherited color,
 * must use explicit values.
 * ======================================== */

:is([data-dark-bg="true"], [data-section-dark-bg="true"]) .references-dropdown__panel,
:is([data-dark-bg="true"], [data-section-dark-bg="true"]) .references-dropdown__panel * {
	color: var(--color-text-primary);
}

:is([data-dark-bg="true"], [data-section-dark-bg="true"]) .references-dropdown__panel a {
	color: var(--color-primary);
}

:is([data-dark-bg="true"], [data-section-dark-bg="true"]) .references-dropdown__panel a:hover {
	color: var(--color-primary-dark);
	opacity: 1;
}

/* Targets ::before, not ::marker — the native marker is suppressed above, so the
 * number the reader sees is the counter on ::before. */
:is([data-dark-bg="true"], [data-section-dark-bg="true"]) .references-dropdown__panel li::before {
	color: var(--color-primary);
}
