/* Tupurin maja calendar + date-summary — linked from /v/tupurin-maja/ only */

/* Calendar skeleton / loading overlay (Tupurin grid) */
.cal-day.cal-day-skeleton {
    aspect-ratio: 1;
    min-height: 3.1rem;
    border: 1px solid color-mix(in srgb, var(--form-border-light) 65%, transparent);
    pointer-events: none;
}

.calendar-block.is-initial-load .cal-mode-bar,
.calendar-block.is-initial-load .cal-clear {
    opacity: 0.55;
    pointer-events: none;
}

.cal-grid-panel.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--form-input-bg) 72%, transparent);
    border-radius: inherit;
    pointer-events: none;
    z-index: 2;
}

.cal-grid-panel.is-loading::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.65rem;
    height: 1.65rem;
    margin: -0.825rem 0 0 -0.825rem;
    border: 2px solid color-mix(in srgb, var(--vilpas-blue) 22%, var(--form-border-light));
    border-top-color: var(--vilpas-blue);
    border-radius: 50%;
    animation: icon-spin 0.85s linear infinite;
    z-index: 3;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .cal-grid-panel.is-loading::before {
        animation: none;
        opacity: 0.75;
    }
}

.cal-status.is-error > .icon {
    color: var(--vilpas-red);
}

/* Step 1 dates flow + calendar grid (Tupurin only) */
/* Step 1: dates and event flow */
.form-dates-flow {
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
}

.form-dates-block {
    min-width: 0;
}

.form-dates-flow .calendar-block {
    margin-bottom: 0;
}

.form-dates-event {
    padding-top: 0.35rem;
    border-top: 1px solid var(--form-border-light);
}

.form-dates-subheading {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0 0 0.9rem;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--vilpas-blue-dark);
}

.form-dates-subheading .icon {
    color: var(--vilpas-red);
    opacity: 0.9;
}

.form-dates-event .field:last-of-type,
.form-dates-ehdot {
    margin-bottom: 0;
}

.price-estimate-row.status-with-icon {
    align-items: center;
}

.price-estimate-row .icon {
    color: var(--vilpas-blue);
}

.field-error.hint-with-icon > .icon {
    color: var(--vilpas-red);
    margin-top: 0.1em;
}

/* Calendar */
.calendar-block {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 1rem;
    padding: 0;
    background: var(--form-input-bg);
    border: 1px solid var(--form-border-light);
    border-radius: var(--form-card-radius);
    overflow: hidden;
}

.cal-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.85rem 1rem 0.95rem;
    background: color-mix(in srgb, var(--vilpas-blue) 4%, var(--form-input-bg));
}

.cal-header + .cal-grid-panel {
    border-top: 1px solid var(--form-border-light);
}

.calendar-toolbar {
    display: grid;
    grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
    align-items: center;
    gap: 0.35rem 0.5rem;
    width: 100%;
}

.calendar-toolbar > #cal-prev {
    justify-self: start;
}

.calendar-toolbar > #cal-next {
    justify-self: end;
}

.calendar-toolbar > .cal-month-label {
    justify-self: center;
    width: 100%;
}

.cal-month-label {
    margin: 0;
    min-width: 0;
    text-align: center;
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    line-height: 1.15;
    text-transform: capitalize;
    color: var(--vilpas-blue-dark);
    letter-spacing: 0.02em;
    overflow-wrap: anywhere;
}

.cal-month-week {
    font-family: var(--font-body, inherit);
    font-size: 0.72em;
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
    color: var(--form-muted);
    white-space: normal;
}

/* Mode toggle removed from UI — day click only; keep rules inert if markup reappears. */
.cal-mode-bar,
.cal-mode-options {
    display: none !important;
}

.date-summary-head-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.5rem;
    justify-content: flex-end;
}

.cal-mode-bar--legacy {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

.cal-mode-label {
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--form-muted);
}

.cal-mode-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    flex: 1 1 auto;
}

