.farrier-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.1em;
  flex-shrink: 0;
}

.farrier-history {
  display: grid;
  gap: 1rem;
}

.farrier-rate-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(100px, 1fr) auto;
  align-items: center;
  gap: 1rem;
}

.cost-rate-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

.cost-rate-list dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.costing-page {
  max-width: 1320px;
  --cost-boarding: #8d5f43;
  --cost-stock: #56827b;
  --cost-medical: #687da6;
  --cost-farrier: #c89c48;
}

.dark .costing-page {
  --cost-boarding: #c39877;
  --cost-stock: #7eb3a8;
  --cost-medical: #93a8ce;
  --cost-farrier: #dcbb72;
}

.dark .costing-page input[type='date'] {
  color-scheme: dark;
}

.costing-page > .stable-page-header {
  margin-bottom: 1.5rem;
  align-items: flex-start;
}

.costing-page > .stable-page-header h1 {
  margin-top: 0;
}

.costing-page > .stable-page-header .stock-actions {
  margin: 0;
  flex-shrink: 0;
}

.costing-page > .stable-page-header .stock-actions a {
  width: auto;
}

.cost-charts {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 1.25rem;
  margin: 1.5rem 0;
}

.cost-chart-card {
  min-width: 0;
  padding: 1.5rem;
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-radius: 14px;
}

.cost-chart-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.cost-chart-heading h2 {
  margin: 0;
  font-size: 1.65rem;
}

.cost-chart-heading > :is(svg, .material-icons) {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--color-text-muted);
}

.cost-chart-heading .stable-eyebrow {
  font-size: 0.65rem;
}

.cost-chart-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.cost-donut {
  position: relative;
  flex: 0 1 210px;
  min-width: 150px;
}

.cost-donut svg {
  display: block;
  width: 100%;
}

.cost-donut-track {
  stroke: var(--color-border);
}

.cost-donut-segment {
  stroke: var(--cost-category-color);
  transition: opacity 160ms ease;
}

.cost-donut-segment.is-muted {
  opacity: 0.2;
}

.cost-color-boarding {
  --cost-category-color: var(--cost-boarding);
}

.cost-color-stock {
  --cost-category-color: var(--cost-stock);
}

.cost-color-medical {
  --cost-category-color: var(--cost-medical);
}

.cost-color-farrier {
  --cost-category-color: var(--cost-farrier);
}

.cost-donut-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  gap: 0.4rem;
}

.cost-donut-label span {
  color: var(--color-text-muted);
  font-size: 0.7rem;
}

.cost-donut-label strong {
  font-size: clamp(0.85rem, 1.1vw, 1.1rem);
  font-variant-numeric: tabular-nums;
}

.cost-chart-legend {
  flex: 1;
  min-width: 0;
}

.cost-legend-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.6rem;
  align-items: center;
  text-align: left;
  width: 100%;
  padding: 0.75rem 0.3rem;
  background: transparent;
  color: var(--color-foreground);
  border: 0;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}

.cost-legend-item[aria-pressed='true'] {
  background: var(--color-background-tertiary);
  border-radius: 6px;
}

.cost-legend-item:focus-visible {
  outline: 2px solid var(--color-primary-light);
  outline-offset: 2px;
}

.cost-legend-item strong {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cost-chart-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cost-category-color);
}

.cost-chart-legend > small {
  display: block;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin-top: 0.75rem;
}

.cost-chart-credit-note {
  flex: 1;
  line-height: 1.5;
}

.cost-chart-credit-note strong {
  font-size: 1.5rem;
}

.cost-chart-hint {
  color: var(--color-text-muted);
  line-height: 1.6;
  font-size: 0.8rem;
}

.cost-comparison {
  display: grid;
  gap: 1rem;
  margin-top: 1.2rem;
}

.cost-comparison-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  color: var(--color-foreground);
  text-decoration: none;
  font-size: 0.85rem;
}

.cost-comparison-row:hover {
  color: var(--color-primary-light);
}

.cost-comparison-row strong {
  font-variant-numeric: tabular-nums;
}

.cost-comparison-track {
  grid-column: 1 / -1;
  height: 7px;
  border-radius: 5px;
  background: var(--color-background-tertiary);
  overflow: hidden;
}

.cost-comparison-track > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--cost-boarding);
}

.cost-billing-stats {
  margin: 1.25rem 0;
}

.cost-billing-stats > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
}

.cost-billing-stats dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cost-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr)) repeat(2, minmax(160px, 1.3fr)) auto;
  align-items: end;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-radius: 12px;
}

.cost-filters .form-group {
  margin: 0;
  min-width: 0;
}

