/* Collapsible settings cards */
.card[data-collapse-key] {
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.card[data-collapse-key].expanded {
  border-color: var(--color-primary-300);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(13, 148, 136, 0.08);
  border-left: 3px solid var(--color-primary-400);
}

.card[data-collapse-key].collapsed {
  box-shadow: var(--shadow-xs);
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}

.card[data-collapse-key].collapsed .card-header {
  margin-bottom: 0;
}

.card[data-collapse-key].collapsed:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--color-primary-200);
}

.card[data-collapse-key] .card-header {
  user-select: none;
}

.settings-section-divider {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-2) 0;
  margin-top: var(--space-2);
}

.card-title .required-badge {
  font-size: 0.6rem;
  font-family: var(--font-sans);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--color-warning-100, #fef3c7);
  color: var(--color-warning-700, #b45309);
  padding: 2px 6px;
  border-radius: 9999px;
  vertical-align: middle;
  margin-left: var(--space-2);
}

[data-theme="dark"] .card-title .required-badge {
  background: rgba(251, 191, 36, 0.15);
  color: var(--color-warning-400, #fbbf24);
}

.card[data-collapse-key] .card-header .collapse-chevron {
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  color: var(--text-tertiary);
}

.card[data-collapse-key].expanded .card-header .collapse-chevron {
  color: var(--color-primary-500);
}

.card[data-collapse-key].collapsed .card-header .collapse-chevron {
  transform: rotate(-90deg);
}

/* Animated expand/collapse body using grid trick */
.card-collapse-wrapper {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.card[data-collapse-key].collapsed .card-collapse-wrapper {
  grid-template-rows: 0fr;
}

.card-collapse-body {
  overflow: hidden;
}

/* Fade content in/out during expand */
.card[data-collapse-key] .card-collapse-body {
  opacity: 1;
  transition: opacity 0.25s ease 0.1s;
}

.card[data-collapse-key].collapsed .card-collapse-body {
  opacity: 0;
  transition: opacity 0.15s ease;
}

/* Header action buttons fade in/out */
.card[data-collapse-key] .card-header .btn {
  transition: opacity 0.2s ease, transform 0.2s ease;
  opacity: 1;
  transform: scale(1);
}

.card[data-collapse-key].collapsed .card-header .btn {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

/* Expanded card title gets teal tint */
.card[data-collapse-key].expanded .card-title {
  color: var(--color-primary-700);
}

[data-theme="dark"] .card[data-collapse-key].expanded .card-title {
  color: var(--color-primary-300);
}

[data-theme="dark"] .card[data-collapse-key].expanded {
  border-color: var(--color-primary-700);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(13, 148, 136, 0.12);
  border-left: 3px solid var(--color-primary-600);
}

[data-theme="dark"] .card[data-collapse-key].collapsed:hover {
  border-color: var(--color-primary-800);
}

/* Rate editor */
.tier-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: var(--space-3);
  align-items: end;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-secondary);
}

.tier-row:last-child {
  border-bottom: none;
}

@media (max-width: 768px) {
  .tier-row {
    grid-template-columns: 1fr 1fr;
  }
}

.tier-add {
  padding: var(--space-3) 0;
}

/* Billing wizard */
.billing-wizard {
  max-width: 700px;
}

.billing-preview-table {
  font-size: var(--text-sm);
}

.billing-preview-table td {
  padding: var(--space-2) var(--space-3);
}

.billing-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-6);
}

.billing-summary-item {
  text-align: center;
}

.billing-summary-value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

.billing-summary-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* Payment recorder */
.payment-record-form {
  display: grid;
  gap: var(--space-4);
}

/* Reports */
.report-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.report-card:hover {
  border-color: var(--color-primary-300);
  box-shadow: var(--shadow-sm);
}
.report-card.active {
  border-color: var(--color-primary-500);
}

.report-card-title {
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-1);
}

.report-card-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* Payment Waterfall */
.waterfall-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.waterfall-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-primary);
  border: 1px solid var(--border-secondary);
  border-bottom: none;
  transition: background var(--transition-fast), opacity var(--transition-fast);
}

.waterfall-item:first-child {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.waterfall-item:last-child {
  border-bottom: 1px solid var(--border-secondary);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.waterfall-item:only-child {
  border-radius: var(--radius-lg);
  border-bottom: 1px solid var(--border-secondary);
}

.waterfall-item.dragging {
  opacity: 0.4;
}

.waterfall-item.drag-over {
  border-top: 2px solid var(--color-primary-500);
  padding-top: calc(var(--space-3) - 1px);
}

.waterfall-item .drag-handle {
  cursor: grab;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  padding: var(--space-1);
}

.waterfall-item .drag-handle:active {
  cursor: grabbing;
}

.waterfall-item .waterfall-rank {
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--text-secondary);
  min-width: 28px;
  text-align: center;
}

.waterfall-item .waterfall-label {
  flex: 1;
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.waterfall-item.disabled .waterfall-label {
  color: var(--text-tertiary);
  text-decoration: line-through;
}

.waterfall-item.disabled .waterfall-rank {
  color: var(--text-tertiary);
}

/* Toggle switch */
.waterfall-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.waterfall-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.waterfall-toggle .toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-primary);
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.waterfall-toggle .toggle-slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition-fast);
}

.waterfall-toggle input:checked + .toggle-slider {
  background: var(--color-primary-500);
}

.waterfall-toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* History filter tabs */
.history-filter-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.history-filter-tabs .btn {
  font-size: var(--text-sm);
}

/* Icon-only action buttons */
.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Ledger table layout — Description absorbs slack, other columns stay fixed */
#ledger-table .data-table {
  table-layout: fixed;
}
#ledger-table .data-table td:first-child,
#ledger-table .data-table th:first-child {
  white-space: nowrap;
}
#ledger-table .data-table td:nth-child(2) {
  white-space: nowrap;
}
#ledger-table .data-table td:nth-child(3) {
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}

/* Ledger table coloring */
.ledger-debit {
  color: var(--color-danger-600);
  font-weight: var(--font-semibold);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.ledger-credit {
  color: var(--color-success-600);
  font-weight: var(--font-semibold);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Adjustment type badge colors */
.badge-returned-check { background: var(--color-danger-100); color: var(--color-danger-700); }
.badge-void { background: var(--color-danger-100); color: var(--color-danger-700); }
.badge-credit-adj { background: var(--color-success-100); color: var(--color-success-700); }
.badge-debit-adj { background: var(--color-warning-100); color: var(--color-warning-700); }
.badge-write-off { background: var(--color-gray-100); color: var(--color-gray-700); }

/* Aging bucket cards */
.aging-buckets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.aging-bucket {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: var(--space-4) var(--space-4) var(--space-3);
  text-align: center;
}

.aging-bucket .aging-bucket-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-2);
}

