:root {
  --palette-navy: #0a1931;
  --palette-sky: #b3cfe5;
  --palette-steel: #4a7fa7;
  --palette-deep: #1a3d63;
  --palette-frost: #f6fafd;

  --bg: var(--palette-frost);
  --ink: var(--palette-navy);
  --muted: var(--palette-steel);
  --card: #ffffff;
  --line: var(--palette-sky);
  --patient: #1a3d63;
  --patient-bg: #d6e8f8;
  --insurance: #2a8fae;
  --insurance-bg: #cceef5;
  --deductible: #7a5535;
  --deductible-bg: #f2e6d8;
  --surface-muted: #eef4fa;
  --input-bg: var(--palette-frost);
  --shadow: 0 20px 50px rgba(10, 25, 49, 0.1);
  --focus-ring: 0 0 0 3px rgba(74, 127, 167, 0.28);
  --radius: 20px;
  color-scheme: light;
  font-family: Outfit, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(179, 207, 229, 0.55), transparent 42%),
    radial-gradient(circle at 88% 8%, rgba(74, 127, 167, 0.18), transparent 38%),
    var(--bg);
}

body.visit-dialog-open .app {
  pointer-events: none;
  user-select: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.is-hidden {
  display: none !important;
}

.print-frame {
  position: fixed;
  width: 0;
  height: 0;
  border: 0;
  visibility: hidden;
  pointer-events: none;
}

.deductible-dialog {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.deductible-dialog::backdrop {
  background: rgba(10, 25, 49, 0.48);
}

.deductible-dialog form {
  padding: 22px;
}

.dialog-lede {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.deductible-choice {
  margin: 0 0 14px;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  font-weight: 600;
  cursor: pointer;
}

.choice:has(input:checked) {
  border-color: var(--palette-deep);
  background: var(--surface-muted);
  box-shadow: var(--focus-ring);
}

.choice input {
  accent-color: var(--ink);
}

.text-input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  padding: 0 14px;
  outline: none;
  font-size: 16px;
}

.text-input:focus {
  border-color: var(--palette-steel);
  box-shadow: var(--focus-ring);
}

.deductible-dialog .field {
  margin-bottom: 12px;
}

.dialog-section {
  margin: 4px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.dialog-section-title {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: 20px;
  font-weight: 560;
  letter-spacing: -0.02em;
}

.dialog-section-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.deductible-amount-field {
  margin-bottom: 8px;
}

.visit-banner {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 12px 16px;
  align-items: end;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.visit-label {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.visit-value {
  margin: 0;
  font-weight: 800;
  font-size: 22px;
  line-height: 1.2;
  color: var(--ink);
}

.deductible-dialog #patient-name,
.deductible-dialog #office-name {
  font-size: 18px;
  font-weight: 700;
}

.date-of-service-field {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  overflow: hidden;
}

.date-of-service-field:focus-within {
  border-color: var(--palette-steel);
  box-shadow: var(--focus-ring);
}

.date-of-service .date-text {
  flex: 1;
  min-width: 0;
  height: 48px;
  border: 0;
  background: transparent;
  padding: 0 14px;
  outline: none;
  font: inherit;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.date-calendar-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 48px;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--palette-deep);
  cursor: pointer;
}

.date-calendar-button:hover {
  background: var(--card);
  color: var(--ink);
}

.date-calendar-button:focus-visible {
  outline: 2px solid var(--palette-steel);
  outline-offset: -2px;
}

.field-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.visit-value-date {
  font-size: 20px;
  font-weight: 700;
}

#edit-visit {
  align-self: center;
}

.deductible-error {
  min-height: 1.2em;
  margin: 0 0 8px;
  color: var(--deductible);
  font-size: 14px;
}

.inline-edit {
  margin-left: 8px;
  font-size: 12px;
  vertical-align: baseline;
}

.app {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.top {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
}

@media (max-width: 640px) {
  .visit-banner {
    grid-template-columns: 1fr;
  }

  #edit-visit {
    justify-self: start;
  }
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--palette-navy);
  color: var(--palette-frost);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand-mark {
  position: relative;
  flex-shrink: 0;
}

.brand-mark-rcm,
.brand-mark-icon {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
}

.brand-mark-rcm {
  animation: brand-mark-rcm 4.8s ease-in-out infinite;
}

.brand-mark-icon {
  opacity: 0;
  animation: brand-mark-icon 4.8s ease-in-out infinite;
}

.brand-mark-icon svg {
  display: block;
}

@keyframes brand-mark-rcm {
  0%,
  38% {
    opacity: 1;
    transform: scale(1);
  }

  48%,
  88% {
    opacity: 0;
    transform: scale(0.94);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes brand-mark-icon {
  0%,
  38% {
    opacity: 0;
    transform: scale(0.9);
  }

  48%,
  88% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(0.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark-rcm {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .brand-mark-icon {
    animation: none;
    opacity: 0;
    transform: none;
  }
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-weight: 560;
  letter-spacing: -0.03em;
}

h1 {
  font-size: 42px;
  line-height: 1;
}

h2 {
  font-size: 28px;
}

.lede,
.hint,
.section-note,
.bar-caption,
.share,
.empty {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.entry,
.ledger {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.entry {
  padding: 22px;
}

.ledger {
  padding: 16px 16px 14px;
}

.ledger h2 {
  font-size: 22px;
}

.code-input {
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  padding: 0 14px;
  outline: none;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.code-input::placeholder {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
}

.code-input:focus {
  border-color: var(--palette-steel);
  box-shadow: var(--focus-ring);
}

.code-input.is-invalid {
  border-color: #c53030;
}

.code-input.is-invalid:focus {
  border-color: #c53030;
  box-shadow: 0 0 0 3px rgba(197, 48, 48, 0.22);
}

.ada-code-error {
  min-height: 0;
  margin: 6px 0 0;
  color: #b42318;
  font-size: 14px;
  line-height: 1.35;
}

.ada-code-error:not(:empty) {
  min-height: 1.2em;
}

.ada-code-wrap {
  position: relative;
}

.ada-suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 240px;
  margin: 0;
  padding: 6px;
  overflow: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.ada-suggestion {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.ada-suggestion:hover,
.ada-suggestion.is-active {
  background: var(--surface-muted);
}

.ada-suggestion-code {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.ada-suggestion-desc {
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
}

.inputs {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 12px;
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.affix {
  display: flex;
  align-items: center;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  padding: 0 14px;
}

.affix:focus-within {
  border-color: var(--palette-steel);
  box-shadow: var(--focus-ring);
}

.affix input {
  width: 100%;
  height: 50px;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.affix span {
  color: var(--muted);
  font-weight: 600;
}

.affix-money input {
  padding-left: 6px;
}

.affix-percent input {
  text-align: right;
  padding-right: 6px;
}

.share {
  margin-top: 12px;
}

.share strong {
  color: var(--patient);
}

.portions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.portion {
  padding: 12px 14px;
  border-radius: 14px;
}

.portion span {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.portion strong {
  font-family: Fraunces, Georgia, serif;
  font-size: 32px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.portion-patient {
  background: var(--patient-bg);
  color: var(--patient);
}

.portion-insurance {
  background: var(--insurance-bg);
  color: var(--insurance);
}

.portion.is-zero strong {
  opacity: 0.45;
}

.button,
.text-button {
  border: 0;
  cursor: pointer;
}

.button {
  height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--palette-navy);
  color: var(--palette-frost);
  font-weight: 600;
}

.button:hover:not(:disabled) {
  background: var(--palette-deep);
}

.button-wide {
  width: 100%;
  margin-top: 16px;
}

.hint {
  margin-top: 10px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.section-note {
  font-size: 13px;
}

.sheet-head,
.service {
  display: grid;
  grid-template-columns: 1.15fr 0.95fr 0.7fr 0.95fr 1fr auto;
  gap: 6px 8px;
  align-items: center;
}

.sheet-head {
  padding: 0 8px 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.services {
  display: grid;
  max-height: 280px;
  overflow: auto;
}

.empty {
  padding: 12px;
  border: 1px dashed var(--palette-steel);
  border-radius: 12px;
  background: var(--input-bg);
  font-size: 13px;
}

.service {
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  background: var(--card);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.service.is-latest {
  background: var(--surface-muted);
}

.service-code {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.patient-amount {
  color: var(--patient);
  font-weight: 700;
}

.insurance-amount {
  color: var(--insurance);
  font-weight: 700;
}

.service-ins {
  color: var(--insurance);
  font-weight: 600;
}

.totals-deductible {
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: 10px;
  background: var(--deductible-bg);
}

.text-button {
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 0;
}

.text-button:hover {
  color: var(--palette-deep);
}

.final {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.hero {
  margin: 2px 0 10px;
  font-family: Fraunces, Georgia, serif;
  font-size: 36px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--patient);
}

#total-patient {
  color: #c53030;
}

.totals {
  margin: 0;
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.totals dt {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  color: var(--muted);
}

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

.totals-patient dd {
  color: var(--patient);
}

.totals-deductible dd {
  color: var(--deductible);
}

.totals-insurance dd {
  color: var(--insurance);
}

.totals-patient dt {
  color: var(--patient);
  opacity: 0.85;
}

.totals-deductible dt {
  color: var(--deductible);
  opacity: 0.85;
}

.totals-insurance dt {
  color: var(--insurance);
  opacity: 0.85;
}

.bar {
  display: flex;
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.bar-patient {
  background: var(--patient);
  width: 0;
}

.bar-deductible {
  background: var(--deductible);
  width: 0;
}

.bar-insurance {
  background: var(--insurance);
  width: 0;
}

.portion-deductible {
  background: var(--deductible-bg);
  color: var(--deductible);
}

.bar-caption {
  margin-top: 8px;
}

.ledger-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.button-print,
.button-reset {
  width: 100%;
  height: 40px;
}

.button-print {
  background: var(--palette-deep);
  color: var(--palette-frost);
}

.button-print:hover:not(:disabled) {
  background: var(--palette-navy);
}

.button-print:disabled {
  opacity: 0.45;
  cursor: default;
}

.button-reset {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ink);
}

.button-reset:hover {
  background: var(--surface-muted);
}

@media print {
  body {
    background: #fff;
  }

  .deductible-dialog,
  .entry,
  .lede,
  .ledger-actions,
  .remove,
  .inline-edit,
  #edit-visit,
  .bar {
    display: none !important;
  }

  .app {
    width: 100%;
    max-width: none;
    padding: 0;
  }

  main {
    grid-template-columns: 1fr;
  }

  .entry,
  .ledger {
    box-shadow: none;
    border: 0;
  }

  .ledger {
    padding: 0;
  }

  .services {
    max-height: none;
    overflow: visible;
  }

  .visit-banner {
    box-shadow: none;
    border: 1px solid #b3cfe5;
    margin-bottom: 12px;
  }

  .visit-value {
    font-size: 20px;
  }

  .service.is-latest {
    background: #fff;
  }

  .totals-deductible.is-hidden {
    display: none !important;
  }

  /* Print uses a narrow page width; reset mobile ledger layout so columns line up. */
  .sheet-head,
  .service {
    display: grid !important;
    grid-template-columns: 1.1fr 0.95fr 0.75fr 0.95fr 1fr;
    gap: 4px 10px;
    align-items: center;
  }

  .service-ins::before,
  .patient-amount::before,
  .insurance-amount::before {
    content: none !important;
  }

  .sheet-head span:nth-child(n + 2),
  .service-charge,
  .service-ins,
  .patient-amount,
  .insurance-amount {
    text-align: right;
    justify-self: stretch;
  }

  .service-code {
    text-align: left;
  }

  .service .remove {
    display: none !important;
  }

  .totals div {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    column-gap: 16px;
  }

  .totals dd {
    min-width: 5.5rem;
    text-align: right;
  }
}

@media (max-width: 640px) {
  .ledger-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  main,
  .inputs {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 34px;
  }

  .hero {
    font-size: 32px;
  }

  .portion strong {
    font-size: 26px;
  }

  .sheet-head {
    display: none;
  }

  .service {
    grid-template-columns: 72px 1fr auto;
    font-size: 12px;
  }

  .service-ins::before {
    content: "Ins ";
    color: var(--muted);
    font-weight: 600;
  }

  .patient-amount::before {
    content: "Pt ";
    font-weight: 600;
  }

  .insurance-amount::before {
    content: "Ins ";
    font-weight: 600;
  }

  .app {
    width: min(1080px, calc(100% - 20px));
    padding-top: 20px;
  }
}

/* Portrait print is usually < 860px wide, so rules above must be overridden here. */
@media print {
  .sheet-head {
    display: grid !important;
  }

  .sheet-head span:last-child {
    display: none !important;
  }

  .sheet-head,
  .service {
    grid-template-columns: 1.1fr 0.95fr 0.75fr 0.95fr 1fr !important;
    gap: 4px 8px !important;
    align-items: center !important;
    font-size: 13px !important;
  }

  .service-ins::before,
  .patient-amount::before,
  .insurance-amount::before {
    content: none !important;
  }

  .sheet-head span:nth-child(n + 2),
  .service-charge,
  .service-ins,
  .patient-amount,
  .insurance-amount {
    text-align: right !important;
    justify-self: stretch !important;
  }

  .service-code {
    text-align: left !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
