/*
  Caelion workspace · v4 (Fable 5.2) · date picker

  The field and its calendar in the four systems. Structure in datepicker.js.
*/

:root[data-layout="v5"] {
  /* ---------- Field ---------- */

  .v4-date {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    min-width: 150px;
    max-width: 100%;
  }

  .field .v4-date,
  .form-grid .v4-date {
    display: flex;
    width: 100%;
  }

  .v4-date .v4-date-text {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding-right: calc(var(--h-ctl) + 2px);
    font-variant-numeric: lining-nums;
  }

  /* the native input stays for the form, out of sight and out of the tab order */
  .v4-date .v4-date-native {
    position: absolute;
    inset: auto auto 0 0;
    width: 1px;
    height: 1px;
    min-height: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
  }

  .v4-date-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    bottom: 3px;
    display: grid;
    place-items: center;
    width: calc(var(--h-ctl) - 6px);
    padding: 0;
    border: 0;
    border-radius: max(3px, calc(var(--r-field) - 3px));
    background: transparent;
    color: var(--t-3);
    transition: background-color var(--d-1) ease, color var(--d-1) ease;
  }

  .v4-date.is-open .v4-date-btn {
    background: var(--f-press);
    color: var(--a-ink);
  }

  .v4-date.is-invalid .v4-date-text {
    border-color: var(--bad);
  }

  /* ---------- Calendar ---------- */

  .v4-dp {
    --cell: 38px;
    position: fixed;
    inset: auto;
    width: calc(var(--cell) * 7 + 28px);
    margin: 0;
    padding: 12px 14px 10px;
    overflow: hidden;
    border: 1px solid var(--b-1);
    border-radius: var(--r-pop);
    background: var(--s-3);
    box-shadow: var(--sh-4);
    color: var(--t-1);
    font-family: var(--font-ui);
    transform-origin: top left;
    opacity: 0;
    scale: .97;
    transition: opacity var(--d-2) ease, scale var(--d-3) var(--e-out), overlay var(--d-2) allow-discrete, display var(--d-2) allow-discrete;
  }

  .v4-dp[data-side="top"] {
    transform-origin: bottom left;
  }

  .v4-dp:popover-open {
    opacity: 1;
    scale: 1;
  }

  @starting-style {
    .v4-dp:popover-open {
      opacity: 0;
      scale: .97;
    }
  }

  .v4-dp > * {
    position: relative;
    z-index: 1;
  }

  .v4-dp-lead {
    display: none;
  }

  .v4-dp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
  }

  .v4-dp-title {
    height: 32px;
    padding: 0 8px;
    margin-left: -4px;
    border: 0;
    border-radius: min(var(--r-ctl), 9px);
    background: transparent;
    color: var(--t-1);
    font: 620 .92rem/1 var(--font-ui);
    letter-spacing: -.01em;
    text-transform: capitalize;
  }

  .v4-dp-nav {
    display: flex;
    gap: 2px;
  }

  .v4-dp-step {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: min(var(--r-ctl), 9px);
    background: transparent;
    color: var(--t-2);
  }

  .v4-dp-step:active {
    transform: scale(.92);
  }

  .v4-dp-grid {
    display: grid;
    grid-template-columns: repeat(7, var(--cell));
    justify-content: center;
  }

  .v4-dp-grid.is-months,
  .v4-dp-grid.is-years {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    min-height: calc(var(--cell) * 7);
    align-content: center;
  }

  /* a month slides in from the side it was asked from (pointer only; keys are instant) */
  .v4-dp-grid[data-from="right"] {
    animation: v4-dp-right var(--d-3) var(--e-out);
  }

  .v4-dp-grid[data-from="left"] {
    animation: v4-dp-left var(--d-3) var(--e-out);
  }

  .v4-dp-dow {
    display: grid;
    place-items: center;
    height: 28px;
    font-size: .7rem;
    font-weight: 570;
    color: var(--t-3);
    text-transform: capitalize;
  }

  .v4-dp-day,
  .v4-dp-cell {
    position: relative;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--t-1);
    font: 500 .84rem/1 var(--font-ui);
  }

  .v4-dp-day {
    width: var(--cell);
    height: var(--cell);
    border-radius: 50%;
  }

  .v4-dp-cell {
    height: 44px;
    border-radius: min(var(--r-ctl), 12px);
    text-transform: capitalize;
  }

  .v4-dp-day.is-outside {
    color: var(--t-4);
  }

  .v4-dp-day.is-today {
    box-shadow: inset 0 0 0 1.5px var(--t-2);
    font-weight: 650;
  }

  .v4-dp-day.is-selected,
  .v4-dp-cell.is-selected {
    background: var(--a-fill);
    color: var(--a-on);
    font-weight: 660;
    box-shadow: 0 3px 10px -3px var(--a-glow);
  }

  .v4-dp-day:disabled {
    color: var(--t-4);
    opacity: .5;
    text-decoration: line-through;
  }

  .v4-dp-foot {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--b-0);
  }

  .v4-dp-link {
    height: 30px;
    padding: 0 10px;
    border: 0;
    border-radius: min(var(--r-ctl), 9px);
    background: transparent;
    color: var(--t-2);
    font: 570 .8rem/1 var(--font-ui);
  }

  .v4-dp-link.is-strong {
    margin-left: auto;
    color: var(--a-ink);
  }

  /* phone: a sheet from the bottom edge */
  .v4-dp.is-sheet {
    --cell: min(46px, calc((100vw - 44px) / 7));
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    padding: 18px 14px calc(14px + env(safe-area-inset-bottom));
    border-radius: calc(var(--r-pop) + 8px) calc(var(--r-pop) + 8px) 0 0;
    scale: 1;
    translate: 0 100%;
    transition: translate var(--d-4) var(--e-drawer), opacity var(--d-2) ease, overlay var(--d-4) allow-discrete, display var(--d-4) allow-discrete;
  }

  .v4-dp.is-sheet:popover-open {
    translate: 0 0;
  }

  .v4-dp.is-sheet::backdrop {
    background: oklch(.2 .02 var(--n-h) / .32);
  }
}

