/* ==========================================================
   Remedly — New Invoice prototype
   Colors sampled from the final mockups.
   ========================================================== */
:root {
  --brand: #19699f;          /* top bar + sidebar */
  --brand-active: #e7f2fb;   /* active sidebar item */
  --primary: #4990e2;        /* buttons, checks, links */
  --primary-dark: #2f74c4;
  --navy: #22489a;           /* Cancel, Check Eligibility */
  --text: #4a4a4a;
  --muted: #8a8f94;
  --placeholder: #a3a7ab;
  --page: #fafafa;
  --card: #f5f5f5;
  --white: #ffffff;
  --border: #dddddd;
  --input-border: #cfd3d6;
  --ins-bg: #dee9f1;         /* insurance block */
  --chip: #e9f0f6;
  --chip-border: #c2c8ce;
  --error: #c62828;
  --error-bg: #fdecec;
  --success: #2e7d4f;
  --focus: 0 0 0 3px rgba(73, 144, 226, .45);
  --sidebar-w: 200px;
  --topbar-h: 52px;
  --radius: 3px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* Single light look on purpose: it recreates the product UI from the mockups. */
html { color-scheme: light; }
body {
  margin: 0;
  font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  background: var(--page);
}
button, input, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[hidden] { display: none !important; }

.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; }
.skip-link { position: absolute; left: 8px; top: -40px; background: var(--white); padding: 8px 12px; z-index: 100; border-radius: var(--radius); }
.skip-link:focus { top: 8px; }

:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  background: var(--brand);
  color: var(--white);
}
.logo { width: calc(var(--sidebar-w) - 16px); font-size: 24px; font-weight: 400; letter-spacing: .5px; }
.topbar-search { position: relative; flex: 0 1 260px; margin: 0 auto; }
.topbar-search input { width: 100%; height: 28px; border: 0; border-radius: 2px; padding: 0 30px 0 10px; background: var(--white); color: var(--text); }
.topbar-search svg { position: absolute; right: 8px; top: 4px; width: 18px; height: 18px; color: var(--muted); }
.topbar-icons { display: flex; align-items: center; gap: 16px; }
.topbar-icons svg { width: 22px; height: 22px; }
.topbar-avatar { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--white); object-fit: cover; }
.icon-btn { display: none; background: none; border: 0; color: inherit; padding: 6px; border-radius: var(--radius); cursor: pointer; }

/* ---------- Shell + sidebar ---------- */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  flex: 0 0 var(--sidebar-w);
  background: var(--brand);
  color: var(--white);
  padding-top: 4px;
  transition: flex-basis .2s ease;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.sidebar-collapse { display: block; margin: 0 8px 4px auto; background: none; border: 0; color: var(--white); padding: 4px; border-radius: var(--radius); cursor: pointer; }
.nav-list, .subnav { list-style: none; margin: 0; padding: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; font-size: 14px; white-space: nowrap; }
.nav-item.is-active { background: var(--brand-active); color: var(--text); }
.nav-item.is-active svg { color: var(--brand); }
.subnav { background: var(--white); color: var(--text); padding: 4px 0; }
.subnav span { display: block; padding: 6px 16px 6px 46px; font-size: 13px; }
.subnav .is-current { color: var(--brand); font-weight: 700; }

.sidebar.is-collapsed { flex-basis: 56px; overflow: hidden; }
.sidebar.is-collapsed .nav-label, .sidebar.is-collapsed .subnav { display: none; }
.sidebar.is-collapsed .sidebar-collapse svg { transform: rotate(180deg); }
.sidebar.is-collapsed .sidebar-collapse { margin-right: 14px; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; padding: 16px 28px 48px; max-width: 1080px; }
.main:focus { outline: none; }
.breadcrumb { margin: 0; font-size: 12px; color: var(--brand); }
.page-title { margin: 2px 0 20px; font-size: 22px; font-weight: 700; color: var(--text); }
.page-title:focus { outline: none; }

.card { background: var(--card); border: 1px solid var(--border); padding: 20px; margin-bottom: 16px; }
.card--panel { padding: 0; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-weight: 700; font-size: 14px; }
.field--half { max-width: 440px; margin-top: 18px; }
input[type="text"], input[type="number"], select {
  height: 34px; width: 100%;
  border: 1px solid var(--input-border); border-radius: 2px;
  background: var(--white);
  padding: 0 10px;
}
select { appearance: none; padding-right: 28px; background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0h10L5 6z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 10px center; }
input[readonly] { background: var(--white); }
input::placeholder { color: var(--placeholder); }
input:focus-visible, select:focus-visible { border-color: var(--primary); }