.aging-bucket .aging-bucket-amount {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  font-variant-numeric: tabular-nums;
}

.aging-bucket .aging-bucket-bar {
  height: 3px;
  border-radius: 2px;
  margin-top: var(--space-3);
}

.aging-bucket.bucket-current .aging-bucket-amount { color: var(--color-success-600); }
.aging-bucket.bucket-current .aging-bucket-bar { background: var(--color-success-500); }

.aging-bucket.bucket-warning .aging-bucket-amount { color: var(--color-warning-600); }
.aging-bucket.bucket-warning .aging-bucket-bar { background: var(--color-warning-500); }

.aging-bucket.bucket-danger .aging-bucket-amount { color: var(--color-danger-600); }
.aging-bucket.bucket-danger .aging-bucket-bar { background: var(--color-danger-500); }

.aging-bucket.bucket-zero .aging-bucket-amount { color: var(--text-tertiary); }
.aging-bucket.bucket-zero .aging-bucket-bar { background: var(--border-secondary); }

.aging-bucket.bucket-total {
  border-color: var(--color-primary-300);
}
.aging-bucket.bucket-total .aging-bucket-label { color: var(--color-primary-600); }
.aging-bucket.bucket-total .aging-bucket-amount { color: var(--text-primary); }
.aging-bucket.bucket-total .aging-bucket-bar { background: var(--color-primary-500); }

@media (max-width: 768px) {
  .aging-buckets {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 480px) {
  .aging-buckets {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Aging ledger table */
.aging-ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.aging-ledger thead th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-primary);
  font-weight: var(--font-semibold);
}

.aging-ledger thead th.text-right { text-align: right; }

.aging-ledger tbody td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-secondary);
  font-variant-numeric: tabular-nums;
}

.aging-ledger tbody tr:hover {
  background: var(--bg-secondary);
}

.aging-ledger .col-date { color: var(--text-secondary); width: 110px; }
.aging-ledger .col-desc { font-weight: var(--font-medium); }
.aging-ledger .col-ref { color: var(--text-tertiary); font-size: var(--text-xs); width: 120px; }
.aging-ledger .col-amount { text-align: right; width: 100px; }
.aging-ledger .col-balance { text-align: right; width: 110px; font-weight: var(--font-semibold); }
.aging-ledger .col-age { text-align: center; width: 90px; }

.aging-ledger .type-bill { color: var(--text-primary); }
.aging-ledger .type-payment { color: var(--color-success-600); }
.aging-ledger .type-adjustment { color: var(--color-warning-700); }
.aging-ledger .bal-zero { color: var(--color-success-600); }
.aging-ledger .bal-owed { color: var(--color-danger-600); }

/* Aging section titles */
.aging-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.aging-section-title h3 {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  margin: 0;
}

.aging-section-title .aging-badge {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-secondary);
}

/* Account Standing card */
.aging-health-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  border-radius: var(--radius-xl);
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-left: 5px solid;
  margin-bottom: var(--space-6);
}

.aging-health-card .health-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.aging-health-card .health-text {
  flex: 1;
}

.aging-health-card .health-title {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  margin-bottom: 2px;
}

.aging-health-card .health-detail {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.aging-health-card.standing-excellent {
  border-left-color: var(--color-success-500);
}
.aging-health-card.standing-excellent .health-icon {
  background: var(--color-success-100);
  color: var(--color-success-600);
}
.aging-health-card.standing-excellent .health-title {
  color: var(--color-success-700);
}

.aging-health-card.standing-good {
  border-left-color: var(--color-primary-500);
}
.aging-health-card.standing-good .health-icon {
  background: var(--color-primary-100);
  color: var(--color-primary-600);
}
.aging-health-card.standing-good .health-title {
  color: var(--color-primary-700);
}

.aging-health-card.standing-at-risk {
  border-left-color: var(--color-warning-500);
}
.aging-health-card.standing-at-risk .health-icon {
  background: var(--color-warning-100);
  color: var(--color-warning-600);
}
.aging-health-card.standing-at-risk .health-title {
  color: var(--color-warning-700);
}

.aging-health-card.standing-delinquent {
  border-left-color: var(--color-danger-500);
}
.aging-health-card.standing-delinquent .health-icon {
  background: var(--color-danger-100);
  color: var(--color-danger-600);
}
.aging-health-card.standing-delinquent .health-title {
  color: var(--color-danger-700);
}

/* Account Statistics row */
.aging-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.aging-stat {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  text-align: center;
}

.aging-stat .stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-2);
}

.aging-stat .stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.aging-stat .stat-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}

@media (max-width: 768px) {
  .aging-stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .aging-stats-row {
    grid-template-columns: 1fr;
  }
}

/* Bill Amounts bar chart */
.aging-chart {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: var(--space-4) var(--space-4) var(--space-2);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  scrollbar-width: thin;
}

.aging-chart::-webkit-scrollbar {
  height: 8px;
}
.aging-chart::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}
.aging-chart::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: 4px;
}
.aging-chart::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

.aging-chart-inner {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  min-height: 180px;
  padding-bottom: var(--space-2);
}

.aging-chart-bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 0 48px;
  max-width: 72px;
  gap: 4px;
}

.aging-chart-amount {
  font-size: 10px;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.aging-chart-bar {
  width: 100%;
  max-width: 36px;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--color-primary-400);
  min-height: 4px;
  transition: background var(--transition-fast);
}

.aging-chart-bar.bar-unpaid {
  background: var(--color-primary-400);
  border: 2px solid var(--color-primary-600);
}

.aging-chart-bar.bar-paid {
  background: var(--color-primary-200);
}

.aging-chart-label {
  font-size: 10px;
  color: var(--text-tertiary);
  text-align: center;
  white-space: nowrap;
  padding-top: 2px;
  border-top: 1px solid var(--border-secondary);
  width: 100%;
}

/* Summary Notes card */
.aging-notes {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-left: 4px solid var(--color-primary-400);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}

.aging-notes h4 {
  font-size: var(--text-base);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  margin: 0 0 var(--space-3) 0;
}

.aging-notes .note-item {
  margin-bottom: var(--space-3);
}

.aging-notes .note-item:last-child {
  margin-bottom: 0;
}

.aging-notes .note-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.aging-notes .note-text {
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: 1.5;
}

/* Wizard Steps */
.wizard-steps {
  display: flex;
  align-items: flex-start;
  margin-bottom: var(--space-8);
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
}

.wizard-step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  border: 2px solid var(--border-primary);
  background: var(--bg-primary);
  color: var(--text-tertiary);
  transition: all var(--transition-base);
  flex-shrink: 0;
}

