/*
  Caelion workspace · v5 · chart options

  Every chart can be read in more than one way, and that is the reader's choice:

    Palette  four sets of seven colours, in a fixed order (money in, money out, then five
             more). Each set was checked with the dataviz validator on v5's own surfaces
             (#ffffff light, #191c22 dark): lightness band, chroma floor, adjacent-pair
             separation under protan and deutan simulation (worst pair ΔE 9.1 to 14.8),
             the normal-vision floor (worst pair ΔE 15.1 to 25.2) and contrast on the
             surface. Signal has three light-mode slots under 3:1, so, as with old gold in
             the default set, every chart keeps its direct labels or its table of figures.
             The loss red and the lateness ramp are states, not series: they do not change.
    Type     where a chart can honestly be drawn another way (the payroll cost columns:
             stacked, side by side, or as shares of each run).
    Table    the same figures as a table, for any chart that carries one.

  The choice is kept on this device (charts.js) and applies to every chart in the suite.
*/

/* ---------- Palettes ---------- */

:root[data-layout="v5"][data-chart-palette="signal"] {
  --viz-in: #2a78d6;
  --viz-out: #eb6834;
  --viz-3: #1baf7a;
  --viz-4: #eda100;
  --viz-5: #e87ba4;
  --viz-6: #008300;
  --viz-7: #6250d6;
  --c-net: #184c8d;
  --c-withheld: #4a7cbd;
  --c-employer: #8eb4e7;
}

:root[data-layout="v5"][data-chart-palette="signal"][data-theme="dark"] {
  --viz-in: #3987e5;
  --viz-out: #d95926;
  --viz-3: #199e70;
  --viz-4: #c98500;
  --viz-5: #d55181;
  --viz-6: #0ca30c;
  --viz-7: #9085e9;
  --c-net: #b5d4fd;
  --c-withheld: #70a1e2;
  --c-employer: #3c6dad;
}

:root[data-layout="v5"][data-chart-palette="tide"] {
  --viz-in: #06a09b;
  --viz-out: #a36203;
  --viz-3: #2a5db5;
  --viz-4: #128745;
  --viz-5: #c373ac;
  --viz-6: #5f4490;
  --viz-7: #0a93b9;
  --c-net: #025956;
  --c-withheld: #078d87;
  --c-employer: #6bc3bd;
}

:root[data-layout="v5"][data-chart-palette="tide"][data-theme="dark"] {
  --viz-in: #079c8d;
  --viz-out: #b0691d;
  --viz-3: #3c7dc3;
  --viz-4: #0a783e;
  --viz-5: #ba7aac;
  --viz-6: #7753ba;
  --viz-7: #089dc6;
  --c-net: #96e1dc;
  --c-withheld: #30b4ad;
  --c-employer: #037c77;
}

:root[data-layout="v5"][data-chart-palette="harvest"] {
  --viz-in: #2683c9;
  --viz-out: #994e02;
  --viz-3: #089ea9;
  --viz-4: #853562;
  --viz-5: #5d7b06;
  --viz-6: #8a57c3;
  --viz-7: #9b7e0b;
}

:root[data-layout="v5"][data-chart-palette="harvest"][data-theme="dark"] {
  --viz-in: #417bb4;
  --viz-out: #bb6406;
  --viz-3: #10a6b1;
  --viz-4: #9a4e72;
  --viz-5: #72a336;
  --viz-6: #9f79ec;
  --viz-7: #ac9030;
}

