/**
 * Indivisible Event Calendar — Frontend Styles
 *
 * Uses container queries for component-level responsiveness
 * and media queries for page-level layout.
 * All colors derived from the Indivisible Design System tokens.
 */

/* ── Color palette for event categories ─────────────────────────── */

:root {
	--iec-palette-0:  oklch(0.59 0.19 27);    /* Red */
	--iec-palette-1:  oklch(0.70 0.16 55);    /* Orange */
	--iec-palette-2:  oklch(0.79 0.15 85);    /* Gold */
	--iec-palette-3:  oklch(0.62 0.17 145);   /* Green */
	--iec-palette-4:  oklch(0.63 0.12 195);   /* Teal */
	--iec-palette-5:  oklch(0.56 0.15 250);   /* Blue */
	--iec-palette-6:  oklch(0.55 0.18 305);   /* Purple */
	--iec-palette-7:  oklch(0.65 0.18 350);   /* Pink */
	--iec-palette-8:  oklch(0.55 0.03 250);   /* Slate */
	--iec-palette-9:  oklch(0.50 0.10 55);    /* Brown */
	--iec-palette-10: oklch(0.74 0.18 130);   /* Lime */
	--iec-palette-11: oklch(0.72 0.10 230);   /* Sky */
}

/* ── Calendar container (establishes container context) ─────────── */

.iec-calendar {
	container-type: inline-size;
	container-name: iec-calendar;
	--iec-control-bg: oklch(from var(--ids-surface-page) calc(l + 0.05) c h);
}

/* ── Event card hero image (shared by grid cards and narrow list) ── */
/* Single source of truth: constrain size, never crop, center in container. */

.iec-card-hero-wrap {
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 0;
}

.iec-card-hero-img {
	display: block;
	width: 100%;
	height: auto;
	max-height: 12rem;
	object-fit: contain;
}

/* ── Calendar header ────────────────────────────────────────────── */

.iec-calendar-header {
	display: flex;
	flex-direction: column;
	gap: var(--ids-space-sm);
}

.iec-header-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--ids-space-md);
	flex-wrap: wrap;
}

.iec-month-nav {
	display: flex;
	align-items: center;
	gap: var(--ids-space-xs);
}

.iec-month-nav .iec-nav-prev,
.iec-month-nav .iec-nav-next {
	min-width: auto;
	padding: 0.2em 0.35em;
	font-size: 1.1rem;
	line-height: 1;
	border-color: transparent;
	color: oklch(from var(--ids-text-on-dark) l c h / 0.5);
}

.iec-month-nav .iec-nav-prev:hover,
.iec-month-nav .iec-nav-next:hover {
	color: var(--ids-text-on-dark);
	background: oklch(from var(--ids-color-white) l c h / 0.08);
}

.iec-month-nav .iec-nav-today {
	border-color: transparent;
	color: oklch(from var(--ids-text-on-dark) l c h / 0.7);
	font-size: var(--ids-font-size-sm);
}

.iec-month-nav .iec-nav-today:hover {
	color: var(--ids-text-on-dark);
	background: oklch(from var(--ids-color-white) l c h / 0.08);
}

.iec-month-label {
	font-weight: 600;
	font-size: 1.15rem;
	min-width: 15ch;
	text-align: center;
}

.iec-category-select {
	/* color-scheme: dark unlocks background-color on macOS Chrome selects,
	   but its UA dark styles require !important to override. */
	appearance: none;
	color-scheme: dark;
	padding: 0.35em 2em 0.35em 0.8em !important;
	border: 1px solid oklch(from var(--ids-color-white) l c h / 0.35) !important;
	border-radius: var(--ids-radius-sm);
	background-color: var(--iec-control-bg) !important;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a0aab4'/%3E%3C/svg%3E") !important;
	background-repeat: no-repeat !important;
	background-position: right 0.6em center !important;
	color: var(--ids-text-on-dark) !important;
	font-size: var(--ids-font-size-sm);
	font-family: inherit;
	cursor: pointer;
}

.iec-category-select option {
	background: oklch(from var(--ids-surface-page) calc(l + 0.10) c h);
	color: var(--ids-text-on-dark);
}

/* ── Month grid ─────────────────────────────────────────────────── */

.iec-month-grid {
	display: grid;
	grid-template-columns: repeat(7, minmax(0, 1fr));
	gap: 1px;
	background: oklch(from var(--ids-border-section) l c h / 0.3);
	border: 1px solid oklch(from var(--ids-border-section) l c h / 0.3);
	border-radius: var(--ids-space-xs);
}

