/* Variables */
:root
{
    --slot-height: 52px;
    --hours-count: 12;
    --time-col-width: 70px;
    --header-height: 44px;
    --day-gap: 0;
    --event-radius: 8px;
    --event-pad: 6px 7px;
    --track-bg: #f5f7fa;
}

/* Base */
*,
*::before,
*::after
{
    box-sizing: border-box;
}
body
{
    margin: 0;
    background: linear-gradient(135deg, #f5f7fa, #eef1f5);
    color: #24313b;
    -webkit-font-smoothing: antialiased;
}

/* Wrapper */
.calendar-module
{
    max-width: 1200px;
    padding: 28px 30px 40px;
    background: var(--color-bg);
    border-radius: var(--module-radius);
    box-shadow: 0 10px 28px -6px rgba(33,53,73,.18), 0 2px 6px rgba(0,0,0,.06);
    position: relative;
    overflow: hidden;
}

/* Toolbar */
.cal-toolbar
{
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-bottom: 18px;
}
.cal-week-label
{
    flex: 1;
    text-align: center;
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: .4px;
    color: #16232c;
}
.cal-btn
{
    background: var(--color-accent);
    color: #fff;
    justify-content: center;
    border: 0;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 90px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 3px 10px -2px rgba(0,70,130,.35);
    transition: .25s;
}
.cal-btn:hover
{
    filter: brightness(1.08);
    box-shadow: 0 6px 16px -4px rgba(0,70,130,.4);
    transform: translateY(-1px);
}
.cal-btn:active
{
    transform: translateY(1px);
    box-shadow: 0 2px 6px -2px rgba(0,70,130,.4);
}

/* Shell */
.cal-shell
{
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: #f9fbfd;
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Head */
.cal-head-row
{
    display: grid;
    grid-template-columns: var(--time-col-width) 1fr;
    background: linear-gradient(180deg, #f8fafc, #eef2f6);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 30;
}
.cal-time-head
{
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #41515e;
    border-right: 1px solid var(--color-border);
    background: #fff;
}
.cal-days-head
{
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    height: var(--header-height);
}
.cal-days-head .day-head
{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .3px;
    color: #25333d;
    border-right: 1px solid var(--color-border);
    position: relative;
    background: linear-gradient(180deg, #f8fafc, #eef2f6);
    padding: 0 2px;
}
.cal-days-head .day-head:last-child
{
    border-right: 0;
}
.cal-days-head .day-head.today::after
{
    content: "";
    position: absolute;
    inset: auto 18% 2px 18%;
    height: 3px;
    border-radius: 2px;
    background: var(--color-accent);
}

/* Scroll Area */
.cal-scroll
{
    flex: 1;
    display: grid;
    grid-template-columns: var(--time-col-width) 1fr;
    overflow: auto;
    position: relative;
    scroll-behavior: smooth;
    background: #fff;
}

/* Time Column */
.cal-time-col
{
    border-right: 1px solid var(--color-border);
    background: #fff;
    position: relative;
    z-index: 10;
}
.cal-slot
{
    height: var(--slot-height);
    font-size: 11px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 6px;
    color: #4d5b66;
    border-top: 1px solid #edf0f3;
}
.cal-slot:first-child
{
    border-top: 0;
}

/* Days Grid */
.cal-days-col
{
    position: relative;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: var(--day-gap);
    min-width: 100%;
}
.cal-day
{
    position: relative;
    min-height: calc(var(--slot-height) * var(--hours-count));
    border-right: 1px solid var(--color-border);
    background: repeating-linear-gradient(
            to bottom,
            #ffffff 0 calc(var(--slot-height) - 1px),
            #eef2f6 calc(var(--slot-height) - 1px) var(--slot-height)
    );
}
.cal-day:last-child
{
    border-right: 0;
}

/* Now Line */
.cal-now
{
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #ff4141, #ff9f43);
    box-shadow: 0 0 6px rgba(255,80,80,.55);
    z-index: 40;
}

/* Events */
.cal-event
{
    position: absolute;
    left: 2px;
    right: 2px;
    padding: 5px 6px;
    background: var(--color-accent);
    color: #fff;
    border-radius: var(--event-radius);
    font-size: 11px;
    line-height: 1.25;
    display: flex;
    flex-direction: column;
    gap: 2px;
    box-shadow: 0 4px 10px -4px rgba(0,64,128,.32), 0 1px 3px rgba(0,0,0,.22);
    cursor: pointer;
    overflow: hidden;
    opacity: .96;
    transition: box-shadow .22s, transform .16s, opacity .22s;
    backdrop-filter: saturate(160%) brightness(1.05);
}
.cal-event:focus-visible
{
    outline: 3px solid #ffb13c;
    outline-offset: 2px;
}
.cal-event .ev-title
{
    font-weight: 600;
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: .25px;
}
.cal-event .ev-time
{
    font-size: 9.5px;
    opacity: .9;
}
.cal-event[data-type="info"]
{
    background: linear-gradient(145deg, #6366f1, #4f46e5);
}
.cal-event.compact
{
    padding: 4px 5px;
    font-size: 10.5px;
}
.cal-event .ev-title.wrap
{
    white-space: normal;
    word-break: break-word;
}

/* Loading */
.cal-loading
{
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(2px);
}
.cal-loading[hidden]
{
    display: none !important;
}
.cal-spinner
{
    width: 48px;
    height: 48px;
    border: 5px solid #e4e9ef;
    border-top: 5px solid var(--color-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin
{
    to
    {
        transform: rotate(360deg);
    }
}

/* Scrollbars */
.cal-scroll::-webkit-scrollbar
{
    width: 10px;
    height: 10px;
}
.cal-scroll::-webkit-scrollbar-track
{
    background: #f1f3f6;
}
.cal-scroll::-webkit-scrollbar-thumb
{
    background: #c2ccd5;
    border-radius: 20px;
    border: 3px solid #f1f3f6;
}
.cal-scroll::-webkit-scrollbar-thumb:hover
{
    background: #9fabb6;
}

/* Desktop tweak */
@media (min-width: 901px)
{
    .cal-days-head .day-head
    {
        padding: 0 6px;
    }
}

/* Tablet large */
@media (max-width: 1100px)
{
    :root
    {
        --slot-height: 54px;
    }
}

/* Tablet medium */
@media (max-width: 900px)
{
    :root
    {
        --slot-height: 64px;
        --time-col-width: 60px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(96px, 1fr);
    }
    .cal-days-head .day-head
    {
        font-size: 11px;
    }
    .cal-event
    {
        font-size: 11px;
        padding: 5px 5px;
    }
}

/* Tablet narrow */
@media (max-width: 760px)
{
    :root
    {
        --slot-height: 68px;
        --time-col-width: 56px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(88px, 1fr);
    }
    .cal-days-head .day-head
    {
        font-size: 10.5px;
    }
    .cal-slot
    {
        font-size: 10.5px;
    }
    .cal-event
    {
        font-size: 10.5px;
    }
}

/* Mobile base */
@media (max-width: 640px)
{
    :root
    {
        --slot-height: 72px;
        --time-col-width: 54px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(80px, 1fr);
    }
    .cal-event
    {
        padding: 4px 5px;
    }
}

/* Mobile tighter */
@media (max-width: 560px)
{
    :root
    {
        --slot-height: 76px;
        --time-col-width: 50px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(72px, 1fr);
    }
    .cal-days-head .day-head
    {
        font-size: 10px;
        letter-spacing: .2px;
    }
    .cal-event .ev-title
    {
        font-size: 10.5px;
    }
    .cal-event .ev-time
    {
        font-size: 9px;
    }
}

/* Mobile very tight */
@media (max-width: 480px)
{
    :root
    {
        --slot-height: 80px;
        --time-col-width: 48px;
    }
    .calendar-module
    {
        padding: 22px 18px 32px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(66px, 1fr);
    }
    .cal-event
    {
        font-size: 10.5px;
    }
}

/* Ultra narrow */
@media (max-width: 420px)
{
    :root
    {
        --slot-height: 84px;
        --time-col-width: 46px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(60px, 1fr);
    }
    .cal-days-head .day-head
    {
        font-size: 9.8px;
    }
    .cal-event
    {
        font-size: 10px;
        padding: 4px 4px;
    }
    .cal-event .ev-time
    {
        font-size: 8.8px;
    }
}

/* Ultra compact */
@media (max-width: 380px)
{
    :root
    {
        --slot-height: 86px;
        --time-col-width: 44px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(56px, 1fr);
    }
    .cal-days-head .day-head
    {
        padding: 0 1px;
        font-size: 9.5px;
    }
    .cal-event
    {
        font-size: 9.7px;
        line-height: 1.18;
    }
    .cal-event .ev-title
    {
        white-space: normal;
    }
}

/* Micro */
@media (max-width: 340px)
{
    :root
    {
        --slot-height: 90px;
        --time-col-width: 42px;
    }
    .cal-days-head,
    .cal-days-col
    {
        grid-auto-columns: minmax(52px, 1fr);
    }
    .cal-days-head .day-head
    {
        font-size: 9px;
    }
    .cal-event
    {
        font-size: 9.4px;
        padding: 3px 4px;
    }
    .cal-event .ev-time
    {
        font-size: 8px;
    }
}

@media (max-width: 560px) {
    .cal-toolbar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "label label"
            "prev  next";
        gap: 8px;
        align-items: center;
        margin-bottom: 16px;
    }
    .cal-week-label {
        grid-area: label;
        margin: 0;
        font-size: .9rem;
        line-height: 1.15;
        text-align: center;
        white-space: nowrap;
    }
    .cal-btn {
        font-size: 12px;
        flex: 0 0 auto;
        width: 100%;
    }

}