.wizard-step.active .wizard-step-circle {
  border-color: var(--color-primary-500);
  background: var(--color-primary-500);
  color: white;
  box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.15);
}

.wizard-step.completed .wizard-step-circle {
  border-color: var(--color-primary-500);
  background: var(--color-primary-100);
  color: var(--color-primary-700);
}

.wizard-step-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-2);
  font-weight: var(--font-medium);
  text-align: center;
  white-space: nowrap;
  transition: color var(--transition-base);
}

.wizard-step.active .wizard-step-label {
  color: var(--color-primary-700);
  font-weight: var(--font-semibold);
}

.wizard-step.completed .wizard-step-label {
  color: var(--color-primary-600);
}

.wizard-step-connector {
  width: 80px;
  height: 2px;
  background: var(--border-primary);
  margin-top: 17px; /* center with 36px circle */
  flex-shrink: 0;
  transition: background var(--transition-base);
}

.wizard-step-connector.completed {
  background: var(--color-primary-500);
}

.wizard-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-secondary);
  margin-top: var(--space-6);
}

.wizard-nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

@media (max-width: 640px) {
  .wizard-step-connector {
    width: 40px;
  }

  .wizard-step-label {
    font-size: 10px;
  }

  .wizard-step-circle {
    width: 32px;
    height: 32px;
    font-size: var(--text-xs);
  }

  .wizard-step-connector {
    margin-top: 15px;
  }
}

/* Dashboard KPIs grid */
.dashboard-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

/* Activity feed on dashboard */
.dashboard-activity {
  max-height: 400px;
  overflow-y: auto;
}

/* Activity dots */
.activity-dot--success { background: var(--color-success-500); }
.activity-dot--primary { background: var(--color-primary-500); }

/* ========== Payment Tracker Tree ========== */
.pay-tree-row { cursor: pointer; }
.pay-tree-row--year { background: var(--bg-secondary); }
.pay-tree-row--year td:first-child {
  font-family: var(--font-display);
  font-weight: 700;
}
.pay-tree-row--quarter td:first-child { padding-left: 24px; font-weight: 600; }
.pay-tree-row--period td:first-child { padding-left: 48px; font-weight: 500; }
.pay-tree-row--unlinked { background: var(--bg-secondary); }
.pay-tree-row--unlinked td:first-child { font-weight: 600; color: var(--text-secondary); }

/* Returned / reversed payments (NSF bounces, voids) — reversed out, not collections */
.pay-tree-row--reversed { background: var(--color-danger-50, #fef2f2); }
.pay-tree-row--reversed td:first-child { font-weight: 600; color: var(--color-danger-600); }
.pay-reversed-amt { text-decoration: line-through; color: var(--color-danger-600); }

.pay-chev {
  display: inline-block;
  transition: transform 0.2s;
  margin-right: 8px;
}
.pay-chev.expanded { transform: rotate(90deg); }

/* ========== Filter Toolbar (adjustments) ========== */
.filter-toolbar {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.filter-toolbar .form-group { margin-bottom: 0; }
.filter-toolbar .form-label { font-size: 0.8rem; }
.filter-toolbar .form-control--date { width: 160px; }
.filter-toolbar .form-control--account { width: 260px; }

/* ========== Adjustment Totals ========== */
.adj-totals {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1rem 0.5rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-primary);
}
.adj-total-item { font-size: 0.85rem; }
.adj-total-label { color: var(--text-tertiary); }
.adj-total-value {
  font-weight: 600;
  font-family: var(--font-mono);
}
.adj-total-value--credit { color: var(--color-success-600); }
.adj-total-value--debit { color: var(--color-danger-600); }
.adj-total-value--gray { color: var(--color-gray-500); }
.adj-total-value--net-positive { color: var(--color-danger-600); font-weight: 700; }
.adj-total-value--net-negative { color: var(--color-success-600); font-weight: 700; }
.adj-total-item--net { margin-left: auto; }

/* ========== Billing Run ========== */
.billing-badge--normal { font-weight: normal; }
.billing-flag { cursor: help; }
.billing-step4-icon {
  width: 64px;
  height: 64px;
  background: var(--color-success-100);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-4);
}
.billing-cb-cell {
  width: 40px;
  text-align: center;
  cursor: pointer;
}

/* ========== Auto-Pay Results ========== */
.autopay-result-stat {
  padding: var(--space-3);
  border-radius: var(--radius-lg);
}

/* ========== Rate Management ========== */
.rate-list-grid {
  display: grid;
  gap: var(--space-6);
}
.rate-list-grid--with-detail {
  grid-template-columns: 1fr 1fr;
}
.rate-status-bar {
  padding: 0;
  width: 4px;
}
.rate-status-bar--current { background: var(--color-success-500); }
.rate-status-bar--future { background: var(--color-primary-500); }
.rate-status-bar--historical { background: var(--color-warning-400); }

.rate-detail-panel {
  border-top: 3px solid;
  position: sticky;
  top: calc(var(--header-height) + var(--space-6));
}
.rate-detail-panel--current { border-color: var(--color-success-500); }
.rate-detail-panel--future { border-color: var(--color-primary-500); }
.rate-detail-panel--historical { border-color: var(--color-warning-400); }

.rate-delta {
  font-size: 0.75rem;
  font-weight: 600;
}
.rate-delta--up { color: var(--color-danger-600); }
.rate-delta--down { color: var(--color-success-600); }

.badge--one-time { font-size: 0.65rem; }

.rate-editor-readonly { background: var(--bg-tertiary); }

.tier-row--3col { grid-template-columns: 1fr 1fr auto; }
.tier-row .mt-first-row { margin-top: 24px; }

/* ========== Cancel / Rebill ========== */
.cancel-rebill-search { max-width: 400px; }
.regen-log {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-height: 300px;
  overflow-y: auto;
}
.regen-success-icon {
  width: 40px;
  height: 40px;
  background: var(--color-success-100);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.row--cancelled { opacity: 0.55; }
.row--cancelled-strike { opacity: 0.55; text-decoration: line-through; }
.cancel-list {
  list-style: disc;
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

/* ========== Customer List ========== */
.credit-info-icon {
  color: var(--color-primary-500);
  font-size: 0.8em;
  cursor: help;
}

/* ========== Customer History ========== */
.credit-balance-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--color-primary-50);
  border: 1px solid var(--color-primary-200);
  border-radius: var(--radius-lg);
  border-left: 4px solid var(--color-primary-500);
}
.credit-balance-banner .cb-icon { font-size: 1.3rem; }
.credit-balance-banner .cb-body { flex: 1; }
.credit-balance-banner .cb-title {
  font-weight: 600;
  color: var(--color-primary-800);
  font-family: var(--font-display);
}
.credit-balance-banner .cb-desc {
  font-size: 0.85rem;
  color: var(--color-primary-700);
}

.aging-explainer {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 6px;
  margin-bottom: 8px;
}

.date-range-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin-top: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
}
.date-range-filter .drf-label { color: var(--text-secondary); font-weight: 500; }
.date-range-filter .drf-input { width: auto; padding: 4px 8px; font-size: 0.85rem; }
.date-range-filter .drf-sep { color: var(--text-tertiary); }
.date-range-filter .drf-note { color: var(--text-tertiary); font-size: 0.8rem; margin-left: 4px; }

