/**
 * Ticket Tailor - Frontend Styles
 * Version: 5.0.0 - FSE Compatible (Removed !important overuse)
 * This version maintains functionality while allowing theme customization
 */

/* ============================================
   BASE LAYOUT - 220px CARDS (FSE Compatible)
   ============================================ */

/* Grid layouts - using specificity instead of !important */
.tt-event-listing.tt-layout-grid,
.tt-event-listing.tt-layout-grid.tt-columns-3,
.tt-event-listing.tt-layout-grid[style*="grid-template-columns"],
.tt-event-listing.tt-columns-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, 220px);
    gap: 3rem;
    justify-content: center;
    align-items: stretch;
    grid-auto-rows: 1fr;
    max-width: 100%;
}

/* Specific column counts */
.tt-event-listing.tt-layout-grid.tt-columns-5 {
    grid-template-columns: repeat(5, 220px);
}

.tt-event-listing.tt-layout-grid.tt-columns-4 {
    grid-template-columns: repeat(4, 220px);
}

.tt-event-listing.tt-layout-grid.tt-columns-3 {
    grid-template-columns: repeat(3, 220px);
}

.tt-event-listing.tt-layout-grid.tt-columns-2 {
    grid-template-columns: repeat(2, 220px);
}

/* Event card base styles */
.tt-event-listing .tt-event-card {
    width: 220px;
    max-width: 220px;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid #e1e1e1;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    height: 100%;
}

.tt-event-listing .tt-event-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
    border-color: #d1d1d1;
}

/* Image container with white background */
.tt-event-listing .tt-event-image {
    width: 220px;
    max-width: 220px;
    height: 147px;
    position: relative;
    overflow: hidden;
    background: #ffffff;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Use contain for thumbnails to prevent cropping */
.tt-event-listing .tt-event-image.tt-image-thumbnail img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    transition: transform 0.3s ease;
    padding: 10px;
}

/* Keep cover for header/banner images */
.tt-event-listing .tt-event-image.tt-image-header img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: transform 0.3s ease;
    padding: 0;
}

/* Default for images without specific class */
.tt-event-listing .tt-event-image img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    transition: transform 0.3s ease;
    padding: 10px;
}

.tt-event-listing .tt-event-card:hover .tt-event-image img {
    transform: scale(1.05);
}

/* Content area */
.tt-event-listing .tt-event-content {
    width: 220px;
    max-width: 220px;
    display: flex;
    flex-direction: column;
    padding: 0.875rem;
    flex: 1;
    box-sizing: border-box;
}

/* ============================================
   EVENT LISTING STYLES
   ============================================ */
.tt-event-listing {
    margin: 2rem auto;
    max-width: 100%;
}

/* Event Listing Wrapper */
.tt-event-listing-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Full Width Wrapper */
.tt-full-width {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.tt-full-width .tt-event-listing {
    max-width: 100%;
    padding: 0 1rem;
}

/* List Layout */
.tt-event-listing.tt-layout-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
}

.tt-event-listing.tt-layout-list .tt-event-card {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.5rem;
    max-width: 900px;
    width: 100%;
}

/* List layout images use contain */
.tt-event-listing.tt-layout-list .tt-event-image img {
    object-fit: contain;
    padding: 10px;
}

/* ============================================
   EVENT CONTENT ELEMENTS
   ============================================ */

