/* Letter list (views/letters-view.js) and the list of the letters drawer, which renders the same
   groups and rows. Groups follow the order of the list, a year or a month in a date order, an
   initial in a name order; their label stands in a margin column and stays in sight while its
   letters scroll past. Rows align in columns, so the eye can run down dates, places or languages.
   Groups are set apart by a hairline, rows by whitespace only. */

/* The scrolling list is the reference of the groups' offsets, which the figure and the jumps read */
.lv-scroll {
    position: relative;
    --lv-label-width: 4.5rem;
    /* Estimated height of a row not yet written; letters-view.js replaces it by the measured one */
    --lv-row-height: 26px;
}

#letters-list.lv-scroll {
    padding: 0 var(--space-lg) var(--space-lg) var(--space-md);
}

.lv-groups,
.lv-rows {
    margin: 0;
    padding: 0;
    list-style: none;
}

.lv-group {
    display: grid;
    grid-template-columns: var(--lv-label-width) minmax(0, 1fr);
    column-gap: var(--space-md);
    border-top: 1px solid var(--color-border-light);
}

.lv-group:first-child {
    border-top: none;
}

/* The quiet label of a group: no heading, it names the value the rows of the group share */
.lv-label {
    position: sticky;
    top: 0;
    align-self: start;
    padding: var(--space-xs) 0;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-tight);
    color: var(--color-text-light);
    font-variant-numeric: tabular-nums;
    hyphens: auto;
    overflow-wrap: anywhere;
}

.lv-label__main {
    display: block;
    font-weight: 600;
    color: var(--color-text);
}

.lv-label__sub {
    display: block;
}

/* Room for rows not yet written, so the scroll bar and a jump reach every letter */
.lv-pending {
    height: calc(var(--rows) * var(--lv-row-height));
}

/* Columns: star, date, persons, place, language, what the source records beyond that. Every row of
   a list has the same tracks, so the columns line up across rows and groups. */
.lv-scroll {
    --lv-date: 6rem;
    --lv-who: minmax(9rem, 3fr);
    --lv-where: minmax(6rem, 2fr);
    --lv-lang: 8rem;
    --lv-notes: minmax(0, 4fr);
}

/* A date order leaves the year of a plain date to the label of its group */
.lv-scroll--compact {
    --lv-date: 5.5rem;
}

/* Rows that name sender and recipients need more room for the persons */
.lv-scroll--pairs {
    --lv-who: minmax(14rem, 5fr);
    --lv-notes: minmax(0, 3fr);
}

/* A list whose letters record nothing beyond place and language keeps its columns close together
   instead of spreading them over the width */
.lv-scroll--plain {
    --lv-who: minmax(9rem, 22rem);
    --lv-where: minmax(6rem, 14rem);
    --lv-notes: 0;
}

.lv-scroll--pairs.lv-scroll--plain {
    --lv-who: minmax(14rem, 32rem);
}

.lv-rows .letter-card {
    display: grid;
    /* The language column holds its colour field and its name */
    grid-template-columns: 24px var(--lv-date) var(--lv-who) var(--lv-where) var(--lv-lang) var(--lv-notes);
    column-gap: var(--space-md);
    align-items: baseline;
    max-width: 84rem;
    padding: 2px var(--space-xs);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-tight);
    cursor: pointer;
    transition: var(--transition-fast);
    transition-property: var(--transition-properties);
}

.lv-rows .letter-card:hover {
    background: var(--color-bg-light);
}

.lv-scroll--plain .lv-notes {
    display: none;
}

.lv-rows .btn-letter-basket {
    align-self: start;
    padding: 0;
}

/* Long dates (a span, a date in words) wrap inside their column instead of running into the next */
.lv-rows .letter-date {
    white-space: normal;
    font-variant-numeric: tabular-nums;
}

.lv-rows .date-with-precision {
    display: inline;
}

/* The persons read as text; names wrap instead of being cut */
.lv-rows .lv-who {
    display: block;
    min-width: 0;
    overflow-wrap: anywhere;
}

.lv-name {
    font-weight: 600;
}

.lv-dir {
    display: inline-block;
    min-width: 2em;
    font-weight: 400;
    color: var(--color-text-light);
}