.view-divider { padding-right: 12px; margin-right: 4px; }

/* Ledger totals bar */
.ledger-totals-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 10px 16px;
  margin-top: 2px;
  border-top: 2px solid var(--border-primary);
  background: var(--bg-secondary);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  font-size: 0.85rem;
}
.ledger-totals-bar .lt-item { display: flex; align-items: center; gap: 6px; }
.ledger-totals-bar .lt-label { color: var(--text-secondary); }
.ledger-totals-bar .lt-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ledger-totals-bar .lt-value--debit { color: var(--color-danger-600); }
.ledger-totals-bar .lt-value--credit { color: var(--color-success-600); }
.ledger-totals-bar .lt-item--balance {
  padding-left: 12px;
  border-left: 1px solid var(--border-primary);
}
.ledger-totals-bar .lt-item--balance .lt-label { font-weight: 600; }
.ledger-totals-bar .lt-item--balance .lt-value { font-weight: 700; }

/* ========== Reports ========== */
.report-summary-box {
  margin-top: 1rem;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.report-summary-box .rsb-label { font-weight: 600; font-family: var(--font-display); }
.report-summary-box .rsb-value { font-size: 1.1rem; }

.report-section-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.report-callout {
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--color-primary-50);
  border: 1px solid var(--color-primary-200);
  border-radius: var(--radius-lg);
  border-left: 4px solid var(--color-primary-500);
  font-size: 0.85rem;
  color: var(--color-primary-800);
}

/* ========== Attachment Section ========== */
.attachment-item {
  padding: var(--space-2);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-1);
}
.attachment-item .att-icon { color: var(--text-tertiary); }
.attachment-item .att-name {
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-item .att-size {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  white-space: nowrap;
}
.attachment-empty {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  padding: var(--space-2);
}
.attachment-section {
  border-top: 1px solid var(--border-primary);
  padding-top: var(--space-3);
}
.attachment-section h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0;
}

/* ========== Company Settings ========== */

/* Radio-card selection pattern (bill style, fee mode) */
.radio-card {
  border: 1px solid var(--border-primary);
  background: var(--bg-primary);
}
.radio-card--selected {
  border-color: var(--color-primary-500);
  background: var(--color-primary-50);
}
.radio-card input[type="radio"] { margin-top: 3px; }
.radio-card > span { display: block; }
.radio-card > span > span { display: block; }

/* Checkbox label rows (interest toggles, active flags) */
.checkbox-label { cursor: pointer; }
.checkbox-label .form-label { margin: 0; }

/* Meter size list */
.meter-size-list { max-width: 400px; }
.meter-size-actions { flex-shrink: 0; }
.meter-size-display {
  flex: 1;
  padding: 6px 10px;
  font-size: var(--text-sm);
  background: var(--bg-secondary);
}
.meter-size-add { max-width: 400px; }
.meter-size-add input { flex: 1; }

/* Settings max-width wrappers */
.settings-form-sm { max-width: 600px; }
.settings-form-md { max-width: 900px; }
.settings-form-narrow { max-width: 300px; }
.settings-form-xs { max-width: 200px; }
.settings-form-field-sm { max-width: 120px; }

/* Inactive row */
.row--inactive { opacity: 0.5; }

/* Disabled move button */
.btn[disabled] { opacity: 0.3; }

/* Rate status bar (reused in company-settings rate schedule table) */
/* .rate-status-bar already defined in Rate Management section */

/* Status message (email test, etc.) */
.settings-status { margin-top: var(--space-3); }
.settings-status-msg { font-size: var(--text-sm); }
.settings-status-msg--success { color: var(--color-success-600); }
.settings-status-msg--error { color: var(--color-danger-600); }

/* Readonly code input */
.form-input--readonly { background: var(--bg-tertiary); }
.form-input--uppercase { text-transform: uppercase; }

/* Empty state percent icon */
.empty-state-icon--text { font-size: 2rem; }