/* Event Title */
.tt-event-listing .tt-event-title {
    margin: 0 0 0.625rem 0;
    font-size: 1rem;
    line-height: 1.3;
    color: #2c3e50;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Date and Venue */
.tt-event-listing .tt-event-date,
.tt-event-listing .tt-event-venue {
    display: flex;
    align-items: flex-start;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: #666;
    line-height: 1.3;
}

.tt-event-listing .tt-event-date .dashicons,
.tt-event-listing .tt-event-venue .dashicons {
    margin-right: 0.375rem;
    color: #2271b1;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    font-size: 14px;
    margin-top: 1px;
}

/* Spacer to push button down */
.tt-event-listing .tt-event-content::before {
    content: "";
    flex: 1;
    min-height: 0.25rem;
}

/* Hide PHP spacer */
.tt-event-listing .tt-event-spacer {
    display: none;
}

/* Button Container */
.tt-event-listing .tt-event-button-container {
    margin-top: auto;
    padding-top: 0.625rem;
    text-align: center;
}

/* Event Button */
.tt-event-listing .tt-event-button,
.tt-event-listing a.tt-event-button {
    display: inline-block;
    width: auto;
    padding: 0.75rem 1.5rem;
    background: #2271b1;
    color: #ffffff;
    text-decoration: none;
    text-align: center;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.tt-event-listing .tt-event-button:hover,
.tt-event-listing a.tt-event-button:hover {
    background: #135e96;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(34, 113, 177, 0.3);
}

/* Event excerpt (list view only) */
.tt-event-listing .tt-event-excerpt {
    font-size: 0.875rem;
    color: #666;
    line-height: 1.4;
    margin-bottom: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   SINGLE EVENT STYLES
   ============================================ */
.tt-single-event {
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 12px;
    overflow: hidden;
    margin: 2rem 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.tt-single-event-wrapper {
    margin: 2rem 0;
}

.tt-event-header-image {
    width: 100%;
    max-height: 400px;
    overflow: hidden;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Single event header images can use cover */
.tt-event-header-image img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

.tt-event-details {
    padding: 2rem;
}

.tt-event-details .tt-event-title {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: #2c3e50;
}

.tt-event-meta {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.tt-meta-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    color: #666;
}

.tt-meta-item strong {
    font-weight: 600;
    color: #333;
}

.tt-event-description {
    font-size: 1rem;
    line-height: 1.6;
    color: #444;
    margin-bottom: 2rem;
}

.tt-event-description p {
    margin-bottom: 1rem;
}

.tt-event-cta {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid #e1e1e1;
    text-align: center;
}

.tt-button {
    display: inline-block;
    padding: 1rem 2rem;
    background: #971320;
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

.tt-button:hover {
    background: #dd1c3d;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.3);
}

/* ============================================
   WORDPRESS BLOCK SUPPORT
   ============================================ */
.wp-block-ticket-tailor-event-listing,
.wp-block-ticket-tailor-single-event,
.wp-block-ticket-tailor-category-events {
    margin: 2rem 0;
}

.alignfull .tt-event-listing {
    padding: 0 2rem;
}

/* ============================================
   STATUS, ERROR & WIDGET STYLES
   ============================================ */
.tt-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
}

.tt-status-on_sale {
    background: #d4f4dd;
    color: #1e7e34;
}

.tt-status-sold_out {
    background: #f8d7da;
    color: #721c24;
}

.tt-status-cancelled {
    background: #e7e7e7;
    color: #666;
}

.tt-status-postponed {
    background: #fff3cd;
    color: #856404;
}

.tt-error,
.tt-no-events {
    padding: 2rem;
    text-align: center;
    background: #f8f9fa;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    color: #666;
    margin: 2rem 0;
}

.tt-error {
    background: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

.tt-block-placeholder {
    padding: 2rem;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
}

.tt-widget-block {
    margin: 2rem 0;
}

.tt-widget-error {
    padding: 1rem;
    background: #f8d7da;
    color: #721c24;
    border-radius: 4px;
    text-align: center;
}

/* ============================================
   CATEGORY EVENTS
   ============================================ */
.tt-category-events-wrapper {
    margin: 2rem 0;
}

.tt-category-header {
    text-align: center;
    margin-bottom: 2rem;
}

.tt-category-title {
    font-size: 2rem;
    color: #2c3e50;
    margin: 0;
}

/* ============================================
   RESPONSIVE DESIGN
   NOTE: !important kept ONLY for mobile overrides
   that must beat inline styles from blocks
   ============================================ */
@media (max-width: 1200px) {
    .tt-event-listing.tt-layout-grid.tt-columns-5 {
        grid-template-columns: repeat(4, 220px);
    }
}

@media (max-width: 1024px) {
    .tt-event-listing.tt-layout-grid.tt-columns-4,
    .tt-event-listing.tt-layout-grid.tt-columns-3 {
        grid-template-columns: repeat(3, 220px);
    }
}

@media (max-width: 768px) {
    .tt-event-listing.tt-layout-grid.tt-columns-5,
    .tt-event-listing.tt-layout-grid.tt-columns-4,
    .tt-event-listing.tt-layout-grid.tt-columns-3,
    .tt-event-listing.tt-layout-grid.tt-columns-2 {
        grid-template-columns: repeat(2, 220px);
    }

    .tt-event-listing.tt-layout-list .tt-event-card {
        grid-template-columns: 1fr;
        width: 100%;
    }
}

/* MOBILE: Single column for all phones and small tablets
   !important required here to override inline styles from block editor */
@media (max-width: 767px) {
    .tt-event-listing.tt-layout-grid,
    .tt-event-listing.tt-layout-grid.tt-columns-2,
    .tt-event-listing.tt-layout-grid.tt-columns-3,
    .tt-event-listing.tt-layout-grid.tt-columns-4,
    .tt-event-listing.tt-layout-grid.tt-columns-5,
    .tt-event-listing.tt-layout-grid[style*="grid-template-columns"],
    .tt-event-listing.tt-columns-responsive {
        grid-template-columns: 220px !important;
        justify-content: center !important;
    }

    .tt-full-width .tt-event-listing {
        padding: 0 0.5rem;
    }
}

/* Very small screens - adjust typography
   !important required to override inline styles */
@media (max-width: 400px) {
    .tt-event-listing .tt-event-title {
        font-size: 0.95rem !important;
    }

    .tt-event-listing .tt-event-date,
    .tt-event-listing .tt-event-venue {
        font-size: 0.8rem !important;
    }

    .tt-event-listing .tt-event-button {
        padding: 0.5rem 0.875rem !important;
        font-size: 0.85rem !important;
    }
}

/* Print styles - keep !important for print media override */
@media print {
    .tt-event-button,
    .tt-button,
    .tt-widget-block {
        display: none !important;
    }

    .tt-event-listing.tt-layout-grid {
        grid-template-columns: repeat(3, 220px) !important;
    }

    .tt-event-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.tt-loading {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.tt-loading::after {
    content: "";
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 0.5rem;
    border: 2px solid #ddd;
    border-top-color: #2271b1;
    border-radius: 50%;
    animation: tt-spin 0.8s linear infinite;
}

@keyframes tt-spin {
    to {
        transform: rotate(360deg);
    }
}

.tt-centered {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 1rem;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.tt-event-button:focus,
.tt-button:focus,
.tt-event-card:focus-within {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

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