/* ==========================================================================
   OurVoteToday — Events Page Stylesheet
   Loaded conditionally on /events and /events/{id} via inc/events.php.
   Reuses design tokens from main.css (--ovt-*, --space-*, etc).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Page container
   -------------------------------------------------------------------------- */
.events-page {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: calc(var(--header-height) + var(--space-lg)) var(--space-sm) var(--space-xl);
}

.events-page__header {
    text-align: center;
    margin-bottom: var(--space-lg);
}

.events-page__title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: clamp(2.5rem, 5vw + 1rem, 4.5rem);
    line-height: 1;
    color: var(--ovt-navy);
    margin: var(--space-xs) 0;
    text-transform: uppercase;
    letter-spacing: -0.01em;
}

.events-page__subtitle {
    font-size: 1.125rem;
    color: rgba(27, 47, 110, 0.72);
    max-width: 40rem;
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Location bar — find events near user (Phase 1)
   -------------------------------------------------------------------------- */
.events-location {
    margin: 0 auto var(--space-md);
    max-width: 720px;
    padding: 0 var(--space-sm);
}

.events-location__form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-sm);
    justify-content: center;
}

.events-location__label {
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--ovt-navy);
    white-space: nowrap;
}

.events-location__input-wrap {
    display: flex;
    flex: 1 1 320px;
    min-width: 0;
    border: 1px solid rgba(27, 47, 110, 0.22);
    border-radius: var(--radius-pill);
    background: #fff;
    overflow: hidden;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.events-location__input-wrap:focus-within {
    border-color: var(--ovt-navy);
    box-shadow: 0 0 0 3px rgba(245, 197, 24, 0.35);
}

.events-location__input {
    flex: 1;
    min-width: 0;
    padding: 0.6rem 1rem;
    border: 0;
    background: transparent;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--ovt-navy);
}

.events-location__input::placeholder {
    color: rgba(27, 47, 110, 0.45);
}

.events-location__input:focus {
    outline: none;
}

.events-location__submit {
    padding: 0.6rem 1.1rem;
    border: 0;
    background: var(--ovt-navy);
    color: var(--ovt-cream);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.events-location__submit:hover,
.events-location__submit:focus-visible {
    background: var(--ovt-dark-navy, #0F1F4A);
    outline: none;
}

.events-location__submit:disabled {
    opacity: 0.55;
    cursor: progress;
}

.events-location__geolocate {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border: 1px solid rgba(27, 47, 110, 0.22);
    border-radius: var(--radius-pill);
    background: transparent;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--ovt-navy);
    cursor: pointer;
    transition: border-color 120ms ease, background-color 120ms ease;
}

.events-location__geolocate:hover,
.events-location__geolocate:focus-visible {
    border-color: var(--ovt-navy);
    background: rgba(245, 197, 24, 0.08);
    outline: none;
}

.events-location__geolocate:focus-visible {
    outline: 3px solid var(--ovt-gold);
    outline-offset: 2px;
}

.events-location__geolocate:disabled {
    opacity: 0.55;
    cursor: progress;
}

.events-location__geo-icon {
    flex-shrink: 0;
    color: var(--ovt-teal, var(--ovt-navy));
}

.events-location__status {
    margin: 0.6rem 0 0;
    min-height: 1.4em;
    text-align: center;
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: rgba(27, 47, 110, 0.75);
}

.events-location__status[data-state="active"] {
    color: var(--ovt-navy);
    font-weight: 500;
}

.events-location__status[data-state="error"] {
    color: var(--ovt-red, #E8341A);
}

.events-location__clear {
    margin-left: 0.25rem;
    padding: 0.15rem 0.6rem;
    border: 1px solid currentColor;
    border-radius: var(--radius-pill);
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.events-location__clear:hover,
.events-location__clear:focus-visible {
    background: rgba(245, 197, 24, 0.15);
    outline: none;
}

@media (max-width: 640px) {
    .events-location__form {
        flex-direction: column;
        align-items: stretch;
    }
    .events-location__label {
        text-align: center;
    }
    .events-location__input-wrap,
    .events-location__geolocate {
        width: 100%;
        justify-content: center;
        /* Column-direction flex makes flex-basis the *height* — without
           resetting, `flex: 1 1 320px` from the desktop rule turns the
           input-wrap into a 320x320 square, and the pill radius clamps
           it into a sphere. (Yes, really.) */
        flex: 0 0 auto;
    }
}

/* --------------------------------------------------------------------------
   Filters
   -------------------------------------------------------------------------- */
.events-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    justify-content: center;
    margin-bottom: var(--space-md);
}

.events-filters__group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    align-items: center;
}

.events-filter__chip {
    display: inline-block;
    padding: 0.5rem 1.1rem;
    border: 1px solid rgba(27, 47, 110, 0.22);
    border-radius: var(--radius-pill);
    background: transparent;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--ovt-navy);
    text-decoration: none;
    transition:
        background var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out),
        color var(--duration-fast) var(--ease-out);
}

