.calendar {
    width: 100%;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: 0 0 18px 18px;
    overflow: hidden;
    background: var(--panel);
    box-shadow: 0 18px 50px rgb(16 24 40 / 6%);
}

.content:has(.calendar) {
    padding: 0 28px 32px;
}

.application-header:has(.calendar-header-controls) {
    flex-wrap: nowrap;
    min-height: 65px;
}

.application-header:has(.calendar-header-controls) > .header-title {
    font-size: 15px;
}

.calendar-header-controls {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.calendar-title {
    min-width: 190px;
    margin: 0;
    font-size: clamp(17px, 2vw, 22px);
    letter-spacing: -0.03em;
    text-align: center;
    white-space: nowrap;
}

.calendar-control {
    display: inline-grid;
    min-width: 44px;
    min-height: 44px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #ffffff;
    color: var(--ink);
    font-weight: 650;
    cursor: pointer;
}

.calendar-control:hover {
    border-color: #c4b5fd;
    background: #f5f3ff;
}

.calendar-control-today {
    padding-inline: 16px;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.calendar-weekdays span {
    padding: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-align: center;
    text-transform: uppercase;
}

.calendar-weekdays .is-weekend {
    background: #f1f3f7;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(6, minmax(0, 1fr));
    height: clamp(480px, calc(100dvh - 150px), 900px);
    min-height: 480px;
}

.calendar-day {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    overflow: hidden;
    border: 0;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 4px 6px 6px;
    background: #ffffff;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.calendar-day:nth-child(7n) {
    border-right: 0;
}

.calendar-day:nth-last-child(-n + 7) {
    border-bottom: 0;
}

.calendar-day:hover {
    background: #f8f7ff;
}

.calendar-day.is-weekend {
    background: #f7f8fa;
}

.calendar-day.is-weekend:hover {
    background: #f1f0f8;
}

.calendar-day.is-outside {
    background: #fafbfc;
    color: #98a2b3;
}

.calendar-day.is-outside.is-weekend {
    background: #f4f5f7;
}

.calendar-day.is-today {
    z-index: 1;
    box-shadow: inset 0 0 0 2px var(--sidebar-active);
}

.calendar-day-number {
    display: grid;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    place-items: center;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
}

.calendar-day.is-today .calendar-day-number {
    background: var(--sidebar-active);
    color: #ffffff;
}

.calendar-events {
    display: grid;
    min-width: 0;
    gap: 3px;
    pointer-events: none;
}

.calendar-event {
    display: block;
    overflow: hidden;
    border-left: 3px solid #8b5cf6;
    border-radius: 5px;
    padding: 5px 7px;
    background: #f0eefe;
    color: #403269;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-event-overflow {
    display: block;
    min-height: 22px;
    overflow: hidden;
    border-radius: 5px;
    padding: 4px 7px;
    background: #e9edf3;
    color: #475467;
    font-size: 12px;
    font-weight: 750;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-event,
.calendar-event-overflow {
    min-height: 25px;
}

.is-measurement-probe {
    visibility: hidden;
}

@media (max-width: 1024px) {
    .calendar-day {
        gap: 2px;
        padding: 4px 5px 5px;
    }

    .calendar-event {
        padding: 4px 5px;
        font-size: 10px;
    }

    .calendar-event-overflow {
        padding: 4px 5px;
        font-size: 10px;
    }

    .calendar-event,
    .calendar-event-overflow {
        min-height: 21px;
    }
}

@media (max-width: 900px) {
    .application-header:has(.calendar-header-controls) {
        flex-wrap: wrap;
        padding-block: 6px;
    }

    .calendar-header-controls {
        flex: 1 0 100%;
        justify-content: flex-end;
        margin-left: 60px;
    }

    .calendar-grid {
        height: clamp(450px, calc(100dvh - 196px), 720px);
        min-height: 450px;
    }
}

@media (max-width: 767px) {
    .calendar {
        border-radius: 0 0 14px 14px;
    }

    .calendar-header-controls {
        display: grid;
        grid-template-columns: 40px 40px minmax(0, 1fr) auto;
        gap: 6px;
        margin-left: 0;
    }

    .calendar-control {
        min-width: 40px;
        min-height: 40px;
    }

    .calendar-control-today {
        padding-inline: 10px;
        font-size: 13px;
    }

    .calendar-title {
        min-width: 0;
        font-size: clamp(16px, 5vw, 21px);
    }

    .calendar-weekdays span {
        padding: 8px 2px;
        font-size: 10px;
    }

    .calendar-grid {
        height: clamp(420px, calc(100dvh - 196px), 580px);
        min-height: 420px;
    }

    .calendar-day {
        gap: 2px;
        padding: 3px 4px 4px;
    }

    .calendar-day-number {
        flex-basis: 24px;
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .calendar-event {
        border-left-width: 2px;
        padding: 3px;
        font-size: 8px;
    }

    .calendar-event-overflow {
        padding: 3px;
        font-size: 8px;
    }

    .calendar-event,
    .calendar-event-overflow {
        min-height: 16px;
    }
}

/* WO-0008A multi-view calendar */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.calendar-surface {
    min-width: 0;
}

.calendar-period-navigation {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    border-radius: 12px;
}

.calendar-view-selector select {
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 34px 0 12px;
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    font-weight: 700;
}

.calendar-hide-completed {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
    white-space: nowrap;
}

.calendar-hide-completed input {
    width: 18px;
    height: 18px;
    accent-color: var(--sidebar-active);
}

.calendar-month-view .calendar-day-number {
    position: relative;
    z-index: 2;
    flex: 0 0 30px;
    border: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.calendar-month-view .calendar-day-number:hover,
.calendar-month-view .calendar-day-number:focus-visible {
    background: #e9e5ff;
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.calendar-month-view .calendar-day.is-today .calendar-day-number {
    background: var(--sidebar-active);
}

.calendar-time-scroll {
    max-height: calc(100dvh - 94px);
    overflow: auto;
    overscroll-behavior: contain;
    background: #ffffff;
    scrollbar-gutter: stable;
}

.calendar-time-layout {
    --calendar-time-gutter: 56px;
    display: grid;
    min-width: calc(var(--calendar-time-gutter) + var(--calendar-day-count) * 160px);
    grid-template-columns: var(--calendar-time-gutter) repeat(var(--calendar-day-count), minmax(160px, 1fr));
    grid-template-rows: auto 78px 94px auto;
    background: #ffffff;
}

.calendar-time-layout[style*="--calendar-day-count: 1"] {
    min-width: 100%;
}

.calendar-time-corner,
.calendar-time-day-header {
    position: sticky;
    z-index: 8;
    top: 0;
    min-height: 48px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.calendar-time-corner {
    z-index: 10;
    left: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    text-transform: uppercase;
}

.calendar-time-day-header {
    display: grid;
    place-items: center;
    border-left: 1px solid var(--border);
}

.calendar-time-day-header.is-weekend {
    background: #f2f4f7;
}

.calendar-time-day-header.is-today {
    background: #f0edff;
}

.calendar-time-day-header .calendar-day-number {
    width: auto;
    height: 36px;
    border: 0;
    border-radius: 18px;
    padding: 0 12px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
}

.calendar-time-day-header.is-today .calendar-day-number {
    background: var(--sidebar-active);
    color: #ffffff;
}

.calendar-time-day-header .calendar-day-number:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.calendar-time-section-label {
    position: sticky;
    z-index: 6;
    left: 0;
    display: flex;
    align-items: flex-start;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 9px 5px;
    background: #f8fafc;
    color: var(--muted);
    font-size: 10px;
    font-weight: 750;
    line-height: 1.25;
    text-align: center;
}

.calendar-time-section-cell {
    min-width: 0;
    overflow: hidden;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 5px;
    background: #ffffff;
}

.calendar-time-section-items {
    display: grid;
    height: 100%;
    min-width: 0;
    align-content: start;
    gap: 3px;
    overflow: hidden;
}

.calendar-time-axis {
    position: sticky;
    z-index: 5;
    left: 0;
    border-right: 1px solid var(--border);
    background: #f8fafc;
}

.calendar-time-axis span {
    position: absolute;
    right: 7px;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}

.calendar-time-day {
    position: relative;
    cursor: crosshair;
    min-width: 0;
    border-right: 1px solid var(--border);
    background-color: #ffffff;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent 27px,
        #e8ebf0 27px,
        #e8ebf0 28px
    );
}

.calendar-timed-event {
    position: absolute;
    z-index: 2;
    align-content: start;
    padding: 4px 6px;
    white-space: normal;
}

.calendar-timed-event .calendar-item-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.calendar-current-time {
    position: absolute;
    z-index: 4;
    right: 0;
    left: 0;
    height: 2px;
    background: #dc2626;
    pointer-events: none;
}

.calendar-current-time::before {
    position: absolute;
    top: -4px;
    left: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #dc2626;
    content: '';
}

.calendar-year-view {
    display: grid;
    grid-template-columns: repeat(3, minmax(250px, 1fr));
    gap: 1px;
    background: var(--border);
}

.calendar-year-month {
    min-width: 0;
    padding: 14px;
    background: #ffffff;
}

.calendar-year-month h2 {
    margin: 0 0 8px;
    font-size: 16px;
    text-align: center;
}

.calendar-year-weekdays,
.calendar-year-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-year-weekdays span {
    padding: 4px 0;
    color: var(--muted);
    font-size: 9px;
    font-weight: 750;
    text-align: center;
}

.calendar-year-day {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border-top: 1px solid #f0f1f4;
}

.calendar-year-day.is-weekend {
    background: #f7f8fa;
}

.calendar-year-day.is-outside {
    opacity: .34;
}

.calendar-year-day .calendar-day-number {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    padding: 2px 2px 15px;
    background: transparent;
    color: var(--ink);
    font-size: 10px;
    cursor: pointer;
}

.calendar-year-day.is-today .calendar-day-number {
    box-shadow: inset 0 0 0 2px var(--sidebar-active);
    color: var(--sidebar-active);
    font-weight: 800;
}

.calendar-year-day .calendar-day-number:focus-visible {
    z-index: 3;
    outline: 3px solid var(--focus);
    outline-offset: -3px;
}

.calendar-year-marker {
    z-index: 1;
    width: 5px;
    height: 5px;
    margin-top: 14px;
    border-radius: 50%;
    pointer-events: none;
}

.calendar-year-marker.is-event {
    pointer-events: auto;
    background: #8b5cf6;
    cursor: pointer;
}

.calendar-year-marker.is-event:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.calendar-year-marker.is-task {
    background: var(--task-color, #667085);
}

.calendar-year-marker.is-overdue {
    box-shadow: 0 0 0 2px #fee2e2;
}

.calendar-year-marker.is-completed {
    opacity: .4;
}

.calendar-year-more {
    z-index: 1;
    margin-top: 14px;
    color: var(--muted);
    font-size: 8px;
    pointer-events: none;
}

@media (max-width: 1180px) {
    .calendar-hide-completed span {
        max-width: 96px;
        white-space: normal;
    }

    .calendar-title {
        min-width: 150px;
    }
}

@media (max-width: 900px) {
    .calendar-header-controls {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        width: 100%;
        margin-left: 0;
    }

    .calendar-period-navigation {
        min-width: 0;
    }

    .calendar-title {
        min-width: 0;
        flex: 1;
    }

    .calendar-year-view {
        grid-template-columns: repeat(2, minmax(240px, 1fr));
    }
}

@media (max-width: 767px) {
    .calendar-header-controls {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .calendar-period-navigation {
        grid-column: 1 / -1;
    }

    .calendar-period-navigation .calendar-title {
        order: 0;
    }

    .calendar-view-selector select,
    .calendar-hide-completed {
        min-height: 40px;
    }

    .calendar-hide-completed span {
        max-width: none;
        font-size: 11px;
        white-space: normal;
    }

    .calendar-time-scroll {
        max-height: calc(100dvh - 154px);
    }

    .calendar-time-layout {
        grid-template-rows: auto 70px 82px auto;
    }

    .calendar-year-view {
        grid-template-columns: 1fr;
    }

    .calendar-year-month {
        padding: 10px;
    }
}

@media (max-width: 420px) {
    .calendar-period-navigation {
        gap: 5px;
    }

    .calendar-period-navigation .calendar-control {
        min-width: 36px;
        min-height: 36px;
    }

    .calendar-period-navigation .calendar-control-today {
        padding-inline: 8px;
    }

    .calendar-view-selector select {
        max-width: 92px;
        padding-inline: 9px 25px;
    }
}

@media (max-width: 420px) {
    .content:has(.calendar) {
        padding: 0 8px 20px;
    }

    .calendar-header-controls {
        grid-template-columns: 36px 36px minmax(0, 1fr) auto;
    }

    .calendar-control {
        min-width: 36px;
        min-height: 36px;
    }
}

/* Persisted Event and Task integration */
.calendar-day-create {
    position: absolute;
    z-index: 0;
    inset: 0;
    display: flex;
    align-items: flex-start;
    border: 0;
    padding: 4px 6px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.calendar-day-create:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: -3px;
}

.calendar-events {
    position: relative;
    z-index: 1;
    margin-top: 32px;
    pointer-events: auto;
}

.calendar-item {
    display: grid;
    min-width: 0;
    min-height: 25px;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 5px;
    overflow: hidden;
    border-radius: 5px;
    padding: 5px 7px;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.25;
    text-decoration: none;
    white-space: nowrap;
}

.calendar-item:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
}

.calendar-item-prefix,
.calendar-task-due {
    font-size: .84em;
    font-weight: 800;
}

.calendar-item-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calendar-event {
    border-left: 3px solid #8b5cf6;
    background: #f0eefe;
    color: #403269;
}

.calendar-event.is-all-day {
    background: #e9e5ff;
}

.calendar-task {
    grid-template-columns: minmax(0, 1fr) auto;
    border-left: 3px solid var(--task-color, #64748b);
    background: #f1f5f9;
    color: #273548;
}

.calendar-task-due {
    color: #667085;
}

.calendar-task.is-overdue {
    background: #fef3f2;
    color: #912018;
}

.calendar-task.is-overdue .calendar-task-due {
    color: #b42318;
}

.calendar-task.is-completed {
    opacity: .72;
}

.calendar-day.is-outside .calendar-item {
    opacity: .62;
}

.calendar-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.calendar-create-dialog {
    width: min(92vw, 430px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    background: #fff;
    color: var(--ink);
    box-shadow: 0 24px 70px rgb(15 23 42 / 28%);
}

.calendar-create-dialog::backdrop {
    background: rgb(15 23 42 / 48%);
}

.calendar-dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    color: var(--ink);
    font-size: 22px;
    cursor: pointer;
}

.calendar-dialog-eyebrow {
    margin: 0 0 7px;
    color: #6d28d9;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.calendar-create-dialog h2 {
    margin: 0;
    font-size: 25px;
}

.calendar-create-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 24px;
}

.calendar-create-actions a,
.calendar-form-actions button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid #6d28d9;
    border-radius: 10px;
    padding: 9px 14px;
    background: #6d28d9;
    color: #fff;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}

.calendar-create-actions a:first-child {
    border-color: var(--border);
    background: #fff;
    color: var(--ink);
}

.calendar-form-page {
    width: min(100%, 860px);
    margin: 0 auto;
}

.calendar-form-page h1 {
    font-size: clamp(30px, 4vw, 44px);
}

.calendar-form-page > p {
    margin: 8px 0 24px;
    color: var(--muted);
}

.calendar-form-back {
    display: inline-block;
    margin-bottom: 18px;
    color: #6d28d9;
    font-weight: 700;
    text-decoration: none;
}

.calendar-entity-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: clamp(22px, 4vw, 36px);
    background: #fff;
    box-shadow: 0 12px 36px rgb(16 24 40 / 5%);
}

.calendar-form-span {
    grid-column: 1 / -1;
}

.calendar-form-field {
    min-width: 0;
}

.calendar-form-field label,
.calendar-form-field legend {
    display: block;
    margin-bottom: 7px;
    font-size: 14px;
    font-weight: 700;
}

.calendar-form-field input,
.calendar-form-field textarea,
.calendar-form-field select {
    width: 100%;
    min-height: 44px;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

.calendar-form-field textarea {
    resize: vertical;
}

.calendar-form-field input:focus,
.calendar-form-field textarea:focus,
.calendar-form-field select:focus {
    border-color: #7c3aed;
    outline: 3px solid rgb(124 58 237 / 15%);
}

.calendar-optional,
.calendar-form-help {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.calendar-form-help,
.calendar-field-error {
    margin: 6px 0 0;
}

.calendar-field-error {
    color: #b42318;
    font-size: 13px;
}

.calendar-duration {
    margin: 0;
    border: 0;
    padding: 0;
}

.calendar-duration > div {
    display: grid;
    grid-template-columns: auto minmax(80px, 140px) auto minmax(80px, 140px);
    align-items: center;
    gap: 10px;
}

.calendar-duration label {
    margin: 0;
}

.calendar-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.calendar-form-actions a {
    color: #6d28d9;
    font-weight: 700;
}
.calendar-delete-form {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.calendar-delete-form button {
    min-height: 44px;
    border: 1px solid #fecaca;
    border-radius: 10px;
    padding: 9px 14px;
    background: #fff;
    color: #b42318;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

@media (max-width: 1024px) {
    .calendar-item {
        min-height: 21px;
        padding: 4px 5px;
        font-size: 10px;
    }
}

@media (max-width: 767px) {
    .calendar-events {
        margin-top: 26px;
    }

    .calendar-day-create {
        padding: 3px 4px;
    }

    .calendar-item {
        min-height: 16px;
        gap: 3px;
        border-left-width: 2px;
        padding: 3px;
        font-size: 8px;
    }

    .calendar-task-due {
        max-width: 48px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .calendar-entity-form {
        grid-template-columns: 1fr;
    }

    .calendar-form-span {
        grid-column: 1;
    }
}

@media (max-width: 480px) {
    .calendar-create-actions {
        grid-template-columns: 1fr;
    }

    .calendar-duration > div {
        grid-template-columns: auto 1fr;
    }
}

.calendar-timed-event {
    white-space: normal;
}

.calendar-time-section-items .calendar-item {
    min-height: 21px;
    padding: 3px 5px;
    font-size: 10px;
}

.calendar-month-view .calendar-events {
    margin-top: 0;
}
