/*
  The screens themselves: the day's work list, the planner calendar, customer services, messages,
  and the pickers.
*/

@layer screens {
  /* Dashboard -------------------------------------------------------------- */

  /* The three numbers that describe the business, set large enough to read at arm's length. */
  .figures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: 0;
    border-top: 1px solid var(--rule-strong);
  }

  .figures__item {
    padding: var(--s-4) 0 var(--s-5);
    border-bottom: 1px solid var(--rule);
  }

  @media (min-width: 48em) {
    .figures__item { padding-inline: var(--s-5); border-bottom: 0; }
    .figures__item:first-child { padding-inline-start: 0; }
    .figures__item + .figures__item { border-inline-start: 1px solid var(--rule); }
  }

  .figures__label {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--ink-2);
  }

  .figures__value {
    display: block;
    font-family: var(--face-display);
    margin-block: var(--s-1);
    font-size: clamp(2rem, 1.4rem + 2vw, 2.75rem);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
  }

  .figures__value--money { color: var(--money); }

  .figures__note { font-size: var(--text-sm); color: var(--ink-3); }

  .notice {
    padding: var(--s-4);
    border: 1px solid var(--rule);
    border-inline-start: 3px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface-sunk);
    margin-bottom: var(--s-5);
  }

  .notice h2 { font-size: var(--text-lg); margin-bottom: var(--s-2); }
  .notice p { margin: 0; }

  /* Work list -------------------------------------------------------------- */

  .work-day-navigator {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-bottom: var(--s-4);
  }

  .work-day-navigator h2 {
    flex: 1 1 auto;
    text-align: center;
    font-size: var(--text-xl);
  }

  .work-day-navigator h2 a {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 0.25em;
  }

  .work-day-navigator__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap);
    min-height: var(--tap);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
  }

  .work-day-navigator__btn:hover { background: var(--surface-sunk); }

  .work-lists {
    display: flex;
    gap: var(--s-4);
    align-items: flex-start;
    overflow-x: auto;
    padding-bottom: var(--s-3);
  }

  .work-lists__real-lists {
    display: flex;
    gap: var(--s-4);
    align-items: flex-start;
  }

  .work-lists__placeholder-list__inner {
    width: 16rem;
    border: 1px dashed var(--rule-strong);
    border-radius: var(--radius-lg);
  }

  .work-list {
    width: 22rem;
    max-width: calc(100vw - var(--s-6));
    background: var(--surface-sunk);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
  }

  @media (max-width: 35.99em) {
    .work-list { width: min(22rem, calc(100vw - var(--s-6))); }
  }

  .work-list__heading {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-4) var(--s-3) var(--s-3);
  }

  .work-list__heading h3 {
    flex: 1 1 auto;
    font-size: var(--text-lg);
    user-select: none;
  }

  /* Three figures for the day: what it is worth, what has been done, what has been paid for. */
  .work-list__totals {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1) var(--s-4);
    padding: 0 var(--s-3) var(--s-3);
    font-size: var(--text-sm);
    color: var(--ink-2);
  }

  .work-list__totals strong {
    font-family: var(--face-display);
    font-variant-numeric: tabular-nums;
    color: var(--ink);
  }

  /* Only money actually collected takes the money colour; the rest is ink. */
  .work-list__totals__item--paid strong { color: var(--money); }

  .work-list__entries {
    max-height: min(60vh, 40rem);
    overflow-y: auto;
    padding: var(--s-1) var(--s-3);
  }

  .work-list__entry {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: var(--s-3);
    margin-bottom: var(--s-2);
    cursor: pointer;
  }

  .work-list__entry:hover { border-color: var(--rule-strong); }

  /* A spine down the left edge carries the state, the way a round book carries a tick column. */
  .work-list__entry::before {
    content: "";
    position: absolute;
    inset-block: -1px;
    inset-inline-start: -1px;
    width: 3px;
    border-start-start-radius: var(--radius);
    border-end-start-radius: var(--radius);
    background: transparent;
  }

  .work-list__entry:has(.work-list__entry__tap--on)::before { background: var(--ink-3); }
  .work-list__entry:has(.work-list__entry__tap--paid.work-list__entry__tap--on)::before { background: var(--money); }

  .work-list__entry__head {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: start;
    gap: var(--s-1) var(--s-2);
  }

  .work-list__entry__address {
    display: block;
    font-weight: 600;
    line-height: 1.25;
  }

  .work-list__entry__name {
    display: block;
    font-size: var(--text-sm);
    color: var(--ink-2);
  }

  /* The price sits in its own column so a list of houses reads down the figures. */
  .work-list__entry__price {
    font-family: var(--face-display);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .work-list__entry__taps {
    display: flex;
    gap: var(--s-2);
    margin-top: var(--s-2);
  }

  .work-list__entry__tap {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-1);
    min-height: 2rem;
    padding: 2px var(--s-2);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-2);
    font-size: var(--text-sm);
    font-weight: 700;
    text-decoration: none;
    user-select: none;
  }

  .work-list__entry__tap svg { width: 14px; height: 14px; }

  .work-list__entry__tap:hover {
    color: var(--ink);
    border-color: var(--ink-3);
    text-decoration: none;
  }

  .work-list__entry__tap--on {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
  }

  .work-list__entry__tap--paid.work-list__entry__tap--on {
    background: var(--money);
    border-color: var(--money);
    color: var(--money-ink);
  }

  .work-list__entry__tap--on:hover {
    background: color-mix(in oklab, var(--ink) 88%, var(--paper));
    border-color: color-mix(in oklab, var(--ink) 88%, var(--paper));
    color: var(--paper);
  }

  .work-list__entry__tap--paid.work-list__entry__tap--on:hover {
    background: color-mix(in oklab, var(--money) 88%, black);
    border-color: color-mix(in oklab, var(--money) 88%, black);
    color: var(--money-ink);
  }

  /* Removing an entry is the one destructive control here, so it is narrow, set apart, and rust. */
  .work-list__entry__tap--remove {
    flex: 0 0 auto;
    min-width: 2rem;
    padding-inline: var(--s-2);
    color: var(--owing);
    border-color: color-mix(in oklab, var(--owing) 40%, var(--rule-strong));
  }

  .work-list__entry__tap--remove:hover {
    background: var(--owing);
    border-color: var(--owing);
    color: var(--owing-ink);
  }

  .work-list__entry__collapse.show { display: flex; }
  .work-list__entry__collapse { gap: var(--s-3); }
  .work-list__entry__customer { flex: 1 1 auto; padding-top: var(--s-2); font-size: var(--text-sm); }
  .work-list__entry__actions { display: flex; flex-direction: column; gap: var(--s-1); }

  .work-list__empty {
    padding: var(--s-4) var(--s-2);
    font-size: var(--text-sm);
    color: var(--ink-3);
  }

  /* A rule marks where the scrolling list ends, so the action below it is not read as another row. */
  .work-list__footer {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-top: 1px solid var(--rule);
  }

  /* button_to wraps its button in a form, which would otherwise take a row of its own. */
  .work-list__footer .button_to { display: contents; }

  .btn-work-list {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    min-width: 2rem;
    min-height: 2rem;
    padding: var(--s-1) var(--s-2);
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--ink-2);
    cursor: pointer;
  }

  .btn-work-list:hover { background: var(--surface-sunk); color: var(--ink); }

  /* The heading and the footer sit on the panel, which is already the sunk colour, so a button
     there has to lift off it instead. Without this its hover state is the colour it sits on. */
  .work-list__heading .btn-work-list:hover,
  .work-list__footer .btn-work-list:hover { background: var(--surface); }

  .sortable-drag { rotate: 2deg; box-shadow: var(--shadow-sheet); }
  .sortable-ghost { opacity: 0; }
  [draggable="true"] { cursor: pointer; }

  /* The entry editor is one column on a phone; two only when there is room for two. */
  .entry-editor { display: grid; gap: var(--s-4); }

  .entry-editor__customer { display: grid; gap: var(--s-1); }

  .entry-editor__address {
    font-family: var(--face-display);
    font-size: var(--text-lg);
    font-weight: 700;
    margin: 0;
  }

  .entry-editor__name {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    color: var(--ink-2);
    margin: 0 0 var(--s-2);
  }

  .entry-editor__map { color: var(--ink-3); line-height: 0; }
  .entry-editor__map:hover { color: var(--accent); }

  .entry-editor .section-heading { margin-block: 0 var(--s-2); }

  .entry-editor__open {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    justify-self: start;
    font-size: var(--text-sm);
  }

  .entry-editor .form-group:last-child { margin-bottom: 0; }
  .entry-editor__panel { display: grid; gap: var(--s-2); align-content: start; }
  .entry-editor__panel .form-group { margin-bottom: var(--s-2); }
  .entry-editor__note { font-size: var(--text-sm); color: var(--ink-2); margin: 0; }

  /* The same three actions as the card, kept quiet because the card is where they belong. */
  .entry-editor__quick {
    display: grid;
    gap: var(--s-2);
    padding-top: var(--s-3);
    border-top: 1px solid var(--rule);
  }

  .entry-editor__quick-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

  .quick--on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
  .quick--on:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }

  .quick--paid.quick--on,
  .quick--paid.quick--on:hover {
    background: var(--money);
    border-color: var(--money);
    color: var(--money-ink);
  }

  .quick--remove { color: var(--owing); border-color: color-mix(in oklab, var(--owing) 40%, var(--rule-strong)); }
  .quick--remove:hover { background: var(--owing); border-color: var(--owing); color: var(--owing-ink); }

  @media (min-width: 36em) {
    .entry-editor { grid-template-columns: 1fr 1fr; align-items: start; }
    .entry-editor__customer,
    .entry-editor__quick { grid-column: 1; }
    .entry-editor__panel { grid-column: 2; grid-row: 1 / span 2; }
  }

  /* Planner calendar ------------------------------------------------------- */

  .calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .calendar .heading {
    padding: var(--s-2);
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--ink-2);
    text-align: end;
    background: var(--surface-sunk);
    border-bottom: 1px solid var(--rule);
  }

  .calendar .day {
    min-height: 5rem;
    border-inline-start: 1px solid var(--rule);
    border-block-start: 1px solid var(--rule);
  }

  .calendar .day:nth-child(7n + 1) { border-inline-start: 0; }
  .calendar .heading + .heading { border-inline-start: 1px solid var(--rule); }

  .calendar .day.today { background: var(--accent-soft); }

  .calendar .day a {
    display: block;
    height: 100%;
    padding: var(--s-2);
    text-align: end;
    text-decoration: none;
    color: var(--ink);
  }

  .calendar .day a:hover { background: var(--surface-sunk); }

  .calendar .day p {
    margin-top: var(--s-1);
    text-align: start;
    font-size: var(--text-xs);
    color: var(--ink-2);
  }

  /* Filters ---------------------------------------------------------------- */

  /* Two selects beside a search box leave no room on a phone, so they fold away behind a toggle.
     On a wider screen the wrapper disappears and they sit in the row as before. */
  .filterbar__toggle { display: none; }

  @media (min-width: 48em) {
    .filterbar__more.filterbar__more { display: contents; }
  }

  @media (max-width: 47.99em) {
    .filterbar__toggle { display: inline-flex; }

    .filterbar__more {
      flex-basis: 100%;
      display: grid;
      gap: var(--s-3);
    }

    .filterbar__more.collapse:not(.show) { display: none; }
    .filterbar__field, .filterbar__field--wide { min-width: 0; }
  }

  /* Customer list ---------------------------------------------------------- */

  /* Five columns do not fit a phone, so each customer becomes two lines: the address and what
     they are worth, then the round, the name and when they were added. */
  @media (max-width: 47.99em) {
    .customer-table thead { display: none; }

    /* Placed explicitly so a long address cannot pull the round up onto the first line. */
    .customer-table tbody tr {
      display: grid;
      grid-template-columns: auto auto 1fr auto;
      column-gap: var(--s-3);
      row-gap: var(--s-1);
      align-items: baseline;
      padding-block: var(--s-3);
      border-bottom: 1px solid var(--rule);
    }

    .customer-table tbody tr:hover { background: none; }

    .customer-table td { display: block; border: 0; padding: 0; }

    .customer-table td:nth-child(1) { grid-row: 1; grid-column: 1 / 4; font-weight: 600; }
    .customer-table td:nth-child(5) { grid-row: 1; grid-column: 4; }
    .customer-table td:nth-child(2) { grid-row: 2; grid-column: 1; }
    .customer-table td:nth-child(3) { grid-row: 2; grid-column: 2; }
    .customer-table td:nth-child(4) { grid-row: 2; grid-column: 3; }

    .customer-table td:nth-child(2),
    .customer-table td:nth-child(3),
    .customer-table td:nth-child(4) {
      font-size: var(--text-sm);
      color: var(--ink-2);
    }
  }

  /* Rounds ----------------------------------------------------------------- */

  /* Wide enough for Plan round and Edit round to sit side by side. */
  .card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
    gap: var(--s-4);
  }

  .round-card + .round-card { margin-top: 0; }

  .round-card__name {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    font-size: var(--text-lg);
  }

  .round-card__count { margin-block: var(--s-2) var(--s-4); color: var(--ink-2); }

  .round-card__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  .roundtags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
    list-style: none;
    padding: 0;
    margin: var(--s-2) 0 0;
  }

  .roundtag {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-1) var(--s-3);
    border: 1px solid var(--rule-strong);
    border-radius: 999px;
    font-size: var(--text-sm);
    color: var(--ink);
    text-decoration: none;
  }

  .roundtag:hover {
    background: color-mix(in oklab, var(--round-color, var(--ink)) 12%, transparent);
    border-color: var(--round-color, var(--rule-strong));
    text-decoration: none;
  }

  /* Each round carries its own colour, so a dot is enough to tell them apart at a glance. */
  .roundtag__dot {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    background: var(--round-color, var(--ink-3));
    flex: none;
  }

  .round-card__dot {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    background: var(--round-color, var(--ink-3));
    flex: none;
  }

  .round-card { border-inline-start: 3px solid var(--round-color, var(--rule)); }

  .colorfield__picker {
    inline-size: 3.5rem;
    block-size: 2.25rem;
    padding: 2px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
  }


  /* Customer services ------------------------------------------------------ */

  .customer-service {
    background: var(--surface-sunk);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    margin-inline: 0;
    margin-bottom: var(--s-4);
    padding: var(--s-3);
  }

  .customer-service__display {
    padding: 0;
    background: none;
    border: 0;
    margin: 0;
  }

  /* Each service is one block in a ruled list, separated rather than boxed. */
  .customer-service__display + .customer-service__display {
    margin-top: var(--s-5);
    padding-top: var(--s-5);
    border-top: 1px solid var(--rule-strong);
  }
  .customer-service .rrule .interval { max-width: 80%; }

  .service-option { padding: var(--s-2); }
  .service-option .name { display: block; font-weight: 700; }
  .service-option .description, .service-option .recurrence_to_s { display: inline-block; }
  .service-option__single-line .description,
  .service-option__single-line .recurrence_to_s,
  .service-option__single-line .price_to_s { padding-inline-start: var(--s-2); color: var(--ink-2); }

  .report-hint { font-size: var(--text-sm); color: var(--ink-2); margin: 0; }

  @media (max-width: 35.99em) {
    .job-form-table .table thead { display: none; }
    .job-form-table .table td { padding: var(--s-2) var(--s-1); }
  }

  /* Messages --------------------------------------------------------------- */

  .messages {
    max-height: 20rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column-reverse;
    margin-bottom: var(--s-2);
  }

  .conversation {
    padding: var(--s-3);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    margin-bottom: var(--s-2);
    cursor: pointer;
  }

  .conversation:hover { background: var(--surface-sunk); }

  .message {
    width: fit-content;
    max-width: min(90%, 32rem);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--radius-lg);
    margin-bottom: var(--s-2);
    overflow-wrap: anywhere;
  }

  .message--inbound { background: var(--surface-sunk); }

  .message--outbound {
    background: var(--money-soft);
    margin-inline-start: auto;
    text-align: end;
  }

  .message__time { display: block; font-size: var(--text-xs); color: var(--ink-2); }

  /* Pickers ---------------------------------------------------------------- */

  .selectize-control { position: relative; }

  .selectize-input {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1);
    align-items: center;
    cursor: text;
  }

  .selectize-input.focus {
    border-color: var(--ink);
    outline: 2px solid var(--ink);
    outline-offset: 1px;
  }

  .selectize-input > input {
    border: 0;
    outline: 0;
    padding: 0;
    background: transparent;
    min-width: 6rem;
    flex: 1 1 auto;
  }

  .selectize-input > input[placeholder] { width: 100% !important; }

  .selectize-input .item {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    padding: 1px var(--s-2);
    border-radius: var(--radius);
    background: var(--surface-sunk);
    font-size: var(--text-sm);
  }

  .selectize-control.single .selectize-input::after {
    content: "";
    margin-inline-start: auto;
    border: 4px solid transparent;
    border-top-color: var(--ink-3);
    translate: 0 2px;
  }

  .selectize-dropdown {
    position: absolute;
    inset-inline: 0;
    top: 100%;
    z-index: 40;
    background: var(--surface);
    border: 1px solid var(--rule-strong);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-sheet);
  }

  .selectize-dropdown-content { max-height: 16rem; overflow-y: auto; }

  .selectize-dropdown .option { padding: var(--s-2) var(--s-3); cursor: pointer; }
  .selectize-dropdown .option.active { background: var(--surface-sunk); }
  .selectize-dropdown .optgroup-header { padding: var(--s-2) var(--s-3); font-size: var(--text-sm); color: var(--ink-2); }

  .algolia-autocomplete, .algolia-autocomplete .aa-input, .algolia-autocomplete .aa-hint { width: 100%; }
  .algolia-autocomplete .aa-hint { color: var(--ink-3); }

  .algolia-autocomplete .aa-dropdown-menu {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--rule-strong);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 40;
  }

  .algolia-autocomplete .aa-dropdown-menu .aa-suggestion { cursor: pointer; padding: var(--s-2) var(--s-3); }
  .algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor { background: var(--surface-sunk); }
  .algolia-autocomplete .aa-dropdown-menu .aa-suggestion em { font-weight: 700; font-style: normal; }

  /* Flatpickr sits on the tokens rather than its own grey. */
  .flatpickr-calendar {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sheet);
    color: var(--ink);
  }

  .flatpickr-day { color: var(--ink); }
  .flatpickr-day.today { border-color: var(--money); }
  .flatpickr-day.selected, .flatpickr-day.selected:hover {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
  }
  .flatpickr-day:hover { background: var(--surface-sunk); }
  .flatpickr-day.flatpickr-disabled, .flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay { color: var(--ink-3); }
  .flatpickr-months .flatpickr-month, .flatpickr-weekdays, span.flatpickr-weekday {
    background: var(--surface);
    color: var(--ink-2);
    fill: var(--ink-2);
  }
  .flatpickr-current-month .flatpickr-monthDropdown-months { background: var(--surface); }

  .search-result .card-header { cursor: pointer; }
  .search-result .card-header:hover { background: var(--surface-sunk); }
  .add-customer-modal .modal-content { min-height: 25rem; }

  .work-day-modal .form-group.string,
  .work-day-modal .form-group.customers_round { width: 100%; }
}