.cal-grid-panel {
    padding: 0.75rem 0.85rem 0.85rem;
    background: color-mix(in srgb, var(--vilpas-blue) 6%, #fff);
    border-bottom: 1px solid color-mix(in srgb, var(--vilpas-blue) 12%, var(--form-border-light));
    position: relative;
}

.cal-footer {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0.65rem 1rem 0.85rem;
    border-top: 1px solid var(--form-border-light);
    background: color-mix(in srgb, var(--form-muted) 4%, var(--form-input-bg));
    contain: layout;
}

.cal-footer-fold {
    margin: 0;
    border: 0;
    background: transparent;
}

.cal-footer-fold-summary {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    padding: 0.35rem 0;
    min-height: 2.75rem;
    list-style: none;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: color-mix(in srgb, var(--form-text) 88%, var(--vilpas-blue));
}

.cal-footer-fold-summary::-webkit-details-marker,
.cal-footer-fold-summary::marker {
    display: none;
    content: "";
}

.cal-footer-fold-summary::after {
    content: "";
    margin-left: auto;
    width: 0.4rem;
    height: 0.4rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    flex-shrink: 0;
    opacity: 0.7;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.cal-footer-fold[open] > .cal-footer-fold-summary {
    margin-bottom: 0.35rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid color-mix(in srgb, var(--form-border-light) 80%, transparent);
}

.cal-footer-fold[open] > .cal-footer-fold-summary::after {
    transform: rotate(-135deg);
    opacity: 1;
}

.cal-footer-fold-summary > .icon {
    flex-shrink: 0;
    color: var(--vilpas-blue);
}

.cal-footer-fold-hint {
    font-weight: 500;
    color: var(--form-muted);
}

.cal-footer-fold-panel {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0.15rem 0 0.25rem;
}

.cal-footer-fold-summary:focus {
    outline: none;
}

.cal-footer-fold-summary:focus-visible {
    outline: 2px solid var(--vilpas-blue);
    outline-offset: 2px;
    border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .cal-footer-fold-summary::after {
        transition: none;
    }
}

/* Selite at the top of the calendar block (Tupurin maja form), so the month
   header sits directly on the day grid. Scoped to the first-child position so the
   unrelated footer-placed fold (public/e) is untouched. */
.calendar-block > .cal-footer-fold:first-child {
    padding: 0 1rem;
    background: color-mix(in srgb, var(--vilpas-blue) 3%, var(--form-input-bg));
}

.calendar-block > .cal-footer-fold:first-child + .cal-header {
    border-top: 1px solid color-mix(in srgb, var(--vilpas-blue) 12%, var(--form-border-light));
}

.calendar-block > .cal-footer-fold:first-child > .cal-footer-fold-summary {
    padding: 0.55rem 0;
    border-radius: var(--form-radius);
    transition: color var(--transition);
}

.calendar-block > .cal-footer-fold:first-child > .cal-footer-fold-summary:hover {
    color: var(--vilpas-blue-dark);
}

.calendar-block > .cal-footer-fold:first-child[open] > .cal-footer-fold-summary {
    margin-bottom: 0.55rem;
}

.calendar-block > .cal-footer-fold:first-child > .cal-footer-fold-summary > .icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--vilpas-blue) 14%, transparent);
    color: var(--vilpas-blue-dark);
}

.calendar-block > .cal-footer-fold:first-child .cal-footer-fold-panel {
    padding: 0 0 0.9rem;
    gap: 0.6rem;
}

.calendar-block > .cal-footer-fold:first-child .cal-legend-wrap {
    padding: 0.65rem 0.75rem;
    border-radius: var(--form-radius);
    background: var(--form-input-bg);
    border: 1px solid var(--form-border-light);
}