.patient-row { display: flex; align-items: center; gap: 48px; }
.patient-row .field { flex: 0 1 220px; }
.patient-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 24px; }
.grid-2--narrow { max-width: 560px; }

/* Panel head */
.panel-head { margin: 0; }
.panel-toggle, .panel-head--static {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 22px 20px; background: var(--white); border: 0;
  font-size: 15px; font-weight: 700; text-align: left; cursor: pointer;
}
.panel-head--static { cursor: default; }
.panel-head--static h2 { margin: 0; font-size: 15px; }
.panel-toggle svg { width: 22px; height: 22px; stroke-width: 2.4; transition: transform .2s; }
.panel-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.panel-body { border-top: 1px solid var(--border); padding-bottom: 20px; }
.charges-top { padding: 16px 20px; border-bottom: 1px solid var(--border); }

.radio-group { border: 0; padding: 0; margin: 16px 0 0; min-width: 0; }
.radio-group legend { font-weight: 700; padding: 0; margin-bottom: 10px; }
.radio-options { display: flex; gap: 40px; flex-wrap: wrap; }
.radio { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.radio input { appearance: none; width: 18px; height: 18px; border: 1px solid var(--input-border); border-radius: 50%; background: var(--white); margin: 0; cursor: pointer; }
.radio input:checked { border-color: var(--primary); background: radial-gradient(var(--primary) 0 4px, var(--white) 5px); }

/* Insurance block */
.insurance { background: var(--ins-bg); margin: 4px 10px 0; padding: 18px 16px 20px; }
.block-title { font-size: 15px; font-weight: 700; margin: 0 0 10px; }
.insurance .block-title + .table-wrap { margin-bottom: 4px; }
#cptTitle { margin-top: 18px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.ins-table th, .summary-table th, .cpt-table th { font-size: 12px; font-weight: 700; text-align: center; padding: 10px 8px; background: var(--card); }
.ins-table td { background: var(--white); padding: 12px 8px; font-size: 12px; text-align: center; border-right: 1px solid var(--border); }
.ins-table td:first-child { text-align: left; }
.ins-table th:first-child { text-align: left; }
.ins-table td:last-child { border-right: 0; }

.link-strong { background: none; border: 0; padding: 2px 4px; color: var(--navy); font-weight: 700; text-transform: uppercase; font-size: 12px; cursor: pointer; border-radius: 2px; }
.link-btn { background: none; border: 0; padding: 4px 2px; color: var(--primary); font-size: 14px; cursor: pointer; border-radius: 2px; }
.link-btn:hover, .link-strong:hover { text-decoration: underline; }

/* CPT table */
.cpt-wrap { background: var(--white); }
.cpt-table th { background: var(--card); }
.cpt-table td { padding: 6px; vertical-align: top; border-right: 1px solid #e6e6e6; border-bottom: 1px solid #e6e6e6; background: var(--white); }
.cpt-table td:last-child { border-right: 0; }
.c-desc { width: 26%; } .c-mod { width: 20%; } .c-dx { width: 34%; } .c-qty { width: 7%; } .c-charge { width: 13%; }
.cpt-table th.c-desc { text-align: left; }

.mods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.mods input { padding: 0 2px; text-align: center; height: 38px; }
.qty-input { text-align: center; height: 38px !important; padding: 0 4px !important; }
.money { position: relative; }
.money span { position: absolute; left: 9px; top: 9px; font-size: 13px; }
.money input { text-align: right; padding-left: 20px; height: 38px; }
.cell-label { display: none; }

.cpt-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-top: 8px; }
.total { margin: 6px 16px 0 0; font-size: 18px; font-weight: 700; display: flex; gap: 40px; }
.total output { min-width: 80px; text-align: right; }

.add-charge-row { padding: 12px 10px 0; }
.btn-outline { background: var(--white); border: 1px solid var(--border); color: var(--primary); padding: 8px 28px; border-radius: 2px; cursor: not-allowed; }

/* ---------- Select control (diagnosis, CPT, associated diagnosis) ---------- */
.select { position: relative; }
.select-control {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  min-height: 38px; padding: 3px 30px 3px 4px;
  background: var(--white); border: 1px solid var(--input-border); border-radius: 2px;
  position: relative;
}
.select-toggle {
  flex: 1 1 60px; min-width: 60px; align-self: stretch;
  background: none; border: 0; text-align: left; padding: 0 6px; color: var(--placeholder); cursor: pointer;
  border-radius: 2px;
}
.select-control::after {
  content: ""; position: absolute; right: 11px; top: 50%; margin-top: -2px;
  border: 5px solid transparent; border-top-color: #888; pointer-events: none;
}
.select-control.is-filled .select-toggle { color: transparent; }
.select.has-error .select-control, input.has-error { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }

.chip {
  display: inline-flex; align-items: flex-start; gap: 6px;
  max-width: 100%;
  background: var(--chip); border: 1px solid var(--chip-border); border-radius: 2px;
  padding: 3px 4px 3px 6px; font-size: 13px; line-height: 1.3; color: var(--text);
}
.chip-text { flex: 1; }
.chip-remove { background: none; border: 0; color: #777; padding: 0 3px; font-size: 16px; line-height: 1; cursor: pointer; border-radius: 2px; }
.chip-remove:hover { color: var(--text); }
.chip--cpt { background: var(--white); border-color: #d8d8d8; width: 100%; padding: 6px 6px 6px 8px; }
.chip--cpt .chip-remove { font-size: 22px; }

.select-panel {
  position: absolute; z-index: 20; left: 0; top: 100%; margin-top: 2px;
  width: max(100%, 280px); max-width: min(420px, 90vw);
  background: var(--white); border: 1px solid var(--border); border-radius: 2px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .15);
  padding: 10px 6px 8px 12px;
}
.select-panel input[type="search"] { width: calc(100% - 6px); height: 32px; border: 1px solid var(--input-border); border-radius: 2px; padding: 0 10px; margin-bottom: 8px; }
.select-panel input[type="search"]::placeholder { font-style: italic; color: var(--placeholder); }
.option-list { list-style: none; margin: 0; padding: 0 6px 0 0; max-height: 200px; overflow-y: auto; }
.option { display: flex; align-items: flex-start; gap: 10px; padding: 7px 4px; cursor: pointer; font-size: 14px; border-radius: 2px; }
.option:hover { background: #f4f8fc; }
.option input { appearance: none; flex: 0 0 18px; width: 18px; height: 18px; margin: 1px 0 0; border: 1px solid #9a9a9a; border-radius: 2px; background: var(--white); cursor: pointer; }
.option input:checked { background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' stroke='white' stroke-width='2' fill='none'/%3E%3C/svg%3E") center/14px no-repeat; border-color: var(--primary); }
.option input:disabled { background: #eee; cursor: not-allowed; }
.option.is-disabled { color: var(--placeholder); cursor: not-allowed; }
.option-empty { padding: 8px 4px; color: var(--muted); font-size: 13px; }
.select-hint { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid #eee; font-size: 12px; color: var(--muted); }

.field-error { color: var(--error); font-size: 12px; margin: 4px 0 0; }
.error-summary { background: var(--error-bg); border-left: 4px solid var(--error); padding: 10px 14px; margin-bottom: 16px; color: var(--text); }
.error-summary:focus { outline: none; box-shadow: var(--focus); }
.error-summary strong { color: var(--error); }
.error-summary ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Charge summary ---------- */
.summary-table th { background: var(--white); border-bottom: 1px solid var(--border); }
.summary-table td { background: var(--white); text-align: center; padding: 10px 8px; font-size: 12px; }
.summary-table td:first-child, .summary-table th:first-child { text-align: left; }
.muted-xs { font-size: 10px; color: var(--muted); }
.row-actions { white-space: nowrap; }
.row-actions svg { width: 16px; height: 16px; vertical-align: middle; margin-left: 8px; }
.summary-totals { margin: 16px 0 0 auto; max-width: 380px; }
.summary-totals div { display: flex; justify-content: space-between; padding: 6px 0; }
.summary-totals dt, .summary-totals dd { margin: 0; }
.summary-totals .grand { border-top: 1px solid #777; margin-top: 10px; padding-top: 14px; font-size: 20px; font-weight: 700; }

/* ---------- Notes ---------- */
.editor { background: var(--white); border: 1px solid var(--border); }
.editor-toolbar { display: flex; gap: 14px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: #f1f1f1; font-size: 13px; color: #333; }
.editor-body { padding: 14px 18px 28px; font-size: 13px; line-height: 1.5; min-height: 100px; }
.editor-body:focus-visible { box-shadow: inset var(--focus); }

/* ---------- Actions ---------- */
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.btn-primary { background: var(--primary); color: var(--white); border: 0; border-radius: 2px; padding: 10px 18px; font-weight: 700; font-size: 13px; cursor: pointer; }
.btn-primary:hover { background: var(--primary-dark); }
.link-cancel { background: none; border: 0; color: var(--navy); padding: 8px; cursor: pointer; border-radius: 2px; }
.link-cancel:hover { text-decoration: underline; }

/* ---------- Confirmation ---------- */
.confirm-card { background: var(--white); padding: 28px; margin-top: 8px; }
.confirm-head { display: flex; gap: 16px; align-items: center; margin-bottom: 8px; }
.confirm-head .page-title { margin: 0; }
.confirm-icon { width: 44px; height: 44px; border-radius: 50%; background: #e3f3ea; color: var(--success); display: grid; place-items: center; }
.confirm-icon svg { width: 24px; height: 24px; stroke-width: 2.6; }
.confirm-meta { margin: 4px 0 0; color: var(--muted); }
.confirm-note { background: var(--brand-active); padding: 10px 14px; margin: 16px 0 0; }
.confirm-section { margin-top: 24px; }
.confirm-section h2 { font-size: 15px; margin: 0 0 10px; }
.confirm-dx { display: flex; flex-wrap: wrap; gap: 6px; }
.confirm-table th { font-size: 12px; text-align: left; padding: 8px; background: var(--card); }
.confirm-table td { padding: 10px 8px; border-bottom: 1px solid #eee; vertical-align: top; font-size: 13px; }
.confirm-table .num { text-align: right; white-space: nowrap; }
.confirm-table tfoot td { font-weight: 700; font-size: 16px; border-bottom: 0; padding-top: 14px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b2f33; color: var(--white); padding: 10px 18px; border-radius: 4px; font-size: 13px; z-index: 50; box-shadow: 0 6px 18px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }

/* ---------- Portfolio label ---------- */
.proto-label {
  position: fixed; z-index: 45; margin: 0;
  right: calc(12px + env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(43, 47, 51, .82); color: var(--white);
  font-size: 11px; padding: 5px 10px; border-radius: 100px; pointer-events: none;
}

/* ==========================================================
   Responsive
   ========================================================== */
@media (max-width: 960px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
  .icon-btn { display: inline-flex; }
  .logo { width: auto; }
  .topbar-search { display: none; }
  .topbar-icons { margin-left: auto; }
  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 40;
    width: 240px; height: auto; transform: translateX(-100%); transition: transform .2s ease;
    overflow-y: auto;
  }
  .sidebar.is-open { transform: none; }
  .sidebar-collapse { display: none; }
  .scrim { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { padding: 14px 16px 40px; }

  /* CPT table becomes stacked cards */
  .cpt-table thead { display: none; }
  .cpt-table, .cpt-table tbody, .cpt-table tr, .cpt-table td { display: block; width: 100%; }
  .cpt-table tr { border-bottom: 6px solid var(--ins-bg); padding: 6px 0; }
  .cpt-table td { border: 0; padding: 6px 10px; }
  .cell-label { display: block; font-size: 12px; font-weight: 700; margin-bottom: 4px; }
  .cpt-table .c-qty-cell, .cpt-table .c-charge-cell { display: inline-block; width: 50%; vertical-align: top; }
}

@media (max-width: 600px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .patient-row { gap: 20px; }
  .insurance { margin: 4px 0 0; padding: 16px 12px; }
  .ins-table thead { display: none; }
  .ins-table, .ins-table tbody, .ins-table tr, .ins-table td { display: block; width: 100%; }
  .ins-table td { display: flex; justify-content: space-between; gap: 12px; text-align: right; border-right: 0; border-bottom: 1px solid #eee; padding: 8px 10px; }
  .ins-table td::before { content: attr(data-label); font-weight: 700; text-align: left; }
  .ins-table td:first-child { text-align: right; }
  .cpt-foot { flex-direction: column; align-items: stretch; }
  .total { justify-content: space-between; margin-right: 0; }
  .summary-totals .grand { font-size: 18px; }
  .form-actions .btn-primary { flex: 1 1 100%; }
  .confirm-card { padding: 20px 16px; }
  .topbar-icons svg:first-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