:root[data-layout="v5"] {
  /* ---------- The options button and its sheet ---------- */

  .c5-host {
    position: relative;
  }

  .c5-open {
    display: grid;
    flex: none;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: var(--r-item);
    background: transparent;
    color: var(--t-4);
    transition: background-color var(--d-1) ease, color var(--d-1) ease;
  }

  .c5-open .icon {
    width: 16px;
    height: 16px;
  }

  .c5-open[aria-expanded="true"] {
    background: var(--f-press);
    color: var(--t-1);
  }

  /* a chart with no head of its own: the button sits in its top corner */
  .c5-open.is-corner {
    position: absolute;
    z-index: 2;
    top: 8px;
    right: 8px;
  }

  /* the heading keeps the left; a link and the options button sit together on the right */
  :is(.panel-head, .pf-head):has(> .c5-open) > :first-child {
    margin-right: auto;
  }

  :is(.panel-head, .pf-head) > .c5-open {
    margin-left: 2px;
  }

  /* a head that holds only its title and the button keeps them on one line: on a phone the title
     gives way and the button stays at the head's end, where it used to drop to a line of its own */
  :is(.panel-head, .pf-head):has(> :first-child + .c5-open) {
    flex-wrap: nowrap;
  }

  :is(.panel-head, .pf-head):has(> :first-child + .c5-open) > :first-child {
    min-width: 0;
  }

  .pf-head > .c5-open {
    align-self: flex-start;
    margin-top: -3px;
  }

  /* on a tile the button stands by the chart itself, on the line of the chart's key or of its
     small heading: the tile's own head is a title and a link, with no room for a third thing */
  .c5-open.is-by-chart {
    top: -6px;
    right: -6px;
  }

  .tile-aging > .c5-open.is-by-chart {
    top: 9px;
  }

  /* the cash card has no head: the button stands on the line of its title, and the payday note
     beside the figure keeps clear of it */
  .cash-card > .c5-open.is-corner {
    top: 17px;
    right: 18px;
  }

  .cash-card.c5-host > .cash-head {
    padding-right: 34px;
  }

  .c5-sheet {
    position: fixed;
    z-index: 30;
    inset: auto;
    gap: 14px;
    width: 264px;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-pop);
    background: var(--s-3);
    color: var(--t-1);
    box-shadow: var(--sh-3);
  }

  /* laid out only while it is open: a display set on the sheet itself would outrank the browser's
     own rule that hides a closed popover, and leave it painted, and pressable, after it closes */
  .c5-sheet:popover-open {
    display: grid;
    animation: c5-pop var(--d-2) var(--e-out) both;
  }

  .c5-sheet h3 {
    margin: 0 0 6px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--t-3);
  }

  .c5-seg {
    display: flex;
    gap: 2px;
    padding: 2px;
    border-radius: 9px;
    background: var(--f-hover);
    box-shadow: inset 0 0 0 1px var(--b-0);
  }

  .c5-seg button {
    flex: 1 1 0;
    height: 28px;
    padding: 0 8px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--t-3);
    font-size: .8rem;
    font-weight: 560;
    white-space: nowrap;
    transition: color var(--d-1) ease, background-color var(--d-1) ease;
  }

  .c5-seg button[aria-checked="true"] {
    background: var(--s-1);
    color: var(--t-1);
    box-shadow: var(--sh-1), 0 0 0 1px var(--b-0);
  }

  .c5-palettes {
    display: grid;
    gap: 2px;
  }

  .c5-palette {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto 16px;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 8px;
    border: 0;
    border-radius: var(--r-item);
    background: transparent;
    color: var(--t-1);
    font-size: .86rem;
    font-weight: 540;
    text-align: left;
    transition: background-color var(--d-1) ease;
  }

  .c5-swatches {
    display: flex;
    gap: 0;
  }

  .c5-swatches i {
    width: 13px;
    height: 13px;
    margin-left: -3px;
    border-radius: 50%;
    background: var(--sw);
    box-shadow: 0 0 0 1.5px var(--s-3);
  }

  .c5-palette .icon {
    width: 15px;
    height: 15px;
    opacity: 0;
  }

  .c5-palette[aria-checked="true"] .icon {
    opacity: 1;
  }

  /* the same picker laid out on the Appearance page */
  /* four sets, two by two: three and one left the last alone, and wrapped the longest name */
  .c5-palettes.is-page {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 4px;
  }

  @container v4-studio (max-width: 520px) {
    .c5-palettes.is-page {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  .c5-palettes.is-page .c5-palette {
    padding: 11px 12px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-ctl);
    background: var(--s-1);
  }

  .c5-palettes.is-page .c5-palette[aria-checked="true"] {
    border-color: var(--t-1);
    background: var(--f-selected);
  }

  .c5-palettes.is-page .c5-swatches i {
    width: 16px;
    height: 16px;
    box-shadow: 0 0 0 1.5px var(--s-1);
  }

  /* ---------- The payroll cost chart, three ways ---------- */

  /* side by side: each part stands on the baseline at its own height, against the same axis */
  .chart[data-type="grouped"] .chart-col {
    flex-direction: row;
    align-items: flex-end;
    gap: 2px;
    width: min(58px, 78%);
    height: 100%;
  }

  .chart[data-type="grouped"] .chart-col .seg {
    flex: 1 1 0 !important;
    height: calc(var(--h) * var(--v, .33));
    border-radius: 3px 3px 0 0;
  }

  /* the take-home part leads when the parts stand in a row */
  .chart[data-type="grouped"] .chart-col .seg.net { order: -2 }
  .chart[data-type="grouped"] .chart-col .seg.withheld { order: -1 }

  .chart[data-type="grouped"] .chart-total {
    display: none;
  }

  /* shares: every run fills the plot, so the mix can be compared from run to run */
  .chart[data-type="share"] .chart-col {
    height: 100% !important;
  }

  .chart[data-type="share"] .chart-total {
    display: none;
  }

  /* as a table: the figures, and nothing drawn */
  [data-c5][data-view="table"] > :is(figure.viz, figure.chart, .chart-legend),
  [data-c5][data-view="table"] > .viz-strip {
    display: none;
  }

  [data-c5][data-view="table"] :is(.chart-table, .viz-figures) > summary {
    display: none;
  }

  [data-c5][data-view="table"] .viz-figures table {
    margin-top: 0;
  }

  .chart-panel[data-view="table"] .chart-foot {
    padding-top: 0;
    border-top: 0;
  }
}