/* SMTP details sub-section */
.smtp-details {
  margin-top: var(--space-4);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.smtp-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  cursor: pointer;
  background: var(--bg-secondary);
  user-select: none;
  list-style: none;
}
.smtp-summary::-webkit-details-marker { display: none; }
.smtp-summary::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.smtp-details[open] .smtp-summary::before {
  transform: rotate(90deg);
}
.smtp-details-body {
  padding: var(--space-4);
}
.smtp-status-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  margin-left: auto;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.smtp-status-badge--platform {
  background: var(--color-primary-100, #ccfbf1);
  color: var(--color-primary-700, #0f766e);
}
.smtp-status-badge--custom {
  background: var(--color-warning-100, #fef3c7);
  color: var(--color-warning-700, #b45309);
}

/* ========== Customer Form ========== */

/* Wizard form wrapper */
.wizard-form-sm { max-width: 700px; }
.wizard-form-md { max-width: 800px; }

/* Meter section dividers */
.meter-section-divider { border-bottom: 1px solid var(--border-secondary); }
.meter-section-header { background: var(--bg-accent); }

/* Replaced meter styling */
.meter--replaced { opacity: 0.6; }
.meter--replaced-name { text-decoration: line-through; }
.badge--replaced { font-size: 10px; padding: 1px 6px; }

/* Meter picker modal */
.meter-picker-list { max-height: 400px; overflow-y: auto; }
.meter-picker-item {
  border-bottom: 1px solid var(--border-secondary);
  cursor: pointer;
}

/* ========== Customer History (ledger) ========== */

/* Ledger formula detail (interest calc, allocation breakdown) */
.ledger-formula {
  font-size: 0.75em;
  font-weight: normal;
  opacity: 0.7;
  margin-top: 2px;
  font-family: var(--font-mono);
  white-space: normal;
}

/* Ledger type label */
.ledger-type-label { font-size: 0.8rem; white-space: nowrap; }

/* Cancelled ledger entry */
.ledger-entry--cancelled {
  opacity: 0.55;
  text-decoration: line-through;
  color: var(--text-tertiary);
}

/* Voided credit */
.ledger-credit--void {
  text-decoration: line-through;
  opacity: 0.6;
}

/* Audit table name */
.audit-table-name { font-size: 0.85rem; color: var(--text-secondary); }

/* Audit old value strikethrough */
.audit-old-value { text-decoration: line-through; opacity: 0.6; }

/* Empty state card (no data found) */
.empty-state-card {
  padding: var(--space-6);
  text-align: center;
  color: var(--text-tertiary);
}
.empty-state-card--error { color: var(--color-danger-600); }

/* Ledger reference truncate */
.ledger-ref { display: block; max-width: 120px; }

/* Bill link with warning color */
.ledger-bill-link { color: var(--color-warning-600); }

/* Ledger attachment clip icon */
.ledger-clip { color: var(--text-tertiary); margin-left: 4px; }

/* Ledger description faded (cancelled payment) */
.ledger-desc--faded { opacity: 0.6; }

/* Edit adjustment attachment area */
.edit-adj-attachments { margin-top: var(--space-4); }

/* Bill body preview (no shadow/border) */
.bill-body-preview { box-shadow: none; border: none; }

/* Address sub-line */
.address-sub { margin-top: 2px; }

/* ========== Shared Utility ========== */
.font-italic { font-style: italic; }

/* ============================================================
   Notices (Phase 1.4b) — the delinquency-notice work queue
   ============================================================ */
.notice-banner {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-5);
  border: 1px solid var(--color-primary-200); border-left: 4px solid var(--color-primary-500);
  background: var(--color-primary-50); border-radius: var(--radius-lg);
  font-size: var(--text-sm); color: var(--text-primary); line-height: var(--leading-relaxed);
}
.notice-banner svg { flex-shrink: 0; margin-top: 2px; color: var(--color-primary-600); }
.notice-banner--warn { border-color: var(--color-accent-100); border-left-color: var(--color-accent-500); background: var(--color-accent-50); }
.notice-banner--warn svg { color: var(--color-accent-600); }
.notice-banner a { color: var(--text-link); font-weight: var(--font-medium); }

.notice-tabs { margin-bottom: var(--space-5); }
.notice-tabs .tab { display: inline-flex; align-items: center; gap: var(--space-2); background: none; border-top: 0; border-left: 0; border-right: 0; font-family: inherit; }
.notice-step {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--font-semibold); font-variant-numeric: tabular-nums;
  background: var(--bg-tertiary); color: var(--text-secondary);
}
.notice-tabs .tab.active .notice-step { background: var(--color-primary-600); color: var(--text-inverse); }
.notice-count {
  min-width: 20px; padding: 1px 7px; border-radius: var(--radius-full); font-size: var(--text-xs);
  font-weight: var(--font-semibold); font-variant-numeric: tabular-nums; text-align: center;
  background: var(--color-primary-100); color: var(--color-primary-800);
}
.notice-count--danger { background: var(--color-danger-100); color: var(--color-danger-700); }
.notice-tabs .tab:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; }

.notice-panel { min-height: 160px; }
.notice-lede { max-width: 72ch; color: var(--text-secondary); font-size: var(--text-sm); line-height: var(--leading-relaxed); margin-bottom: var(--space-4); }
.notice-toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.notice-section { margin-bottom: var(--space-8); }
.notice-section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.notice-h2 { font-family: var(--font-display); font-size: var(--text-lg); font-weight: var(--font-semibold); margin: 0 0 var(--space-2); }
.notice-section-head .notice-h2 { margin: 0; }
.notice-empty {
  padding: var(--space-6) var(--space-4); text-align: center; color: var(--text-tertiary); font-size: var(--text-sm);
  border: 1px dashed var(--border-primary); border-radius: var(--radius-xl); background: var(--bg-surface);
}

.notice-table { background: var(--bg-surface); border: 1px solid var(--border-primary); border-radius: var(--radius-xl); overflow: hidden; }
.notice-table tbody tr { cursor: pointer; }
.notice-table tbody tr:hover { background: var(--bg-accent); }
.notice-table td { vertical-align: top; }
.notice-check { width: 40px; }
.notice-check input { width: 16px; height: 16px; accent-color: var(--color-primary-600); }
.notice-who { display: flex; flex-direction: column; text-decoration: none; }
.notice-who-name { color: var(--color-primary-700); font-weight: var(--font-medium); }
.notice-who-acct { color: var(--text-tertiary); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.notice-who:hover .notice-who-name { text-decoration: underline; }
.notice-actions { display: flex; flex-wrap: nowrap; gap: var(--space-1); justify-content: flex-end; }
.mn-table tr.mn-archived td { color: var(--text-tertiary); }
.mn-progress { height: 8px; border-radius: var(--radius-full); background: var(--color-gray-200); overflow: hidden; }
.mn-progress span { display: block; height: 100%; background: var(--color-primary-600); transition: width var(--transition-base); }
.mn-send-summary { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-3); }
.mn-big { font-family: var(--font-display); font-size: var(--text-4xl); font-weight: var(--font-bold); color: var(--color-primary-700); font-variant-numeric: tabular-nums; line-height: 1; }
.notice-lang { font-weight: var(--font-semibold); color: var(--color-info-500); text-transform: none; }
.notice-channel { display: inline-flex; align-items: center; gap: 4px; color: var(--text-secondary); font-size: var(--text-xs); }

/* The stage track: one segment per notice stage — delivered, in progress, not yet */
.stage-track { display: inline-flex; gap: 3px; vertical-align: middle; }
.stage-seg { width: 18px; height: 6px; border-radius: var(--radius-full); background: var(--color-gray-200); }
.stage-seg.is-done { background: var(--color-primary-600); }
.stage-seg.is-pending { background: var(--color-accent-400); }

.notice-batches { display: grid; gap: var(--space-3); }
.notice-batch {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-3);
  padding: var(--space-4); background: var(--bg-surface); border: 1px solid var(--border-primary);
  border-left: 4px solid var(--color-info-500); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
}