.lv-rows .letter-arrow {
    margin: 0 var(--space-xs);
}

.lv-place,
.lv-lang {
    min-width: 0;
    color: var(--color-text-light);
    overflow-wrap: anywhere;
}

.lv-lang {
    display: flex;
    align-items: baseline;
    gap: var(--space-xs);
}

/* The records beyond place and language run as one line of text that wraps, not as a stack */
.lv-notes.letter-meta {
    display: block;
    min-width: 0;
    font-size: var(--font-size-sm);
}

.lv-notes.letter-meta > span {
    display: inline;
    margin-right: var(--space-md);
}

.list-result .lv-centre {
    font-weight: 400;
    color: var(--color-text-light);
}

/* Phones: a row takes two lines. The persons with the star before and the date after them, below
   place, language and the rest */
@media (max-width: 767px) {
    .lv-scroll {
        --lv-label-width: 3.5rem;
    }

    #letters-list.lv-scroll {
        padding: 0 var(--space-sm) var(--space-lg);
    }

    .lv-group {
        column-gap: var(--space-sm);
    }

    .lv-label {
        font-size: var(--font-size-xs);
    }

    .lv-rows .letter-card {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        column-gap: var(--space-sm);
        row-gap: 0;
        padding: var(--space-xs) 0;
    }

    .lv-rows .btn-letter-basket {
        order: 0;
        align-self: baseline;
    }

    /* Star, persons and date fill the first line exactly, so the rest begins the second */
    .lv-rows .lv-who {
        order: 1;
        flex: 0 0 calc(100% - 24px - 5rem - 2 * var(--space-sm));
    }

    .lv-rows .letter-date {
        order: 2;
        flex: 0 0 5rem;
        text-align: right;
    }

    /* The second line starts under the persons */
    .lv-rows .lv-place {
        order: 3;
        flex-basis: auto;
        margin-left: calc(24px + var(--space-sm));
    }

    .lv-place:empty {
        display: none;
    }

    .lv-place:empty ~ .lv-lang {
        margin-left: calc(24px + var(--space-sm));
    }

    .lv-rows .lv-lang {
        order: 4;
    }

    .lv-rows .lv-notes {
        order: 5;
        flex-basis: 100%;
        margin-left: calc(24px + var(--space-sm));
    }

    .lv-rows .lv-notes:empty {
        display: none;
    }
}

/* The figure above the list: the letters of the selection per year (per initial in a name order),
   stacked by language in the colours they have everywhere. A rust line under the columns marks
   where the list is; a column jumps there. */
.lv-profile {
    padding: var(--space-sm) var(--space-lg) calc(var(--space-lg) + var(--font-size-xs)) calc(var(--space-md) + 4.5rem + var(--space-md));
}

/* The key stands under the profile and begins where its columns begin */
#letters-key {
    padding: 0 var(--space-lg) var(--space-sm) calc(var(--space-md) + 4.5rem + var(--space-md));
}

@media (max-width: 767px) {
    #letters-key {
        padding: 0 var(--space-sm) var(--space-sm);
    }
}

.lv-profile__bars {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 48px;
}

