/**
 * ChurchTools Week Calendar Styles
 * 
 * @package ChurchTools_Events
 * @since 0.4
 */

/* Main Container */
.ct-week-calendar {
    max-width: 100%;
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Legend */
.ct-calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.legend-name {
    font-weight: 500;
}

/* Navigation */
.ct-week-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 20px;
    padding: 15px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ct-week-nav button {
    padding: 8px 16px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    color: #333;
}

.ct-week-nav button:hover {
    background: #f5f5f5;
    border-color: #b0b0b0;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ct-week-nav button:active {
    transform: translateY(0);
    box-shadow: none;
}

.ct-week-nav .today {
    background: #007bff;
    color: white;
    border-color: #0056b3;
}

.ct-week-nav .today:hover {
    background: #0056b3;
}

.ct-week-nav .current-week {
    font-weight: 600;
    font-size: 16px;
    color: #333;
    flex: 1;
    text-align: center;
}

/* Calendar Grid - DESKTOP */
.ct-week-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: auto 1fr; /* WICHTIG: Erste Row = Headers, Zweite Row = Cells */
    gap: 10px;
    background: #fff;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Day Container - DESKTOP */
.day-container {
    display: contents; /* Macht Container transparent für Grid */
}

/* Day Headers - DESKTOP */
.day-header {
    grid-row: 1; /* WICHTIG: Alle Headers in erste Row */
    text-align: center;
    font-weight: 700;
    font-size: 16px;
    padding: 16px 8px;
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
    border-radius: 6px;
    color: #333;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.day-header .date {
    display: block;
    font-size: 22px;
    font-weight: 800;
    color: #007bff;
    margin-top: 6px;
}

/* Heutiger Tag: Datum-Kreis hervorheben */
.day-header.is-today {
    background: linear-gradient(to bottom, #dbeeff, #c5dffa);
    color: #0056b3;
}

.day-header.is-today .date {
    color: #0056b3;
}

/* Day Cells - DESKTOP */
.day-cell {
    grid-row: 2; /* WICHTIG: Alle Cells in zweite Row */
    min-height: var(--day-height, 150px);
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.day-cell:empty {
    background: #fafafa;
}

/* Event Cards */
.ct-event-card {
    padding: 8px 10px;
    border-radius: 6px;
    border-left: 4px solid;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.ct-event-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.ct-event-card:active {
    transform: translateY(0);
}

.event-time {
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 2px;
    opacity: 0.9;
}

.event-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.event-calendar {
    display: none;
}

/* Modal */
.ct-modal {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ct-modal-content {
    position: relative;
    background-color: #f0f0f1;
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
    overflow: hidden;
}

@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

/* Close Button — dunkler Kreis mit × */
.ct-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease;
    z-index: 20;
    text-shadow: none;
}

.ct-modal-close:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* Farbiger Header-Banner (wenn kein Bild vorhanden) */
.ct-modal-header-banner {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 28px 60px 28px 24px; /* rechts Platz für Close-Button */
    min-height: 110px;
}

.ct-modal-header-date {
    flex-shrink: 0;
    text-align: center;
    line-height: 1;
}

.ct-modal-header-day {
    display: block;
    font-size: 54px;
    font-weight: 900;
    line-height: 1;
}

.ct-modal-header-month {
    display: block;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1.5px;
    margin-top: 2px;
    text-transform: uppercase;
}

.ct-modal-header-info {
    flex: 1;
    min-width: 0;
}

.ct-modal-header-title {
    font-size: 20px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
    margin-bottom: 4px;
}

.ct-modal-header-subtitle {
    font-size: 13px;
    font-weight: 500;
    opacity: 0.9;
    margin-bottom: 8px;
}

.ct-modal-header-time {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    opacity: 0.85;
}

/* Headerbild (wenn vorhanden) */
.ct-modal-image {
    display: block;
    width: 100%;
    height: 200px;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

/* Modal Body */
.ct-modal-body {
    padding: 20px;
    background: #f0f0f1;
}

/* Titel-Bereich im Body (nur wenn Bild vorhanden) */
.ct-modal-title-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e0e0e0;
}

.ct-modal-title-in-body {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.3;
}

.ct-modal-subtitle-in-body {
    margin: 0;
    font-size: 14px;
    color: #555;
}

/* Section-Header "Veranstaltungsdetails" */
.ct-modal-section-header {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Karten-Row */
.ct-modal-cards {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.ct-modal-card {
    flex: 1;
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.ct-modal-card-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #1a1a1a;
}

.ct-modal-card-value {
    font-size: 14px;
    color: #555;
    line-height: 1.5;
}

/* "Weitere Veranstaltungen"-Button */
.ct-modal-events-btn {
    display: inline-block;
    margin-top: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-decoration: none !important;
    text-align: center;
    transition: opacity 0.2s ease;
    align-self: flex-start;
}

.ct-modal-events-btn:hover {
    opacity: 0.85;
}

/* Beschreibungs-Box */
.ct-modal-description {
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-top: 12px;
}

.ct-modal-desc-label {
    font-size: 11px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.ct-modal-desc-value {
    font-size: 14px;
    color: #333;
    line-height: 1.6;
}

.ct-modal-desc-value a {
    color: #007bff;
    word-break: break-all;
}

/* Responsive Design - Tablet */
@media (max-width: 1024px) and (min-width: 768px) {
    .ct-week-grid {
        gap: 8px;
        padding: 10px;
    }
    
    .day-header {
        font-size: 13px;
        padding: 10px 6px;
    }
    
    .day-header .date {
        font-size: 16px;
    }
    
    .event-title {
        font-size: 13px;
    }
    
    .event-time,
    .event-calendar {
        font-size: 11px;
    }
    
    .ct-event-card {
        padding: 8px;
    }
}

/* Responsive Design - Mobile */
@media (max-width: 767px) {
    .ct-week-calendar .ct-week-grid {
        display: flex !important; /* WICHTIG: Kein Grid auf Mobile! */
        flex-direction: column !important;
        gap: 15px !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
    }
    
    /* Day Container wird zum Block (Header + Cell zusammen) */
    .ct-week-calendar .day-container {
        display: flex !important; /* WICHTIG: Block statt contents! */
        flex-direction: column !important;
        gap: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        border: 1px solid #e0e0e0 !important;
        border-radius: 8px !important;
        overflow: hidden !important;
    }
    
    .ct-week-calendar .day-header {
        grid-row: auto !important; /* WICHTIG: Grid-Row-Regel aufheben */
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 12px 15px !important;
        font-size: 16px !important;
        position: static !important; /* Kein sticky auf Mobile */
        margin: 0 !important;
        border-radius: 0 !important; /* Header ist oben im Container */
        box-shadow: none !important;
    }
    
    .ct-week-calendar .day-header .date {
        display: inline !important;
        margin-top: 0 !important;
        margin-left: 10px !important;
        font-size: 16px !important;
    }
    
    .ct-week-calendar .day-cell {
        grid-row: auto !important; /* WICHTIG: Grid-Row-Regel aufheben */
        min-height: auto !important;
        padding: 12px !important;
        margin: 0 !important;
        border: none !important; /* Border kommt vom Container */
        border-radius: 0 !important; /* Cell ist unten im Container */
        background: #fafafa !important;
    }
    
    .ct-event-card {
        padding: 12px;
    }
    
    .event-title {
        font-size: 15px;
        -webkit-line-clamp: 3;
    }
    
    .event-time {
        font-size: 13px;
    }
    
    .event-calendar {
        font-size: 12px;
    }
    
    .ct-week-nav {
        flex-wrap: wrap;
    }
    
    .ct-week-nav .current-week {
        order: -1;
        flex-basis: 100%;
        margin-bottom: 10px;
        font-size: 15px;
    }
    
    .ct-week-nav button {
        flex: 1;
        min-width: 100px;
    }
    
    .ct-calendar-legend {
        gap: 10px;
        padding: 12px;
    }
    
    .legend-item {
        font-size: 13px;
    }
    
    .ct-modal-content {
        margin: 5% auto;
        width: 95%;
    }

    .ct-modal-header-banner {
        padding: 20px 50px 20px 16px;
        gap: 14px;
        min-height: auto;
    }

    .ct-modal-header-day {
        font-size: 40px;
    }

    .ct-modal-header-title {
        font-size: 16px;
    }

    .ct-modal-cards {
        flex-direction: column;
    }

    .ct-modal-body {
        padding: 16px;
    }
}

/* Loading State */
.ct-week-calendar.loading .ct-week-grid {
    opacity: 0.5;
    pointer-events: none;
}

.ct-week-calendar.loading::after {
    content: "Lädt...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 30px;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Print Styles */
@media print {
    .ct-week-nav,
    .ct-calendar-legend {
        display: none;
    }
    
    .ct-event-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .ct-week-grid {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* ------------------------------------------------------------------ */
/* Template event trigger                                              */
/* Wrapper around each [ct_template]-rendered event. display:contents  */
/* keeps the wrapper out of the layout so existing template CSS (flex  */
/* lists etc.) is unaffected, while clicks still bubble to it and open */
/* the shared event modal.                                             */
/* ------------------------------------------------------------------ */
.ct-event-trigger {
    display: contents;
    cursor: pointer;
}
.ct-event-trigger > * {
    cursor: pointer;
}
