:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #dcdfe4;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-dark: #1a5fd0;
  --green: #1a7f37;
  --red: #c0392b;
  --amber: #9a6700;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  background: var(--surface); color: var(--text);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(20, 33, 61, .06);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1600px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 28px; height: 60px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-name {
  color: var(--muted); font-weight: 600; font-size: 13px;
  border-left: 1px solid var(--border); padding-left: 12px;
  text-transform: uppercase; letter-spacing: .06em;
}
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 6px;
  font-weight: 500;
}
.topbar nav a:hover { color: #14213d; background: #eef1f5; }
.topbar nav a.active { color: #14213d; background: #e2edfd; }
.user-menu { display: flex; align-items: center; gap: 10px; color: var(--muted); white-space: nowrap; }
.brand-name { white-space: nowrap; }
.linklike {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; text-decoration: underline; padding: 0;
}
.linklike:hover { color: #14213d; }

.container { max-width: 1280px; margin: 24px auto; padding: 0 20px; }
/* Column-heavy pages (cases, worklist) use nearly the full window width. */
.container.wide { max-width: 1600px; }
.login-logo { display: block; margin: 0 auto 18px; height: 44px; width: auto; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash-success { background: #dcf5e4; color: var(--green); }
.flash-error, .flash-danger { background: #fde8e6; color: var(--red); }
.flash-warning { background: #fff3d1; color: var(--amber); }
.flash-info { background: #e2edfd; color: var(--accent-dark); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 20px; margin-bottom: 18px;
}

table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left;
  white-space: nowrap;
}
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.data th a.th-sort { color: inherit; text-decoration: none; }
table.data th a.th-sort:hover { color: var(--accent-dark); }
table.data tr:hover td { background: #f0f4fb; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.wrap-ok { white-space: normal; min-width: 150px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }

.btn {
  display: inline-block; background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: 7px; cursor: pointer; font: inherit;
  text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #eef1f5; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-danger { background: #b00020; color: #fff; border: none; }
.btn-danger:hover { background: #8f0019; }
.danger-zone { border-color: #f3c2c2; }

form.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
/* Only the filter-bar's own labels stack (caption above control) — use the direct-child
   selector so it doesn't leak into the nested checkbox labels inside a multiselect panel. */
form.filters > label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input[type=text], input[type=password], input[type=email], input[type=date],
input[type=number], select, textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px;
  font: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b3ceff; border-color: var(--accent); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.form-grid label, .form-stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-stack label { margin-bottom: 12px; }
.form-grid input, .form-grid select { width: 100%; }
textarea { width: 100%; min-height: 60px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge-pending { background: #fff3d1; color: var(--amber); }
.badge-signed_off { background: #e2edfd; color: var(--accent-dark); }
.badge-billed { background: #ede2fd; color: #6f42c1; }
.badge-paid { background: #dcf5e4; color: var(--green); }
.badge-closed { background: #e5e7eb; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.tiles.compact { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 12px 0 14px; }
.tiles.compact .tile { padding: 10px 14px; }
.tiles.compact .value { font-size: 17px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.tile .label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.pagination { display: flex; gap: 6px; align-items: center; margin: 14px 0; }
.pagination a, .pagination span.current {
  padding: 5px 11px; border: 1px solid var(--border); border-radius: 6px;
  text-decoration: none; color: var(--text); background: var(--surface);
}
.pagination span.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.muted { color: var(--muted); }
.right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.login-box { max-width: 380px; margin: 80px auto; }
.app-footer { margin: 32px 0 8px; text-align: center; font-size: 12px; color: var(--muted); }

/* Sticky column headers: the wrap scrolls vertically, the header row stays. */
.table-wrap.sticky { max-height: calc(100vh - 230px); overflow: auto; }
.table-wrap.sticky thead th {
  position: sticky; top: 0; background: var(--surface); z-index: 5;
  box-shadow: 0 1px 0 var(--border);
}
/* Frozen first column (Case #): stays visible while scrolling right. */
.table-wrap.sticky td:first-child,
.table-wrap.sticky thead th:first-child {
  position: sticky; left: 0; background: var(--surface); z-index: 4;
  box-shadow: 1px 0 0 var(--border);
}
.table-wrap.sticky thead th:first-child { z-index: 6; }  /* corner: above both */
table.data tr:hover td:first-child { background: #f0f4fb; }
tr.addrow > td:first-child, tr.expansion > td:first-child { z-index: 1; }
/* Keep the revealed add form visible wherever the user has scrolled. */
tr.addrow .add-charge { position: sticky; left: 16px; width: max-content; }

/* Click-to-expand CPT charges row */
tr.case-row { cursor: pointer; }
td.expander, th.expander { width: 24px; color: var(--accent); font-weight: 700; text-align: center; }
form.add-charge {
  display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-top: 12px;
}
form.add-charge label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.rate-note { font-size: 12px; align-self: center; }

/* Multi-CPT chip filter */
.chipbox {
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
  padding: 4px 6px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); min-height: 34px; min-width: 190px;
}
.chipbox input[type=text] { border: none; outline: none; padding: 3px 4px; min-width: 76px; flex: 1; }
.chipbox input[type=text]:focus { outline: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #e2edfd; color: var(--accent-dark); border-radius: 999px;
  padding: 2px 6px 2px 10px; font-size: 12px; font-weight: 600;
}
.chip-x {
  border: none; background: none; cursor: pointer; color: var(--accent-dark);
  font-size: 14px; line-height: 1; padding: 0 3px;
}
.chip-x:hover { color: var(--red); }
tr.addrow > td { background: #f2f6fd; white-space: normal; }
td.cpt-add-cell { white-space: nowrap; }
td.cpt-add-cell .btn { margin-left: 4px; vertical-align: middle; }
/* Keep the ✕ (remove) and ＋ (add) buttons on one line beside the CPT code. */
td.cpt-add-cell form.inline-remove { display: inline-block; vertical-align: middle; }
td.line-actions { white-space: nowrap; }
td.line-actions form { display: inline-block; margin-left: 4px; }
table.data.mini input { padding: 4px 6px; }
tr.expansion > td.expansion-cell {
  background: #f2f6fd; padding: 0; white-space: normal;
  border-bottom: 2px solid var(--accent);
}
.expansion-inner { padding: 12px 18px 16px; }
.expansion-head { display: flex; gap: 18px; align-items: baseline; margin-bottom: 8px; }
table.data.mini { width: auto; min-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
table.data.mini th, table.data.mini td { padding: 5px 12px; }
table.data.mini tfoot th { border-top: 1px solid var(--border); }

.dropzone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 36px;
  text-align: center; color: var(--muted); background: var(--surface);
}
.dropzone.drag { border-color: var(--accent); background: #eef4ff; }

.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.chart-box h2 { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* Master-import job progress log */
.joblog {
  margin: 10px 0 0; padding: 10px 12px; max-height: 220px; overflow: auto;
  background: #0f1720; color: #cfe3dc; border-radius: 8px;
  font: 12px/1.5 ui-monospace, "SF Mono", Consolas, monospace; white-space: pre-wrap;
}

/* Checkbox multi-select dropdown (facility / CPT filters) */
.ms { position: relative; display: inline-block; }
.ms-toggle {
  font: inherit; font-size: 13px; padding: 6px 10px; min-width: 120px; text-align: left;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.ms-toggle:hover { border-color: var(--accent); }
.ms-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-label.has-sel { color: var(--accent-dark); font-weight: 600; }
.ms-caret { color: var(--muted); font-size: 11px; flex: none; }
.ms-panel {
  position: absolute; z-index: 50; top: calc(100% + 4px); left: 0; width: 280px; max-width: 84vw;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0,0,0,.16); padding: 8px;
}
.ms-head { display: flex; gap: 6px; margin-bottom: 6px; }
.ms-search {
  width: 100%; box-sizing: border-box; flex: 1; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 13px;
}
.ms-clear {
  font: inherit; font-size: 12px; padding: 0 10px; white-space: nowrap; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--muted);
}
.ms-clear:hover { color: var(--red); border-color: var(--red); }
.ms-options { max-height: 264px; overflow-y: auto; }
.ms-option {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px;
  cursor: pointer; font-size: 13px; color: var(--text);
}
.ms-option:hover { background: var(--bg); }
.ms-option input { flex: none; margin: 0; }