.cost-filters :is(input:not([type='submit']), select) {
  width: 100%;
}

.costing-page :is(input, select, textarea) {
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
  color: var(--color-foreground);
  background: var(--color-background);
}

.costing-page input[type='submit'] {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.cost-period-links {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0.85rem 0 1.5rem;
  font-size: 0.85rem;
}

.cost-period-links span {
  margin-left: auto;
  color: var(--color-text-muted);
}

.cost-period-links a {
  color: var(--color-foreground-secondary);
  text-underline-offset: 0.2em;
}

.cost-table a {
  color: var(--color-foreground);
  text-underline-offset: 0.2em;
}

.cost-summary {
  display: grid;
  grid-template-columns: 1.6fr repeat(4, 1fr);
  gap: 1px;
  margin: 1.5rem 0;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-border);
}

.cost-summary article {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1.35rem;
  background: var(--color-background-secondary);
}

.cost-summary strong {
  font-size: clamp(1rem, 1.6vw, 1.5rem);
  font-variant-numeric: tabular-nums;
}

.cost-summary small {
  color: var(--color-text-muted);
  line-height: 1.5;
}

.cost-summary .cost-summary-total {
  background: var(--color-primary-dark);
  color: var(--color-on-primary);
}

.cost-summary-total .stable-eyebrow {
  color: #e0cbbb;
  margin: 0;
}

.cost-summary-total strong {
  font-size: clamp(1.35rem, 2vw, 1.9rem);
}

.cost-summary-total > span:last-child {
  font-size: 0.8rem;
  line-height: 1.5;
}

.cost-notice {
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--color-primary-light);
  border-radius: 0 10px 10px 0;
  margin: 1.25rem 0;
  background: var(--color-background-secondary);
}

.cost-notice p {
  margin: 0.5rem 0 0;
  line-height: 1.6;
}

.cost-invoice-start {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: center;
  margin: 2rem 0;
}

.cost-invoice-start h2 {
  margin: 0 0 0.4rem;
  font-size: 1.6rem;
}

.cost-invoice-start p {
  margin: 0;
  color: var(--color-text-muted);
}

.cost-invoice-start form {
  display: flex;
  gap: 0.75rem;
  align-items: end;
}

.cost-invoice-start .form-group {
  margin: 0;
  min-width: 180px;
}

.cost-tabs {
  display: flex;
  gap: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  margin: 1.5rem 0 1rem;
}

.cost-tabs a {
  color: var(--color-text-muted);
  padding: 0.8rem 0.15rem;
  text-decoration: none;
  font-weight: 700;
  border-bottom: 3px solid transparent;
}

.cost-tabs .is-active {
  color: var(--color-foreground);
  border-bottom-color: var(--color-primary-light);
}

.cost-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-background-secondary);
}

.cost-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.cost-table th {
  text-align: left;
}

.cost-table caption.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.cost-table :is(th, td) {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
  line-height: 1.55;
}

.cost-table thead {
  background: var(--color-background-tertiary);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
}

.cost-table tbody tr:last-child :is(th, td) {
  border-bottom: 0;
}

.cost-table tbody th {
  min-width: 150px;
}

.cost-table tbody tr:hover {
  background: var(--color-background);
}

.cost-table tfoot {
  border-top: 2px solid var(--color-border);
  font-weight: 700;
}

.cost-table tfoot :is(th, td) {
  border-bottom: 0;
}

.cost-table .cost-number {
  text-align: right;
  white-space: nowrap;
}

.cost-number {
  font-variant-numeric: tabular-nums;
}

.cost-emphasis {
  font-weight: 700;
}

.cost-table small {
  display: block;
  color: var(--color-text-muted);
  font-weight: 400;
  margin-top: 0.25rem;
}

.cost-description {
  display: block;
  margin-top: 0.2rem;
  overflow-wrap: anywhere;
  min-width: 150px;
}

.cost-badge {
  display: inline-block;
  border: 1px solid var(--color-border);
  border-radius: 100px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: var(--color-background-tertiary);
}

.cost-allocation-panel {
  margin: 1.5rem 0;
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-background-secondary);
}

.cost-allocation-panel h2 {
  margin: 0;
  display: inline;
}

.cost-allocation-panel summary {
  cursor: pointer;
}

.cost-allocation-panel p {
  max-width: 760px;
  line-height: 1.6;
}

.cost-allocation-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 2rem;
  padding: 1rem 0;
  border-top: 1px solid var(--color-border);
}

.cost-allocation-row :is(span, small) {
  display: block;
  margin-top: 0.4rem;
}

.cost-allocation-row .form-group {
  margin: 0;
}

