/* A clinic on its own page's map (vets/show): an indigo square, as casas de acogida and puntos de recogida have theirs.
   Two classes: views/map.css loads after this file, and its plain .map-marker would win */
.map-marker.map-marker--vet {
  background: var(--category-indigo);
  border-radius: 4px;
}

/* A clinic's page (vets/show), "Mis facturas" and "Gastos": interventions, what they cost and their invoices */

/* "Download all" under the invoices count, and each row's invoice, with a paperclip like a cat's history */
.vet-invoices__download,
.vet-invoices__file {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;

  svg {
    width: var(--icon-sm);
    height: var(--icon-sm);
  }
}

.vet-invoices__download {
  align-self: flex-start;
  margin-top: var(--space-2);
}

/* Phones: each row becomes a small block (date and cost, then the cat and its invoice, then what was done,
   then whose it is in "Gastos"), so nothing needs scrolling sideways. The header row goes: each value is clear from where it sits */
@media (max-width: 40rem) {
  .vet-interventions {
    thead {
      display: none;
    }

    tr {
      display: grid;
      grid-template-columns: 1fr auto;
      grid-template-areas:
        "date cost"
        "cat invoice"
        "kind kind"
        "vet vet";
      gap: var(--space-1) var(--space-3);
      padding: var(--space-3) var(--space-4);
      border-bottom: var(--border);
    }

    td {
      padding: 0;
      border: 0;
    }
  }

  .vet-interventions__date { grid-area: date; color: var(--color-text-muted); font-size: var(--text-sm); }
  .vet-interventions__cost { grid-area: cost; font-weight: var(--weight-medium); }
  .vet-interventions__cat { grid-area: cat; }
  .vet-interventions__invoice { grid-area: invoice; text-align: right; }
  .vet-interventions__kind { grid-area: kind; }
  .vet-interventions__vet { grid-area: vet; color: var(--color-text-muted); font-size: var(--text-sm); }
}

/* A partida, the town hall's or a clinic's (budgets/_budgets): what's set aside, spent and left, a bar of the money
   gone (green on pace, amber ahead of it, red over) and one of the period gone (grey) */
.vet-budget .card__header {
  align-items: flex-start;
}

.vet-budget__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.vet-budget .stat {
  padding: 0;
}

.vet-budget__remaining--over {
  color: var(--color-danger);
}

.vet-budget__bar {
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-surface-sunken);

  span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--color-success);
  }
}

.vet-budget__bar--ahead span {
  background: var(--color-warning);
}

.vet-budget__bar--over span {
  background: var(--color-danger);
}

/* The period's days gone by: the pace to compare the spending with, in plain grey, apart from the money's colours */
.vet-budget__bar--time span {
  background: var(--color-text-muted);
}

.vet-budget__bars {
  display: grid;
  gap: var(--space-3);
}

/* Its name and its percentage on one line, the bar under both */
.vet-budget__bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);

  .vet-budget__bar {
    grid-column: 1 / -1;
  }
}

.vet-budget__bar-value {
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

.vet-budget__pace {
  margin: 0;
  color: var(--color-text-muted);
}

.vet-budget__pace--ahead {
  color: var(--color-warning-text);
}

.vet-budget__pace--over {
  color: var(--color-danger);
}

.vet-budget__invoice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* Phones: the header's buttons go under its title; the three amounts become "label … amount" rows; each earlier
   partida a small block (its dates, then each amount with its name, then its invoice and "Editar"), never sideways */
@media (max-width: 40rem) {
  .vet-budget .card__header {
    flex-wrap: wrap;
  }

  .vet-budget__stats {
    gap: var(--space-2);

    .stat {
      flex-direction: row-reverse;
      justify-content: space-between;
      align-items: baseline;
    }

    .stat__value {
      font-size: var(--text-lg);
    }
  }

  .vet-budgets {
    thead {
      display: none;
    }

    tr {
      display: flex;
      flex-direction: column;
      gap: var(--space-1);
      padding: var(--space-3) var(--space-4);
      border-bottom: var(--border);
    }

    td {
      padding: 0;
      border: 0;
      text-align: left;
    }

    td[data-label] {
      display: flex;
      justify-content: space-between;

      &::before {
        content: attr(data-label);
        color: var(--color-text-muted);
        font-size: var(--text-sm);
      }
    }
  }

  .vet-budgets__period {
    font-weight: var(--weight-medium);
  }

  .vet-budgets__invoice,
  .vet-budgets__edit {
    display: flex;
    justify-content: flex-end;
  }
}

/* Gastos, "Por clínica" (expenses/_clinic): a card per clinic, the one with most room first. The border says how its
   partida goes (green with room, amber ahead of the days, red over); without one it's greyed */
.expenses-tabs {
  align-self: flex-start;
}

.clinic-ranking {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;

  > li {
    display: flex;
  }
}

.clinic-card {
  flex: 1;
  border-top: 4px solid var(--color-border);
}

.clinic-card--roomy { border-top-color: var(--color-success); }
.clinic-card--ahead { border-top-color: var(--color-warning); }
.clinic-card--over { border-top-color: var(--color-danger); }

.clinic-card--none {
  background: var(--color-surface-sunken);
}

.clinic-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  height: 100%;
}

