/**
 * Accessible Events Calendar — front-end styles.
 *
 * Design notes:
 * - Every color/spacing value is a CSS custom property with a WCAG 2.2 AA
 *   compliant fallback, so the calendar is safe out of the box and fully
 *   restylable from Settings > Event Calendar or a theme stylesheet.
 * - --aec-font defaults to "inherit" so the calendar always matches the
 *   surrounding theme's font unless explicitly overridden.
 * - All type sizes use rem/em so the layout respects user browser zoom
 *   and OS text-size settings (WCAG 1.4.4 Resize Text).
 * - Interactive targets are at least 44x44px (exceeds the WCAG 2.2 2.5.8
 *   24px minimum). Focus states use a highly visible outline (2.4.7,
 *   2.4.11) and are never removed without a visible replacement.
 * - Respects prefers-reduced-motion.
 */

.aec-calendar-wrap {
	--aec-font: inherit;
	--aec-color-primary: #1d4ed8;
	--aec-color-primary-contrast: #ffffff;
	--aec-color-text: #1f2933;
	--aec-color-bg: #ffffff;
	--aec-color-border: #d7dce1;
	--aec-color-muted: #5b6b79;
	--aec-color-today-bg: #eef4ff;
	--aec-color-focus: #0b3ea8;
	--aec-color-tab-bg: #eef1f4;
	--aec-color-tab-text: #5b6b79;
	--aec-color-tab-active-bg: #1d4ed8;
	--aec-color-tab-active-text: #ffffff;
	--aec-radius: 8px;
	--aec-space: 0.5rem;

	font-family: var(--aec-font);
	color: var(--aec-color-text);
	background: var(--aec-color-bg);
	border: 1px solid var(--aec-color-border);
	border-radius: var(--aec-radius);
	padding: 1.25rem;
	max-width: 100%;
	box-sizing: border-box;
	line-height: 1.5;
	overflow-wrap: break-word;
	word-break: break-word;
}

.aec-calendar-wrap *,
.aec-calendar-wrap *::before,
.aec-calendar-wrap *::after {
	box-sizing: inherit;
	font-family: inherit;
}

.aec-calendar-wrap h2,
.aec-calendar-wrap h3,
.aec-calendar-wrap h4,
.aec-calendar-wrap h5 {
	font-family: inherit;
	color: var(--aec-color-text);
	margin: 0 0 0.5em;
}

.aec-calendar-wrap a {
	color: var(--aec-color-primary);
}

.aec-calendar-wrap p {
	margin: 0 0 0.75em;
}

/* Visually hidden but available to screen readers (WCAG 4.1.2 / 1.3.1) */
.aec-visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Universal focus visibility (WCAG 2.4.7 Focus Visible) */
.aec-calendar-wrap a:focus-visible,
.aec-calendar-wrap button:focus-visible,
.aec-calendar-wrap summary:focus-visible,
.aec-calendar-wrap [tabindex]:focus-visible {
	outline: 3px solid var(--aec-color-focus);
	outline-offset: 2px;
	border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
	.aec-calendar-wrap * {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}

/* -------------------- Tabs -------------------- */

.aec-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-bottom: 1.25rem;
}

.aec-tab {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding: 0.55rem 1.15rem;
	text-decoration: none;
	font-weight: 600;
	color: var(--aec-color-tab-text);
	background: var(--aec-color-tab-bg);
	border: 1px solid var(--aec-color-border);
	border-radius: var(--aec-radius);
}

.aec-tab:hover {
	border-color: var(--aec-color-tab-active-bg);
	color: var(--aec-color-tab-active-bg);
}

.aec-tab.is-active,
.aec-tab.is-active:hover {
	color: var(--aec-color-tab-active-text);
	background: var(--aec-color-tab-active-bg);
	border-color: var(--aec-color-tab-active-bg);
}

/* -------------------- Month grid -------------------- */

.aec-month-nav {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	margin-bottom: 0.75rem;
}