.events-filter__chip:hover,
.events-filter__chip:focus-visible {
    border-color: var(--ovt-navy);
    background: rgba(245, 197, 24, 0.08);
    outline: none;
}

.events-filter__chip:focus-visible {
    outline: 3px solid var(--ovt-gold);
    outline-offset: 2px;
}

.events-filter__chip--active {
    background: var(--ovt-navy);
    border-color: var(--ovt-navy);
    color: var(--ovt-cream);
}

.events-filter__chip--clear {
    background: transparent;
    border-style: dashed;
    color: rgba(27, 47, 110, 0.72);
}

.events-filter__chip--apply {
    background: var(--ovt-navy);
    border-color: var(--ovt-navy);
    color: var(--ovt-cream);
}

.events-filter__chip--apply:hover,
.events-filter__chip--apply:focus-visible {
    background: var(--ovt-dark-navy, #0F1F4A);
    border-color: var(--ovt-dark-navy, #0F1F4A);
}

.events-filters__custom-range {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-sm);
    justify-content: center;
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.75rem var(--space-sm);
    border-radius: 10px;
    background: rgba(245, 242, 236, 0.6);
}

.events-filters__custom-range[hidden] {
    display: none;
}

.events-filters__date-label {
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ovt-navy);
}

.events-filters__date-label input[type="date"] {
    padding: 0.4rem 0.6rem;
    border: 1px solid rgba(27, 47, 110, 0.22);
    border-radius: 8px;
    background: #fff;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--ovt-navy);
}

.events-filters__date-label input[type="date"]:focus {
    border-color: var(--ovt-navy);
    outline: 3px solid var(--ovt-gold);
    outline-offset: 1px;
}

.events-filters__legacy-note {
    width: 100%;
    margin: 0;
    text-align: center;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: rgba(27, 47, 110, 0.72);
}

.events-filters__legacy-note a {
    margin-left: 0.4rem;
    color: var(--ovt-navy);
    font-weight: 600;
    text-decoration: underline;
}

/* Rename the old Location empty-state class to the unified one */
.events-filter__empty {
    margin: 0 0 var(--space-md);
    padding: var(--space-md);
    border: 1px dashed rgba(27, 47, 110, 0.3);
    border-radius: 10px;
    background: rgba(245, 242, 236, 0.6);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: rgba(27, 47, 110, 0.8);
    text-align: center;
}

/* --------------------------------------------------------------------------
   Layout: map + list
   -------------------------------------------------------------------------- */
.events-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: var(--space-md);
    align-items: start;
}

/* --------------------------------------------------------------------------
   Map
   -------------------------------------------------------------------------- */
.events-layout__map {
    position: sticky;
    top: calc(var(--header-height) + var(--space-sm));
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 10px 30px -12px rgba(15, 31, 74, 0.18);
}

.events-map {
    width: 100%;
    height: min(70vh, 640px);
    background: var(--ovt-cream);
}

/* Leaflet visual tuning — muted palette for editorial feel */
.leaflet-container {
    font-family: var(--font-body);
    background: #eef0eb;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px -4px rgba(15, 31, 74, 0.24);
}

.leaflet-popup-content {
    font-family: var(--font-body);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--ovt-navy);
    margin: 0.75rem 1rem;
}

.leaflet-popup-content strong {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1rem;
    text-transform: uppercase;
    color: var(--ovt-navy);
}

/* --------------------------------------------------------------------------
   Event list
   -------------------------------------------------------------------------- */