@media (max-width: 599px) {
    .calendar-block > .cal-footer-fold:first-child {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

.cal-meta {
    display: grid;
    gap: 0.5rem;
}

@media (min-width: 640px) {
    .cal-meta {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: start;
    }

    .cal-header {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0.75rem;
    }

    .calendar-toolbar {
        width: 100%;
    }

    .cal-month-label {
        min-width: 0;
    }

    .cal-mode-bar {
        flex: 1 1 16rem;
        justify-content: flex-end;
    }

    .cal-mode-label {
        margin-right: 0.15rem;
    }
}

.mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 2.75rem;
    padding: 0.42rem 0.75rem;
    border: 1px solid var(--form-border-light);
    border-radius: 999px;
    font-size: 0.84rem;
    cursor: pointer;
    background: var(--form-input-bg);
    color: var(--form-text);
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
    transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}

.mode-toggle:has(input:checked) {
    border-color: var(--vilpas-red);
    background: color-mix(in srgb, var(--vilpas-red) 6%, #fff);
    box-shadow: 0 0 0 1px var(--vilpas-red);
}

.mode-toggle input {
    margin: 0;
}

.cal-hint,
.cal-status {
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--form-muted);
    margin: 0;
    padding: 0.55rem 0.7rem;
    border-radius: var(--form-radius);
    background: var(--form-input-bg);
    border: 1px solid var(--form-border-light);
}

.cal-status {
    align-self: start;
    /* Stable footprint while “Ladataan…” → ready text swaps (CLS). */
    min-height: 3.25rem;
}

.cal-hint.hint-with-icon,
.cal-status.status-with-icon {
    display: flex;
    align-items: flex-start;
    gap: 0.4em;
}

.cal-hint.hint-with-icon > .icon,
.cal-status.status-with-icon > .icon {
    flex-shrink: 0;
    margin-top: 0.2em;
    margin-bottom: 0;
    line-height: 1;
    color: var(--vilpas-blue);
}

.cal-status.status-with-icon > .icon {
    color: var(--form-muted);
}

.cal-retry {
    align-self: start;
    font-size: 0.82rem;
}

.calendar-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* Form calendar stays light in both themes — same saturated Selite tokens as .cal-legend */
    --status-free-swatch: var(--free);
    --status-partial-swatch: var(--partial);
    --status-pending-swatch: var(--pending);
    --status-jaosto-swatch: var(--jaosto);
    --status-booked-swatch: var(--booked);
    --status-cleaning-swatch: var(--cleaning);
    --status-selected-swatch: var(--vilpas-blue);
    --swatch-border: #1a1a1a;
    /* Past / adjacent-month mute — neutral grey fill; day-num slightly greyer than
       current-month ink (still AAA ≥7:1 on muted fill). Labels stay quieter. */
    --cal-day-muted-bg: color-mix(in srgb, var(--form-muted) 18%, #fff);
    --cal-day-muted-bg-past: color-mix(in srgb, var(--form-muted) 32%, #fff);
    --cal-day-muted-text: color-mix(in srgb, var(--form-text) 72%, var(--form-muted));
    --cal-day-muted-label: color-mix(in srgb, var(--form-muted) 88%, var(--form-text));
    --cal-day-muted-border: color-mix(in srgb, var(--form-muted) 42%, var(--form-border-light));
}

.cal-weekdays,
.cal-week {
    display: grid;
    grid-template-columns: minmax(1.65rem, 2rem) repeat(7, minmax(0, 1fr));
    gap: 4px;
}

.cal-weekday-num {
    font-size: 0.62rem;
    letter-spacing: 0.03em;
    padding-inline: 0;
}

.cal-week-num {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 3.1rem;
    font-size: 0.62rem;
    font-weight: 600;
    line-height: 1.15;
    text-align: center;
    color: var(--form-muted);
    padding: 0.1rem 0.05rem;
}

.cal-week-num.empty {
    visibility: hidden;
}

.cal-days {
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* Reserve 6 week rows so skeleton → labeled days does not shove .cal-footer (CLS). */
    min-height: calc(6 * 3.1rem + 5 * 4px);
    contain: layout;
}

.cal-weekdays {
    padding-bottom: 0.35rem;
    margin-bottom: 2px;
    border-bottom: 1px solid color-mix(in srgb, var(--vilpas-blue) 14%, var(--form-border-light));
}

.cal-weekday {
    text-align: center;
    font-size: 0.7rem;
    color: var(--form-muted);
    padding: 0.15rem 0 0.25rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cal-weekday-weekend {
    color: var(--vilpas-blue-dark);
}

.cal-day {
    aspect-ratio: 1;
    min-height: 3.1rem;
    height: 100%;
    border: 1px solid var(--form-border-light);
    border-radius: var(--form-radius);
    background: var(--form-input-bg);
    color: var(--form-text);
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.22rem 0.28rem 0.28rem;
    position: relative;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.1rem;
    min-width: 0;
    overflow: hidden;
    contain: layout paint;
    transition: border-color var(--transition), box-shadow var(--transition), transform 0.15s ease;
}

/* Top stripe unused when cell fill already matches Selite swatch; keep for maintenance dual-cue */
.cal-day::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0;
    border-radius: var(--form-radius) var(--form-radius) 0 0;
    opacity: 1;
    pointer-events: none;
}

.cal-day.has-maintenance.has-cleaning::before {
    background: color-mix(in srgb, var(--status-selected-swatch) 55%, var(--status-cleaning-swatch));
    height: 4px;
}

.cal-day.has-maintenance.has-cleaning {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--status-cleaning-swatch) 45%, var(--status-selected-swatch));
}

.cal-day:not(.empty):not([aria-disabled="true"]):hover {
    border-color: color-mix(in srgb, var(--vilpas-blue) 55%, var(--form-border-light));
}

.cal-day:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    z-index: 2;
}

.cal-day-num {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1.1;
    flex-shrink: 0;
}

.cal-day.is-today .cal-day-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-start;
    min-width: 1.45rem;
    min-height: 1.45rem;
    padding: 0 0.2rem;
    border-radius: 999px;
    background: var(--vilpas-blue-dark);
    color: #fff;
    font-size: 0.82rem;
}

