/**
 * Mint Calendar skin.
 *
 * The library is vendored verbatim at
 * resources/3rdparty/mint-calendar/mint-calendar.js. It emits class names
 * only and ships no inline styling, so all of its appearance lives here.
 *
 * Upstream's own mint-calendar.css is deliberately NOT vendored alongside
 * the JS: it is another project's skin (Inter pulled from Google Fonts,
 * 32px radii, hardcoded greys and blues), and making it look like this
 * app through it would mean an `!important` override on nearly
 * every property -- unlayered third-party CSS beats every layer, so normal
 * specificity would not help (css-conventions.md §1). Re-skinning is
 * cheaper and honest. Every rule below is therefore our own authored CSS
 * and opens `@layer components` like any other stylesheet, and references
 * semantic tokens only (§2).
 *
 * The class names are the library's (`mc-*`, plus `hasDatepicker`), so they
 * are already prefixed and scoped to the widget rather than being shared
 * vocabulary. Rendered reference with live demos: /dev/mint-calendar.htm.
 *
 * Loaded globally by base.twig, next to mint-calendar.js and mint-date.js --
 * see docs/architecture/ui-patterns.md's "Date picking" for why that is not per-page.
 */
@layer components {

    /* --- Trigger input ---------------------------------------------------
       `hasDatepicker` is the library's own class (a jQuery-UI legacy name,
       not app vocabulary). It goes on the read-only input the picker
       creates when mounted on a <div>, and on an existing <input> it takes
       over.

       A field upgraded by mint-date.js already carries .field-input -- the
       trigger inherits the original input's classes -- so the geometry
       below is scoped to triggers that do NOT, rather than restating what
       components.css already owns. Both classes sit in this layer at equal
       specificity, so an unscoped rule here would quietly outrank
       .field-input on source order and give date fields a second,
       divergent look. That is the exact defect the single-input decision
       (C-02, C-07) was made to avoid. */
    .hasDatepicker {
        cursor: pointer;
        /* The library reserves 36px of padding-right on the trigger with an
           inline style; fill it with the calendar affordance a native
           <input type="date"> drew for itself. The stroke colour is baked
           in -- a data: URI cannot read currentColor -- and is
           --color-ui-500, the same value select.field-input's chevron uses. */
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2362748e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right var(--spacing-s3) center;
        background-size: 16px;
    }

    /* A trigger the library built for itself, with no .field-input to
       inherit from. Mirrors .field-input so it still looks like a form
       control. */
    .hasDatepicker:not(.field-input) {
        display: block;
        width: 100%;
        height: 40px;
        padding: 0 var(--spacing-s3);
        font-size: var(--font-size-r);
        border: 1px solid var(--border-colour);
        border-radius: var(--radius-m);
        background-color: var(--surface-colour);
        color: var(--text-colour-regular);
    }

    .hasDatepicker:not(.field-input):focus-visible {
        outline: none;
        border-color: var(--border-colour-brand);
        box-shadow: var(--focus-ring);
    }

    /* --- Popover ---------------------------------------------------------
       The library reparents this to <body> with position: fixed while open,
       so it escapes any ancestor overflow or transform, and moves it back on
       close. Only the stacking context is set here: above the sidebar (40)
       and the fixed header (50). */
    .mc-popover {
        z-index: 60;
    }

    /* --- Root / card ----------------------------------------------------- */

    .mc-root {
        font-family: var(--font-family);
        font-size: var(--font-size-r);
        color: var(--text-colour-regular);
        line-height: var(--line-height-regular);
    }

    .mc-root *,
    .mc-root *::before,
    .mc-root *::after {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
    }

    /* Deliberately no `border` reset here: `.mc-root button` (0,1,1)
       outranks every .mc-* class below (0,1,0) in the same layer, so a
       blanket `border: none` would silently win over the borders
       .mc-nav-btn / .mc-flex-btn / .mc-month-chip set for themselves. The
       buttons that want no border say so individually. */
    .mc-root button {
        font: inherit;
        color: inherit;
        background: none;
        cursor: pointer;
    }

    .mc-card {
        width: 320px;
        max-width: calc(100vw - var(--spacing-s4));
        background-color: var(--surface-colour);
        border: 1px solid var(--border-colour);
        border-radius: var(--radius-l);
        box-shadow: var(--elevation-3);
        overflow: hidden;
    }

    /* --- Header ----------------------------------------------------------
       Fixed height: .mc-calendar is a virtual scroller (the library appends
       and prepends months as you near either edge), so it needs a bounded
       flex parent to scroll inside at all. */
    .mc-when-body {
        position: relative;
        display: flex;
        flex-direction: column;
        height: 400px;
    }

    .mc-when-top {
        padding: var(--spacing-s3) var(--spacing-s3) 0;
    }

    .mc-card-title {
        margin-bottom: var(--spacing-s3);
        font-size: var(--font-size-m);
        font-weight: var(--font-weight-semibold);
        color: var(--text-colour-dark);
    }

    /* --- Dates / Flexible tab bar (range mode only) ----------------------- */

    .mc-tab-bar {
        display: flex;
        width: 100%;
        padding: 2px;
        margin-bottom: var(--spacing-s3);
        border: 1px solid var(--border-colour);
        border-radius: var(--radius-m);
        background-color: var(--surface-colour-sunken);
    }

    .mc-tab {
        flex: 1;
        padding: var(--spacing-s1) var(--spacing-s3);
        border: none;
        border-radius: var(--radius-s);
        font-size: var(--font-size-s);
        font-weight: var(--font-weight-medium);
        color: var(--text-colour-faint);
    }

    .mc-tab:hover {
        color: var(--text-colour-regular);
    }

    .mc-tab.active {
        background-color: var(--surface-colour);
        box-shadow: var(--elevation-1);
        font-weight: var(--font-weight-semibold);
        color: var(--text-colour-brand);
    }

    /* --- Quick-jump month/year navigator ---------------------------------- */

    .mc-nav {
        display: flex;
        gap: var(--spacing-s2);
    }

    .mc-nav-cell {
        position: relative;
        flex: 1;
    }

    .mc-nav-btn {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: var(--spacing-s1) var(--spacing-s2);
        border: 1px solid var(--border-colour);
        border-radius: var(--radius-m);
        background-color: var(--surface-colour);
        font-size: var(--font-size-s);
        font-weight: var(--font-weight-semibold);
        color: var(--text-colour-dark);
    }

    .mc-nav-btn:hover {
        background-color: var(--surface-colour-sunken);
    }

    .mc-nav-btn.open {
        border-color: var(--border-colour-brand);
    }

    .mc-nav-btn svg {
        color: var(--text-colour-faint);
        transition: transform var(--transition-duration) var(--transition-timing);
    }

    .mc-nav-btn.open svg {
        transform: rotate(180deg);
    }

    .mc-nav-panel {
        position: absolute;
        top: calc(100% + 2px);
        left: 0;
        right: 0;
        z-index: 30;
        max-height: 240px;
        overflow-y: auto;
        padding: var(--spacing-s1);
        border: 1px solid var(--border-colour);
        border-radius: var(--radius-m);
        background-color: var(--surface-colour);
        box-shadow: var(--elevation-3);
    }

    .mc-nav-opt {
        display: block;
        width: 100%;
        padding: var(--spacing-s1) var(--spacing-s2);
        border: none;
        border-radius: var(--radius-s);
        font-size: var(--font-size-s);
        text-align: left;
        color: var(--text-colour-regular);
    }

    .mc-nav-opt:hover {
        background-color: var(--surface-colour-sunken);
    }

    /* Solid brand fill for the current selection -- the same "this is the
       selected one" treatment the sidebar and the segmented control use. */
    .mc-nav-opt.active {
        background-color: var(--surface-colour-brand);
        color: var(--text-colour-white);
        font-weight: var(--font-weight-semibold);
    }

    /* --- Day-of-week header ----------------------------------------------- */

    .mc-dow-row {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        margin-top: var(--spacing-s3);
        padding: var(--spacing-s2) 0;
        border-top: 1px solid var(--border-colour);
        border-bottom: 1px solid var(--border-colour);
        text-align: center;
        font-size: var(--font-size-2xs);
        font-weight: var(--font-weight-semibold);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-colour-faint);
    }

    /* --- Calendar scroll area ---------------------------------------------
       The scrollbar is hidden because the month list is effectively endless
       -- a thumb that never grows or reaches an end is noise, not
       information. Scrolling itself is untouched. */
    .mc-calendar {
        flex: 1;
        overflow-y: auto;
        padding: var(--spacing-s3);
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .mc-calendar::-webkit-scrollbar {
        display: none;
    }

    .mc-month {
        margin-bottom: var(--spacing-s5);
    }

    .mc-month-title {
        margin-bottom: var(--spacing-s2);
        font-size: var(--font-size-r);
        font-weight: var(--font-weight-semibold);
        color: var(--text-colour-dark);
    }

    .mc-days-grid {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        row-gap: 2px;
        text-align: center;
    }

    /* --- Day cell ---------------------------------------------------------- */

    .mc-day-cell,
    .mc-empty-cell {
        height: 36px;
    }

    .mc-day-cell {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Continuous band behind the days between start and end. Sits under
       .mc-day-btn (z-index 1) and spans the full cell width so adjacent
       cells join up; the library adds .round-left/.round-right on the two
       ends. */
    .mc-range-bg {
        position: absolute;
        top: 1px;
        bottom: 1px;
        display: none;
        background-color: var(--surface-colour-brand-soft);
    }

    .mc-range-bg.visible {
        display: block;
        left: 0;
        right: 0;
    }

    .mc-range-bg.round-left {
        border-radius: var(--radius-pill) 0 0 var(--radius-pill);
    }

    .mc-range-bg.round-right {
        border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
    }

    .mc-day-btn {
        position: relative;
        z-index: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border: 1px solid transparent;
        border-radius: var(--radius-pill);
        font-size: var(--font-size-s);
        color: var(--text-colour-regular);
    }

    .mc-day-btn:hover:not(:disabled) {
        border-color: var(--border-colour-brand);
        color: var(--text-colour-brand);
    }

    .mc-day-btn.selected,
    .mc-day-btn.selected:hover {
        background-color: var(--surface-colour-brand);
        border-color: var(--surface-colour-brand);
        color: var(--text-colour-white);
    }

    .mc-day-btn.in-range {
        color: var(--text-colour-dark);
    }

    /* Struck through as well as dimmed: colour alone is not an accessible
       way to say "you cannot pick this". */
    .mc-day-btn:disabled {
        color: var(--text-colour-disabled);
        cursor: not-allowed;
        text-decoration: line-through;
    }

    /* --- Flexible view (range mode, "Flexible" tab) -------------------------
       Holiday-booking vocabulary inherited from upstream. Nothing here
       uses it -- see /dev/mint-calendar.htm -- but it is skinned
       so that a range picker mounted by hand does not render half-styled. */

    .mc-flex-scroll {
        flex: 1;
        overflow-y: auto;
        padding: 0 var(--spacing-s3) var(--spacing-s3);
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .mc-flex-scroll::-webkit-scrollbar {
        display: none;
    }

    .mc-flex-section {
        margin-bottom: var(--spacing-s5);
    }

    .mc-flex-section-title {
        margin-bottom: var(--spacing-s2);
        font-size: var(--font-size-m);
        font-weight: var(--font-weight-semibold);
        color: var(--text-colour-dark);
    }

    .mc-flex-buttons {
        display: flex;
        gap: var(--spacing-s2);
    }

    .mc-flex-btn,
    .mc-month-chip {
        padding: var(--spacing-s2);
        border: 1px solid var(--border-colour);
        border-radius: var(--radius-m);
        background-color: var(--surface-colour);
        font-size: var(--font-size-s);
        text-align: center;
        color: var(--text-colour-regular);
    }

    .mc-flex-btn {
        flex: 1;
    }

    .mc-flex-btn:hover,
    .mc-month-chip:hover {
        border-color: var(--border-colour-brand);
    }

    .mc-flex-btn.active,
    .mc-month-chip.active {
        border-color: var(--border-colour-brand);
        background-color: var(--surface-colour-brand-soft);
        font-weight: var(--font-weight-semibold);
    }

    .mc-month-chips {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-s2);
    }

    .mc-month-chip-name {
        font-weight: var(--font-weight-semibold);
        color: var(--text-colour-dark);
    }

    .mc-month-chip-year {
        font-size: var(--font-size-xs);
        color: var(--text-colour-faint);
    }
}