.cost-method {
  margin: 1.5rem 0;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  line-height: 1.7;
}

.cost-method summary {
  cursor: pointer;
  font-weight: 700;
}

.invoice-review-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
}

.invoice-review-heading h2 {
  margin: 0;
}

.invoice-preview input[type='checkbox'] {
  accent-color: var(--color-primary);
  width: 20px;
  height: 20px;
}

.invoice-review-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.7fr);
  gap: 3rem;
  margin: 2rem 0;
}

.invoice-review-fields textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font: inherit;
}

.invoice-total-panel {
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-background-secondary);
}

.invoice-total-panel > strong {
  display: block;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.invoice-total-panel :is(p, small) {
  display: block;
  color: var(--color-text-muted);
  line-height: 1.6;
  font-size: 0.85rem;
  margin: 1rem 0;
}

.invoice-total-panel input {
  width: 100%;
}

.invoice-total-panel input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.invoice-paper {
  padding: clamp(1.25rem, 5vw, 3.5rem);
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 30px #0000000a;
}

.invoice-paper-heading {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--color-primary-light);
}

.invoice-paper-heading h1 {
  margin: 0 0 0.5rem;
  font-size: 2.5rem;
}

.invoice-paper p {
  margin: 0.35rem 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.invoice-number {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-width: 180px;
  text-align: right;
}

.invoice-number strong {
  font-size: 1.3rem;
}

.invoice-number span {
  font-size: 0.85rem;
}

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 2rem 0;
}

.invoice-parties h2 {
  margin: 0;
  font-size: 1.65rem;
}

.invoice-parties .stable-eyebrow {
  margin-top: 1rem;
}

.invoice-balance {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 2rem;
  padding: 1.5rem 0;
}

.invoice-balance strong {
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.invoice-notes {
  padding: 1.25rem 0;
  border-top: 1px solid var(--color-border);
}

.invoice-notes h2 {
  font-size: 1.35rem;
}

.invoice-paper-footer {
  margin-top: 2rem;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

@media (max-width: 1000px) {
  .cost-charts {
    grid-template-columns: minmax(0, 1fr);
  }

  .cost-chart-content {
    gap: 2rem;
  }

  .cost-filters {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .cost-summary {
    grid-template-columns: repeat(4, 1fr);
  }

  .cost-summary-total {
    grid-column: 1 / -1;
  }

  .cost-invoice-start {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 600px) {
  .cost-filters {
    grid-template-columns: minmax(0, 1fr);
  }

  .costing-page > .stable-page-header .stock-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .costing-page > .stable-page-header .stock-actions a {
    flex: 1 1 auto;
    min-width: 0;
  }

  .cost-chart-card {
    padding: 1.1rem;
  }

  .cost-chart-content {
    flex-direction: column;
    gap: 1rem;
  }

  .cost-donut {
    width: 210px;
    flex-basis: auto;
  }

  .cost-chart-legend {
    width: 100%;
  }

  .cost-donut-label strong {
    font-size: 1.1rem;
  }

  .costing-page {
    padding: 1.5rem 1rem;
  }

  .cost-summary {
    grid-template-columns: 1fr 1fr;
  }

  .cost-summary article {
    padding: 1rem;
  }

  .cost-period-links span {
    margin-left: 0;
    width: 100%;
  }

  .cost-invoice-start form {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .cost-allocation-row {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .invoice-review-footer {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .invoice-paper-heading {
    flex-direction: column;
    gap: 1rem;
  }

  .invoice-number {
    text-align: left;
  }

  .invoice-parties {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .farrier-rate-row {
    grid-template-columns: 1fr;
    gap: 0;
    margin-bottom: 1.5rem;
  }
}

@media print {
  body:has(.invoice-page) :is(.sidebar, .navbar, .invoice-actions, #flash-container) {
    display: none;
  }

  body:has(.invoice-page) .main-container {
    margin: 0;
    padding: 0;
  }

  .invoice-page {
    padding: 0;
  }

  .invoice-paper {
    --color-background-secondary: white;
    --color-background-tertiary: #f3ece4;
    --color-foreground: #332720;
    --color-text-muted: #66574c;
    --color-border: #d8c8b9;
    color: #332720;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .invoice-table tr {
    break-inside: avoid;
  }
}

.table-scroll-hint {
  display: none;
}

@media (max-width: 600px) {
  .table-scroll-hint {
    display: block;
    margin: 0.75rem 0;
    color: var(--color-text-muted);
    font-size: 0.875rem;
  }

  .cost-table a {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
  }
}

@media print {
  .table-scroll-hint {
    display: none;
  }
}