.notice-detail { display: grid; grid-template-columns: minmax(180px, 220px) 1fr; gap: var(--space-5); }
.notice-facts { display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-3); margin: 0; font-size: var(--text-sm); align-content: start; }
.notice-facts dt { color: var(--text-tertiary); }
.notice-facts dd { margin: 0; }
.notice-letter-frame { width: 100%; height: 460px; border: 1px solid var(--border-primary); border-radius: var(--radius-lg); background: #fff; }
@media (max-width: 720px) {
  .notice-detail { grid-template-columns: 1fr; }
  .notice-facts { grid-template-columns: 1fr; }
}

/* Settings: Delinquency Notices and Business Days & Holidays (Phase 1.4b) */
.lang-order { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-width: 520px; }
.lang-item { display: flex; align-items: center; gap: var(--space-3); padding: 6px var(--space-3); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); background: var(--bg-surface); }
.income-panel { margin-top: var(--space-4); padding: var(--space-4); border: 1px solid var(--border-primary); border-radius: var(--radius-xl); background: var(--bg-secondary); }
.notice-toggle { display: inline-block; vertical-align: middle; }   /* a sized box outside flex layouts (table cells) */
.notice-toggle input:focus-visible + .toggle-slider { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.notice-toggle input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
.notice-master {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-4);
  padding: var(--space-4); margin-bottom: var(--space-5); border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl); background: var(--bg-secondary);
}
.notice-fieldset { border: 0; padding: 0; margin: 0; }
.notice-fieldset[disabled] { opacity: 0.75; }
.notice-radio { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-2) 0; font-size: var(--text-sm); line-height: var(--leading-relaxed); cursor: pointer; }
.notice-radio input { margin-top: 4px; accent-color: var(--color-primary-600); }
.notice-h4 { font-family: var(--font-display); font-size: var(--text-base); font-weight: var(--font-semibold); margin: var(--space-6) 0 var(--space-1); }
.notice-types-table td { vertical-align: top; }
.merge-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-2); }
.merge-chip {
  padding: 3px 10px; border: 1px solid var(--color-primary-200); border-radius: var(--radius-full); background: var(--color-primary-50);
  color: var(--color-primary-800); font: inherit; font-size: var(--text-xs); cursor: pointer; transition: background var(--transition-fast);
}
.merge-chip:hover { background: var(--color-primary-100); }
.merge-chip:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.notice-body-input { font-family: var(--font-mono); font-size: var(--text-sm); line-height: var(--leading-relaxed); }
.notice-preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: var(--space-4) 0 var(--space-3); }
.holiday-year { padding: var(--space-3) 0; border-top: 1px solid var(--border-secondary); }
.holiday-year:first-of-type { border-top: 0; }
.holiday-year-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-2); }
.holiday-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.holiday-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px 3px 10px; border-radius: var(--radius-full);
  background: var(--bg-tertiary); font-size: var(--text-sm); font-variant-numeric: tabular-nums;
}
.holiday-remove { display: inline-grid; place-items: center; width: 18px; height: 18px; border: 0; border-radius: var(--radius-full); background: none; color: var(--text-tertiary); cursor: pointer; }
.holiday-remove:hover { background: var(--color-danger-100); color: var(--color-danger-700); }
.holiday-remove:focus-visible { outline: 2px solid var(--border-focus); }
.notice-dash-item { color: var(--text-link); font-weight: var(--font-medium); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.notice-dash-item--danger { color: var(--color-danger-600); }
.notice-dash-item:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

/* Notice wording revisions (Settings → Delinquency Notices → Edit) */
.notice-wording { border-top: 1px solid var(--border-secondary); padding-top: var(--space-2); }
.notice-wording-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.notice-wording-head .notice-h4 { margin: var(--space-2) 0 0; }
.notice-rev-status { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.notice-wording-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: calc(-1 * var(--space-2)); }
.notice-history { margin-top: var(--space-3); font-size: var(--text-sm); }
.notice-history summary { cursor: pointer; color: var(--text-link); font-weight: var(--font-medium); width: fit-content; }
.notice-history summary:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.notice-history-list { list-style: none; margin: var(--space-2) 0; padding: 0; }
.notice-history-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--border-secondary); color: var(--text-secondary); }
.notice-history-list li strong { color: var(--text-primary); font-weight: var(--font-semibold); }
.notice-inline-confirm { margin-top: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid var(--color-primary-200); border-left: 4px solid var(--color-primary-600); border-radius: var(--radius-lg); background: var(--color-primary-50); font-size: var(--text-sm); }
.notice-inline-confirm p { margin: 0 0 var(--space-2); line-height: var(--leading-relaxed); }

/* Notice format (Letter / Postcard) and the editor's conversion note */
.format-toggle { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.format-option {
  position: relative; display: flex; align-items: center; gap: var(--space-3); min-width: 220px; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-primary); border-radius: var(--radius-lg); background: var(--bg-surface); cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.format-option input { position: absolute; opacity: 0; pointer-events: none; }
.format-option strong { display: block; font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--text-primary); }
.format-option small { display: block; font-size: var(--text-xs); color: var(--text-secondary); }
.format-option:has(input:checked) { border-color: var(--color-primary-500); box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12); }
.format-option:has(input:focus-visible) { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.format-option.is-disabled { cursor: not-allowed; background: var(--bg-secondary); }
.format-option.is-disabled strong, .format-option.is-disabled small { color: var(--text-tertiary); }
/* a small drawing of the sheet, to scale: letter 8.5 × 11 portrait, postcard 6 × 4 landscape */
.format-sheet { flex-shrink: 0; border: 1.5px solid var(--color-gray-400); border-radius: 2px; background: #fff; }
.format-sheet--letter { width: 26px; height: 34px; background: linear-gradient(var(--color-gray-300), var(--color-gray-300)) 5px 7px / 9px 2px no-repeat, linear-gradient(var(--color-gray-300), var(--color-gray-300)) 5px 15px / 16px 2px no-repeat, linear-gradient(var(--color-gray-300), var(--color-gray-300)) 5px 19px / 14px 2px no-repeat, #fff; }
.format-option:has(input:checked) .format-sheet { border-color: var(--color-primary-600); }
.format-sheet--card { width: 36px; height: 24px; }
.notice-convert { margin-bottom: var(--space-3); font-size: var(--text-sm); line-height: var(--leading-relaxed); }
.notice-convert-list { margin: var(--space-1) 0 var(--space-2); padding-left: 1.25em; }
.notice-preview-tabs { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--border-primary); border-radius: var(--radius-md); }
.notice-preview-tabs[hidden] { display: none; }
.notice-preview-tabs [aria-pressed="true"] { background: var(--color-primary-100); color: var(--color-primary-800); }

/* Mass notices: email and letter counts side by side; printing letters */
.mn-send-summary { flex-wrap: wrap; align-items: flex-start; gap: var(--space-6); }
.mn-send-line { display: flex; align-items: center; gap: var(--space-3); min-width: 220px; flex: 1 1 260px; }
.mn-letters { margin-top: var(--space-2); padding: var(--space-3) var(--space-4); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); background: var(--bg-secondary); }
.mn-letters .data-table { margin-top: var(--space-2); background: var(--bg-surface); }
.mn-date { width: 150px; height: 30px; padding: 2px 8px; font-size: var(--text-sm); }
.mn-letters .table-scroll { overflow-x: auto; }
.mn-mail-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.mn-batch-actions { flex-wrap: wrap; justify-content: flex-end; }

/* Payment plan panel (Account Ledger, 1.5b) */
.plan-panel { margin: var(--space-4) 0; padding: var(--space-4) var(--space-5); }
.plan-panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.plan-panel-title { font-family: var(--font-display); font-size: var(--text-lg); font-weight: var(--font-semibold); margin: 0; }
.plan-panel-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.plan-idle { margin: var(--space-2) 0 0; font-size: var(--text-sm); color: var(--text-secondary); }
.plan-behind { margin-top: var(--space-3); }
.plan-review { margin: var(--space-2) 0 0; }
.plan-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); margin-top: var(--space-4); }
.plan-figures > div { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3) var(--space-4); border: 1px solid var(--border-secondary); border-radius: var(--radius-lg); background: var(--bg-secondary); }
.plan-figure-label { font-size: var(--text-xs); color: var(--text-secondary); font-weight: var(--font-medium); letter-spacing: 0.03em; }
.plan-figure-value { font-size: var(--text-xl); font-weight: var(--font-semibold); color: var(--text-primary); font-variant-numeric: tabular-nums; }
.plan-figure-sub { font-size: var(--text-xs); color: var(--text-tertiary); }
.plan-progress { height: 6px; margin: var(--space-4) 0 var(--space-3); border-radius: var(--radius-full); background: var(--color-gray-200); overflow: hidden; }
.plan-progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--color-primary-500), var(--color-primary-600)); }
.plan-schedule td, .plan-schedule th { padding-top: 6px; padding-bottom: 6px; }
.plan-covered { list-style: none; margin: var(--space-2) 0 0; padding: 0; border: 1px solid var(--border-secondary); border-radius: var(--radius-lg); }
.plan-covered li { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); border-bottom: 1px solid var(--border-secondary); }
.plan-covered li:last-child { border-bottom: 0; }
@media (max-width: 640px) { .plan-figures { grid-template-columns: 1fr; } .plan-panel-actions { margin-left: 0; } }
.plan-rules { display: grid; gap: var(--space-2); margin: var(--space-3) 0 0; padding: var(--space-3) var(--space-4); border: 1px solid var(--border-secondary); border-radius: var(--radius-lg); background: var(--bg-secondary); }
.plan-rules > div { display: grid; grid-template-columns: 150px 1fr; gap: var(--space-3); font-size: var(--text-sm); }
.plan-rules dt { font-weight: var(--font-semibold); color: var(--text-primary); }
.plan-rules dd { margin: 0; color: var(--text-secondary); }
@media (max-width: 640px) { .plan-rules > div { grid-template-columns: 1fr; gap: 2px; } }