/* Two or more bookings on one day: clearer outer edge + count badge (bottom right). */
.cal-day.has-multi-booking {
    border-color: #111;
    border-width: 2px;
    padding: calc(0.22rem - 1px) calc(0.28rem - 1px) calc(0.28rem - 1px);
}

[data-theme="dark"] .cal-day.has-multi-booking {
    border-color: #fff;
}

.cal-day-count {
    position: absolute;
    right: 0.2rem;
    bottom: 0.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.15rem;
    height: 1.15rem;
    padding: 0 0.25rem;
    border: 1px solid #fff;
    border-radius: 999px;
    background: #111;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
}

.cal-day-label {
    font-size: 0.63rem;
    line-height: 1.25;
    font-weight: 600;
    color: var(--form-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    /* Always reserve two label lines so has-label paint does not change cell height. */
    min-height: calc(0.63rem * 1.25 * 2);
    word-break: break-word;
    hyphens: auto;
}

.cal-day.has-label .cal-day-num {
    font-size: 0.8rem;
}

.cal-day.status-free,
.cal-day.status-partial,
.cal-day.status-booked,
.cal-day.status-pending,
.cal-day.status-cleaning,
.cal-day.has-cleaning,
.cal-day.selected,
.cal-day.range-start,
.cal-day.range-end,
.cal-day.in-range {
    color: var(--status-fill-text);
    border-color: var(--swatch-border);
}

.cal-day.status-free .cal-day-num,
.cal-day.status-free .cal-day-label,
.cal-day.status-partial .cal-day-num,
.cal-day.status-partial .cal-day-label,
.cal-day.status-booked .cal-day-num,
.cal-day.status-booked .cal-day-label,
.cal-day.status-pending .cal-day-num,
.cal-day.status-pending .cal-day-label,
.cal-day.status-cleaning .cal-day-num,
.cal-day.status-cleaning .cal-day-label,
.cal-day.has-cleaning .cal-day-num,
.cal-day.has-cleaning .cal-day-label,
.cal-day.selected .cal-day-num,
.cal-day.range-start .cal-day-num,
.cal-day.range-end .cal-day-num,
.cal-day.in-range .cal-day-num,
.cal-day.selected .cal-day-label,
.cal-day.range-start .cal-day-label,
.cal-day.range-end .cal-day-label,
.cal-day.in-range .cal-day-label {
    color: var(--status-fill-text);
}

/* Today pill: dark blue chip remains readable on saturated fills */
.cal-day.is-today .cal-day-num {
    color: #fff;
    box-shadow: 0 0 0 1px color-mix(in srgb, #fff 55%, transparent);
}

.cal-day.empty {
    visibility: hidden;
    pointer-events: none;
}

.cal-day.other-month .cal-day-num {
    font-weight: 600;
}

.cal-day.status-free {
    background: var(--status-free-swatch);
}

.cal-day.status-partial {
    background: var(--status-partial-swatch);
}

.cal-day.status-booked {
    background: var(--status-booked-swatch);
    cursor: not-allowed;
}

.cal-day.status-pending {
    background: var(--status-pending-swatch);
    border-style: dashed;
    border-color: var(--swatch-border);
    cursor: not-allowed;
}

.cal-day.status-jaosto {
    background: var(--status-jaosto-swatch);
    color: var(--jaosto-text);
    border-color: var(--swatch-border);
}

.cal-day.status-jaosto:not(.is-today) .cal-day-num,
.cal-day.status-jaosto .cal-day-label {
    color: var(--jaosto-text);
}

.cal-day.status-jaosto.is-today .cal-day-num {
    color: #fff;
}

.cal-day.status-cleaning,
.cal-day.has-cleaning {
    background: var(--status-cleaning-swatch);
}

.cal-day.selected,
.cal-day.range-start,
.cal-day.range-end {
    background: var(--status-selected-swatch);
    border-color: var(--swatch-border);
    border-width: 2px;
    padding: calc(0.22rem - 1px) calc(0.28rem - 1px) calc(0.28rem - 1px);
    font-weight: 700;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--status-selected-swatch) 35%, transparent);
}

.cal-day.in-range {
    background: var(--status-selected-swatch);
    border-color: var(--swatch-border);
}

/*
 * Unavailable mute (past + adjacent-month trail/lead): neutral grey fill + muted text.
 * Must win over status-* / has-cleaning so past never reads as Selite free/partial/booked.
 * Selected/range other-month keeps selected blue. Future booked/pending keep Selite hues.
 * `.is-today` is excluded from the day-num color mute so the blue today pill keeps white
 * ink (muted dark-on-blue made the number invisible when today peeks from the adjacent month).
 */
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range),
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).status-free,
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).status-partial,
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).status-booked,
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).status-pending,
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).status-jaosto,
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).status-cleaning,
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).has-cleaning {
    background: var(--cal-day-muted-bg);
    color: var(--cal-day-muted-text);
    border-color: var(--cal-day-muted-border);
    border-style: solid;
    box-shadow: none;
}

