.billing-entry-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  min-width: 0;
}

.billing-entry-main {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.billing-entry-page .package-card,
.billing-entry-page .package-summary-card {
  max-width: 100%;
  min-width: 0;
}

.billing-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
  gap: 8px 10px;
  align-items: end;
  padding: 10px 12px;
  min-width: 0;
}

.billing-status-banner {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 900;
}

.billing-status-banner.cancelled {
  border: 1px solid color-mix(in oklab, #dc2626 34%, var(--package-card-border, #dbe3ee));
  background: color-mix(in oklab, #dc2626 10%, var(--package-card-bg, #fff));
  color: #b91c1c;
}

.billing-status-banner.cancelled span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 12px;
  line-height: 1;
}

.billing-status-banner strong {
  flex: 1 1 360px;
  color: inherit;
  font-weight: 700;
  opacity: .86;
}

.billing-header label,
.billing-patient-card label,
.billing-footer-total label {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.billing-header span,
.billing-patient-card span,
.billing-footer-total label span {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted, #64748b);
}

.billing-lookup-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 6px;
}

.doctor-select-wrap {
  position: relative;
  display: grid;
  align-items: center;
  z-index: 12;
}

.doctor-select-wrap > i {
  position: absolute;
  left: 11px;
  z-index: 1;
  color: var(--text-muted, #64748b);
  font-size: 13px;
  pointer-events: none;
}

.doctor-select-wrap .form-control {
  padding-left: 34px;
  padding-right: 34px;
  font-weight: 700;
}

.doctor-select-wrap.invalid .form-control {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px color-mix(in oklab, #dc2626 16%, transparent);
}

.doctor-clear {
  position: absolute;
  right: 8px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in oklab, var(--text-muted, #64748b) 10%, transparent);
  color: var(--text-muted, #64748b);
  cursor: pointer;
}

.doctor-clear:hover {
  background: color-mix(in oklab, #dc2626 12%, transparent);
  color: #dc2626;
}

.doctor-suggestion-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 180px;
  overflow: auto;
  padding: 5px;
  border: 1px solid var(--border-color, #d5e0ef);
  border-radius: 11px;
  background: var(--card-bg, #ffffff);
  color: var(--text-color, #0f172a);
  box-shadow: 0 18px 40px rgba(15, 23, 42, .18);
}

.doctor-suggestion {
  width: 100%;
  min-height: 34px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.doctor-suggestion span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.doctor-suggestion small {
  color: var(--text-muted, #64748b);
  font-weight: 800;
}

.doctor-suggestion:hover,
.doctor-suggestion.active {
  background: var(--accent-color, #2563eb);
  color: #ffffff;
}

.doctor-suggestion:hover span,
.doctor-suggestion.active span {
  color: #ffffff;
}

.doctor-suggestion:hover small,
.doctor-suggestion.active small {
  color: rgba(255, 255, 255, .84);
}

.field-validation {
  margin-top: 2px;
  color: #dc2626;
  font-size: 11px;
  font-weight: 800;
}

.billing-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  align-items: center;
  gap: 7px;
  justify-content: stretch;
  min-width: 0;
}

.billing-actions .btn {
  width: 100%;
  min-width: 0;
}

.billing-actions #billCancel {
  min-width: 0;
}

.billing-patient-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
  gap: 8px 10px;
  padding: 10px 12px;
  min-width: 0;
}

.billing-patient-card label.wide {
  grid-column: span 2;
}

.billing-total-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  gap: 8px;
  min-width: 0;
}

@media (max-width: 1320px) {
  .billing-header {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .billing-total-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  .billing-header {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .billing-patient-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.package-summary-card.discount {
  border-color: color-mix(in oklab, #ea580c 28%, var(--package-card-border, var(--border-color, #dbe3ee)));
  background: linear-gradient(135deg, var(--package-card-bg, var(--card-bg, #ffffff)) 0%, var(--package-orange-soft, #fff7ed) 100%);
}

.package-summary-card.discount i {
  background: var(--package-orange-soft, #ffedd5);
  color: #ea580c;
}

.billing-items-wrap {
  height: clamp(340px, 46vh, 520px);
  max-height: 520px;
}

.billing-items-table {
  min-width: 1020px;
}

.billing-items-table th:nth-child(3),
.billing-items-table td:nth-child(3) {
  width: 92px;
  text-align: center;
}

.billing-items-table th:nth-child(4),
.billing-items-table td:nth-child(4),
.billing-items-table th:nth-child(5),
.billing-items-table td:nth-child(5),
.billing-items-table th:nth-child(6),
.billing-items-table td:nth-child(6) {
  width: 112px;
  text-align: right;
}

.billing-items-table th:nth-child(7),
.billing-items-table td:nth-child(7) {
  width: 150px;
}

.billing-items-table th:nth-child(8),
.billing-items-table td:nth-child(8) {
  width: 145px;
}

.billing-items-table th:last-child,
.billing-items-table td:last-child {
  width: 72px;
}

.billing-items-table .form-control {
  min-height: 30px;
  padding: 3px 7px;
}

.billing-items-table .bill-qty,
.billing-items-table .bill-rate {
  text-align: right;
}

.billing-items-table .bill-unit {
  color: var(--text-soft, #334155);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.billing-footer-total {
  position: sticky;
  bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: max-content 18px max-content 18px 138px 18px max-content;
  align-items: end;
  justify-content: end;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(90deg, var(--package-blue-soft, #f8fbff) 0%, var(--package-card-bg, var(--card-bg, #fff)) 50%, var(--package-purple-soft, #fbf7ff) 100%);
}

.billing-footer-total div {
  display: grid;
  gap: 3px;
}

.billing-footer-total div span {
  color: var(--text-muted, #64748b);
  font-size: 11px;
  font-weight: 800;
}

.billing-footer-total strong {
  color: var(--package-text, var(--text-color, #0f172a));
  font-size: 14px;
}

.billing-footer-total label {
  width: 138px;
}

.billing-footer-total .final {
  justify-self: start;
  text-align: right;
}

.billing-footer-total .final strong {
  color: #7c3aed;
  font-size: 21px;
}

.billing-footer-total > i {
  align-self: center;
  color: var(--package-text-muted, var(--text-muted, #94a3b8));
}

.patient-picker-modal {
  width: min(680px, 100%);
}

.patient-picker-list .item-picker-row {
  grid-template-columns: minmax(0, 1fr) 120px 120px;
}

.lookup-modal.saved-bills-modal {
  display: flex;
  flex-direction: column;
  width: min(1040px, calc(100vw - 18px));
  max-height: min(680px, calc(100vh - 28px));
  padding: 12px;
}

.lookup-modal.saved-bills-modal .lookup-head {
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.lookup-modal.saved-bills-modal .lookup-head h2 {
  font-size: 16px;
  line-height: 1.2;
}

.lookup-modal.saved-bills-modal .lookup-head p {
  margin-top: 3px;
  line-height: 1.25;
}

.lookup-modal.saved-bills-modal .lookup-head .row-action {
  width: 34px;
  height: 34px;
  min-width: 34px;
  align-self: flex-start;
}

.lookup-modal.saved-bills-modal .lookup-search-wrap {
  flex: 0 0 auto;
  margin-bottom: 8px;
}

.saved-bills-filter {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: max-content;
  margin: 0 0 8px;
  padding: 3px;
  border: 1px solid var(--package-card-border, #dbe3ee);
  border-radius: 999px;
  background: var(--package-surface, #f8fafc);
}

.saved-bills-filter button {
  min-height: 26px;
  padding: 4px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--package-text-soft, #334155);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.saved-bills-filter button:hover {
  background: var(--package-surface-hover, #eef4ff);
}

.saved-bills-filter button.active {
  background: linear-gradient(135deg, var(--primary-color, #2563eb), #1d4ed8);
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .22);
}

.lookup-modal.saved-bills-modal .lookup-search-wrap .form-control {
  height: 36px;
  min-height: 36px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.lookup-modal.saved-bills-modal .lookup-search-wrap i {
  top: 50%;
  transform: translateY(-50%);
}

.lookup-modal.saved-bills-modal .lookup-footer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--package-card-border, #dbe3ee);
  background: var(--package-card-bg, #fff);
  color: var(--package-text-soft, #334155);
  font-size: 12px;
  font-weight: 900;
}

.lookup-modal.saved-bills-modal .lookup-footer > div {
  display: flex;
  gap: 8px;
}

.saved-bills-grid-head,
.saved-bill-row {
  display: grid;
  grid-template-columns: 82px 138px 84px minmax(145px, 1.15fr) minmax(118px, .85fr) 90px 74px;
  gap: 7px;
  align-items: center;
}

.saved-bills-grid-head {
  flex: 0 0 auto;
  margin-top: 0;
  padding: 8px 9px;
  border: 1px solid var(--package-card-border, #dbe3ee);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: var(--package-surface, #f8fafc);
  color: var(--package-text-soft, #334155);
  font-size: 12px;
  font-weight: 900;
}

.saved-bills-grid-head span:nth-child(6) {
  text-align: right;
}

.saved-bills-grid-head span:nth-child(7) {
  text-align: center;
}

.saved-bills-list {
  flex: 1 1 auto;
  min-height: 260px;
  overflow: auto;
  border: 1px solid var(--package-card-border, #dbe3ee);
  border-radius: 0 0 8px 8px;
  background: var(--package-card-bg, #fff);
}

.saved-bill-row {
  width: 100%;
  min-height: 38px;
  padding: 8px 9px;
  border: 0;
  border-bottom: 1px solid var(--package-card-border, #dbe3ee);
  background: var(--package-card-bg, #fff);
  color: var(--package-text, #0f172a);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.saved-bill-row span,
.saved-bill-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-bill-row:hover:not(.selected),
.saved-bill-row.focused:not(.selected) {
  background: var(--package-surface-hover, #f1f5f9);
}

.saved-bill-row.selected {
  background: linear-gradient(135deg, var(--primary-color, #2563eb), #1d4ed8);
  color: #fff;
  outline: 1px solid color-mix(in oklab, var(--primary-color, #2563eb) 72%, #fff);
}

.saved-bill-row .bill-no {
  font-weight: 900;
}

.saved-bill-row .patient-name {
  font-weight: 900;
}

.saved-bill-row .amount {
  justify-self: end;
  text-align: right;
  font-weight: 900;
}

.saved-bill-row em {
  justify-self: center;
  min-width: 70px;
  padding: 3px 8px;
  border-radius: 999px;
  font-style: normal;
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.saved-bill-row em.active {
  background: color-mix(in oklab, #16a34a 14%, var(--package-card-bg, #fff));
  color: #15803d;
}

.saved-bill-row em.cancelled {
  background: color-mix(in oklab, #dc2626 14%, var(--package-card-bg, #fff));
  color: #b91c1c;
}

.saved-bill-row.selected em {
  background: rgba(255, 255, 255, .18);
  color: #fff;
}

.saved-bills-list .package-empty {
  display: grid;
  place-items: center;
  min-height: 170px;
  color: var(--package-text-muted, #64748b);
}

[data-theme="dark"] .saved-bills-grid-head,
[data-theme="dark"] .saved-bill-row,
[data-theme="dark"] .saved-bills-list {
  border-color: color-mix(in oklab, var(--package-card-border, #334155) 84%, #60a5fa);
}

[data-theme="dark"] .saved-bill-row.selected {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
}

[data-theme="dark"] .lookup-modal.saved-bills-modal .lookup-footer {
  background: var(--package-card-bg, #111827);
}

[data-theme="dark"] .saved-bills-filter {
  background: color-mix(in oklab, var(--package-card-bg, #111827) 86%, #60a5fa);
  border-color: color-mix(in oklab, var(--package-card-border, #334155) 84%, #60a5fa);
}

.cancel-bill-overlay {
  z-index: 70;
}

.cancel-bill-modal {
  width: min(560px, calc(100vw - 36px));
  padding: 18px;
  border: 1px solid var(--package-card-border, #dbe3ee);
  border-radius: 16px;
  background: var(--package-card-bg, #fff);
  color: var(--package-text, #0f172a);
  box-shadow: 0 28px 70px rgba(15, 23, 42, .24);
}

.cancel-bill-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.cancel-bill-head h2 {
  margin: 0;
  color: var(--package-text, #0f172a);
  font-size: 20px;
  line-height: 1.2;
}

.cancel-bill-head p {
  margin: 4px 0 0;
  color: var(--package-text-muted, #64748b);
  font-size: 13px;
}

.cancel-bill-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.cancel-bill-summary div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--package-card-border, #dbe3ee);
  border-radius: 12px;
  background: var(--package-surface, #f8fafc);
}

.cancel-bill-summary span,
.cancel-reason-field span {
  color: var(--package-text-muted, #64748b);
  font-size: 12px;
  font-weight: 900;
}

.cancel-bill-summary strong {
  min-width: 0;
  overflow: hidden;
  color: var(--package-text, #0f172a);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cancel-reason-field {
  display: grid;
  gap: 7px;
}

.cancel-reason-field b,
.cancel-modal-error {
  color: #dc2626;
}

.cancel-reason-field textarea {
  min-height: 104px;
  resize: vertical;
}

.cancel-modal-error {
  font-size: 12px;
  font-weight: 800;
}

.cancel-bill-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.cancel-bill-actions .btn {
  min-width: 132px;
}

[data-theme="dark"] .cancel-bill-modal {
  background: var(--package-card-bg, #111827);
  border-color: color-mix(in oklab, var(--package-card-border, #334155) 84%, #60a5fa);
  box-shadow: 0 28px 70px rgba(0, 0, 0, .42);
}

[data-theme="dark"] .cancel-bill-summary div {
  background: color-mix(in oklab, var(--package-card-bg, #111827) 86%, #60a5fa);
  border-color: color-mix(in oklab, var(--package-card-border, #334155) 84%, #60a5fa);
}

@media (max-width: 980px) {
  .lookup-modal.saved-bills-modal {
    width: min(760px, calc(100vw - 32px));
  }

  .saved-bills-grid-head,
  .saved-bill-row {
    grid-template-columns: 86px 135px minmax(150px, 1fr) 105px 82px;
  }

  .saved-bills-grid-head span:nth-child(3),
  .saved-bills-grid-head span:nth-child(5),
  .saved-bill-row span:nth-child(3),
  .saved-bill-row span:nth-child(5) {
    display: none;
  }
}

@media (max-width: 640px) {
  .cancel-bill-summary {
    grid-template-columns: 1fr;
  }

  .cancel-bill-actions {
    justify-content: stretch;
  }

  .cancel-bill-actions .btn {
    flex: 1;
  }
}

@media (max-width: 1180px) {
  .billing-entry-page,
  .billing-total-strip {
    grid-template-columns: 1fr;
  }

  .billing-entry-page {
    overflow: visible;
  }

  .billing-actions {
    justify-content: flex-end;
  }

  .billing-patient-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .billing-header {
    grid-template-columns: 1fr;
  }

  .billing-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .billing-patient-card,
  .billing-patient-card label.wide {
    grid-template-columns: 1fr;
    grid-column: auto;
  }

  .billing-actions,
  .billing-footer-total {
    align-items: stretch;
    flex-direction: column;
  }

  .billing-actions .btn,
  .billing-footer-total label {
    width: 100%;
  }
}

@media print {
  .billing-actions,
  .package-side-rail,
  .package-grid-actions,
  #sidebar,
  #topbar {
    display: none !important;
  }

  .billing-entry-page {
    display: block;
  }

  .package-card,
  .package-summary-card {
    box-shadow: none !important;
  }
}