.iec-weekday-header {
	padding: var(--ids-space-xs) var(--ids-space-sm);
	font-weight: 600;
	font-size: 0.85rem;
	text-align: center;
	background: oklch(from var(--ids-surface-page) calc(l - 0.05) c h);
	color: var(--ids-text-on-dark);
}

.iec-day {
	min-height: 5rem;
	padding: var(--ids-space-xs);
	background: var(--ids-surface-page);
	position: relative;
}

.iec-day-number {
	font-size: 0.85rem;
	font-weight: 500;
	color: var(--ids-text-on-dark);
}

.iec-day.iec-today {
	background: oklch(from var(--ids-color-light-blue) l c h / 0.25);
	outline: 2px solid oklch(from var(--ids-color-light-blue) l c h / 0.5);
	outline-offset: -2px;
}

.iec-day.iec-today .iec-day-number {
	font-weight: 700;
	color: oklch(from var(--ids-color-light-blue) calc(l + 0.25) c h);
}

.iec-day.iec-other-month {
	opacity: 0.4;
}

/* ── Day click expansion (month view) ──────────────────────────── */

.iec-day.iec-day-has-events {
	cursor: pointer;
}

.iec-day.iec-day-has-events:hover {
	background: oklch(from var(--ids-accent-primary) l c h / 0.06);
}

.iec-day-expanded {
	grid-column: 1 / -1;
	background: oklch(from var(--ids-surface-page) calc(l - 0.03) c h);
	border: 1px solid oklch(from var(--ids-border-section) l c h / 0.3);
	border-radius: var(--ids-space-xs);
	padding: var(--ids-space-md);
	display: flex;
	flex-direction: column;
	gap: var(--ids-space-sm);
}

.iec-day-expanded-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.iec-day-expanded-header h4 {
	margin: 0;
	font-size: 1rem;
}

.iec-day-expanded-close {
	background: oklch(from var(--ids-surface-page) calc(l + 0.08) c h);
	border: 1px solid oklch(from var(--ids-border-section) l c h / 0.2);
	border-radius: 50%;
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1rem;
	cursor: pointer;
	line-height: 1;
	color: inherit;
	flex-shrink: 0;
}

.iec-day-expanded-close:hover {
	background: oklch(from var(--ids-surface-page) calc(l + 0.15) c h);
}

a.iec-day-detail-item,
a.iec-day-detail-item:visited {
	display: flex;
	align-items: center;
	gap: var(--ids-space-sm);
	padding: var(--ids-space-sm);
	margin: 0 calc(-1 * var(--ids-space-sm));
	border-bottom: 1px solid oklch(from var(--ids-border-section) l c h / 0.15);
	border-radius: var(--ids-space-xs);
	text-decoration: none;
	color: inherit;
	cursor: pointer;
}

a.iec-day-detail-item:hover {
	background: oklch(from var(--ids-surface-page) calc(l + 0.04) c h);
}

a.iec-day-detail-item:last-child {
	border-bottom: none;
}

.iec-day-detail-thumb-link {
	flex-shrink: 0;
	display: block;
	line-height: 0;
	width: 56px;
	height: 56px;
	overflow: hidden;
	border-radius: var(--ids-space-xs);
}

.iec-day-detail-thumb {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
}