.cal-day.past,
.cal-day.past.status-free,
.cal-day.past.status-partial,
.cal-day.past.status-booked,
.cal-day.past.status-pending,
.cal-day.past.status-jaosto,
.cal-day.past.status-cleaning,
.cal-day.past.has-cleaning,
.cal-day.past.has-maintenance.has-cleaning {
    background: var(--cal-day-muted-bg-past);
    color: var(--cal-day-muted-text);
    border-color: var(--cal-day-muted-border);
    border-style: solid;
    box-shadow: none;
    cursor: not-allowed;
}

/* Same-booker inset ring must survive past/other-month mute (those set box-shadow: none). */
.cal-day.past.has-booker-bundle,
.cal-day.other-month.has-booker-bundle:not(.selected):not(.range-start):not(.range-end):not(.in-range) {
    box-shadow: inset 0 0 0 2px var(--bundle-color, hsl(210 58% 32%));
}

.cal-day.other-month:not(.is-today):not(.selected):not(.range-start):not(.range-end):not(.in-range) .cal-day-num,
.cal-day.other-month:not(.is-today):not(.selected):not(.range-start):not(.range-end):not(.in-range) .cal-day-label,
.cal-day.past:not(.is-today) .cal-day-num,
.cal-day.past:not(.is-today) .cal-day-label,
.cal-day.past:not(.is-today).status-free .cal-day-num,
.cal-day.past:not(.is-today).status-free .cal-day-label,
.cal-day.past:not(.is-today).status-partial .cal-day-num,
.cal-day.past:not(.is-today).status-partial .cal-day-label,
.cal-day.past:not(.is-today).status-booked .cal-day-num,
.cal-day.past:not(.is-today).status-booked .cal-day-label,
.cal-day.past:not(.is-today).status-pending .cal-day-num,
.cal-day.past:not(.is-today).status-pending .cal-day-label,
.cal-day.past:not(.is-today).status-cleaning .cal-day-num,
.cal-day.past:not(.is-today).status-cleaning .cal-day-label,
.cal-day.past:not(.is-today).has-cleaning .cal-day-num,
.cal-day.past:not(.is-today).has-cleaning .cal-day-label {
    color: var(--cal-day-muted-text);
}

.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range) .cal-day-label,
.cal-day.past .cal-day-label {
    color: var(--cal-day-muted-label);
}