.clinic-card__best {
  margin: 0;
  color: var(--color-success-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.clinic-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.clinic-card__name {
  margin: 0;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);

  a {
    color: inherit;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
    }
  }
}

.clinic-card__left,
.clinic-card__in-dates {
  margin: 0;
}

.clinic-card__in-dates {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
}

/* At the card's foot, however tall the others in its row are */
.clinic-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: auto;
}

/* Gastos' overview (expenses/index, expenses/_kind): a card per kind of partida, as the clinics' cards */
.expense-kinds {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;

  > li {
    display: flex;
  }
}

.expense-kind__name {
  font-size: var(--text-lg);
}

.expense-kind__figures {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
  margin: 0;

  strong {
    font-size: var(--text-xl);
    font-variant-numeric: tabular-nums;
  }
}

/* Gastos › Pienso: what each purchase brought, aligned with its column */
.food-purchases .food-receipt-lines {
  margin: 0;
  padding: 0;
}

/* A partida's clinics (budgets/vets/index, _row): a full-width row each, its name and verdict, the two bars, what's
   left and its buttons side by side; stacked on phones. The top border says how its sub-partida goes, as the cards */
.clinic-rows {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.clinic-row {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(14rem, 2fr) minmax(12rem, 1fr);
  align-items: center;
  gap: var(--space-4) var(--space-6);
  padding: var(--space-4) var(--space-5);
  border-top: 4px solid var(--color-border);
}

.clinic-row__name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);

  .clinic-card__best,
  .clinic-card__name,
  p {
    flex-basis: 100%;
    margin: 0;
  }
}

.clinic-row__money {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
  text-align: right;
}

@media (max-width: 48rem) {
  .clinic-row {
    grid-template-columns: 1fr;
  }

  .clinic-row__money {
    align-items: flex-start;
    text-align: left;
  }
}

/* After .clinic-row's own border, so its colour still says how the sub-partida goes */
.clinic-row.clinic-card--roomy { border-top-color: var(--color-success); }
.clinic-row.clinic-card--ahead { border-top-color: var(--color-warning); }
.clinic-row.clinic-card--over { border-top-color: var(--color-danger); }

/* The spending categories (budget_categories/index): on phones the table keeps its columns and scrolls sideways in its
   .table-wrapper, rather than squeezing the procedures' names into a narrow column */
.budget-categories {
  min-width: 44rem;
}

.budget-categories__name {
  font-weight: var(--weight-medium);
}

/* A long list of procedures: two lines, then "…" (the whole of it in its title and on the category's page) */
.budget-categories__procedures {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* A figure card whose "figure" is a name (a clinic's total invoice among its interventions' figures): smaller, as a title */
.stat__value--text {
  font-size: var(--text-lg);
}

/* A partida's share-out among categories on its edit page (budgets/_allocations_form): a row each with its name and
   what's spent, its amount and the button to take it away; the totals at the foot */
.allocation-rows {
  display: grid;
  gap: var(--space-3);
}

.allocation-row {
  display: grid;
  grid-template-columns: 1fr minmax(8rem, 11rem) auto;
  align-items: center;
  gap: var(--space-3);

  .label {
    margin: 0;
  }
}

.allocation-row__name {
  display: flex;
  flex-direction: column;
}

.allocation-add__controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);

  > :first-child {
    flex: 1;
    min-width: 12rem;
  }
}

.allocation-totals {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2) var(--space-6);
  margin: 0;
  padding-top: var(--space-3);
  border-top: var(--border);

  div {
    text-align: right;
  }

  dt {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  dd {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
  }
}

@media (max-width: 40rem) {
  .allocation-row {
    grid-template-columns: 1fr auto;

    .allocation-row__name {
      grid-column: 1 / -1;
    }
  }
}