/* ---------- The period filters above Performance and Cash flow ---------- */

:root[data-layout="v5"] {
  /* the comparison and the custom dates wear the dress of every other field in the suite */
  .pf-filters label {
    font-size: .84rem;
    font-weight: 500;
    color: var(--t-3);
  }

  .pf-filters :is(select, input:not([type="hidden"])) {
    width: auto;
    min-height: 0;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-field);
    background-color: var(--s-1);
    color: var(--t-1);
    font-size: .84rem;
    font-weight: 570;
    box-shadow: var(--sh-1);
    transition: border-color var(--d-1) ease, box-shadow var(--d-1) ease;
  }

  /* the same chevron as every other choice in the suite */
  .pf-filters select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b857c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 15 5 5 5-5'/%3E%3Cpath d='m7 9 5-5 5 5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 14px;
  }

  .pf-filters :is(select, input):focus-visible {
    outline: 0;
    border-color: var(--a-ring);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--a-ring) 22%, transparent);
  }

  /* the custom dates open under their chip, from whichever end keeps them inside the window (v5.js) */
  .pf-custom-form {
    gap: 12px;
    width: min(264px, calc(100vw - 36px));
    padding: 14px;
    border: 1px solid var(--b-1);
    border-radius: var(--r-pop);
    background: var(--s-3);
    box-shadow: var(--sh-3);
  }

  .pf-custom.opens-left .pf-custom-form {
    left: auto;
    right: 0;
  }

  .pf-custom-form label {
    gap: 6px;
  }

  .pf-custom-form .v4-date {
    display: flex;
    width: 100%;
  }

  .pf-custom-form :is(input:not([type="hidden"])) {
    width: 100%;
    height: var(--h-field);
    font-weight: 450;
    box-shadow: none;
    background-color: var(--s-well);
  }

  .pf-custom-form .btn {
    justify-self: start;
  }
}

@keyframes c5-pop {
  from { opacity: 0; transform: translateY(-4px) scale(.98) }
}

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

    .c5-seg button:not([aria-checked="true"]):hover {
      color: var(--t-1);
    }

    .pf-filters :is(select, input):hover:not(:focus-visible) {
      border-color: var(--b-2);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  :root[data-layout="v5"] .c5-sheet:popover-open {
    animation: none;
  }
}

@media print {
  :root[data-layout="v5"] .c5-open {
    display: none !important;
  }
}
