/**
 * Add to Calendar Button Styles
 * Frontend stylesheet for Listeo Add to Calendar plugin
 *
 * Theme colour is injected via PHP as --listeo-atc-color / --listeo-atc-color-rgb.
 * Falls back to the Listeo CSS variable, then to the default brand red.
 */

/* =============================================
   CSS Variables
   ============================================= */
:root {
    --listeo-atc-color:     var(--listeo-primary-color, #f91942);
    --listeo-atc-color-rgb: 249, 25, 66;
}

/* =============================================
   Container
   ============================================= */
.listeo-add-to-calendar {
    position: relative;
    display: inline-block;
    /* z-index: auto keeps the container OUT of the stacking context so the
       portal-positioned dropdown (appended to <body>) can use its own z-index
       without being trapped by an ancestor context. */
    z-index: auto;
}

/* =============================================
   Main Button
   ============================================= */
.listeo-add-to-calendar-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 22px;
    font-size: 14px;
    font-weight: 600;
    line-height: 26px;
    cursor: pointer;
    border-radius: 50px;
    transition: all 0.2s ease-in-out;
    border: none;
    outline: none;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.listeo-add-to-calendar-btn:focus-visible {
    outline: 2px solid var(--listeo-atc-color);
    outline-offset: 2px;
}

.listeo-add-to-calendar-btn::before {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background-color: #fff;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    transition: opacity 0.2s;
    border-radius: 50px;
}

.listeo-add-to-calendar-btn:hover::before {
    opacity: 0.1;
}

/* Primary */
.listeo-add-to-calendar.style-primary .listeo-add-to-calendar-btn {
    background-color: var(--listeo-atc-color);
    color: #fff;
    border: none;
}

/* Secondary */
.listeo-add-to-calendar.style-secondary .listeo-add-to-calendar-btn {
    background-color: transparent;
    color: var(--listeo-atc-color);
    border: 1px solid var(--listeo-atc-color);
}

.listeo-add-to-calendar.style-secondary .listeo-add-to-calendar-btn::before {
    display: none;
}

.listeo-add-to-calendar.style-secondary .listeo-add-to-calendar-btn:hover {
    background-color: var(--listeo-atc-color);
    color: #fff;
}

/* Minimal */
.listeo-add-to-calendar.style-minimal .listeo-add-to-calendar-btn {
    background-color: transparent;
    color: var(--listeo-atc-color);
    border: none;
    padding: 8px 12px;
    font-weight: 500;
}

.listeo-add-to-calendar.style-minimal .listeo-add-to-calendar-btn::before {
    display: none;
}

.listeo-add-to-calendar.style-minimal .listeo-add-to-calendar-btn:hover {
    background-color: rgba(var(--listeo-atc-color-rgb), 0.08);
}

/* =============================================
   SVG Icons
   ============================================= */
.listeo-add-to-calendar-btn .calendar-icon,
.listeo-add-to-calendar-btn .dropdown-arrow {
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.listeo-add-to-calendar-btn > span {
    position: relative;
    z-index: 1;
}

.listeo-add-to-calendar-btn .dropdown-arrow {
    transition: transform 0.25s ease;
    margin-left: 2px;
}

.listeo-add-to-calendar.open .dropdown-arrow {
    transform: rotate(180deg);
}

/* =============================================
   Dropdown Panel
   ============================================= */
.listeo-calendar-dropdown {
    position: absolute;
    top: 100%;
    left: 0;

    /*
     * z-index 9999 — above Listeo's sticky header (~999) and any overlay
     * elements.  When the portal pattern moves the dropdown to <body>, this
     * value is scoped to the document root stacking context (highest possible),
     * so it wins over every theme element without !important spam.
     */
    z-index: 9999;

    min-width: 260px;
    margin-top: 8px;
    padding: 0;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);

    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

/*
 * Open state used when dropdown is in its original DOM position
 * (triggered by .open on the parent container).
 */
.listeo-add-to-calendar.open .listeo-calendar-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/*
 * Open state used when dropdown has been portal-ed to <body>.
 * The .open class on the container no longer selects it, so we use a
 * class directly on the dropdown element.
 */
.listeo-calendar-dropdown.atc-portal-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Dropdown position variants (in-DOM mode only) */
.listeo-add-to-calendar[data-position="top"] .listeo-calendar-dropdown {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 8px;
}

.listeo-add-to-calendar[data-position="right"] .listeo-calendar-dropdown {
    top: 0;
    left: 100%;
    margin-top: 0;
    margin-left: 8px;
}

.listeo-add-to-calendar[data-position="left"] .listeo-calendar-dropdown {
    top: 0;
    left: auto;
    right: 100%;
    margin-top: 0;
    margin-right: 8px;
}

/* =============================================
   Dropdown Header
   ============================================= */
.calendar-dropdown-header {
    padding: 16px 20px 14px;
    border-bottom: 1px solid #eee;
}

.calendar-dropdown-header strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.calendar-dropdown-header .event-date,
.calendar-dropdown-header .event-time {
    display: block;
    font-size: 13px;
    color: #888;
    line-height: 1.5;
    font-weight: 500;
}

.calendar-dropdown-header .event-time {
    color: var(--listeo-atc-color);
    font-weight: 600;
}

/* =============================================
   Calendar Options List
   ============================================= */
.calendar-options {
    list-style: none;
    margin: 0;
    padding: 6px 0;
}

.calendar-options li {
    margin: 0;
}

.calendar-options a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #555;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease;
    border: none;
}

.calendar-options a:hover {
    background-color: #f8f8f8;
    color: #333;
}

.calendar-options a:focus-visible {
    outline: none;
    background-color: rgba(var(--listeo-atc-color-rgb), 0.06);
    color: var(--listeo-atc-color);
}

.calendar-provider-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.calendar-options span {
    font-size: 14px;
    font-weight: 500;
}

/* =============================================
   Staggered animation on open
   ============================================= */
.calendar-options li {
    opacity: 0;
    transform: translateX(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.listeo-add-to-calendar.open .calendar-options li,
.atc-portal-open .calendar-options li {
    opacity: 1;
    transform: translateX(0);
}

.listeo-add-to-calendar.open .calendar-options li:nth-child(1),
.atc-portal-open .calendar-options li:nth-child(1) { transition-delay: 0.04s; }

.listeo-add-to-calendar.open .calendar-options li:nth-child(2),
.atc-portal-open .calendar-options li:nth-child(2) { transition-delay: 0.07s; }

.listeo-add-to-calendar.open .calendar-options li:nth-child(3),
.atc-portal-open .calendar-options li:nth-child(3) { transition-delay: 0.10s; }

.listeo-add-to-calendar.open .calendar-options li:nth-child(4),
.atc-portal-open .calendar-options li:nth-child(4) { transition-delay: 0.13s; }

.listeo-add-to-calendar.open .calendar-options li:nth-child(5),
.atc-portal-open .calendar-options li:nth-child(5) { transition-delay: 0.16s; }

.listeo-add-to-calendar.open .calendar-options li:nth-child(6),
.atc-portal-open .calendar-options li:nth-child(6) { transition-delay: 0.19s; }

/* =============================================
   Sidebar / Widget integration
   ============================================= */
.listing-widget .listeo-add-to-calendar,
.boxed-widget.listeo-atc-widget .listeo-add-to-calendar {
    display: block;
    margin-top: 10px;
}

.listing-widget .listeo-add-to-calendar-btn,
.boxed-widget.listeo-atc-widget .listeo-add-to-calendar-btn {
    width: 100%;
    justify-content: center;
}

/* Ensure the widget container never clips the portal dropdown */
.boxed-widget.listeo-atc-widget {
    overflow: visible;
}

.listing-sidebar .listeo-add-to-calendar {
    display: block;
    overflow: visible;
}

.listing-sidebar .listeo-add-to-calendar-btn {
    width: 100%;
    justify-content: center;
}

/* =============================================
   Navigation area integration
   ============================================= */
.listeo-atc-nav-item {
    display: inline-block;
    margin-right: 10px;
}

.listeo-atc-nav-item .listeo-add-to-calendar-btn {
    padding: 6px 16px;
    font-size: 13px;
    line-height: 22px;
}

/* =============================================
   Content wrapper (fallback / after-content)
   ============================================= */
.listeo-atc-content-wrapper {
    margin: 20px 0;
}

/* =============================================
   Archive Listing Card Integration
   ============================================= */
.listeo-atc-archive-wrapper {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

.listeo-atc-archive-wrapper .listeo-add-to-calendar {
    display: block;
}

.listeo-atc-archive-wrapper .listeo-add-to-calendar-btn {
    padding: 6px 10px;
    font-size: 12px;
    line-height: 18px;
    border-radius: 4px;
}

.listing-card-nl .listeo-atc-archive-wrapper {
    border-top: none;
    padding-top: 0;
    margin-top: 8px;
}

.details-sidebar-col-nl .listeo-atc-archive-wrapper {
    margin-top: auto;
}

.listing-compact .listeo-atc-archive-wrapper,
.compact-layout .listeo-atc-archive-wrapper {
    margin-top: 8px;
    padding-top: 8px;
}

.list-layout .listeo-atc-archive-wrapper {
    margin-top: 10px;
}

/* =============================================
   Dark Mode Support
   ============================================= */
body#dark-mode .listeo-calendar-dropdown {
    background-color: #2a2a2a;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

body#dark-mode .calendar-dropdown-header {
    border-bottom-color: #3a3a3a;
}

body#dark-mode .calendar-dropdown-header strong {
    color: #eee;
}

body#dark-mode .calendar-dropdown-header .event-date {
    color: #999;
}

body#dark-mode .calendar-options a {
    color: #ccc;
}

body#dark-mode .calendar-options a:hover {
    background-color: #333;
    color: #fff;
}

body#dark-mode .calendar-provider-icon.apple path {
    fill: #fff;
}

body#dark-mode .calendar-provider-icon.ics {
    stroke: #ccc;
}

/* =============================================
   Mobile — bottom-sheet
   ============================================= */
@media (max-width: 480px) {
    .listeo-calendar-dropdown:not(.atc-portal-open) {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        margin: 0;
        border-radius: 12px 12px 0 0;
        transform: translateY(100%);
        max-height: 70vh;
        overflow-y: auto;
    }

    .listeo-add-to-calendar.open .listeo-calendar-dropdown:not(.atc-portal-open) {
        transform: translateY(0);
    }

    .calendar-dropdown-header {
        padding: 20px 20px 16px;
    }

    .calendar-options a {
        padding: 14px 20px;
    }

    /* Backdrop on mobile */
    .listeo-add-to-calendar.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 9998;
    }
}

/* =============================================
   Print
   ============================================= */
@media print {
    .listeo-add-to-calendar {
        display: none;
    }
}