.iec-day-detail-body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.iec-day-detail-title {
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.iec-day-detail-meta {
	display: flex;
	align-items: baseline;
	gap: var(--ids-space-sm);
}

.iec-day-detail-time {
	font-size: 0.85rem;
	color: oklch(from var(--ids-text-on-dark) l c h / 0.7);
}

.iec-day-detail-category {
	margin-left: auto;
	font-size: 0.8rem;
	font-style: italic;
	color: oklch(from var(--ids-text-on-dark) l c h / 0.55);
}

.iec-day-detail-location {
	font-size: 0.8rem;
	color: oklch(from var(--ids-text-on-dark) l c h / 0.6);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.iec-day-detail-item.iec-cancelled .iec-day-detail-title {
	text-decoration: line-through;
	opacity: 0.6;
}

/* ── Event pills (month view) ───────────────────────────────────── */

.iec-day-events {
	display: flex;
	flex-direction: column;
	gap: 2px;
	margin-top: var(--ids-space-xs);
}

.iec-calendar a.iec-event-pill {
	--iec-pill-color: var(--ids-accent-primary);
	display: block;
	font-size: 0.75rem;
	font-weight: 600;
	line-height: 1.3;
	padding: 2px var(--ids-space-xs);
	border-radius: 3px;
	color: oklch(0.15 0 0);
	text-decoration: none;
	overflow-wrap: break-word;
	background: oklch(from var(--iec-pill-color) calc(l * 0.85 + 0.25) calc(c * 0.55) h);
}

.iec-calendar a.iec-event-pill:visited {
	color: oklch(0.15 0 0);
}

.iec-calendar a.iec-event-pill:hover {
	background: oklch(from var(--iec-pill-color) calc(l * 0.85 + 0.20) calc(c * 0.55) h);
	color: oklch(0.15 0 0);
}

.iec-event-pill.iec-cancelled {
	opacity: 0.5;
	text-decoration: line-through;
}

/* ── List view ──────────────────────────────────────────────────── */

.iec-event-list {
	display: flex;
	flex-direction: column;
	gap: var(--ids-space-md);
}

.iec-list-month-heading {
	margin: var(--ids-space-sm) 0 0;
	font-size: 1rem;
	font-weight: 600;
	border-bottom: 1px solid oklch(from var(--ids-border-section) l c h / 0.3);
	padding-bottom: var(--ids-space-xs);
}

.iec-list-item {
	display: flex;
	align-items: flex-start;
	gap: var(--ids-space-md);
	padding: var(--ids-space-md);
	border-left: 5px solid transparent;
}

.iec-event-date {
	flex-shrink: 0;
	min-width: 4rem;
	text-align: center;
	font-weight: 600;
}

.iec-list-thumb-wrap {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	overflow: hidden;
	border-radius: var(--ids-space-xs);
}

.iec-list-thumb {
	display: block;
	width: 40px;
	height: 40px;
	max-width: 40px;
	max-height: 40px;
	object-fit: contain;
	border-radius: var(--ids-space-xs);
}

.iec-event-info {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: var(--ids-space-xs);
}

.iec-event-title {
	font-weight: 600;
	text-decoration: none;
}

.iec-event-time {
	font-size: 0.9rem;
}

.iec-event-category {
	margin-left: var(--ids-space-sm);
	font-style: italic;
	font-size: 0.8rem;
}

.iec-event-location {
	font-size: 0.9rem;
}

.iec-list-item.iec-cancelled .iec-event-title {
	text-decoration: line-through;
	opacity: 0.6;
}

.iec-list-item.iec-all-day .iec-event-date::after {
	content: "";
}

/* ── Grid view ──────────────────────────────────────────────────── */

.iec-event-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--ids-space-md);
}

.iec-grid-card {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border-left: 5px solid transparent;
}

/* .iec-grid-hero-link and .iec-grid-hero use shared .iec-card-hero-wrap
   and .iec-card-hero-img classes defined above. */

.iec-grid-hero-placeholder {
	width: 100%;
	aspect-ratio: 16 / 9;
	background: oklch(from var(--ids-surface-page) calc(l + 0.03) c h);
}

.iec-grid-card-body {
	padding: var(--ids-space-sm);
	display: flex;
	flex-direction: column;
	gap: var(--ids-space-xs);
}

.iec-grid-date {
	font-weight: 600;
	font-size: 0.9rem;
}

.iec-grid-card.iec-cancelled h3 a {
	text-decoration: line-through;
	opacity: 0.6;
}

/* ── Category badge ─────────────────────────────────────────────── */

.iec-category-badge {
	display: inline-block;
	padding: 2px var(--ids-space-sm);
	border-radius: var(--ids-space-xs);
	font-size: 0.75rem;
	font-weight: 600;
	color: oklch(from var(--ids-color-white) l c h);
	align-self: flex-start;
}

/* ── Map containers ────────────────────────────────────────────── */

.iec-map {
	height: 300px;
	width: 100%;
	border-radius: var(--ids-space-xs);
}

.iec-map-all {
	height: 450px;
	width: 100%;
	border-radius: var(--ids-space-xs);
}

.iec-map:focus-within,
.iec-map-all:focus-within {
	outline: 2px solid var(--ids-accent-primary);
}

/* ── Directions link ──────────────────────────────────────────── */

.iec-directions-link.ids-btn.ids-btn-sm {
	background: var(--ids-color-light-blue);
	color: var(--ids-color-white);
	border-color: var(--ids-color-light-blue);
	text-decoration: none;
	margin-top: var(--ids-space-xs);
	display: inline-block;
}

