/* ==========================================================================
   Retainers, billed time and bills to a firm

   The screens here share one idea worth getting right: a quarter's credit only
   means anything against the budget it started at, so the bar carries the
   proportion and the figures carry the amounts. Aqua inside the budget, amber
   at 90% used, coral over it — the same thresholds the alerts are raised on,
   because a screen and an alert that disagree are worse than neither (see
   RetainerQuarter).
   ========================================================================== */

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

.firm-retainer__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-6);
}

@media (max-width: 960px) {
  .firm-retainer__grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --- The summary card ----------------------------------------------------- */

.retainer-summary__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

.retainer-summary__note {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-medium);
}

/* --- The meter ------------------------------------------------------------ */

.retainer-meter {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--tint-navy-04);
}

.retainer-meter__kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
  margin: 0;
}

.retainer-meter__kpi dt {
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.retainer-meter__kpi dd {
  margin: var(--space-1) 0 0;
  font-family: var(--font-family-bold);
  font-size: var(--font-size-xlarge);
  font-weight: bold;
  color: var(--color-primary-dark);
  font-variant-numeric: tabular-nums;
}

.retainer-meter__kpi--left dd {
  color: var(--color-success-dark);
}

.retainer-meter__kpi--over dd {
  color: var(--color-danger);
}

.retainer-meter__kpi--expired dd {
  color: var(--color-text-muted);
}

.retainer-meter__kpi-note {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

.retainer-meter__track {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background-color: var(--color-border);
  overflow: hidden;
}

.retainer-meter__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 7px;
  background-color: var(--color-primary-green);
}

.retainer-meter--running_out .retainer-meter__fill {
  background-color: var(--color-warning);
}

/* Spend past the budget, striped so it reads as "beyond" rather than as more
   of the same. */
.retainer-meter__over {
  position: absolute;
  top: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    -45deg,
    var(--color-danger) 0 6px,
    var(--color-danger-light) 6px 12px
  );
}

/* Where today falls in the quarter, so spend running ahead of time shows. */
.retainer-meter__today {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  border-radius: 2px;
  background-color: var(--color-primary-dark);
}

.retainer-meter__legend {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

@media (max-width: 720px) {
  .retainer-meter__kpis {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --- Alerts --------------------------------------------------------------- */

.retainer-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--color-warning);
  background-color: var(--color-yellow-100);
  font-size: var(--font-size-medium);
}

.retainer-alert p {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
}

.retainer-alert--over {
  border-left-color: var(--color-danger);
  background-color: var(--tint-danger-10);
}

.retainer-alert--settled {
  border-left-color: var(--color-primary-green);
  background-color: var(--tint-green-10);
}

.retainer-alert--expired {
  border-left-color: var(--color-border-strong);
  background-color: var(--color-surface-sunken);
}

/* --- Spend log, quarters, schedule, overspend ------------------------------ */

.retainer-spend__scroll {
  overflow-x: auto;
}

.retainer-spend__table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-medium);
}

.retainer-spend__table th,
.retainer-spend__table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

.retainer-spend__table thead th {
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.retainer-spend__table tfoot td {
  border-bottom: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

.retainer-spend__numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* The running total once it has passed the budget. */
.retainer-spend__numeric--over {
  color: var(--color-danger);
  font-weight: bold;
}

.retainer-spend__source {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

.retainer-spend__description {
  max-width: 28rem;
}

.retainer-spend__row--adjustment {
  background-color: var(--tint-navy-04);
}

.retainer-spend__empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
}

.retainer-quarters__row--selected {
  background-color: var(--tint-green-10);
}

.retainer-quarters__now {
  margin-left: var(--space-2);
  padding: 0 var(--space-2);
  border-radius: 999px;
  background-color: var(--tint-green-16);
  font-size: var(--font-size-small);
}

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

.retainer-schedule__status form {
  display: inline;
}

/* The quarterly budgets the retainer form previews before it is saved. */
.retainer-form__budget .retainer-spend__table td {
  padding: var(--space-1) var(--space-2);
}

/* --- Service Information's empty state ------------------------------------ */

.firm-placeholder__choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
}

.firm-placeholder__note {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2) var(--space-5);
  margin: var(--space-3) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

/* --- The marker on a firm's directory card -------------------------------- */

/* A badge rather than another chip. The header already carries up to three
   chips that mean something has gone wrong, and a fourth saying "this is how
   they pay" would compete with them for the same glance (see
   firms/index/_index_list). */
.firm-pill__retainer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: var(--tint-green-16);
  color: var(--color-primary-dark);
}