/* Auto-pay line on the Account Ledger (Phase 1.7) */
.autopay-line { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border: 1px solid var(--border-primary); border-left: 4px solid var(--color-primary-500); border-radius: var(--radius-lg); background: var(--bg-surface); font-size: var(--text-sm); }
.autopay-line.is-failed { border-left-color: var(--color-danger-600); }
.autopay-waiting { margin-top: var(--space-2); color: var(--color-warning-600); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* Door-notice visits from the meter-reader app (1.4c) */
.notice-visits { grid-column: 1 / -1; margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border-primary); }
.notice-visit { padding: var(--space-2) 0 var(--space-2) var(--space-3); border-left: 3px solid var(--color-primary-500); margin-bottom: var(--space-2); }

/* Fixed late fee (Settings → Due Date & Late Fee): the read-only start date, and the auto-pay timing warning */
.late-fee-start { padding: var(--space-2) 0; font-weight: var(--font-semibold); font-variant-numeric: tabular-nums; }
.late-fee-warning {
  margin-top: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid var(--color-warning-100);
  border-left: 4px solid var(--color-warning-500); border-radius: var(--radius-lg); background: var(--color-warning-50);
  color: var(--color-warning-700); font-size: var(--text-sm); line-height: var(--leading-relaxed);
}

/* Phones: the payment tree and the reports' tables scroll inside their card instead of widening the page (a wider page
   pushed the bottom bar's More button, the only menu button at this width, off screen). */
@media (max-width: 767px) {
  #payment-table,
  #report-content {
    overflow-x: auto;
  }

  .rate-list-grid > * {
    min-width: 0;   /* the rate table scrolls in its own container */
  }
}

/* Leads (Platform Admin, Phase B slice 2): the waiting strip, the filters, the status select drawn as a status badge
   (colours as the badges: new primary, contacted info, demo/board warning, won success, lost/spam gray). Each lead's
   name and Open link go to its record page (below). */
.leads-summary { padding: var(--space-3) var(--space-4); font-size: var(--text-sm); color: var(--text-secondary); }
.leads-summary strong { font-family: var(--font-display); font-size: var(--text-lg); color: var(--text-primary); font-variant-numeric: tabular-nums; }
.leads-summary--waiting { border-left: 4px solid var(--color-primary-500); }
.leads-filter { flex: 0 0 170px; }
.leads-table th, .leads-table td { padding-left: var(--space-3); padding-right: var(--space-3); }
.leads-table td { vertical-align: top; }
.leads-person { min-width: 140px; overflow-wrap: anywhere; }
.leads-wrap { min-width: 92px; }
.leads-status {
  appearance: none; -webkit-appearance: none; min-height: 28px; padding: 3px var(--space-6) 3px var(--space-3);
  border: 1px solid transparent; border-radius: var(--radius-full); font: inherit; font-size: var(--text-xs);
  font-weight: var(--font-medium); cursor: pointer; transition: box-shadow var(--transition-fast);
  background-repeat: no-repeat; background-position: right 8px center; background-size: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2357534e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
.leads-status:hover { box-shadow: 0 0 0 1px currentColor; }
.leads-status:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.leads-status:disabled { opacity: 0.6; cursor: progress; }
.leads-status option { background: var(--bg-primary); color: var(--text-primary); }
.leads-status--new { background-color: var(--color-primary-100); color: var(--color-primary-700); }
.leads-status--contacted { background-color: var(--color-info-50); color: var(--color-info-500); }
.leads-status--demo, .leads-status--board { background-color: var(--color-warning-100); color: var(--color-warning-700); }
.leads-status--won { background-color: var(--color-success-100); color: var(--color-success-700); }
.leads-status--lost, .leads-status--spam { background-color: var(--color-gray-100); color: var(--color-gray-700); }
@media (max-width: 640px) { .leads-filter { flex: 1 1 140px; } }
.leads-name { color: var(--text-primary); text-decoration: none; }
.leads-name:hover { color: var(--color-primary-700); text-decoration: underline; text-underline-offset: 2px; }
.leads-name:focus-visible, .leads-open:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: 2px; }
.leads-open { gap: var(--space-1); white-space: nowrap; }
.leads-kind { margin-top: var(--space-1); }

/* A lead's record (Leads CRM Phase 1, docs/plans/leads-crm-correspondence.md). The correspondence reads as one
   thread, oldest first; who spoke is carried by the edge of each entry: received = stone, sent = teal (ours),
   internal note = dashed. Bodies keep their line breaks exactly as recorded. */