/* Today pill: keep white ink + blue chip even when the cell is other-month muted. */
.cal-day.is-today .cal-day-num {
    color: #fff;
    background: var(--vilpas-blue-dark);
    box-shadow: 0 0 0 1px color-mix(in srgb, #fff 55%, transparent);
}

.cal-day.past.has-maintenance.has-cleaning::before,
.cal-day.other-month:not(.selected):not(.range-start):not(.range-end):not(.in-range).has-maintenance.has-cleaning::before {
    height: 0;
    background: transparent;
}

.cal-day[aria-disabled="true"] {
    cursor: not-allowed;
}

.cal-day:disabled {
    cursor: not-allowed;
}

.cal-day-tooltip {
    position: fixed;
    z-index: 40;
    max-width: min(19rem, calc(100vw - 1.25rem));
    padding: 0.6rem 0.7rem;
    border-radius: var(--form-radius);
    border: 1px solid color-mix(in srgb, var(--vilpas-blue) 22%, var(--form-border-light));
    background: var(--form-input-bg);
    color: var(--form-text);
    box-shadow:
        0 6px 18px color-mix(in srgb, var(--form-text) 16%, transparent),
        0 0 0 1px color-mix(in srgb, var(--form-text) 4%, transparent);
    pointer-events: none;
    font-size: 0.8rem;
    line-height: 1.4;
}

.cal-day-tooltip.is-pinned {
    border-color: var(--vilpas-blue);
    box-shadow:
        0 8px 22px color-mix(in srgb, var(--form-text) 18%, transparent),
        0 0 0 2px color-mix(in srgb, var(--vilpas-blue) 35%, transparent);
}

.cal-day-tooltip-line {
    margin: 0;
}

.cal-day-tooltip-line + .cal-day-tooltip-line {
    margin-top: 0.28rem;
    padding-top: 0.28rem;
    border-top: 1px solid color-mix(in srgb, var(--form-border-light) 80%, transparent);
}

.cal-day-tooltip-line:first-child {
    font-weight: 600;
    color: var(--vilpas-blue-dark);
}

.cal-day-tooltip-status {
    font-weight: 700;
    color: var(--vilpas-blue-dark);
}

/* Past "Mennyt" — muted grey, not active blue (beats :first-child blue). */
.cal-day-tooltip-past,
.cal-day-tooltip-line:first-child.cal-day-tooltip-past {
    font-weight: 700;
    color: var(--cal-day-muted-text, color-mix(in srgb, var(--form-text) 62%, var(--form-muted)));
}

.cal-day-tooltip-bundle {
    font-weight: 600;
    color: color-mix(in srgb, var(--vilpas-red) 75%, var(--form-text));
}

.cal-day.has-booker-bundle {
    --bundle-color: hsl(210 58% 32%);
    box-shadow: inset 0 0 0 2px var(--bundle-color);
}

.cal-day.has-booker-bundle[data-booker-bundle="0"] {
    --bundle-color: hsl(210 58% 32%);
}

.cal-day.has-booker-bundle[data-booker-bundle="1"] {
    --bundle-color: hsl(28 65% 35%);
}

.cal-day.has-booker-bundle[data-booker-bundle="2"] {
    --bundle-color: hsl(145 48% 28%);
}

.cal-day.has-booker-bundle[data-booker-bundle="3"] {
    --bundle-color: hsl(280 48% 36%);
}

.cal-day.has-booker-bundle[data-booker-bundle="4"] {
    --bundle-color: hsl(350 55% 36%);
}

.cal-day.has-booker-bundle[data-booker-bundle="5"] {
    --bundle-color: hsl(185 52% 30%);
}

.cal-day.has-booker-bundle[data-booker-bundle="6"] {
    --bundle-color: hsl(55 65% 26%);
}

.cal-day.has-booker-bundle[data-booker-bundle="7"] {
    --bundle-color: hsl(320 52% 36%);
}

.cal-day.has-booker-bundle.bundle-edge-start,
.cal-day.has-booker-bundle.bundle-edge-middle,
.cal-day.has-booker-bundle.bundle-edge-end,
.cal-day.has-booker-bundle.bundle-edge-single {
    outline: 2px solid var(--bundle-color);
    outline-offset: -3px;
}

.cal-day.has-booker-bundle.selected,
.cal-day.has-booker-bundle.range-start,
.cal-day.has-booker-bundle.range-end,
.cal-day.has-booker-bundle.in-range {
    outline-color: var(--vilpas-blue);
}

.date-summary {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 0;
    padding: 0;
    background: var(--form-input-bg);
    border: 1px solid var(--form-border-light);
    border-radius: var(--form-card-radius);
    color: var(--form-text);
    overflow: hidden;
    box-shadow: 0 1px 0 color-mix(in srgb, var(--form-text) 4%, transparent);
}

.date-summary-primary {
    padding: 0.95rem 1.05rem 1rem;
    background:
        linear-gradient(
            90deg,
            color-mix(in srgb, var(--vilpas-red) 88%, #000) 0 3px,
            color-mix(in srgb, var(--vilpas-blue) 8%, #fff) 3px
        );
    border-bottom: 1px solid color-mix(in srgb, var(--vilpas-blue) 14%, var(--form-border-light));
}

.date-summary-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.55rem;
}

.date-summary-label {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--vilpas-blue-dark);
}

.date-summary-count {
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.2;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--vilpas-blue) 14%, #fff);
    border: 1px solid color-mix(in srgb, var(--vilpas-blue) 22%, var(--form-border-light));
    color: var(--vilpas-blue-dark);
    white-space: nowrap;
}

.date-summary-kind {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 650;
    line-height: 1.25;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--form-muted) 10%, #fff);
    border: 1px solid color-mix(in srgb, var(--form-muted) 22%, var(--form-border-light));
    color: color-mix(in srgb, var(--form-text) 78%, var(--form-muted));
    max-width: 22rem;
}

.date-summary-text {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--form-text);
    letter-spacing: -0.01em;
}

.date-summary-text.is-multiple {
    font-size: 1rem;
    font-weight: 600;
}

.date-summary-date-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.date-summary-date-list li {
    padding: 0.35rem 0.7rem;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.3;
    border-radius: var(--form-radius);
    background: #fff;
    border: 1px solid color-mix(in srgb, var(--vilpas-blue) 32%, var(--form-border-light));
    box-shadow: 0 1px 0 color-mix(in srgb, var(--form-text) 5%, transparent);
    font-variant-numeric: tabular-nums;
}

