/* =============================================================================
 * Organic Calendar (widgets/OrganicCalendarWidget.php, web/js/organic-calendar.js)
 *
 * Calendar left, persistent agenda right (55 / 45, stacked on phones).
 * Every populated date wears ONE soft organic circle in the brand's primary
 * green; its diameter is  cell width x (0.44 + 0.44 x --oc-ratio), where
 * --oc-ratio is the bounded square-root density (1 event = 0, 10+ = 1). The
 * cells are square and the circle never exceeds 88% of the cell, so circles
 * can never touch a neighbouring date. Shade deepens slightly with density,
 * but size alone carries the meaning. Selection is a separate outline ring,
 * today a small dot - neither changes the density encoding.
 * ========================================================================== */

.organic-calendar.oc2 {
    --oc-green: var(--color-primary-500, #527a5d);
    --oc-green-deep: var(--color-primary-800, #294c38);
    --oc-sage: color-mix(in srgb, var(--oc-green) 9%, var(--bg-primary, #fffefb));
    --oc-line: color-mix(in srgb, var(--oc-green) 18%, transparent);
    --oc-muted: color-mix(in srgb, var(--oc-green-deep) 62%, transparent);
    /* One consistent organic outline for every date (never re-randomised). */
    --oc-shape: 47% 53% 51% 49% / 52% 46% 54% 48%;
    font-family: var(--font-family-body, inherit);
    color: var(--oc-green-deep);
    position: relative;
}

.organic-calendar.oc2.is-loading .oc-grid {
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

.oc2 .oc-layout {
    display: grid;
    grid-template-columns: minmax(0, 55fr) minmax(0, 45fr);
    gap: clamp(1.5rem, 2.2vw, 2rem);
    align-items: stretch;
}

.oc2 .oc-cal {
    min-width: 0;
}

/* --- Month header ------------------------------------------------------- */
.oc2 .oc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.oc2 .oc-month-label {
    flex: 1 1 auto;
    margin: 0;
    text-align: center;
    font-family: var(--font-family-heading, inherit);
    font-weight: var(--website-font-weight-heading, 400);
    font-size: clamp(1.5rem, 1.1rem + 1.3vw, 2.25rem);
    color: var(--oc-green-deep);
}

.oc2 .oc-nav {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--oc-line);
    background: var(--bg-primary, #fffefb);
    color: var(--oc-green-deep);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.oc2 .oc-nav:hover {
    border-color: var(--oc-green);
}

.oc2 .oc-fullscreen {
    flex: 0 0 auto;
}

/* --- Weekday row + grid ------------------------------------------------- */
.oc2 .oc-dow,
.oc2 .oc-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.oc2 .oc-dow-cell {
    text-align: center;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--oc-muted);
    padding-bottom: 0.5rem;
}

.oc2 .oc-dow-narrow {
    display: none;
}

.oc2 .oc-cell {
    aspect-ratio: 1;
    min-width: 0;
    container-type: inline-size;
    position: relative;
}

.oc2 .oc-day {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-width: min(44px, 100%);
    min-height: 44px;
    margin: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--oc-muted);
    font: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
}

.oc2 .oc-cell {
    min-height: 44px;
}

.oc2 .oc-blob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: var(--oc-shape);
    transform: translate(-50%, -50%);
    transition: width 0.2s ease, height 0.2s ease, background-color 0.2s ease;
    /* Linear diameter scale, 1 event = min .. 10+ events = max. cqi resolves
       against the square .oc-cell, so both extremes also respect the cell's
       height; the max leaves room for the selection ring (2 x 5px) so the
       largest circle never touches its neighbours. */
    --oc-dmin: min(24px, 34cqi);
    --oc-dmax: min(64px, calc(100cqi - 12px));
    --oc-d: calc(var(--oc-dmin) + (var(--oc-dmax) - var(--oc-dmin)) * var(--oc-ratio, 0));
}

.oc2 .oc-day.has-events {
    color: var(--oc-green-deep);
    font-weight: 700;
}

.oc2 .oc-day.has-events .oc-blob {
    width: var(--oc-d);
    height: var(--oc-d);
    background: color-mix(in srgb, var(--oc-green) calc(22% + 20% * var(--oc-ratio, 0)), var(--bg-primary, #fffefb));
}

.oc2 .oc-day-num {
    position: relative;
    z-index: 1;
    font-size: clamp(0.8rem, 0.7rem + 0.35vw, 1.0625rem);
    font-variant-numeric: tabular-nums;
}

/* Selection: an outline ring only. The circle keeps its data-driven diameter;
   an empty selected day gets a ring at the smallest size. */
.oc2 .oc-day.is-selected .oc-blob {
    box-shadow: 0 0 0 3px var(--bg-primary, #fffefb), 0 0 0 5px var(--oc-green);
}

.oc2 .oc-day.is-selected:not(.has-events) .oc-blob {
    width: var(--oc-dmin);
    height: var(--oc-dmin);
}

.oc2 .oc-day.is-selected.has-events .oc-blob {
    background: var(--oc-green);
}

.oc2 .oc-day.is-selected.has-events {
    color: #fff;
}

.oc2 .oc-day.is-selected:not(.has-events) .oc-blob {
    background: transparent;
}

/* Today: a small dot under the number, never a size or colour change. */
.oc2 .oc-day.is-today .oc-day-num::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -0.4em;
    width: 5px;
    height: 5px;
    margin-left: -2.5px;
    border-radius: 50%;
    background: currentColor;
}

.oc2 .oc-day:focus-visible {
    outline: 2px solid var(--oc-green-deep);
    outline-offset: -2px;
}

.oc2 .oc-moon {
    position: absolute;
    top: 6%;
    left: 8%;
    z-index: 1;
    font-size: 0.7rem;
    line-height: 1;
}

.oc2 .oc-total {
    margin: 0.75rem 0 0;
    font-size: 0.875rem;
    color: var(--oc-muted);
}

/* --- Size key ----------------------------------------------------------- */
.oc2 .oc-key {
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: var(--oc-muted);
}

.oc2 .oc-key-items {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.25rem;
}

.oc2 .oc-key-note {
    margin: 0.4rem 0 0;
}

.oc2 .oc-key-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.oc2 .oc-key-dot {
    display: inline-block;
    flex: none;
    border-radius: var(--oc-shape);
}

.oc2 .oc-key-dot.is-empty {
    border: 1px solid var(--oc-line);
}

.oc2 .oc-key-dot.is-sized {
    background: color-mix(in srgb, var(--oc-green) calc(22% + 20% * var(--oc-ratio, 0)), var(--bg-primary, #fffefb));
}

/* --- Agenda panel ------------------------------------------------------- */
.oc2 .oc-agenda {
    min-width: 0;
    background: var(--oc-sage);
    border: 1px solid var(--oc-line);
    border-radius: var(--radius-xl, 1.25rem);
    padding: clamp(1.25rem, 2vw, 2rem);
    display: flex;
    flex-direction: column;
    max-height: 44rem;
}

.oc2 .oc-agenda-eyebrow {
    margin: 0 0 0.5rem;
    font-family: var(--font-family-eyebrow, var(--font-family-body, inherit));
    font-size: 0.8125rem;
    font-weight: var(--website-font-weight-eyebrow, 600);
    letter-spacing: var(--website-font-tracking-eyebrow, 0.18em);
    text-transform: uppercase;
    color: var(--oc-green-deep);
}

.oc2 .oc-agenda-title {
    margin: 0 0 1rem;
    font-family: var(--font-family-heading, inherit);
    font-weight: var(--website-font-weight-heading, 400);
    font-size: clamp(1.35rem, 1rem + 1vw, 2rem);
    line-height: 1.2;
    color: var(--oc-green-deep);
}

.oc2 .oc-agenda-body {
    overflow-y: auto;
    min-height: 0;
    scrollbar-width: thin;
}

.oc2 .oc-agenda-note {
    margin: 0;
    color: var(--oc-muted);
    line-height: 1.6;
}

.oc2 .oc-agenda-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.oc2 .oc-agenda-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.9rem 0;
    border-bottom: 1px solid var(--oc-line);
}

.oc2 .oc-agenda-item:first-child {
    padding-top: 0;
}

.oc2 .oc-agenda-link {
    display: inline-flex;
    align-items: baseline;
    gap: 0.35rem;
    color: var(--oc-green-deep);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.0625rem;
    line-height: 1.35;
}

.oc2 .oc-agenda-link:hover .oc-agenda-item-title {
    text-decoration: underline;
}

.oc2 .oc-agenda-arrow {
    font-weight: 400;
    font-size: 0.9em;
    opacity: 0.7;
}

.oc2 .oc-agenda-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.oc2 .oc-agenda-cat {
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-full, 999px);
    background: color-mix(in srgb, var(--oc-green) 14%, transparent);
    color: var(--oc-green-deep);
}

.oc2 .oc-agenda-meta {
    font-size: 0.875rem;
    color: var(--oc-muted);
}

.oc2 .oc-agenda-excerpt {
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--oc-green-deep);
    opacity: 0.85;
}

/* --- Dark mode ------------------------------------------------------------ */
[data-bs-theme="dark"] .organic-calendar.oc2 {
    --oc-green-deep: var(--text-primary, #e6efe8);
    --oc-sage: color-mix(in srgb, var(--oc-green) 14%, var(--bg-primary, #151a17));
    --oc-line: color-mix(in srgb, var(--oc-green) 35%, transparent);
    --oc-muted: color-mix(in srgb, var(--text-primary, #e6efe8) 65%, transparent);
}

[data-bs-theme="dark"] .oc2 .oc-day.has-events .oc-blob {
    background: color-mix(in srgb, var(--oc-green) calc(38% + 25% * var(--oc-ratio, 0)), var(--bg-primary, #151a17));
}

[data-bs-theme="dark"] .oc2 .oc-nav {
    background: transparent;
}

/* --- Phones: calendar first, agenda directly below ---------------------- */
@media (max-width: 767.98px) {
    .oc2 .oc-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .oc2 .oc-agenda {
        max-height: none;
    }

    .oc2 .oc-dow-short {
        display: none;
    }

    .oc2 .oc-dow-narrow {
        display: inline;
    }

    .oc2 .oc-moon {
        display: none;
    }

    .oc2 .oc-head .wb-section-fullscreen-label {
        display: none;
    }

    .oc2 .oc-head .oc-fullscreen {
        width: 44px;
        height: 44px;
        padding: 0;
        border-radius: 50%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .oc2 .oc-blob {
        transition: none;
    }
}

/* Fullscreen: let the calendar breathe inside the overlay. */
.wb-section-fullscreen-active .organic-calendar.oc2,
.organic-calendar.oc2:fullscreen {
    padding: 1.5rem;
    background: var(--bg-primary, #fffefb);
    overflow: auto;
}