.iec-directions-link.ids-btn.ids-btn-sm:hover {
	background: oklch(from var(--ids-color-light-blue) calc(l - 0.08) c h);
	border-color: oklch(from var(--ids-color-light-blue) calc(l - 0.08) c h);
}

/* ── Location archive map/search spacing ─────────────────────────── */
.iec-location-archive-header .iec-map-all {
	margin-bottom: 1rem;
}

/* ── Subscribe panel ───────────────────────────────────────────── */

.iec-subscribe-panel {
	display: flex;
	align-items: center;
	gap: var(--ids-space-sm);
	margin-left: auto;
}

.iec-subscribe-panel .ids-btn-ghost {
	border-color: transparent;
	color: oklch(from var(--ids-text-on-dark) l c h / 0.7);
	font-size: var(--ids-font-size-sm);
}

.iec-subscribe-panel .ids-btn-ghost:hover {
	color: var(--ids-text-on-dark);
	background: oklch(from var(--ids-color-white) l c h / 0.08);
}

/* ── Single event page: theme overrides ────────────────────────── */

body.single-event .wp-block-post-featured-image {
	aspect-ratio: auto !important;
	/* Mirror .iec-card-hero-wrap — can't add classes to theme block markup. */
	display: flex;
	align-items: center;
	justify-content: center;
}

body.single-event .wp-block-post-featured-image img {
	/* Mirror .iec-card-hero-img — never crop, constrain height, center. */
	display: block;
	max-width: 100%;
	max-height: 300px;
	width: auto;
	height: auto;
}

body.single-event .wp-block-post-date {
	display: none;
}

body.single-event .wp-block-post-content {
	max-width: 720px;
	margin-left: auto;
	margin-right: auto;
}

/* ── Back to calendar link (outside the card) ─────────────────── */

.iec-back-to-calendar {
	display: inline-block;
	font-size: var(--ids-font-size-sm);
	color: oklch(from var(--ids-text-on-dark) l c h / 0.6);
	text-decoration: none;
	margin-bottom: var(--ids-space-xs);
}

.iec-back-to-calendar:hover {
	color: var(--ids-text-on-dark);
}

.iec-back-to-calendar::before {
	content: "\2190\00a0";
}

/* ── Event meta card ──────────────────────────────────────────── */

.iec-event-meta.ids-card {
	padding: 1rem 1rem 1rem 1.5rem;
	border-left: 4px solid transparent;
	border-radius: var(--ids-space-xs);
	background: oklch(from var(--ids-surface-page) calc(l + 0.03) c h);
	display: flex;
	flex-direction: column;
	gap: var(--ids-space-md);
}

.iec-event-meta .iec-meta-section {
	display: flex;
	flex-direction: column;
	gap: var(--ids-space-xs);
}

.iec-event-meta .iec-event-datetime {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.25rem 0.5rem;
}

.iec-event-meta .iec-event-datetime .iec-category-label {
	margin-left: auto;
}

.iec-event-meta .iec-event-location-detail {
	margin-top: 0.5rem;
}

.iec-event-meta .iec-location-name {
	font-size: 1.1em;
	font-weight: 600;
	color: var(--ids-color-light-blue);
}

.iec-event-meta .iec-map {
	height: 200px;
}

.iec-event-meta .iec-event-actions {
	display: flex;
	gap: var(--ids-space-md);
	align-items: center;
}

.iec-event-meta .iec-event-actions a {
	color: oklch(from var(--ids-accent-primary) calc(l + 0.15) c h);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.iec-event-meta .iec-event-actions a:hover {
	color: var(--ids-text-on-dark);
}

/* ── Event actions (Download / Subscribe) ─────────────────────── */

.iec-event-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--ids-space-sm);
}

/* ── Ghost button contrast fix for dark theme ────────────────────── */
.iec-event-actions .ids-btn-ghost,
.iec-location-meta .ids-btn-ghost {
	color: oklch(from var(--ids-surface-page) calc(l + 0.50) c h);
	border-color: oklch(from var(--ids-surface-page) calc(l + 0.45) c h);
}

.iec-event-actions .ids-btn-ghost:hover,
.iec-location-meta .ids-btn-ghost:hover {
	background: oklch(from var(--ids-surface-page) calc(l + 0.10) c h);
}

/* ── Error message ──────────────────────────────────────────────── */