.date-summary-secondary {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0.8rem 1.05rem 0.95rem;
    background: color-mix(in srgb, var(--form-muted) 3%, var(--form-input-bg));
}

.date-summary-block {
    padding: 0.65rem 0.75rem;
    border-radius: var(--form-radius);
    font-size: 0.85rem;
}

.date-summary-block-title {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    margin: 0 0 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--form-muted);
}

.date-summary-block-body {
    margin: 0;
    line-height: 1.45;
}

.date-summary-availability.is-partial {
    background: color-mix(in srgb, var(--partial) 12%, #fff);
    border: 1px solid color-mix(in srgb, var(--partial) 35%, var(--form-border-light));
}

.date-summary-availability.is-partial .date-summary-block-title .icon {
    color: var(--partial-text);
}

.date-summary-availability.is-blocked {
    background: color-mix(in srgb, var(--booked) 10%, #fff);
    border: 1px solid color-mix(in srgb, var(--booked) 30%, var(--form-border-light));
}

.date-summary-availability.is-blocked .date-summary-block-title .icon {
    color: var(--booked-text);
}

.date-summary-cleaning {
    background: color-mix(in srgb, var(--cleaning) 10%, #fff);
    border: 1px solid color-mix(in srgb, var(--cleaning) 30%, var(--form-border-light));
}

.date-summary-cleaning .date-summary-block-title .icon {
    color: var(--cleaning-text);
}

.date-summary-cleaning-lead {
    margin: 0 0 0.25rem;
    font-weight: 600;
    color: var(--form-text);
}

.date-summary-cleaning-list {
    margin: 0;
    padding-left: 1.1rem;
    list-style: disc;
}

.date-summary-cleaning-list li {
    margin: 0.15rem 0;
    line-height: 1.4;
}

.date-summary-cleaning-list li::marker {
    color: var(--cleaning-text);
}

.date-summary-pricing {
    background: color-mix(in srgb, var(--vilpas-blue) 8%, #fff);
    border: 1px solid color-mix(in srgb, var(--vilpas-blue) 24%, var(--form-border-light));
}

.date-summary-pricing .date-summary-block-title .icon {
    color: var(--vilpas-blue);
}

.date-summary-pricing-amount {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.35rem 1rem;
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--form-text);
}

.date-summary-pricing-lead {
    font-size: 0.88rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--form-text) 82%, var(--form-muted));
}

.date-summary-pricing-euro {
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--vilpas-blue-dark);
    font-variant-numeric: tabular-nums;
}

.date-summary-pricing-currency {
    font-size: 0.85em;
    font-weight: 700;
}

.date-summary-pricing-fold {
    margin: 0.45rem 0 0;
}

.date-summary-pricing-fold[hidden] {
    display: none;
}

.date-summary-pricing-fold > summary {
    cursor: pointer;
    list-style: none;
    font-size: 0.78rem;
    font-weight: 650;
    color: var(--vilpas-blue-dark);
    padding: 0.15rem 0;
}

.date-summary-pricing-fold > summary::-webkit-details-marker,
.date-summary-pricing-fold > summary::marker {
    display: none;
    content: "";
}

.date-summary-pricing-fold > summary::after {
    content: "";
    display: inline-block;
    width: 0.4rem;
    height: 0.4rem;
    margin-left: 0.4rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-0.1rem);
    vertical-align: middle;
    opacity: 0.75;
}

.date-summary-pricing-fold[open] > summary::after {
    transform: rotate(225deg) translateY(-0.05rem);
}

.date-summary-pricing-hint {
    margin: 0.35rem 0 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--form-muted);
}