/* The firm's name and its marker, as one thing. */
.firm-pill__heading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.firm-pill__retainer-icon {
  width: 15px;
  height: 15px;
}

/* --- The time log's Billing panel ----------------------------------------- */

.time-entry-billing__choice {
  margin: 0 0 var(--space-4);
  padding: 0;
  border: 0;
}

.time-entry-billing__options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.time-entry-billing__option {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.time-entry-billing__option:has(input:checked) {
  border-color: var(--color-primary-dark);
  background-color: var(--tint-navy-04);
}

.time-entry-billing__option--billed:has(input:checked) {
  border-color: var(--color-danger);
  background-color: var(--tint-danger-10);
}

.time-entry-billing__option span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.time-entry-billing__option small {
  color: var(--color-text-muted);
}

.time-entry-billing__billed {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.time-entry-billing__billed.hidden {
  display: none;
}

/* The client's red warning, with the tick that has to be given. */
.time-entry-billing__warning {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-md);
  background-color: var(--tint-danger-10);
  font-size: var(--font-size-medium);
}

.time-entry-billing__warning p {
  margin: 0 0 var(--space-2);
}

.time-entry-billing__warning-title {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  color: var(--color-danger);
  font-weight: bold;
}

.time-entry-billing__confirm {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  font-weight: bold;
  cursor: pointer;
}

.time-entry-billing__preview {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.time-entry-billing__note {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-medium);
}

.time-entry-billing__cost {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.time-entry-billing__cost-line {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: baseline;
}

.time-entry-billing__cost-line strong {
  font-size: var(--font-size-xlarge);
  font-variant-numeric: tabular-nums;
}

.time-entry-billing__cost-vat,
.time-entry-billing__muted {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

.time-entry-billing__destination {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--color-border-strong);
  background-color: var(--color-surface-sunken);
  font-size: var(--font-size-medium);
}

.time-entry-billing__destination p {
  margin: 0;
}

.time-entry-billing__destination--retainer {
  border-left-color: var(--color-primary-green);
  background-color: var(--tint-green-10);
}

.time-entry-billing__destination--over {
  border-left-color: var(--color-warning);
  background-color: var(--color-yellow-100);
}

.time-entry-billing__destination--month-end {
  border-left-color: var(--color-primary-dark);
  background-color: var(--tint-navy-06);
}

.time-entry-billing__meter {
  position: relative;
  height: 8px;
  margin-top: var(--space-2);
  border-radius: 4px;
  background-color: var(--color-border);
  overflow: hidden;
}

.time-entry-billing__meter i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background-color: var(--color-primary-green);
}

.time-entry-billing__meter .time-entry-billing__meter-add {
  background-color: var(--color-primary-dark);
}

/* The firm a billed hour was charged to, under its record on the time log. */
.time-entry__firm {
  display: block;
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

.time-entry__locked {
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

/* --- The time log's two views ---------------------------------------------- */

.time-log-tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-3);
}

.time-log-tabs__tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: bold;
}

.time-log-tabs__tab--current {
  border-bottom-color: var(--color-primary-dark);
  color: var(--color-primary-dark);
}

.time-log-tabs__count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background-color: var(--color-danger);
  color: var(--color-white);
  font-size: var(--font-size-small);
  text-align: center;
}

/* --- Month-end billing ------------------------------------------------------ */

.month-end-billing__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  overflow-y: auto;
}

.month-end-billing__intro,
.month-end-billing__empty {
  margin: 0;
  color: var(--color-text-muted);
}

.month-end-billing__when {
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

/* --- A firm's Invoices tab --------------------------------------------------- */

.firm-invoices__recipients {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  margin: 0;
  font-size: var(--font-size-medium);
}

.firm-invoices__recipients--missing {
  color: var(--color-danger);
}

.invoice-row__sent-to {
  max-width: 14rem;
  font-size: var(--font-size-small);
  overflow-wrap: anywhere;
}

/* A case invoice's reference is built from names and runs long; two lines of
   it is enough to know which case. */
.invoice-row__subject {
  max-width: 16rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* The bill actions wrap rather than push the table past the screen. */
.invoice-row__actions .table-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 9rem;
}

.invoice-row__when {
  display: block;
  color: var(--color-text-muted);
}

/* --- Invoices — Scheduled --------------------------------------------------- */

.scheduled-invoices__horizon {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.scheduled-invoices__horizon-label {
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}

.scheduled-invoices__note {
  margin-left: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
}