.events-layout__list {
    max-height: min(70vh, 640px);
    overflow-y: auto;
    padding-right: var(--space-xs);
    scroll-behavior: smooth;
}

.events-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.events-list__row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--ovt-white);
    border: 1px solid rgba(27, 47, 110, 0.1);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition:
        background var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out),
        transform var(--duration-fast) var(--ease-out);
}

.events-list__row:hover {
    background: rgba(245, 197, 24, 0.05);
    border-color: rgba(245, 197, 24, 0.35);
    transform: translateY(-1px);
}

.events-list__row:focus-visible {
    outline: 3px solid var(--ovt-gold);
    outline-offset: 2px;
}

.events-list__row.is-active {
    background: rgba(27, 47, 110, 0.04);
    border-color: var(--ovt-navy);
}

.events-list__thumb {
    grid-row: 1 / -1;
    width: 84px;
    height: 84px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--ovt-cream);
}

.events-list__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.events-list__body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.events-list__date {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ovt-gold);
    margin: 0;
}

.events-list__date time {
    color: inherit;
}

.events-list__time {
    display: inline-block;
    margin-left: 0.5rem;
    color: rgba(27, 47, 110, 0.72);
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
}

.events-list__title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.375rem;
    line-height: 1.1;
    color: var(--ovt-navy);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: -0.005em;
    /* Prevent long titles from breaking layout */
    overflow-wrap: anywhere;
}

.events-list__location {
    font-size: 0.875rem;
    color: rgba(27, 47, 110, 0.72);
    margin: 0;
}

.events-list__no-map {
    font-size: 0.75rem;
    font-style: italic;
    color: rgba(27, 47, 110, 0.5);
}

.events-list__excerpt {
    font-size: 0.875rem;
    line-height: 1.5;
    color: rgba(27, 47, 110, 0.8);
    margin: 0.25rem 0 0;
    /* Limit to 2 lines visually as a backstop in case wp_trim_words misses */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.events-list__meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    align-items: center;
    justify-content: space-between;
    margin: 0.25rem 0 0;
}

.events-list__type-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: rgba(0, 168, 168, 0.12);
    color: var(--ovt-teal);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.events-list__website {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ovt-navy);
    text-decoration: none;
}

.events-list__website:hover {
    color: var(--ovt-gold);
}

/* --------------------------------------------------------------------------
   Empty states
   -------------------------------------------------------------------------- */
.events-empty {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    background: var(--ovt-white);
    border: 1px dashed rgba(27, 47, 110, 0.2);
    border-radius: var(--radius-md);
}

.events-empty__title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.75rem;
    text-transform: uppercase;
    color: var(--ovt-navy);
    margin: 0 0 var(--space-xs);
}

.events-empty__body {
    font-size: 1rem;
    color: rgba(27, 47, 110, 0.72);
    max-width: 28rem;
    margin: 0 auto var(--space-sm);
}

/* --------------------------------------------------------------------------
   Event detail drawer (native <dialog>)
   -------------------------------------------------------------------------- */

/*
 * Dialog closed state (base). The native `display: none` behavior kicks in
 * automatically when the `open` attribute is absent; we override display to
 * enable open/close animations via `transition-behavior: allow-discrete`.
 */
.event-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(480px, 100%);
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    padding: 0;
    border: none;
    background: var(--ovt-cream);
    color: var(--ovt-navy);
    box-shadow: -20px 0 60px -20px rgba(15, 31, 74, 0.35);
    overflow-y: auto;
    overscroll-behavior: contain;

    /* Animation base state */
    transform: translateX(100%);
    opacity: 0;
    transition:
        transform var(--duration-med) var(--ease-out),
        opacity var(--duration-med) var(--ease-out),
        overlay var(--duration-med) allow-discrete,
        display var(--duration-med) allow-discrete;
}

.event-drawer[open] {
    transform: translateX(0);
    opacity: 1;
}

/*
 * Starting state for the entry animation. When the dialog transitions
 * from closed → open, browsers apply @starting-style values for one
 * frame so the transition has something to animate from.
 */
@starting-style {
    .event-drawer[open] {
        transform: translateX(100%);
        opacity: 0;
    }
}

