/*mle-baked*/
/**
 * MLE Ledger v1.0 - Styles
 * Extracted verbatim from mle_ledger_v1_spec.html
 */
:root {
  --mle-blue: #2c7be5;
  --mle-blue-dark: #1f5fb8;
  --mle-blue-light: #e8f2ff;
  --mle-blue-pale: #f4f9ff;
  --mle-green: #28a745;
  --mle-green-light: #e8f5e9;
  --mle-red: #dc3545;
  --mle-amber: #d97706;
  --mle-amber-light: #fef3c7;
  --mle-gray-50: #f8f9fa;
  --mle-gray-100: #f1f3f5;
  --mle-gray-200: #e9ecef;
  --mle-gray-300: #dee2e6;
  --mle-gray-500: #adb5bd;
  --mle-gray-600: #6c757d;
  --mle-gray-700: #495057;
  --mle-gray-800: #343a40;
  --mle-border: #dee2e6;
}
* { box-sizing: border-box; }
body.mle-ledger-body {
  background: var(--mle-gray-50);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  color: var(--mle-gray-800);
  padding: 20px;
  margin: 0;
}

/* HEADER */
.ledger-header {
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ledger-title { display: flex; align-items: center; gap: 14px; }
.ledger-title .header-icon {
  width: 40px; height: 40px;
  background: var(--mle-blue-light);
  color: var(--mle-blue);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.ledger-title h4 {
  margin: 0;
  font-weight: 600;
  color: var(--mle-gray-800);
  font-size: 16px;
  display: flex; align-items: center; gap: 8px;
}
.ledger-title h4 .badge-version {
  background: var(--mle-gray-200);
  color: var(--mle-gray-700);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.patient-info .badge-muted { background: var(--mle-gray-200); color: var(--mle-gray-600); padding: 1px 5px; border-radius: 3px; font-size: 10px; font-weight: 500; }
.patient-info { color: var(--mle-gray-600); font-size: 12px; margin-top: 3px; }
.patient-info strong { color: var(--mle-gray-800); font-weight: 600; }
.patient-info .sep { color: var(--mle-gray-300); margin: 0 8px; }

.header-actions { display: flex; gap: 6px; }
.btn-mle, .btn-mle-outline {
  border: none;
  padding: 7px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn-mle { background: var(--mle-blue); color: white; }
.btn-mle:hover { background: var(--mle-blue-dark); color: white; text-decoration: none; }
.btn-mle-outline { background: white; color: var(--mle-gray-700); border: 1px solid var(--mle-border); }
.btn-mle-outline:hover { background: var(--mle-gray-50); border-color: var(--mle-gray-500); color: var(--mle-gray-700); text-decoration: none; }

/* SUMMARY CARDS */
.summary-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.summary-card {
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  padding: 12px 14px;
}
.summary-card .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--mle-gray-600);
  font-weight: 600;
}
.summary-card .value {
  font-size: 18px;
  font-weight: 600;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  color: var(--mle-gray-800);
}
.summary-card.balance { border-left: 3px solid var(--mle-blue); }
.summary-card.balance .value { color: var(--mle-blue); }
.summary-card.payments .value { color: var(--mle-green); }
.summary-card.adj-clinic .value { color: var(--mle-amber); }
.summary-card.adj-insurance .value { color: var(--mle-amber); }
.summary-card.writeoff .value { color: var(--mle-red); }
.summary-card.credit-card {
  border-left: 3px solid #8b5cf6;
  background: #faf5ff;
}
.summary-card.credit-card .label { color: #7c3aed; }
.summary-card.credit-card .value { color: #7c3aed; }
.credit-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.btn-credit-apply, .btn-credit-refund {
  font-size: 10px;
  font-weight: 600;
  font-family: inherit;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.btn-credit-apply {
  background: var(--mle-green);
  color: white;
}
.btn-credit-apply:hover { background: #218838; }
.btn-credit-refund {
  background: white;
  color: var(--mle-gray-700);
  border: 1px solid var(--mle-border);
}
.btn-credit-refund:hover { background: var(--mle-gray-100); }

/* FILTER BAR */
.filter-bar {
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-bar label {
  font-size: 10px;
  color: var(--mle-gray-600);
  margin: 0;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.filter-bar select, .filter-bar input {
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--mle-border);
  border-radius: 4px;
  background: white;
  color: var(--mle-gray-800);
}
.filter-bar select:focus, .filter-bar input:focus {
  outline: none;
  border-color: var(--mle-blue);
  box-shadow: 0 0 0 2px var(--mle-blue-light);
}
.filter-pill {
  background: var(--mle-blue-light);
  color: var(--mle-blue);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--mle-border);
  border-radius: 4px;
  overflow: hidden;
}
.view-toggle button {
  background: white;
  border: none;
  padding: 5px 12px;
  font-size: 11px;
  color: var(--mle-gray-700);
  cursor: pointer;
  border-right: 1px solid var(--mle-border);
}
.view-toggle button:last-child { border-right: none; }
.view-toggle button.active { background: var(--mle-blue); color: white; }
.view-toggle button:hover:not(.active) { background: var(--mle-gray-50); }

/* LEDGER TABLE */
.ledger-table-wrap {
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  overflow: hidden;
  transition: opacity 140ms ease;
}
.ledger-table-wrap.is-refreshing {
  opacity: 0.55;
  pointer-events: none;
}
table.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
table.ledger thead th {
  background: var(--mle-gray-100);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--mle-gray-700);
  padding: 11px 12px;
  border-bottom: 2px solid var(--mle-border);
  text-align: right;
  white-space: nowrap;
}
table.ledger thead th.left { text-align: left; }
table.ledger thead th.center { text-align: center; }

table.ledger tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--mle-gray-100);
  text-align: right;
  vertical-align: middle;
}
table.ledger tbody td.left { text-align: left; }
table.ledger tbody td.center { text-align: center; }
table.ledger tbody tr:hover { background: var(--mle-blue-pale); }

tr.encounter-header td {
  background: var(--mle-blue-light);
  font-weight: 600;
  color: var(--mle-blue-dark);
  border-top: 2px solid var(--mle-blue);
  border-bottom: 1px solid var(--mle-blue);
  padding: 9px 12px;
  font-size: 12px;
}
tr.encounter-header.open td {
  background: var(--mle-amber-light);
  color: #92400e;
  border-top-color: var(--mle-amber);
  border-bottom-color: var(--mle-amber);
}
tr.encounter-header .enc-link {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  margin-left: 6px;
}
tr.encounter-header .enc-link:hover { text-decoration: underline; }
tr.encounter-header .enc-meta { font-weight: 400; color: inherit; opacity: 0.85; margin-left: 2px; }

.tx-icon {
  display: inline-block;
  width: 20px;
  text-align: center;
  margin-right: 8px;
  color: var(--mle-gray-500);
  font-size: 12px;
}
.tx-icon.charge { color: var(--mle-gray-600); }
.tx-icon.copay-charge { color: #7c3aed; }
.tx-icon.payment-pat { color: var(--mle-green); }
.tx-icon.payment-ins { color: var(--mle-blue); }
.tx-icon.adj { color: var(--mle-amber); }
.tx-icon.writeoff { color: var(--mle-red); }

.amt-charge { color: var(--mle-gray-800); font-weight: 500; }
.amt-payment { color: var(--mle-green); font-weight: 500; }
.amt-adj { color: var(--mle-amber); font-weight: 500; }
.amt-writeoff { color: var(--mle-red); font-weight: 500; }
.amt-balance { font-weight: 600; color: var(--mle-blue); }
.amt-zero { color: var(--mle-gray-300); }

tr.totals-row td {
  background: var(--mle-gray-100);
  font-weight: 700;
  border-top: 2px solid var(--mle-gray-300);
  padding: 13px 12px;
  font-size: 13px;
  color: var(--mle-gray-800);
}
tr.totals-row td.balance-final {
  background: var(--mle-blue);
  color: white;
  font-size: 14px;
  font-weight: 700;
}

.source-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-left: 6px;
  vertical-align: middle;
}
.source-pill.era { background: #e3f2fd; color: #1976d2; }
.source-pill.manual { background: #f3e5f5; color: #7b1fa2; }
.source-pill.copay { background: var(--mle-green-light); color: #2e7d32; }
.source-pill.pending { background: #e0f2fe; color: #0369a1; }
.source-pill.unbilled { background: #f1f5f9; color: #64748b; }
.source-pill.paid { background: #d1fae5; color: #065f46; }
.source-pill.partial { background: #fef3c7; color: #92400e; }
.source-pill.rejected { background: #fee2e2; color: #991b1b; }
.source-pill.prepost { background: #f3e8ff; color: #7c3aed; border: 1px dashed #c4b5fd; letter-spacing: 0.5px; }

.prepost-header td {
  background: #faf5ff !important;
  border-bottom: 1px dashed #e9d5ff;
  padding: 8px 12px;
  font-size: 12px;
}
.prepost-row td {
  background: #faf5ff !important;
  border-bottom: 1px dashed #f3e8ff;
  opacity: 0.85;
  font-style: italic;
}
.prepost-summary td {
  background: #f5f0ff !important;
  border-bottom: 2px dashed #e9d5ff;
  font-style: italic;
}
.prepost-amt {
  color: #7c3aed;
  font-weight: 600;
  font-style: italic;
  text-align: right;
}

.row-actions {
  color: var(--mle-gray-500);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 3px;
  background: transparent;
  border: none;
  font-size: 13px;
  line-height: 1;
}
.row-actions:hover { color: var(--mle-blue); background: var(--mle-gray-100); }
.row-actions.active { color: var(--mle-blue); background: var(--mle-blue-light); }

/* Row action dropdown menu */
.row-menu {
  position: absolute;
  z-index: 1000;
  min-width: 210px;
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  padding: 4px;
  font-size: 12px;
}
.row-menu[hidden] { display: none; }
.row-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  background: none;
  border-radius: 4px;
  color: var(--mle-gray-800);
  cursor: pointer;
  font-size: 12px;
}
.row-menu button:hover { background: var(--mle-blue-pale); color: var(--mle-blue-dark); }
.row-menu button.danger { color: var(--mle-red); }
.row-menu button.danger:hover { background: #fee2e2; color: #991b1b; }
.row-menu button:disabled {
  color: var(--mle-gray-300);
  cursor: not-allowed;
  background: transparent;
}
.row-menu button i { width: 14px; text-align: center; }

/* Row detail modal */
.row-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 50, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.row-modal[hidden] { display: none; }
.row-modal-card {
  background: white;
  border-radius: 10px;
  width: 520px;
  max-width: 90vw;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}
.row-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--mle-border);
}
.row-modal-title { font-size: 15px; font-weight: 600; color: var(--mle-gray-800); }
.row-modal-sub   { font-size: 11px; color: var(--mle-gray-600); margin-top: 2px; }
.row-modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--mle-gray-500);
  cursor: pointer;
  padding: 0 6px;
}
.row-modal-close:hover { color: var(--mle-gray-800); }
.row-modal-body {
  margin: 0;
  padding: 14px 20px 18px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 14px;
  font-size: 12px;
}
.row-modal-body dt {
  color: var(--mle-gray-600);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 10px;
  align-self: center;
}
.row-modal-body dd {
  margin: 0;
  color: var(--mle-gray-800);
  font-variant-numeric: tabular-nums;
}

.tx-note {
  color: var(--mle-gray-600);
  font-size: 11px;
  margin-top: 3px;
  padding-left: 28px;
}

.dash { color: var(--mle-gray-300); }
.payer-name { font-size: 11px; color: var(--mle-gray-700); }

/* Encounter tag inside description — hidden by default, visible only in Date group mode */
.enc-tag {
  display: none;
  font-size: 10px;
  font-weight: 600;
  color: var(--mle-blue-dark);
  background: var(--mle-blue-light);
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 6px;
  letter-spacing: 0.3px;
}
body.group-date .enc-tag { display: inline-block; }

.legend {
  margin-top: 14px;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  font-size: 11px;
  color: var(--mle-gray-600);
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
}
.legend strong { color: var(--mle-gray-800); }
.legend .legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend .legend-divider { border-left: 1px solid var(--mle-border); height: 16px; }

/* Flag banner (patient-level) */
.flag-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  border: 1px solid transparent;
}
.flag-banner i { font-size: 16px; }
.flag-banner .flag-sep { margin: 0 6px; color: currentColor; opacity: 0.4; }
.flag-banner.flag-yellow {
  background: var(--mle-amber-light);
  color: #78350f;
  border-color: var(--mle-amber);
}
.flag-banner.flag-red {
  background: #fee2e2;
  color: #991b1b;
  border-color: var(--mle-red);
}

/* Homepage (no patient selected) */
.home-header {
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.home-stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.home-stat {
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  padding: 14px 16px;
}
.home-stat.red    { border-left: 3px solid var(--mle-red); }
.home-stat.yellow { border-left: 3px solid var(--mle-amber); }
.home-stat.total  { border-left: 3px solid var(--mle-blue); }
.home-stat .label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--mle-gray-600); font-weight: 600; }
.home-stat .value { font-size: 20px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.home-stat.red .value    { color: var(--mle-red); }
.home-stat.yellow .value { color: var(--mle-amber); }
.home-stat.total .value  { color: var(--mle-blue); }

/* Rows added by the wider patient search on the review-list page */
tr.mle-extra td { background: var(--mle-gray-50); }
tr.mle-extra:first-of-type td { border-top: 2px dashed var(--mle-border); }

.level-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.level-pill.red    { background: #fee2e2; color: #991b1b; }
.level-pill.yellow { background: var(--mle-amber-light); color: #78350f; }

tr.review-row:hover { background: var(--mle-blue-pale, #eff6ff); }
tr.review-row:active { background: var(--mle-blue-light, #dbeafe); }

/* Patient name link — opens demographics in OpenEMR's chart frame */
.patient-link {
  color: var(--mle-blue);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.15s, color 0.15s;
}
.patient-link strong { color: inherit; }
.patient-link:hover {
  color: var(--mle-blue-dark);
  border-bottom-color: var(--mle-blue);
  text-decoration: none;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--mle-gray-600);
  font-size: 13px;
}
.empty-state i { font-size: 32px; color: var(--mle-gray-300); margin-bottom: 10px; display: block; }

/* Payment History panel */
.payment-history-panel {
  background: white;
  border: 1px solid var(--mle-border);
  border-radius: 8px;
  margin: 0 12px 12px;
  overflow: hidden;
}
.ph-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; cursor: pointer; user-select: none;
}
.ph-header:hover { background: var(--mle-gray-50); }
.ph-header h5 {
  margin: 0; font-size: 12px; font-weight: 700; color: var(--mle-gray-800);
  text-transform: uppercase; letter-spacing: .3px;
  display: flex; align-items: center; gap: 8px;
}
.ph-toggle {
  font-size: 10px; color: var(--mle-gray-500);
  transition: transform .15s;
}
.ph-header.open .ph-toggle { transform: rotate(90deg); }
.ph-body { display: none; padding: 0 16px 12px; }
.ph-body.open { display: block; }
.ph-table { width: 100%; border-collapse: collapse; }
.ph-table thead th {
  text-align: left; font-size: 10px; font-weight: 700; color: var(--mle-gray-600);
  text-transform: uppercase; letter-spacing: .3px; padding: 5px 10px;
  border-bottom: 2px solid var(--mle-gray-200);
}
.ph-table tbody td {
  padding: 7px 10px; border-bottom: 1px solid var(--mle-gray-100);
  font-size: 12px; color: var(--mle-gray-800); vertical-align: middle;
}
.ph-table tbody tr:hover td { background: var(--mle-blue-pale); }
.ph-date { font-weight: 600; white-space: nowrap; }
.ph-amount { font-weight: 700; color: var(--mle-green); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ph-method-pill {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; background: var(--mle-gray-100); color: var(--mle-gray-700);
}
.ph-ref { font-size: 11px; color: var(--mle-gray-600); }
.ph-memo { font-size: 11px; color: var(--mle-gray-500); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph-receipt-btn {
  background: none; border: 1px solid var(--mle-gray-200); border-radius: 4px;
  padding: 3px 7px; font-size: 11px; color: var(--mle-gray-500); cursor: pointer;
}
.ph-receipt-btn:hover { background: var(--mle-gray-100); color: var(--mle-gray-800); }
.ph-show-all {
  display: block; width: 100%; margin-top: 6px; padding: 6px;
  background: none; border: 1px dashed var(--mle-gray-300); border-radius: 4px;
  font-size: 11px; font-weight: 600; color: var(--mle-gray-600);
  cursor: pointer; text-align: center;
}
.ph-show-all:hover { background: var(--mle-gray-50); color: var(--mle-gray-800); }

@media print {
  .header-actions, .filter-bar, .row-actions, .view-toggle { display: none !important; }
  body.mle-ledger-body { padding: 0; background: white; }
  .ledger-header, .summary-card, .ledger-table-wrap, .legend { border-radius: 0; }
  .payment-history-panel { break-inside: avoid; }
  .ph-body { display: block !important; }
  .ph-extra { display: table-row !important; }
  .ph-show-all, .ph-receipt-btn { display: none !important; }
}