.lead-back { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-sm); color: var(--text-secondary); text-decoration: none; }
.lead-back:hover { color: var(--color-primary-700); }
.lead-back:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: 2px; }
.lead-header .page-title { margin-top: var(--space-2); }
.lead-contact { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); margin-top: var(--space-2); font-size: var(--text-sm); }
.lead-contact a { display: inline-flex; align-items: center; gap: var(--space-1); overflow-wrap: anywhere; }
.lead-header-side { display: grid; justify-items: start; gap: var(--space-1); min-width: 180px; }
.lead-header-side .form-label { margin-bottom: 0; }

.lead-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); gap: var(--space-6); align-items: start; }
.lead-side { display: grid; gap: var(--space-5); }
.lead-thread { padding: 0; overflow: hidden; }
.lead-thread > .card-header { padding: var(--space-5) var(--space-6) 0; }
.lead-empty { padding: var(--space-2) var(--space-6) var(--space-6); color: var(--text-tertiary); }

.lead-entries { list-style: none; margin: 0; padding: 0 var(--space-6) var(--space-6); display: grid; gap: var(--space-4); }
.lead-entry {
  position: relative; padding: var(--space-4) var(--space-5); border: 1px solid var(--border-primary);
  border-left: 4px solid var(--color-gray-400); border-radius: var(--radius-lg); background: var(--bg-primary);
  scroll-margin-top: var(--space-6); transition: background-color 600ms ease;
}
.lead-entry--out { border-left-color: var(--color-primary-500); background: var(--color-primary-50); }
.lead-entry--note { border-style: dashed; border-left-style: dashed; border-left-color: var(--color-gray-400); background: var(--bg-secondary); }
.lead-entry--editing { border-left-color: var(--color-accent-500); }
.lead-entry--flash { background: var(--color-accent-50, #fffbeb); }
.lead-entry-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.lead-entry-channel { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-sm); color: var(--text-secondary); }
.lead-entry-when { margin-left: auto; font-size: var(--text-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lead-entry-route { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-5); margin: var(--space-2) 0 0; font-size: var(--text-sm); overflow-wrap: anywhere; }
.lead-entry-subject { margin: var(--space-3) 0 0; font-weight: var(--font-semibold); color: var(--text-primary); overflow-wrap: anywhere; }
.lead-entry-body { margin-top: var(--space-2); max-width: 78ch; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; color: var(--text-primary); }
.lead-entry-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2);
  margin-top: var(--space-3); padding-top: var(--space-2); border-top: 1px solid var(--border-primary); font-size: var(--text-xs); }
.lead-entry-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.lead-entry-actions .btn, .lead-file .btn { gap: var(--space-1); }
.lead-remove { color: var(--text-secondary); }
.lead-remove:hover:not(:disabled) { color: var(--color-danger-600); }

.lead-file-chips { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0 0; padding: 0; }
.lead-file-chip {
  display: inline-flex; align-items: center; gap: var(--space-2); max-width: 100%; padding: 4px var(--space-3);
  border: 1px solid var(--border-primary); border-radius: var(--radius-full); background: var(--bg-primary);
  font: inherit; font-size: var(--text-sm); color: var(--text-primary); cursor: pointer; transition: border-color var(--transition-fast);
}
.lead-file-chip span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-file-chip:hover { border-color: var(--color-primary-500); }
.lead-file-chip:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.lead-compose { padding: var(--space-5) var(--space-6) var(--space-6); border-top: 1px solid var(--border-primary); background: var(--bg-secondary); }
.lead-compose-title { margin: 0 0 var(--space-4); font-family: var(--font-display); font-size: var(--text-base); font-weight: var(--font-semibold); }
.lead-entry-form .form-group { margin-bottom: var(--space-4); }
.lead-body-input { min-height: 180px; resize: vertical; font-family: var(--font-sans); line-height: 1.6; }
.lead-direction { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-4); padding: 0; border: 0; }
.lead-direction legend { float: left; margin: 0 var(--space-2) 0 0; }
.lead-direction-option { position: relative; }
.lead-direction-option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.lead-direction-option span {
  display: inline-block; padding: 6px var(--space-4); border: 1px solid var(--border-primary); border-radius: var(--radius-full);
  background: var(--bg-primary); font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--text-secondary);
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.lead-direction-option input:checked + span { background: var(--color-primary-600); border-color: var(--color-primary-600); color: #fff; }
.lead-direction-option input:focus-visible + span { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.lead-form-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-2); }
.lead-form-actions--split { justify-content: space-between; align-items: center; }
.form-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.lead-files { list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.lead-file { display: grid; gap: var(--space-1); padding: var(--space-3) 0; border-bottom: 1px solid var(--border-primary); }
.lead-file:first-child { padding-top: 0; }
.lead-file .btn { justify-self: start; margin-left: calc(-1 * var(--space-2)); }
.lead-file-name {
  display: inline-flex; align-items: flex-start; gap: var(--space-2); padding: 0; border: 0; background: none; text-align: left;
  font: inherit; font-weight: var(--font-medium); color: var(--color-primary-700); cursor: pointer; overflow-wrap: anywhere;
}
.lead-file-name svg { flex-shrink: 0; margin-top: 3px; }
.lead-file-name:hover span { text-decoration: underline; text-underline-offset: 2px; }
.lead-file-name:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: 2px; }
.lead-file-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; font-size: var(--text-xs); color: var(--text-tertiary); }
.lead-file-note { margin: 0; font-size: var(--text-sm); color: var(--text-secondary); }
.lead-jump { padding: 0; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.lead-upload .form-group { margin-bottom: var(--space-3); }
.lead-inline { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.lead-inline .form-input { flex: 1 1 200px; width: auto; }
#lead-notes { min-height: 120px; resize: vertical; }

.lead-revisions { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.lead-revision { padding: var(--space-4); border: 1px solid var(--border-primary); border-left: 4px solid var(--color-gray-300); border-radius: var(--radius-lg); }
.lead-revision-head { margin: 0 0 var(--space-1); font-weight: var(--font-semibold); }

@media (prefers-reduced-motion: reduce) {
  .lead-entry, .lead-file-chip, .lead-direction-option span { transition: none; }
}
@media (max-width: 1100px) {
  .lead-layout { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .lead-thread > .card-header, .lead-entries, .lead-compose { padding-left: var(--space-4); padding-right: var(--space-4); }
  .lead-entry { padding: var(--space-3) var(--space-4); }
  .lead-entry-when { margin-left: 0; width: 100%; }
  .form-row--3 { grid-template-columns: 1fr 1fr; }
  .lead-header-side { min-width: 0; }
}