.event-drawer::backdrop {
    background: rgba(15, 31, 74, 0);
    transition:
        background var(--duration-med) var(--ease-out),
        overlay var(--duration-med) allow-discrete,
        display var(--duration-med) allow-discrete;
}

.event-drawer[open]::backdrop {
    background: rgba(15, 31, 74, 0.48);
    backdrop-filter: blur(2px);
}

@starting-style {
    .event-drawer[open]::backdrop {
        background: rgba(15, 31, 74, 0);
    }
}

.event-drawer__close {
    position: sticky;
    top: 0;
    right: 0;
    margin-left: auto;
    display: block;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--ovt-navy);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
}

.event-drawer__close:hover,
.event-drawer__close:focus-visible {
    color: var(--ovt-red);
    outline: none;
}

.event-drawer__close:focus-visible {
    outline: 3px solid var(--ovt-gold);
    outline-offset: -6px;
    border-radius: var(--radius-sm);
}

.event-drawer__body {
    padding: 0 var(--space-md) var(--space-md);
    margin-top: -44px; /* pull content up under the absolute close button */
}

.event-drawer__eyebrow {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    background: rgba(0, 168, 168, 0.12);
    color: var(--ovt-teal);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: var(--space-md) 0 var(--space-sm);
}

.event-drawer__title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: clamp(1.75rem, 3vw + 0.5rem, 2.5rem);
    line-height: 1.05;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    color: var(--ovt-navy);
    margin: 0 0 var(--space-xs);
    overflow-wrap: anywhere;
}

.event-drawer__when {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.9375rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ovt-gold);
    margin: 0 0 var(--space-md);
}

.event-drawer__image {
    margin: 0 0 var(--space-md);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(27, 47, 110, 0.06);
}

.event-drawer__image img {
    width: 100%;
    height: auto;
    display: block;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.event-drawer__where {
    font-size: 0.9375rem;
    color: rgba(27, 47, 110, 0.85);
    margin: 0 0 var(--space-sm);
}

.event-drawer__where strong {
    display: inline-block;
    margin-right: 0.25rem;
    font-weight: 700;
    color: var(--ovt-navy);
}

.event-drawer__description {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--ovt-navy);
    margin: 0 0 var(--space-md);
}

.event-drawer__description p {
    margin: 0 0 var(--space-sm);
}

.event-drawer__description p:last-child {
    margin-bottom: 0;
}

.event-drawer__actions {
    margin: var(--space-md) 0 0;
}

.event-drawer__actions .btn {
    display: inline-block;
    padding: 0.65rem 1.25rem;
    border: 1px solid var(--ovt-navy);
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--ovt-navy);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.875rem;
    text-decoration: none;
    transition:
        background var(--duration-fast) var(--ease-out),
        color var(--duration-fast) var(--ease-out);
}

.event-drawer__actions .btn:hover,
.event-drawer__actions .btn:focus-visible {
    background: var(--ovt-navy);
    color: var(--ovt-cream);
    outline: none;
}

/* Mobile: bottom sheet instead of right drawer */
@media (max-width: 768px) {
    .event-drawer {
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: auto;
        max-height: 90vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
        box-shadow: 0 -20px 60px -20px rgba(15, 31, 74, 0.35);
    }
    .event-drawer[open] {
        transform: translateY(0);
    }
    @starting-style {
        .event-drawer[open] {
            transform: translateY(100%);
        }
    }
    .event-drawer__body {
        padding: 0 var(--space-sm) var(--space-md);
    }
    .event-drawer__title {
        font-size: 1.625rem;
    }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .event-drawer,
    .event-drawer::backdrop {
        transition-duration: 0.01ms;
    }
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .events-layout {
        grid-template-columns: 1fr;
    }
    .events-layout__map {
        position: static;
    }
    .events-map {
        height: 60vh;
    }
    .events-layout__list {
        max-height: none;
        overflow: visible;
        padding-right: 0;
    }
}

@media (max-width: 768px) {
    .events-page {
        padding: calc(var(--header-height) + var(--space-md)) var(--space-sm) var(--space-lg);
    }
    .events-filters {
        gap: var(--space-sm);
    }
    .events-list__row {
        grid-template-columns: 1fr;
    }
    .events-list__thumb {
        width: 100%;
        height: 180px;
        grid-row: auto;
    }
}