.aec-month-label {
	font-size: 1.25rem;
	margin: 0;
	text-align: center;
	flex: 1;
}

.aec-nav-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	border: 1px solid var(--aec-color-border);
	border-radius: var(--aec-radius);
	background: var(--aec-color-bg);
	color: var(--aec-color-text);
	text-decoration: none;
	font-size: 1.25rem;
	line-height: 1;
}

.aec-nav-btn:hover {
	background: var(--aec-color-today-bg);
	border-color: var(--aec-color-primary);
}

.aec-calendar-table {
	width: 100%;
	border-collapse: collapse;
	table-layout: fixed;
}

.aec-calendar-table th {
	padding: 0.5rem 0.25rem;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--aec-color-muted);
	border-bottom: 1px solid var(--aec-color-border);
	text-align: center;
}

.aec-calendar-table th abbr {
	text-decoration: none;
}

.aec-day-cell {
	position: relative;
	height: 4.5rem;
	vertical-align: top;
	border: 1px solid var(--aec-color-border);
	padding: 0.25rem;
	text-align: center;
}

.aec-day-outside {
	background: transparent;
	color: var(--aec-color-muted);
	opacity: 0.55;
}

.aec-day-today {
	background: var(--aec-color-today-bg);
}

.aec-day-number {
	display: inline-block;
	font-size: 0.95rem;
}

.aec-day-today .aec-day-number {
	font-weight: 700;
	text-decoration: underline;
}

/* Tighten the grid on phones so a full week always fits without horizontal
   scrolling, while keeping day buttons at an accessible tap size. */
@media (max-width: 480px) {
	.aec-day-cell {
		height: 3.25rem;
		padding: 0.15rem;
	}

	.aec-day-number {
		font-size: 0.8rem;
	}

	.aec-calendar-table th {
		padding: 0.35rem 0.1rem;
		font-size: 0.7rem;
	}

	.aec-month-label {
		font-size: 1.05rem;
	}

	.aec-nav-btn {
		min-width: 40px;
		min-height: 40px;
	}
}

@media (max-width: 360px) {
	.aec-day-cell {
		height: 2.75rem;
	}
}

.aec-day-btn {
	width: 100%;
	min-height: 44px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	gap: 0.25rem;
	background: transparent;
	border: 0;
	cursor: pointer;
	color: var(--aec-color-text);
	padding: 0.25rem 0;
}

.aec-day-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--aec-color-primary);
	display: inline-block;
}

.aec-day-has-events {
	font-weight: 600;
}

.aec-day-popover {
	position: absolute;
	z-index: 20;
	top: 100%;
	left: 0;
	width: max-content;
	min-width: 220px;
	max-width: min(280px, calc(100vw - 2rem));
	max-height: min(320px, calc(100vh - 6rem));
	overflow-y: auto;
	background: var(--aec-color-bg);
	border: 1px solid var(--aec-color-border);
	border-radius: var(--aec-radius);
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
	padding: 0.5rem;
	text-align: left;
}

/* Flip to the left edge of the day button when the default position would
   overflow the right edge of the viewport (class added by JS). */
.aec-day-popover.aec-popover-align-right {
	left: auto;
	right: 0;
}

.aec-day-popover-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	margin-bottom: 0.35rem;
	padding-bottom: 0.35rem;
	border-bottom: 1px solid var(--aec-color-border);
}

.aec-day-popover-title {
	font-weight: 700;
	font-size: 0.9rem;
}

.aec-day-popover-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	min-width: 32px;
	min-height: 32px;
	border: 0;
	background: transparent;
	color: var(--aec-color-muted);
	font-size: 1.25rem;
	line-height: 1;
	cursor: pointer;
	border-radius: var(--aec-radius);
}

.aec-day-popover-close:hover {
	background: var(--aec-color-today-bg);
	color: var(--aec-color-text);
}

.aec-day-popover-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.aec-day-popover-list li {
	padding: 0.5rem 0;
	border-bottom: 1px solid var(--aec-color-border);
	font-size: 0.9rem;
}