.date-summary-warning {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    margin: 0;
    padding: 0.55rem 0.65rem;
    border-radius: var(--form-radius);
    background: color-mix(in srgb, var(--vilpas-red) 8%, #fff);
    border: 1px solid color-mix(in srgb, var(--vilpas-red) 28%, var(--form-border-light));
}

.cal-legend-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.cal-legend {
    /* Form panel stays light in both themes — force saturated chips + dark outline */
    --status-free-swatch: var(--free);
    --status-partial-swatch: var(--partial);
    --status-pending-swatch: var(--pending);
    --status-jaosto-swatch: var(--jaosto);
    --status-booked-swatch: var(--booked);
    --status-cleaning-swatch: var(--cleaning);
    --status-selected-swatch: var(--vilpas-blue);
    --swatch-border: #1a1a1a;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.25rem, 1fr));
    gap: 0.45rem 0.9rem;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.8rem;
    line-height: 1.35;
    font-weight: 600;
    color: var(--form-text);
}

.cal-legend li {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.swatch {
    width: var(--swatch-size);
    height: var(--swatch-size);
    border-radius: 3px;
    border: 2px solid var(--swatch-border);
    flex-shrink: 0;
    box-sizing: border-box;
    box-shadow: none;
}

.swatch-free { background: var(--status-free-swatch); }
.swatch-partial { background: var(--status-partial-swatch); }
.swatch-booked { background: var(--status-booked-swatch); }
.swatch-jaosto { background: var(--status-jaosto-swatch); }
.swatch-pending {
    background: var(--status-pending-swatch);
    border-style: dashed;
    border-color: var(--swatch-border);
}
.swatch-cleaning {
    background-color: var(--status-cleaning-swatch);
    background-image: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 3px,
        color-mix(in srgb, #fff 28%, transparent) 3px,
        color-mix(in srgb, #fff 28%, transparent) 6px
    );
}
.swatch-selected {
    background: var(--status-selected-swatch);
    border-color: var(--swatch-border);
}
.swatch-bundle {
    background: color-mix(in srgb, var(--free) 42%, #fff);
    border: 2px solid hsl(210 58% 32%);
    box-shadow: inset 0 0 0 1px hsl(210 58% 32%);
}

.cal-status.is-error {
    color: var(--vilpas-red);
}

@media (max-width: 599px) {
    .form-section {
        padding: 1rem;
    }

    .btn-primary {
        width: 100%;
    }

    .cal-grid-panel {
        padding: 0.6rem 0.55rem 0.65rem;
    }

    .cal-header,
    .cal-footer {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .cal-month-label {
        font-size: 1.2rem;
    }

    .cal-mode-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .cal-mode-options {
        width: 100%;
    }

    .mode-toggle {
        flex: 1 1 calc(50% - 0.25rem);
        justify-content: center;
    }

    #cal-clear {
        width: 100%;
        justify-content: center;
    }

    .cal-meta {
        grid-template-columns: 1fr;
    }

    .cal-week-num {
        display: none;
    }

    .cal-weekdays,
    .cal-week {
        grid-template-columns: repeat(7, minmax(0, 1fr));
    }

    .cal-weekday-num {
        display: none;
    }

    .cal-weekday {
        font-size: 0.75rem;
    }

    .cal-day {
        /* Width follows the column: a 2.75rem square overlapped its neighbours on
           phones narrower than ~370px (seven 44px squares do not fit). */
        aspect-ratio: auto;
        min-height: 2.75rem;
        padding: 0.14rem 0.16rem 0.18rem;
    }

    .cal-days {
        min-height: calc(6 * 2.75rem + 5 * 4px);
    }

    .cal-day-label {
        font-size: 0.62rem;
        -webkit-line-clamp: 2;
        min-height: calc(0.62rem * 1.25 * 2);
    }

    .cal-day.selected,
    .cal-day.range-start,
    .cal-day.range-end {
        padding: calc(0.14rem - 1px) calc(0.16rem - 1px) calc(0.18rem - 1px);
    }

    .cal-day-num {
        font-size: 0.82rem;
    }

    .cal-day.is-today .cal-day-num {
        min-width: 1.35rem;
        min-height: 1.35rem;
        font-size: 0.76rem;
    }

    .cal-legend {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.45rem 0.65rem;
        font-size: 0.8rem;
    }

    .cal-day-tooltip {
        max-width: calc(100vw - 1rem);
        font-size: 0.78rem;
    }

    .cal-day:not(.empty):not([aria-disabled="true"]):hover {
        transform: none;
    }

    .date-summary-primary,
    .date-summary-secondary {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .date-summary-text {
        font-size: 1.05rem;
    }

    .date-summary-date-list {
        gap: 0.3rem;
    }

    .date-summary-date-list li {
        flex: 1 1 calc(50% - 0.3rem);
        text-align: center;
    }

    .form-dates-event {
        padding-top: 0.15rem;
    }
}

/* Narrow phones (320-380px): no room for status words in a ~32px column. The
   colour, the Selite legend and the tap tooltip carry the status; the number
   is centred. */
@media (max-width: 380px) {
    .cal-day-label {
        display: none;
    }

    .cal-day {
        justify-content: center;
        align-items: center;
    }

    .cal-day.is-today .cal-day-num {
        align-self: center;
    }

    /* Two legend columns cannot fit "Odottaa vahvistusta" next to a swatch. */
    .cal-legend {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 640px) {
    .date-summary-secondary {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
    }

    .date-summary-pricing,
    .date-summary-warning {
        grid-column: 1 / -1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cal-day,
    .mode-toggle {
        transition: none;
    }

    .cal-day:not(.empty):not([aria-disabled="true"]):hover {
        transform: none;
    }
}