.iec-error {
	text-align: center;
}

/* ── Container queries: calendar component responds to its width ── */

@container iec-calendar (max-width: 768px) {
	.iec-event-grid {
		grid-template-columns: repeat(2, 1fr);
	}

	.iec-day {
		min-height: 3.5rem;
	}
}

@container iec-calendar (max-width: 600px) {
	.iec-calendar a.iec-event-pill {
		font-size: 0;
		width: 8px;
		height: 8px;
		border-radius: 50%;
		padding: 0;
		display: inline-block;
		background: var(--iec-pill-color);
		pointer-events: none;
	}

	.iec-day-events {
		flex-direction: row;
		flex-wrap: wrap;
		gap: 3px;
	}

	.iec-calendar a.iec-event-pill:focus-visible {
		outline: none;
	}
}

@container iec-calendar (max-width: 480px) {
	/* Reduce header gap for compact layout */
	.iec-calendar-header {
		gap: var(--ids-space-xs);
	}

	/* ── Row 1 header: month nav stacks above view switcher ── */
	.iec-header-row:first-child {
		flex-direction: column;
		align-items: stretch;
	}

	.iec-month-nav {
		justify-content: center;
	}

	/* Full-width view switcher, hide Grid button */
	.iec-view-switcher {
		align-self: stretch;
	}

	.iec-view-btn[data-view="grid"] {
		display: none;
	}

	.iec-view-btn {
		flex: 1;
	}

	/* ── Row 2 header: category + subscribe side by side ── */
	.iec-header-row:last-child {
		flex-direction: row;
		align-items: flex-end;
	}

	.iec-category-label {
		flex: 1;
	}

	.iec-category-label select {
		width: 100%;
	}

	/* Hide "Subscribe" text, show only emoji at larger touch-friendly size */
	.iec-subscribe-label {
		display: none;
	}

	.iec-subscribe-panel .iec-subscribe-webcal {
		font-size: 1.5rem;
		padding: var(--ids-space-xs);
	}

	.iec-subscribe-panel {
		margin-left: auto;
	}

	/* ── Calendar body compact adjustments (unchanged from current) ── */
	.iec-event-grid {
		grid-template-columns: 1fr;
	}

	.iec-month-grid .iec-weekday-header {
		font-size: 0.7rem;
		padding: var(--ids-space-xs) 2px;
	}

	.iec-day {
		min-height: 2.5rem;
		padding: 2px;
	}

	.iec-day-number {
		font-size: 0.75rem;
	}

	.iec-list-item {
		flex-direction: column;
		gap: 0;
		padding: 0;
	}

	.iec-list-item .iec-event-date {
		order: 1;
		min-width: unset;
		text-align: left;
		padding: var(--ids-space-sm) var(--ids-space-sm) 0;
	}

	/* Narrow list items display as cards — image fills width, constrained height, no crop. */
	.iec-list-item .iec-list-thumb-wrap {
		order: 0;
		width: 100%;
		height: auto;
		border-radius: 0;
		overflow: hidden;
	}

	.iec-list-item .iec-list-thumb {
		width: 100%;
		height: auto;
		max-width: 100%;
		max-height: 12rem;
		object-fit: contain;
		border-radius: 0;
	}

	.iec-list-item .iec-event-info {
		order: 2;
		padding: 0 var(--ids-space-sm) var(--ids-space-sm);
	}
}

/* ── Focus styles ──────────────────────────────────────────────── */

.iec-event-pill:focus-visible,
.iec-event-title:focus-visible,
.iec-directions-link:focus-visible,
.iec-add-to-cal:focus-visible,
.iec-subscribe-webcal:focus-visible,
.iec-copy-url:focus-visible {
	outline: 2px solid var(--ids-accent-primary);
	outline-offset: 2px;
}

/* ── Admin: recurrence notices ─────────────────────────────────── */

.iec-recurrence-notice p {
	font-size: 14px;
}

.iec-recurrence-actions .button {
	margin-bottom: var(--ids-space-xs, 4px);
}

.iec-recurrence-result .notice {
	margin: var(--ids-space-sm, 8px) 0 0;
}

/* ── Map responsive sizing ─────────────────────────────────────── */

@media (max-width: 480px) {
	.iec-map {
		height: 220px;
	}

	.iec-map-all {
		height: 300px;
	}
}

/* ── Screen reader text ────────────────────────────────────────── */

.screen-reader-text {
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	width: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	word-wrap: normal;
}