.aec-day-popover-list li:last-child {
	border-bottom: 0;
}

.aec-day-popover-list a {
	display: inline-block;
	padding: 0.15rem 0;
	min-height: 24px;
}

.aec-day-popover-time {
	display: block;
	color: var(--aec-color-muted);
	font-size: 0.8rem;
}

/* On small screens the floating popover becomes a fixed bottom sheet, which
   can never overflow the viewport regardless of which day was tapped. */
@media (max-width: 480px) {
	.aec-day-popover {
		position: fixed;
		left: 0.75rem;
		right: 0.75rem;
		bottom: 0.75rem;
		top: auto;
		width: auto;
		max-width: none;
		min-width: 0;
		max-height: min(60vh, 420px);
		box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
	}

	.aec-day-popover.aec-popover-align-right {
		left: 0.75rem;
		right: 0.75rem;
	}

	.aec-day-popover-title {
		font-size: 1rem;
	}
}

/* -------------------- Upcoming list -------------------- */

.aec-upcoming-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.aec-upcoming-item {
	display: flex;
	gap: 0.75rem;
	align-items: flex-start;
	border: 1px solid var(--aec-color-border);
	border-radius: var(--aec-radius);
	padding: 0.75rem;
	background: var(--aec-color-bg);
}

.aec-upcoming-date {
	flex: 0 0 auto;
	width: 3.25rem;
	text-align: center;
	background: var(--aec-color-primary);
	color: var(--aec-color-primary-contrast);
	border-radius: var(--aec-radius);
	padding: 0.35rem 0;
	line-height: 1.2;
}

.aec-upcoming-month {
	display: block;
	font-size: 0.7rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.aec-upcoming-day {
	display: block;
	font-size: 1.25rem;
	font-weight: 700;
}

.aec-upcoming-content {
	flex: 1 1 auto;
	min-width: 0;
}

.aec-upcoming-title {
	font-size: 1rem;
	margin: 0 0 0.25em;
}

.aec-upcoming-title a {
	text-decoration: none;
}

.aec-upcoming-title a:hover {
	text-decoration: underline;
}

.aec-upcoming-time {
	margin: 0;
	font-size: 0.85rem;
	color: var(--aec-color-muted);
}

.aec-upcoming-image {
	flex: 0 0 auto;
	width: 56px;
	height: 56px;
	overflow: hidden;
	border-radius: var(--aec-radius);
}

.aec-upcoming-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.aec-upcoming-image .aec-default-image {
	width: 100%;
	height: 100%;
}

@media (max-width: 400px) {
	.aec-upcoming-item {
		padding: 0.6rem;
		gap: 0.5rem;
	}

	.aec-upcoming-date {
		width: 2.75rem;
	}

	.aec-upcoming-image {
		width: 44px;
		height: 44px;
	}
}

.aec-no-events {
	color: var(--aec-color-muted);
	font-style: italic;
}

.aec-month-empty-note {
	margin-top: 1rem;
	padding-top: 1rem;
	border-top: 1px solid var(--aec-color-border);
}

.aec-empty-cta {
	margin-top: 0.5rem;
}

/* -------------------- Badges -------------------- */

.aec-badge {
	display: inline-flex;
	align-items: center;
	gap: 0.3em;
	font-size: 0.75rem;
	font-weight: 600;
	padding: 0.15em 0.6em;
	border-radius: 999px;
	background: var(--aec-color-today-bg);
	color: var(--aec-color-primary);
	border: 1px solid var(--aec-color-primary);
	margin: 0.25em 0 0;
}

/* -------------------- Buttons -------------------- */

.aec-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0.5rem 1.1rem;
	border-radius: var(--aec-radius);
	text-decoration: none;
	font-weight: 600;
	border: 2px solid var(--aec-color-primary);
	margin: 0.25rem 0.5rem 0.25rem 0;
}