@keyframes v4-dp-right {
  from { opacity: 0; transform: translateX(14px) }
}

@keyframes v4-dp-left {
  from { opacity: 0; transform: translateX(-14px) }
}

@media (hover: hover) and (pointer: fine) {
  :root[data-layout="v5"] {
    .v4-date-btn:hover {
      background: var(--f-hover);
      color: var(--t-1);
    }

    .v4-dp-title:hover,
    .v4-dp-step:hover,
    .v4-dp-link:hover {
      background: var(--f-hover);
      color: var(--t-1);
    }

    .v4-dp-day:not(.is-selected, :disabled):hover,
    .v4-dp-cell:not(.is-selected):hover {
      background: var(--f-hover);
    }
  }
}

/* ---------- Material 3: the docked date picker ---------- */

:root[data-layout="v5"][data-ds="material"] {
  .v4-dp {
    --cell: 40px;
    padding: 0 12px 8px;
    border: 0;
    border-radius: 16px;
    background: var(--s-2);
    box-shadow: var(--sh-3);
  }

  .v4-dp-lead {
    display: grid;
    gap: 10px;
    margin: 0 -12px 4px;
    padding: 16px 24px 12px;
    border-bottom: 1px solid var(--b-0);
  }

  .v4-dp-lead small {
    font-size: .76rem;
    font-weight: 560;
    letter-spacing: .03em;
    color: var(--t-2);
  }

  .v4-dp-lead b {
    font-size: 1.7rem;
    font-weight: 450;
    letter-spacing: 0;
    text-transform: capitalize;
  }

  .v4-dp-title {
    border-radius: 999px;
    font-size: .875rem;
    font-weight: 600;
    color: var(--t-2);
  }

  .v4-dp-title::after {
    content: "";
    display: inline-block;
    margin-left: 8px;
    border: 5px solid transparent;
    border-top-color: currentColor;
    border-bottom: 0;
    vertical-align: middle;
  }

  .v4-dp-step {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  .v4-dp-day.is-today {
    box-shadow: inset 0 0 0 1px var(--a-fill);
    color: var(--a-ink);
  }

  .v4-dp-day.is-selected,
  .v4-dp-cell.is-selected {
    color: var(--a-on);
    box-shadow: none;
  }

  .v4-dp-cell {
    border-radius: 999px;
  }

  .v4-dp-foot {
    border-top: 0;
  }

  .v4-dp-link {
    height: 40px;
    padding: 0 12px;
    border-radius: 999px;
    color: var(--a-ink);
    font-weight: 600;
  }

  .v4-date-btn {
    border-radius: 50%;
  }
}

/* ---------- Fluent 2: CalendarDatePicker on Acrylic ---------- */

:root[data-layout="v5"][data-ds="fluent"] {
  .v4-dp {
    --cell: 40px;
    padding: 6px 8px 8px;
    border: 1px solid var(--b-1);
    border-radius: 8px;
    background: var(--grain), color-mix(in oklch, var(--s-3) 76%, transparent);
    -webkit-backdrop-filter: blur(30px) saturate(1.25);
    backdrop-filter: blur(30px) saturate(1.25);
    box-shadow: var(--sh-3);
  }

  .v4-dp-title {
    height: 36px;
    border-radius: 4px;
    font-size: .9rem;
    font-weight: 600;
  }

  .v4-dp-step {
    height: 36px;
    border-radius: 4px;
  }

  /* Windows turns its month steppers to point up and down */
  .v4-dp-step svg {
    rotate: 90deg;
  }

  .v4-dp-dow {
    font-size: .75rem;
    font-weight: 600;
    color: var(--t-1);
  }

  .v4-dp-day {
    font-size: .875rem;
    font-weight: 400;
  }

  /* today is filled; the chosen day wears a ring */
  .v4-dp-day.is-today {
    background: var(--a-fill);
    color: var(--a-on);
    box-shadow: none;
    font-weight: 600;
  }

  .v4-dp-day.is-selected {
    background: transparent;
    color: var(--a-ink);
    box-shadow: inset 0 0 0 1.5px var(--a-fill);
    font-weight: 400;
  }

  .v4-dp-day.is-selected.is-today {
    background: var(--a-fill);
    color: var(--a-on);
    box-shadow: inset 0 0 0 1px var(--a-fill), inset 0 0 0 3px var(--s-3);
  }

  .v4-dp-cell {
    height: 52px;
    border-radius: 50%;
    font-weight: 400;
  }

  .v4-dp-cell.is-selected {
    background: var(--a-fill);
    color: var(--a-on);
    box-shadow: none;
  }

  .v4-dp-grid.is-months,
  .v4-dp-grid.is-years {
    grid-template-columns: repeat(4, 1fr);
  }

  .v4-dp-link {
    border-radius: 4px;
    font-weight: 400;
  }

  .v4-date-btn {
    border-radius: 3px;
  }
}

:root[data-layout="v5"][data-ds="fluent"][data-translucency="reduced"] .v4-dp {
  background: var(--s-3);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* ---------- Liquid Glass: a pane of glass, capsule days ---------- */

:root[data-layout="v5"][data-ds="glass"] {
  .v4-dp {
    --cell: 40px;
    padding: 14px 16px 10px;
    border-radius: 28px;
    corner-shape: squircle;
    --lg-tint: var(--lg-tint-strong);
    --lg-blur: 10px;
    --lg-shadow: var(--sh-4);
  }

  .v4-dp-title {
    border-radius: 999px;
    font-size: 1rem;
    font-weight: 680;
  }

  .v4-dp-step {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: color-mix(in oklch, var(--t-1) 7%, transparent);
    color: var(--a-ink);
  }

  .v4-dp-day {
    font-size: 1rem;
    font-weight: 450;
    transition: transform var(--d-3) var(--e-spring);
  }

  .v4-dp-day:active:not(:disabled) {
    transform: scale(1.18);
  }

  .v4-dp-day.is-today {
    box-shadow: none;
    color: var(--a-ink);
    font-weight: 700;
  }

  .v4-dp-day.is-selected {
    box-shadow: inset 0 1px 0 oklch(1 0 0 / .4), 0 4px 12px -4px var(--a-glow);
    color: var(--a-on);
  }

  .v4-dp-foot {
    border-top: 0;
  }

  .v4-dp-link {
    border-radius: 999px;
    background: color-mix(in oklch, var(--t-1) 6%, transparent);
    padding: 0 14px;
    height: 32px;
  }

  .v4-date-btn {
    border-radius: 50%;
  }
}

:root[data-layout="v5"][data-ds="glass"][data-translucency="reduced"] .v4-dp {
  background: var(--s-3);
}
