#calendar-grid {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-lg);
}

.edt-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    gap: 1rem;
    color: var(--text-muted);
}

.edt-loader .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-soft);
    border-left-color: var(--primary-color, #3498db);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.cour {
    background: var(--ressource-color, #0099ff);
    color: var(--schedule-event-text-color, var(--font-ressource-color));

    border-radius: 8px;
    padding: 4px 6px;
    min-height: 1px;
    transition: min-height 0.25s ease, box-shadow 0.2s ease, z-index 0s;
    border: 1px solid var(--border-soft);
    cursor: pointer;
    width: auto;
    margin-left: 0;

    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;

    box-sizing: border-box;

    &::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }

    &::-webkit-scrollbar-track {
        background: transparent;
    }

    &::-webkit-scrollbar-thumb {
        background: var(--ressource-color, #0099ff);
        border-radius: 10px;
        border: 3px solid transparent;
        background-clip: content-box;
    }

    &::-webkit-scrollbar-thumb:hover {
        background: var(--ressource-color, #0099ff);
        background-clip: content-box;
        filter: brightness(1.15);
    }

    scrollbar-width: thin;
    scrollbar-color: var(--ressource-color, #0099ff) transparent;
}

/* Stable palette for overlaid custom timetables. */
.cour.edt1 { background: var(--ressource-color, #0099ff); color: var(--schedule-event-text-color, var(--font-ressource-color)); }
.cour.edt2 { --ressource-color: #2e7d32; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt3 { --ressource-color: #6a1b9a; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt4 { --ressource-color: #c45100; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt5 { --ressource-color: #00bcd4; --font-ressource-color: #17202a; --schedule-event-text-color: #17202a; }
.cour.edt6 { --ressource-color: #ffeb3b; --font-ressource-color: #202020; --schedule-event-text-color: #202020; }
.cour.edt7 { --ressource-color: #3949ab; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt8 { --ressource-color: #00796b; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt9 { --ressource-color: #ffb300; --font-ressource-color: #202020; --schedule-event-text-color: #202020; }
.cour.edt10 { --ressource-color: #ad1457; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt11 { --ressource-color: #455a64; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt12 { --ressource-color: #c0ca33; --font-ressource-color: #202020; --schedule-event-text-color: #202020; }
.cour.edt13 { --ressource-color: #0277bd; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt14 { --ressource-color: #558b2f; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt15 { --ressource-color: #7e57c2; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt16 { --ressource-color: #bf360c; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt17 { --ressource-color: #00838f; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt18 { --ressource-color: #f9a825; --font-ressource-color: #202020; --schedule-event-text-color: #202020; }
.cour.edt19 { --ressource-color: #512da8; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt20 { --ressource-color: #00897b; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt21 { --ressource-color: #6d4c41; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt22 { --ressource-color: #546e7a; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt23 { --ressource-color: #8e24aa; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt24 { --ressource-color: #33691e; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt25 { --ressource-color: #283593; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt26 { --ressource-color: #00695c; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt27 { --ressource-color: #9e6d00; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt28 { --ressource-color: #6a1b4d; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt29 { --ressource-color: #006064; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt30 { --ressource-color: #37474f; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt31 { --ressource-color: #827717; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }
.cour.edt32 { --ressource-color: #303f9f; --font-ressource-color: #fff; --schedule-event-text-color: #fff; }

/* One outline and one set of details for events that change width. */
.cour.cour-shaped,
.cour.cour-shaped:hover {
    padding: 0;
    border: 0 !important;
    border-radius: 0;
    background: transparent !important;
    box-shadow: none !important;
    min-height: 0;
    overflow: hidden;
}

.cour-shaped .event-card-outline {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.event-card-outline path {
    fill: var(--event-shape-fill);
    stroke: var(--border-soft);
    stroke-width: 1px;
    vector-effect: non-scaling-stroke;
}

.cour-shaped .event-card-copy {
    position: absolute;
    box-sizing: border-box;
    padding: 4px 6px;
    justify-content: space-between;
    overflow: auto;
    scrollbar-width: thin;
}

.cour.is-custom.cour-shaped::after {
    left: var(--custom-event-grip-left, auto);
    top: var(--custom-event-grip-top, 4px);
    right: auto;
}

.cour.is-custom.cour-shaped.is-shape-preview::after {
    left: auto;
    top: 4px;
    right: 8px;
}

.cour.cour-shaped.is-shape-preview {
    background: var(--event-shape-fill) !important;
    border-radius: 8px;
}

.cour-shaped.is-shape-preview .event-card-outline {
    display: none;
}

.cour-shaped.is-shape-preview .event-card-copy {
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

.cour:hover {
    min-height: 8em;
    z-index: 50 !important;
    box-shadow: var(--shadow-lg);

    overflow: auto;
}

.cour.is-custom {
    cursor: grab;
    z-index: 60 !important;
}

.cour.is-custom.is-shared-event {
    cursor: pointer;
}

.cour.is-custom.is-clipped-event {
    cursor: pointer;
}

.cour.is-custom.is-clipped-event .custom-event-resize-handle {
    display: none;
}

.cour.is-custom:hover {
    min-height: 32px;
    overflow: hidden;
}

.cour.is-custom::after {
    content: "⋮⋮";
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: -2px;
    line-height: 1;
    opacity: 0.45;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.cour.is-custom:hover::after {
    opacity: 0.9;
}

.cour.is-custom.is-dragging,
.cour.is-custom.is-resizing {
    cursor: grabbing;
    z-index: 120 !important;
    box-shadow: 0 14px 24px rgba(0, 0, 0, 0.28);
    transition: none;
}

.cour.is-custom .custom-event-resize-handle {
    position: absolute;
    left: 0;
    right: 0;
    height: 9px;
    z-index: 5;
    cursor: ns-resize;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0));
    opacity: 0.14;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.cour.is-custom .custom-event-resize-handle-top {
    top: 0;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.cour.is-custom .custom-event-resize-handle-bottom {
    bottom: 0;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    transform: rotate(180deg);
}

.cour.is-custom:hover .custom-event-resize-handle {
    opacity: 0.35;
}

.cour.is-custom .custom-event-resize-handle:hover {
    opacity: 0.95;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
}

.cour.cour-merged {
    border: 1px solid color-mix(in srgb, #ffd60a 45%, var(--border-soft));
    box-shadow: 0 8px 18px rgba(255, 214, 10, 0.25), 0 6px 14px rgba(0, 0, 0, 0.15);
}

.cour div {
    display: flex;
    flex-direction: column;
}

.cour .name {
    font-weight: bold;
    font-size: 0.85em;
    margin: 0;
    line-height: 1.2;
}

.cour .location {
    font-weight: 600;
    font-size: 0.75em;
    margin: 2px 0 0;
    opacity: 0.9;
}

.cour .prof,
.cour .time {
    color: color-mix(in srgb, var(--schedule-event-text-color, var(--font-ressource-color)), transparent 15%);
    font-size: 0.75em;
    margin: 0;
}

.cour .time {
    margin-top: auto;
}

@media (max-width: 768px) {
    #calendar-grid {
        overflow: hidden;
        overflow-y: hidden;
    }

    #calendar-grid > .edt-days-header,
    #calendar-grid > .edt-days-header + div {
        min-width: 0;
        width: 100%;
    }

    .edt-days-header {
        box-sizing: border-box;
        padding-left: 42px !important;
    }

    .edt-time-rail {
        flex-basis: 42px !important;
    }

    .edt-time-rail [style*="font-size"] {
        left: 3px !important;
        font-size: 9px !important;
    }

    .edt-time-rail [style*="right"] {
        right: 3px !important;
    }

    .edt-days-area,
    .edt-days-area .day-col,
    .edt-days-area .day-group-split,
    .edt-days-area .day-compare-lane {
        min-width: 0;
    }

    .edt-days-header .day-label {
        min-width: 0;
        min-height: 42px;
        font-size: 0.64rem;
        line-height: 1.05;
        gap: 0.08rem;
    }

    .edt-days-header .day-label .day-name {
        display: none;
    }

    .edt-days-header .day-label::before {
        content: attr(data-short-day);
        font-size: 0.68rem;
        font-weight: 700;
        white-space: nowrap;
    }

    .edt-days-header .day-label .date {
        font-size: 0.62rem;
        white-space: nowrap;
    }

    .day-compare-heads {
        gap: 0.1rem;
        margin-top: 0.15rem;
    }

    .day-compare-avatar {
        width: 16px;
        height: 16px;
        border-radius: 5px;
        font-size: 0.55rem;
    }

    .cour {
        padding: 3px;
        border-radius: 5px;
    }

    .cour .name {
        font-size: 0.65rem;
        line-height: 1.1;
        overflow-wrap: anywhere;
    }

    .cour .prof,
    .cour .time {
        display: none;
    }

    .cour .location {
        display: block;
        margin-top: 2px;
        overflow: hidden;
        font-size: 0.58rem;
        font-weight: 700;
        line-height: 1.1;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

.calendar-grid button img {
    width: 20px;
    height: 20px;
}

body.schedule-event-dragging {
    cursor: grabbing;
    user-select: none;
}

.edt-days-header {
    display: flex;
    align-items: flex-end;
    gap: 0;
    margin: 0 0 0.25rem 0;
    padding-left: 64px;
}

.edt-days-header .days-labels {
    flex: 1;
    display: flex;
    gap: 0;
}

.edt-days-header .day-label {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    opacity: 0.9;
    text-align: center;
    gap: 0.15rem;
    min-height: 54px;
}

.edt-days-header .day-label .date {
    font-size: 0.85em;
    opacity: 0.6;
    font-weight: 400;
}

.edt-days-header .day-label.current-day {
    background: rgba(255, 214, 10, 0.12);
    border-radius: 10px;
}

.day-compare-heads {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    flex-wrap: wrap;
    margin-top: 0.25rem;
}

.day-compare-avatar {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.day-compare-avatar.is-self {
    outline: 2px solid color-mix(in srgb, var(--primary-color) 55%, transparent);
    outline-offset: 1px;
}

.day-compare-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

.day-group-split {
    width: 100%;
}

.day-compare-lane:nth-child(odd) .day-compare-timeline {
    background: rgba(255, 255, 255, 0.03);
}

.day-compare-lane:nth-child(even) .day-compare-timeline {
    background: rgba(0, 0, 0, 0.04);
}

.day-compare-timeline {
    transition: background 0.2s ease;
}

.day-compare-timeline:hover {
    background: rgba(255, 214, 10, 0.05);
}

.timeline-event-selection {
    position: absolute;
    left: 3px;
    right: 3px;
    z-index: 55;
    min-height: 24px;
    display: flex;
    align-items: flex-start;
    padding: 0.3rem 0.45rem;
    box-sizing: border-box;
    border: 1px dashed color-mix(in srgb, var(--primary-color) 78%, #fff);
    border-radius: 7px;
    background: color-mix(in srgb, var(--primary-color) 28%, transparent);
    color: #fff;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.timeline-event-selection__time {
    padding: 0.12rem 0.32rem;
    border-radius: 4px;
    background: color-mix(in srgb, var(--primary-color) 76%, #101820);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.day-col {
    border-right: 1px solid var(--border-soft);
}

.day-col:last-child {
    border-right: none;
}

.day-col.day-col-current {
    background: rgba(255, 214, 10, 0.08);
}

.cal-skeleton {
    display: flex;
    gap: 8px;
    padding: 8px 0 8px 64px;
    height: 600px;
    width: 100%;
    box-sizing: border-box;
    margin-top: 8px;
}

.cal-skeleton-col {
    flex: 1;
    position: relative;
    border-radius: 8px;
    background: var(--bg-tertiary);
}

.cal-skeleton-block {
    position: absolute;
    left: 4px;
    right: 4px;
    border-radius: 8px;
    background: var(--border-soft);
    background-image: linear-gradient(90deg,
            transparent 0%,
            var(--border-hard) 50%,
            transparent 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}