.aec-btn-primary {
	background: var(--aec-color-primary);
	color: var(--aec-color-primary-contrast);
}

.aec-btn-primary:hover {
	filter: brightness(0.92);
}

.aec-btn-secondary {
	background: transparent;
	color: var(--aec-color-primary);
}

.aec-btn-secondary:hover {
	background: var(--aec-color-today-bg);
}

.aec-add-to-calendar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.25rem 0.5rem;
	margin: 1rem 0;
}

.aec-add-to-calendar-label {
	font-weight: 600;
	margin-right: 0.25rem;
}

/* -------------------- Full event list (collapsible) -------------------- */

.aec-event-list {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.aec-event-details {
	border: 1px solid var(--aec-color-border);
	border-radius: var(--aec-radius);
	background: var(--aec-color-bg);
	overflow: hidden;
}

.aec-event-summary {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
	min-height: 44px;
	padding: 0.85rem 1rem;
	cursor: pointer;
	font-weight: 600;
	list-style: none;
}

.aec-event-summary::-webkit-details-marker {
	display: none;
}

.aec-event-summary::before {
	content: "+";
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.5em;
	height: 1.5em;
	flex: 0 0 auto;
	border: 2px solid var(--aec-color-primary);
	border-radius: 50%;
	color: var(--aec-color-primary);
	font-size: 1rem;
	line-height: 1;
}

.aec-event-details[open] > .aec-event-summary::before {
	content: "–";
}

.aec-event-summary-date {
	color: var(--aec-color-muted);
	font-weight: 600;
	white-space: nowrap;
}

.aec-event-summary-title {
	flex: 1 1 auto;
}

.aec-event-body {
	padding: 0 1rem 1.25rem;
	border-top: 1px solid var(--aec-color-border);
}

.aec-event-image {
	margin: 1rem 0;
	max-width: 320px;
}

.aec-event-image img {
	width: 100%;
	height: auto;
	border-radius: var(--aec-radius);
	display: block;
}

.aec-event-image .aec-default-image {
	width: 100%;
	height: 160px;
	border-radius: var(--aec-radius);
}

/* Shared placeholder tile used whenever an event has no image of its own. */
.aec-default-image {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--aec-color-today-bg);
	color: var(--aec-color-primary);
}

.aec-event-meta {
	margin: 1rem 0;
	display: grid;
	gap: 0.5rem;
}

.aec-event-meta > div {
	display: grid;
	grid-template-columns: 6rem 1fr;
	gap: 0.5rem;
}

.aec-event-meta dt {
	font-weight: 700;
	color: var(--aec-color-muted);
}

.aec-event-meta dd {
	margin: 0;
}

.aec-event-excerpt {
	font-style: italic;
	color: var(--aec-color-muted);
}

.aec-event-description {
	margin: 0.75rem 0;
}

.aec-event-permalink {
	font-weight: 600;
}

/* -------------------- Standalone upcoming/list wraps -------------------- */

.aec-upcoming-wrap,
.aec-list-wrap {
	max-width: 100%;
}

/* -------------------- Small-screen refinements -------------------- */

@media (max-width: 480px) {
	.aec-calendar-wrap {
		padding: 0.85rem;
	}

	.aec-event-summary {
		padding: 0.75rem;
		gap: 0.5rem;
	}

	.aec-event-summary-date {
		font-size: 0.85rem;
	}

	.aec-event-body {
		padding: 0 0.75rem 1rem;
	}

	/* Stack the "When / Where / Repeats" label above its value instead of
	   a fixed 6rem label column, which gets cramped on narrow phones. */
	.aec-event-meta > div {
		grid-template-columns: 1fr;
		gap: 0.15rem;
	}

	.aec-tab {
		padding: 0.5rem 0.75rem;
		font-size: 0.9rem;
	}

	.aec-btn {
		padding: 0.5rem 0.85rem;
		font-size: 0.9rem;
	}

	.aec-add-to-calendar {
		gap: 0.4rem;
	}
}
