/**
 * BrightFrame Availability Calendar - public calendar.
 *
 * Colours come from CSS custom properties set inline on .bfav-calendar
 * (Settings > Calendar appearance). Two states only: available and booked.
 * Past days are greyed. Booked days also strike the number so the state
 * does not rely on colour alone.
 */

.bfav-calendar {
    --bfav-available: #16a34a;
    --bfav-available-bg: rgba(22, 163, 74, 0.14);
    --bfav-booked: #dc2626;
    --bfav-booked-bg: rgba(220, 38, 38, 0.14);
    --bfav-accent: #2563eb;
    --bfav-text: #1f2937;
    --bfav-muted: #6b7280;
    --bfav-past-bg: #f3f4f6;
    --bfav-past-text: #9ca3af;
    --bfav-radius: 8px;

    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    color: var(--bfav-text);
    font-family: inherit;
    line-height: 1.3;
    position: relative;
}

.bfav-calendar *,
.bfav-calendar *::before,
.bfav-calendar *::after {
    box-sizing: border-box;
}

/* Header */
.bfav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 14px;
}

.bfav-title {
    flex: 1;
    margin: 0;
    padding: 0;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.2;
}

.bfav-calendar .bfav-nav {
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    margin: 0;
    border: 1px solid #d1d5db;
    border-radius: 50%;
    background: #fff;
    color: var(--bfav-accent);
    cursor: pointer;
    box-shadow: none;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.bfav-calendar .bfav-nav:hover:not(:disabled),
.bfav-calendar .bfav-nav:focus-visible {
    background: #f3f4f6;
    border-color: var(--bfav-accent);
    outline: none;
}

.bfav-calendar .bfav-nav:disabled {
    opacity: 0.3;
    cursor: default;
}

/* Months */
.bfav-months {
    display: grid;
    grid-template-columns: 1fr;
    gap: 28px;
}

.bfav-months-2 .bfav-months {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bfav-months-3 .bfav-months {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.bfav-month {
    min-width: 0;
    /* Lets each month decide, from its OWN width, whether the state word fits. */
    container-type: inline-size;
}

.bfav-month-title {
    font-weight: 600;
    font-size: 1rem;
    text-align: center;
    margin: 0 0 8px;
}

.bfav-weekdays,
.bfav-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 5px;
}

.bfav-weekday {
    padding: 4px 0 6px;
    text-align: center;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bfav-muted);
}

/* Days */
.bfav-day {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 68px;
    padding: 6px 7px;
    border-radius: var(--bfav-radius);
    border: 1px solid transparent;
    font-size: 0.9rem;
    overflow: hidden;
}

.bfav-day-empty {
    background: transparent;
}

.bfav-day-num {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1;
}

.bfav-day-state {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bfav-day-available {
    background: var(--bfav-available-bg);
    color: var(--bfav-available);
    border-color: transparent;
}

.bfav-day-available .bfav-day-num {
    color: var(--bfav-text);
}

.bfav-day-booked {
    background: var(--bfav-booked-bg);
    color: var(--bfav-booked);
}

.bfav-day-booked .bfav-day-num {
    text-decoration: line-through;
    text-decoration-thickness: 2px;
    color: var(--bfav-booked);
}

.bfav-day-past {
    background: var(--bfav-past-bg);
    color: var(--bfav-past-text);
}

.bfav-day-past .bfav-day-num {
    color: var(--bfav-past-text);
    font-weight: 500;
}

.bfav-day-today {
    border-color: var(--bfav-accent);
    box-shadow: inset 0 0 0 1px var(--bfav-accent);
}

.bfav-day-today .bfav-day-num::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 5px;
    border-radius: 50%;
    background: var(--bfav-accent);
    vertical-align: 2px;
}

/* Legend */
.bfav-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 20px;
    list-style: none;
    margin: 14px 0 0;
    padding: 0;
    font-size: 0.85rem;
    color: var(--bfav-muted);
}

.bfav-legend li {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0;
    padding: 0;
}

.bfav-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.bfav-swatch-available {
    background: var(--bfav-available-bg);
    border-color: var(--bfav-available);
}

.bfav-swatch-booked {
    background: var(--bfav-booked-bg);
    border-color: var(--bfav-booked);
}

/* Loading */
.bfav-calendar.bfav-loading .bfav-inner {
    opacity: 0.55;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.bfav-calendar.bfav-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--bfav-accent);
    border-radius: 50%;
    animation: bfav-spin 0.8s linear infinite;
}

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

.bfav-error {
    margin: 10px 0 0;
    padding: 10px 12px;
    border-radius: 6px;
    background: #fef2f2;
    color: #991b1b;
    font-size: 0.9rem;
}

/* A month narrower than ~440px cannot fit "AVAILABLE" in a cell: drop the word,
   keep the colour, the strike-through and the key. Same look as the phone view. */
@container (max-width: 440px) {
    .bfav-day {
        min-height: 52px;
        justify-content: center;
        align-items: center;
        padding: 4px;
    }
    .bfav-day-state {
        display: none;
    }
    .bfav-day-today .bfav-day-num::after {
        display: block;
        width: 5px;
        height: 5px;
        margin: 3px auto 0;
    }
}

/* Tablet: 3 months become 2 columns */
@media (max-width: 1024px) {
    .bfav-months-3 .bfav-months {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Phone: one month per row, square cells, no state word (colour + strike + key) */
@media (max-width: 640px) {
    .bfav-months-2 .bfav-months,
    .bfav-months-3 .bfav-months {
        grid-template-columns: 1fr;
    }

    .bfav-title {
        font-size: 1.15rem;
    }

    .bfav-calendar .bfav-nav {
        width: 38px;
        height: 38px;
    }

    .bfav-weekdays,
    .bfav-days {
        gap: 3px;
    }

    .bfav-day {
        min-height: 0;
        aspect-ratio: 1 / 1;
        padding: 4px;
        justify-content: center;
        align-items: center;
        border-radius: 6px;
    }

    .bfav-day-num {
        font-size: 0.9rem;
    }

    .bfav-day-state {
        display: none;
    }

    .bfav-day-today .bfav-day-num::after {
        display: block;
        width: 5px;
        height: 5px;
        margin: 3px auto 0;
    }
}
