/* Charts and the month calendar: src/ui/charts.tsx and MonthCalendar.tsx.
 * See base.css for the order. Marks are thin with a 4px rounded end and a
 * square base; touching parts are split by a 2px gap in the card colour;
 * gridlines are solid hairlines. */

[data-color="on-time"],
[data-mark="present"] {
  --chart-color: var(--chart-on-time);
}

[data-color="late"],
[data-mark="late"] {
  --chart-color: var(--chart-late);
}

[data-color="absent"],
[data-mark="absent"] {
  --chart-color: var(--chart-absent);
}

[data-color="bar"] {
  --chart-color: var(--chart-bar);
}

/* ---- Legend ------------------------------------------------------------- */

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

.chart-legend li {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.chart-key {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 2px;
  background: var(--chart-color);
}

/* ---- Column chart ------------------------------------------------------- */

.chart {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  min-width: 0;
}

.chart-frame {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.5rem;
  row-gap: 0.375rem;
  padding-top: 1rem;
}

.chart-ticks,
.chart-columns,
.chart-labels {
  margin: 0;
  padding: 0;
  list-style: none;
}

.chart-ticks {
  position: relative;
  min-width: 1.75rem;
  height: 9rem;
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.chart-ticks li {
  position: absolute;
  right: 0;
  transform: translateY(50%);
  white-space: nowrap;
}

.chart-plot {
  position: relative;
  height: 9rem;
  min-width: 0;
}

.chart-grid {
  position: absolute;
  inset-inline: 0;
  border-top: 1px solid var(--hairline);
}

/* The baseline, a step firmer than the gridlines. */
.chart-grid:first-child {
  border-top-color: var(--border);
}

.chart-columns {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.chart-column {
  position: relative;
  display: flex;
  flex: 1;
  align-items: flex-end;
  justify-content: center;
  min-width: 0;
  height: 100%;
}

.chart-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: min(1.5rem, 72%);
  overflow: hidden;
  border-radius: 4px 4px 0 0;
  transition: filter 0.15s;
}

.chart-part {
  flex-basis: 0;
  min-height: 2px;
  background: var(--chart-color);
}

.chart-stack[data-faded] .chart-part {
  background: color-mix(in oklab, var(--chart-color) 35%, var(--card));
}

a.chart-stack:hover,
.chart-stack:hover {
  filter: brightness(1.12);
}

a.chart-stack:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* The value printed on the highlighted column's cap. */
.chart-cap {
  position: absolute;
  margin-bottom: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}

.chart-labels {
  display: flex;
  grid-column: 2;
  gap: 2px;
  color: var(--muted-foreground);
  font-size: 0.6875rem;
}

.chart-labels li {
  flex: 1;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
}

/* ---- The table every column chart opens into ---------------------------- */

.chart-table summary {
  width: fit-content;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  cursor: pointer;
}

.chart-table table {
  width: 100%;
  margin-top: 0.5rem;
  border-collapse: collapse;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.chart-table :is(th, td) {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--hairline);
  text-align: end;
}

.chart-table thead th {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
}

.chart-table th[scope="row"] {
  font-weight: 500;
  text-align: start;
}

/* ---- Bar list: ranked bars with their values ---------------------------- */

.bar-list {
  display: grid;
  gap: 0.875rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 0.375rem 0.75rem;
}

.bar-text {
  display: grid;
  min-width: 0;
}

.bar-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  grid-column: 1 / -1;
  height: 0.5rem;
}

.bar-fill {
  display: block;
  min-width: 2px;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--chart-bar);
  transition: filter 0.15s;
}

a.bar-row:hover .bar-fill {
  filter: brightness(1.12);
}

a.bar-row:hover .bar-text > :first-child {
  text-decoration: underline;
}

/* ---- Month calendar ------------------------------------------------------ */

.calendar {
  display: grid;
  gap: 0.5rem;
  margin: 0;
}

.calendar-week,
.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.calendar-week li {
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 500;
  text-align: center;
}

.calendar-day,
.calendar-key {
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 4px);
  background: var(--muted);
}

.calendar-day {
  position: relative;
  display: grid;
  place-items: center;
  height: 2.75rem;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.calendar-key {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 3px;
}

/* Attended, Late and Absent: a wash of the mark's colour, and a dot in full
   colour under the date so the three stay apart at a glance. */
.calendar-day:is(
  [data-mark="present"],
  [data-mark="late"],
  [data-mark="absent"]
) {
  background: color-mix(in oklab, var(--chart-color) 22%, var(--card));
}

/* The legend shows the dot's colour, the part that tells the three apart. */
.calendar-key:is(
  [data-mark="present"],
  [data-mark="late"],
  [data-mark="absent"]
) {
  background: var(--chart-color);
}

.calendar-day:is(
    [data-mark="present"],
    [data-mark="late"],
    [data-mark="absent"]
  )::after {
  content: "";
  position: absolute;
  bottom: 0.3125rem;
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 999px;
  background: var(--chart-color);
}

:is(.calendar-day, .calendar-key)[data-mark="leave"] {
  background: var(--info-soft);
}

:is(.calendar-day, .calendar-key):is([data-mark="holiday"], [data-mark="off"]) {
  background: transparent;
  border-color: var(--hairline);
  color: var(--muted-foreground);
}

.calendar-day:is([data-mark="upcoming"], [data-mark="none"]) {
  background: transparent;
  color: var(--muted-foreground);
}

.calendar-day[data-mark="upcoming"] {
  border-color: var(--hairline);
}