.lv-bar {
    position: relative;
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    justify-content: flex-end;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.lv-bar--empty {
    cursor: default;
}

/* The letters off the time axis stand apart from the years, as on the time view */
.lv-bar--off {
    flex: 0 0 3rem;
    margin-left: var(--space-md);
}

.lv-bar__stack {
    display: flex;
    flex-direction: column-reverse;
    width: 100%;
}

.lv-bar__seg {
    flex-basis: 0;
    min-height: 0;
}

.lv-bar__seg--plain {
    background: var(--color-data);
}

.lv-bar:hover .lv-bar__stack {
    opacity: 0.8;
}

.lv-bar__tick {
    position: absolute;
    top: 100%;
    left: 50%;
    padding-top: var(--space-xs);
    transform: translateX(-50%);
    font-size: var(--font-size-xs);
    line-height: 1;
    color: var(--color-text-light);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.lv-bar.is-current::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -3px;
    height: 2px;
    background: var(--color-primary);
}

@media (max-width: 767px) {
    .lv-profile {
        padding: var(--space-xs) var(--space-sm) calc(var(--space-lg) + var(--font-size-xs)) calc(var(--space-sm) + 3.5rem + var(--space-sm));
    }

    .lv-profile__bars {
        height: 36px;
    }

    .lv-bar--off {
        flex-basis: 2.5rem;
        margin-left: var(--space-sm);
    }
}

/* The column the keyboard stands on while the figure has focus */
.lv-profile:focus-visible {
    outline-offset: var(--space-xs);
}

.lv-profile:focus-visible .lv-bar.is-active {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.letter-calendar {
    container-type: inline-size;
    margin: 0 var(--space-md) var(--space-sm);
    flex: none;
}
.letter-calendar > summary {
    width: fit-content;
    cursor: pointer;
    font-weight: 650;
    padding: .3rem 0;
}
.lc-controls, .lc-partial {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: .4rem 1rem;
    padding: .3rem 0;
}
.lc-week { display: none; }
.lc-legend { display: inline-flex; gap: .65rem; margin-inline-start: .7rem; font-weight: normal; }
.lc-legend span::before { content: ''; display: inline-block; width: .85rem; height: 3px; margin-right: .2rem; vertical-align: middle; }
.lc-in::before, .lc-bars::before { background: var(--color-data); }
.lc-out::before, .lc-bars::after { background: var(--color-role-organization); }
.lc-day:has(.lc-bars) { position: relative; padding-bottom: 6px; background: var(--color-bg-light); color: var(--color-text); }
.lc-bars { position: absolute; inset: auto 2px 1px; display: grid; gap: 1px; height: 5px; }
.lc-bars::before, .lc-bars::after { content: ''; display: block; height: 2px; }
.lc-bars::before { width: var(--received); }
.lc-bars::after { width: var(--sent); }
.lc-unit { font-size: .82rem; font-weight: 650; margin: .3rem 0; }
.lc-controls label { font-size: .85rem; }
.lc-controls select { max-width: 100%; color: inherit; }
.lc-axis, .lc-month { display: grid; grid-template-columns: 5rem minmax(0, 1fr); align-items: center; }
.lc-days, .lc-axis > div { display: grid; grid-template-columns: repeat(31, minmax(0, 1fr)); gap: 1px; }
.lc-axis, .lc-month-name { font-size: .76rem; color: var(--color-text-light); }
.lc-axis > div { text-align: center; }
.lc-month { margin-top: 2px; }
.lc-day, .lc-blank { min-height: 24px; display: grid; place-items: center; }
.lc-day { cursor: pointer; border: 0; border-radius: 2px; background: var(--color-bg-light); color: var(--color-text); font: inherit; font-size: .78rem; padding: 0; }
.lc-day[data-multiple="true"]:not(:has(.lc-bars)) { background: var(--color-data); color: white; }
.lc-day[aria-pressed="true"], .lc-loose[aria-pressed="true"] { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.lc-blank { background: color-mix(in srgb, var(--color-bg-light) 35%, transparent); }
.lc-date { display: none; }
.lc-loose { color: var(--color-link); background: none; border: 0; padding: .2rem 0; text-decoration: underline; cursor: pointer; font: inherit; font-size: .85rem; }
.lc-evidence h3 { margin: .7rem 0 .3rem; font-size: 1rem; }
.lc-evidence-list { max-height: 18rem; overflow: auto; }
#letters-view:has(.letter-calendar[open]) { overflow-y: auto; }
#letters-view:has(.letter-calendar[open]) > .entity-list { min-height: 14rem; }
@container (max-width: 52rem) {
    .lc-plot { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: .65rem 1rem; }
    .lc-axis { display: none; }
    .lc-month { display: block; }
    .lc-month-name { display: block; font-weight: 650; color: var(--color-text); }
    .lc-week, .lc-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
    .lc-week { text-align: center; font-size: .66rem; color: var(--color-text-light); }
    .lc-days > :first-child { grid-column-start: var(--offset); }
    .lc-date { display: inline; }
    .lc-blank { color: var(--color-text-light); font-size: .72rem; }
    .lc-count { font-size: .62rem; }
    .lc-day { display: flex; justify-content: space-evenly; align-items: baseline; padding: 2px 1px; }
    .lc-count::before { content: '×'; }
}
