// tab-discharge.jsx — F8 Discharge summary check + tariff audit + claim package
// Three sequential gates: completeness → tariff audit → implant reconciliation.
// Only when all green does claim package ZIP generate.

const PCDT2_t = window.PCT;
const PCDT2_d = window.PCA;

function DischargeTab({ claim, insurer }) {
  const store = useStore();

  // Sequential gates
  const completeness = useCompletenessState(claim);
  const tariffAudit = useTariffAuditState(claim, insurer);
  const implantGate = useImplantGateState(claim);
  const allOk = completeness.complete && tariffAudit.acknowledged && implantGate.ok;

  const handleGenerateZip = () => {
    store.updateClaim(claim.id, { status: 'CLAIM_SUBMITTED' });
    store.toast({ icon:'whatsapp', title:'Claim package ZIP generated', body:`Ready to upload to ${insurer.name} portal` });
  };

  return (
    <div style={{ display:'grid', gridTemplateColumns:'1fr 320px', gap:14 }}>
      <div style={{ display:'flex', flexDirection:'column', gap:14 }}>
        <GateStrip
          gates={[
            { id:1, label:'Discharge summary', ok: completeness.complete, count: completeness },
            { id:2, label:'Tariff audit',      ok: tariffAudit.acknowledged, count: tariffAudit },
            { id:3, label:'Implant gate',      ok: implantGate.ok, count: implantGate },
          ]}
        />

        <CompletenessCard claim={claim} state={completeness}/>
        <TariffAuditCard claim={claim} insurer={insurer} state={tariffAudit}/>
        <ImplantGateCard claim={claim} state={implantGate}/>

        <FinalPackageCard claim={claim} insurer={insurer} ready={allOk} onGenerate={handleGenerateZip}/>
      </div>

      <div style={{ display:'flex', flexDirection:'column', gap:14 }}>
        <DischargeChecklistGuide insurer={insurer}/>
        <RohiniReminderCard/>
      </div>
    </div>
  );
}

// ── Completeness ───────────────────────────────────────────
const COMPLETENESS_ITEMS = [
  { id:'admDate',    label:'Admission date &amp; time',                ocrPattern:'date' },
  { id:'disDate',    label:'Discharge date &amp; time',                ocrPattern:'date' },
  { id:'icd',        label:'Primary ICD-10 diagnosis code',             ocrPattern:'icd' },
  { id:'secondary',  label:'Secondary diagnoses (comorbidities)',       ocrPattern:'icd' },
  { id:'rohini',     label:'ROHINI ID (13-digit, hospital)',            ocrPattern:'rohini' },
  { id:'doctorReg',  label:"Doctor's name &amp; registration number",   ocrPattern:'reg' },
  { id:'course',     label:'Clinical course (not just Dx + advice)' },
  { id:'condition',  label:'Condition at discharge' },
  { id:'implant',    label:'Implant brand/model/batch (if used)', conditional:'implant' },
  { id:'icuHours',   label:'ICU hours (if ICU stay)',             conditional:'icu' },
];

function useCompletenessState(claim) {
  const integrated = window.__pcStore?.state.mode === 'integrated';
  const [checked, setChecked] = React.useState(() => {
    // In integrated mode, pre-tick items with ocrPattern (EHR auto-validated)
    // In standalone, only pre-tick if discharge summary uploaded AND OCR detects
    if (integrated) {
      return new Set(COMPLETENESS_ITEMS.filter(i => i.ocrPattern).map(i => i.id));
    }
    if (claim.documents?.includes('DISCHARGE_SUMMARY')) {
      return new Set(['admDate','disDate','icd','rohini','doctorReg']);
    }
    return new Set();
  });

  const hasImplant = (claim.charges || []).some(c => c.category === 'IMPLANT');
  const hasICU = claim.roomType === 'ICU' || (claim.charges || []).some(c => c.description?.toLowerCase().includes('icu'));

  const required = COMPLETENESS_ITEMS.filter(it => {
    if (it.conditional === 'implant' && !hasImplant) return false;
    if (it.conditional === 'icu' && !hasICU) return false;
    return true;
  });
  const complete = required.every(it => checked.has(it.id));

  return { items: required, checked, toggle: (id) => setChecked(prev => {
    const next = new Set(prev);
    if (next.has(id)) next.delete(id); else next.add(id);
    return next;
  }), complete, done: checked.size, total: required.length };
}

function CompletenessCard({ claim, state }) {
  const integrated = useIntegrated();
  const hasDS = (claim.documents || []).includes('DISCHARGE_SUMMARY');
  return (
    <AppCard>
      <div style={{ display:'flex', justifyContent:'space-between', alignItems:'flex-start', gap:14 }}>
        <div>
          <AppSectionLabel>Gate 1 · Discharge summary completeness</AppSectionLabel>
          <div style={{ fontSize:15, fontWeight:600, marginTop:8 }}>
            {state.complete ? <span style={{ color: PCDT2_t.c.success }}>All mandatory items confirmed</span> :
             `${state.done} of ${state.total} items confirmed`}
          </div>
          <div style={{ fontSize:12.5, color: PCDT2_t.c.textMuted, marginTop:4, lineHeight:1.55 }}>
            {integrated
              ? <span><HmsBadge variant="chip">EHR</HmsBadge> &nbsp;Items cross-validated against <strong>clinical-service</strong> EHR record · confirm soft items below.</span>
              : hasDS ? 'OCR detected the discharge summary — auto-validated items shown pre-ticked. Confirm each before proceeding.'
                      : 'Upload the discharge summary PDF, then confirm each item is present.'}
          </div>
        </div>
        <div style={{
          padding:'8px 14px', borderRadius:8,
          background: state.complete ? PCDT2_t.c.successTint : PCDT2_t.c.warningTint,
          color: state.complete ? PCDT2_t.c.success : PCDT2_t.c.warning,
          fontFamily: PCDT2_t.f.mono, fontSize:18, fontWeight:600, letterSpacing:'-.02em',
          fontVariantNumeric:'tabular-nums',
        }}>{state.done}/{state.total}</div>
      </div>

      {!hasDS && (
        <div style={{ marginTop:14 }}>
          <UploadZone
            docType="DISCHARGE_SUMMARY"
            label="Upload discharge summary PDF"
            required
            onUpload={(p) => {
              const store = window.__pcStore;
              if (store) {
                store.addDocument(claim.id, 'DISCHARGE_SUMMARY');
                store.toast({ icon:'whatsapp', title:'Discharge summary uploaded', body:'OCR auto-validating admission date, ICD-10, ROHINI…' });
              }
            }}
          />
        </div>
      )}

      <div style={{
        marginTop:14,
        display:'grid', gridTemplateColumns:'1fr 1fr', gap:0,
        border: `1px solid ${PCDT2_t.c.border}`, borderRadius:8, overflow:'hidden',
      }}>
        {state.items.map((it, i) => {
          const ok = state.checked.has(it.id);
          return (
            <div key={it.id} onClick={() => state.toggle(it.id)} style={{
              display:'flex', alignItems:'center', gap:11,
              padding:'12px 14px',
              borderRight: (i % 2 === 0) ? `1px solid ${PCDT2_t.c.border}` : 'none',
              borderTop: i >= 2 ? `1px solid ${PCDT2_t.c.border}` : 'none',
              cursor:'pointer', background: ok ? PCDT2_t.c.successTint + '50' : 'transparent',
            }}>
              <div style={{
                width:18, height:18, borderRadius:5,
                background: ok ? PCDT2_t.c.success : '#fff',
                border: ok ? '0' : `1.5px solid ${PCDT2_t.c.borderStrong}`,
                display:'grid', placeItems:'center', flexShrink:0,
              }}>
                {ok && <AppIcon name="check" size={11} color="#fff" stroke={2.8}/>}
              </div>
              <span style={{ fontSize:12.5, color: PCDT2_t.c.text, lineHeight:1.4 }} dangerouslySetInnerHTML={{__html: it.label}}/>
              {it.ocrPattern && (hasDS || integrated) && (
                integrated
                  ? <span style={{ marginLeft:'auto' }}><HmsBadge variant="stamp"/></span>
                  : <span style={{
                      marginLeft:'auto', fontSize:9, fontWeight:600, fontFamily: PCDT2_t.f.mono,
                      padding:'1px 5px', borderRadius:3,
                      background: PCDT2_t.c.accentTint, color: PCDT2_t.c.accent,
                      letterSpacing:'.04em',
                    }}>OCR</span>
              )}
            </div>
          );
        })}
      </div>
    </AppCard>
  );
}

// ── Tariff audit ──────────────────────────────────────────
function useTariffAuditState(claim, insurer) {
  const store = useStore();
  const tariff = store.tariffFor(claim.insurer);
  const charges = claim.charges || [];

  // Match each charge to a tariff row by description similarity
  const flags = charges.map(c => {
    if (!tariff) return null;
    const row = tariff.rows.find(r =>
      c.description.toLowerCase().includes(r.description.toLowerCase().slice(0,12)) ||
      r.description.toLowerCase().includes(c.description.toLowerCase().slice(0,12))
    );
    if (!row) return null;
    const over = c.amount > row.maxAmount;
    if (!over) return null;
    return {
      chargeId: c.id, description: c.description, billed: c.amount,
      maxAllowed: row.maxAmount, overage: c.amount - row.maxAmount, tariffCode: row.code,
    };
  }).filter(Boolean);

  const [acks, setAcks] = React.useState(new Set());
  const acknowledged = !tariff || flags.length === 0 || flags.every(f => acks.has(f.chargeId));

  return {
    tariff, flags, acks, acknowledged,
    ack: (id) => setAcks(prev => new Set([...prev, id])),
    done: acks.size, total: flags.length,
  };
}

function TariffAuditCard({ claim, insurer, state }) {
  if (!state.tariff) {
    return (
      <AppCard>
        <AppSectionLabel>Gate 2 · Tariff audit</AppSectionLabel>
        <div style={{
          marginTop:12, padding:'12px 14px',
          background: PCDT2_t.c.surface2, borderRadius:7,
          display:'flex', gap:10, alignItems:'center',
          fontSize:12.5, color: PCDT2_t.c.textMuted, lineHeight:1.55,
        }}>
          <AppIcon name="info" size={14} color={PCDT2_t.c.textMuted}/>
          <span>
            No contracted tariff schedule uploaded for <strong>{insurer.name}</strong>. Skipping line-by-line audit.
            A note will be recorded on the claim cover sheet.
            <a href="#/settings/tariffs" style={{ color: PCDT2_t.c.accent, marginLeft:6, textDecoration:'none' }}>
              Upload tariff →
            </a>
          </span>
        </div>
      </AppCard>
    );
  }

  return (
    <AppCard>
      <div style={{ display:'flex', justifyContent:'space-between', alignItems:'flex-start' }}>
        <div>
          <AppSectionLabel>Gate 2 · Tariff audit</AppSectionLabel>
          <div style={{ fontSize:15, fontWeight:600, marginTop:8 }}>
            {state.flags.length === 0
              ? <span style={{ color: PCDT2_t.c.success }}>All line items within contracted tariff</span>
              : `${state.flags.length} line item${state.flags.length > 1 ? 's' : ''} over tariff`}
          </div>
          <div style={{ fontSize:12, color: PCDT2_t.c.textMuted, marginTop:4 }}>
            Compared against <strong>{insurer.name}</strong> tariff effective {state.tariff.effectiveFrom}
          </div>
        </div>
        {state.flags.length > 0 && (
          <div style={{
            padding:'6px 12px', borderRadius:7,
            background: PCDT2_t.c.errorTint, color: PCDT2_t.c.error,
            fontFamily: PCDT2_t.f.mono, fontSize:13, fontWeight:600,
          }}>
            +{PCDT2_d.inr(state.flags.reduce((s, f) => s + f.overage, 0))} over
          </div>
        )}
      </div>

      {state.flags.length > 0 && (
        <div style={{ marginTop:14 }}>
          {state.flags.map(f => {
            const acked = state.acks.has(f.chargeId);
            return (
              <div key={f.chargeId} style={{
                display:'grid', gridTemplateColumns:'1fr 100px 100px 110px 100px',
                gap:10, padding:'10px 12px', alignItems:'center',
                borderTop: `1px solid ${PCDT2_t.c.border}`,
                background: acked ? PCDT2_t.c.successTint + '30' : 'transparent',
              }}>
                <div>
                  <div style={{ fontSize:12.5, fontWeight:500 }}>{f.description}</div>
                  <div style={{ fontSize:10.5, color: PCDT2_t.c.textDim, fontFamily: PCDT2_t.f.mono, marginTop:2 }}>
                    Tariff code <strong style={{ color: PCDT2_t.c.text }}>{f.tariffCode}</strong>
                  </div>
                </div>
                <div style={{ textAlign:'right' }}>
                  <div style={{ fontSize:9.5, color: PCDT2_t.c.textDim, fontFamily: PCDT2_t.f.mono, textTransform:'uppercase' }}>Billed</div>
                  <AppMoney value={f.billed} size={12}/>
                </div>
                <div style={{ textAlign:'right' }}>
                  <div style={{ fontSize:9.5, color: PCDT2_t.c.textDim, fontFamily: PCDT2_t.f.mono, textTransform:'uppercase' }}>Allowed</div>
                  <AppMoney value={f.maxAllowed} size={12}/>
                </div>
                <div style={{ textAlign:'right' }}>
                  <div style={{ fontSize:9.5, color: PCDT2_t.c.error, fontFamily: PCDT2_t.f.mono, textTransform:'uppercase' }}>Overage</div>
                  <span style={{ fontSize:13, fontWeight:600, color: PCDT2_t.c.error, fontFamily: PCDT2_t.f.mono }}>+{PCDT2_d.inr(f.overage)}</span>
                </div>
                <div style={{ display:'flex', justifyContent:'flex-end' }}>
                  {acked ? (
                    <span style={{
                      display:'inline-flex', alignItems:'center', gap:5,
                      padding:'4px 10px', borderRadius:5,
                      background: PCDT2_t.c.success, color:'#fff',
                      fontSize:11, fontWeight:600, fontFamily: PCDT2_t.f.sans,
                    }}>
                      <AppIcon name="check" size={11}/> Acked
                    </span>
                  ) : (
                    <AppBtn size="sm" kind="ghost" onClick={() => state.ack(f.chargeId)}>Acknowledge</AppBtn>
                  )}
                </div>
              </div>
            );
          })}
        </div>
      )}

      <div style={{
        marginTop:14, padding:'10px 12px',
        background: PCDT2_t.c.surface2, borderRadius:6,
        fontSize:11.5, color: PCDT2_t.c.textMuted, lineHeight:1.55,
        display:'flex', gap:8, alignItems:'flex-start',
      }}>
        <AppIcon name="info" size={13} color={PCDT2_t.c.textMuted}/>
        <span>
          Items over the contracted rate must be acknowledged before claim submission.
          The hospital may absorb the difference, or negotiate with the patient — TPAs will only honour the tariff cap.
        </span>
      </div>
    </AppCard>
  );
}

// ── Implant gate ──────────────────────────────────────────
function useImplantGateState(claim) {
  const implants = (claim.charges || []).filter(c => c.category === 'IMPLANT');
  const missing = implants.filter(c => c.implantMissing);
  const hasImplants = implants.length > 0;
  return {
    hasImplants,
    implants,
    missing,
    ok: missing.length === 0,
    done: implants.length - missing.length,
    total: implants.length,
  };
}

function ImplantGateCard({ claim, state }) {
  if (!state.hasImplants) {
    return (
      <AppCard>
        <AppSectionLabel>Gate 3 · Implant reconciliation</AppSectionLabel>
        <div style={{
          marginTop:12, padding:'12px 14px',
          background: PCDT2_t.c.successTint, borderRadius:7,
          display:'flex', gap:10, alignItems:'center',
          fontSize:12.5, color: PCDT2_t.c.success, fontWeight:500,
        }}>
          <AppIcon name="check" size={14} color={PCDT2_t.c.success}/>
          No implants used on this admission · gate auto-passed
        </div>
      </AppCard>
    );
  }

  return (
    <AppCard>
      <div style={{ display:'flex', justifyContent:'space-between', alignItems:'flex-start' }}>
        <div>
          <AppSectionLabel>Gate 3 · Implant reconciliation</AppSectionLabel>
          <div style={{ fontSize:15, fontWeight:600, marginTop:8 }}>
            {state.ok ? <span style={{ color: PCDT2_t.c.success }}>All implants reconciled</span>
                      : `${state.missing.length} implant${state.missing.length > 1 ? 's' : ''} missing barcode`}
          </div>
          <div style={{ fontSize:12, color: PCDT2_t.c.textMuted, marginTop:4, lineHeight:1.55 }}>
            {state.ok ? 'Manufacturer barcodes attached for every implant charge.' :
                        'Claim submission is blocked until all implant barcodes are attached.'}
          </div>
        </div>
        <div style={{
          padding:'8px 14px', borderRadius:8,
          background: state.ok ? PCDT2_t.c.successTint : PCDT2_t.c.errorTint,
          color: state.ok ? PCDT2_t.c.success : PCDT2_t.c.error,
          fontFamily: PCDT2_t.f.mono, fontSize:18, fontWeight:600,
          fontVariantNumeric:'tabular-nums',
        }}>{state.done}/{state.total}</div>
      </div>

      <div style={{ marginTop:14 }}>
        {state.implants.map(im => (
          <div key={im.id} style={{
            display:'grid', gridTemplateColumns:'1fr 1fr 100px',
            gap:10, padding:'10px 12px', alignItems:'center',
            borderTop: `1px solid ${PCDT2_t.c.border}`,
            background: im.implantMissing ? PCDT2_t.c.warningTint + '40' : PCDT2_t.c.successTint + '30',
          }}>
            <div>
              <div style={{ fontSize:13, fontWeight:500 }}>{im.description}</div>
              <div style={{ fontSize:11, color: PCDT2_t.c.textMuted, fontFamily: PCDT2_t.f.mono, marginTop:2 }}>
                <AppMoney value={im.amount} size={11}/>
              </div>
            </div>
            {im.implantBarcode ? (
              <div style={{ fontSize:11, color: PCDT2_t.c.textMuted, fontFamily: PCDT2_t.f.mono, lineHeight:1.5 }}>
                <div>{im.implantBarcode.brand}</div>
                <div style={{ color: PCDT2_t.c.textDim }}>batch {im.implantBarcode.batch}</div>
              </div>
            ) : (
              <div style={{ fontSize:11.5, color: PCDT2_t.c.warning, fontWeight:500 }}>Barcode not uploaded</div>
            )}
            <div style={{ display:'flex', justifyContent:'flex-end' }}>
              {im.implantMissing ? (
                <AppBtn size="sm" kind="ghost" icon="upload">Upload</AppBtn>
              ) : (
                <span style={{ display:'inline-flex', alignItems:'center', gap:5, color: PCDT2_t.c.success, fontSize:11, fontWeight:600 }}>
                  <AppIcon name="check" size={11}/> Reconciled
                </span>
              )}
            </div>
          </div>
        ))}
      </div>
    </AppCard>
  );
}

// ── Final package ─────────────────────────────────────────
function FinalPackageCard({ claim, insurer, ready, onGenerate }) {
  return (
    <AppCard>
      <div style={{ display:'flex', justifyContent:'space-between', alignItems:'flex-start', gap:14 }}>
        <div>
          <AppSectionLabel>Final claim package</AppSectionLabel>
          <div style={{ fontSize:15, fontWeight:600, marginTop:8 }}>
            {ready
              ? <span style={{ color: PCDT2_t.c.success }}>Ready to generate the submission ZIP</span>
              : 'Complete the gates above to unlock'}
          </div>
          <div style={{ fontSize:12.5, color: PCDT2_t.c.textMuted, marginTop:4, lineHeight:1.55 }}>
            Generates a ZIP with cover sheet, all documents in {insurer.name} sequence, tariff audit sign-off,
            and the {claim.documents.length} attached files. ROHINI {PCDT2_d.tenant.rohini} stamped on every PDF.
          </div>
        </div>
        <AppBtn kind={ready ? 'brand' : 'ghost'} icon="download" disabled={!ready} onClick={onGenerate}>
          Generate &amp; download ZIP
        </AppBtn>
      </div>

      <div style={{
        marginTop:14, padding:'14px 16px',
        background: ready ? PCDT2_t.c.successTint : PCDT2_t.c.surface2,
        borderRadius:8,
        display:'grid', gridTemplateColumns:'auto 1fr auto', gap:14, alignItems:'center',
      }}>
        <div style={{
          width:42, height:42, borderRadius:8,
          background:'#fff', color: ready ? PCDT2_t.c.success : PCDT2_t.c.textDim,
          display:'grid', placeItems:'center',
          border: `1px solid ${PCDT2_t.c.border}`,
        }}>
          <AppIcon name="docs" size={20}/>
        </div>
        <div>
          <div style={{ fontSize:13, fontWeight:600 }}>{claim.id}_FINAL.zip</div>
          <div style={{ fontSize:11, color: PCDT2_t.c.textMuted, fontFamily: PCDT2_t.f.mono, marginTop:2 }}>
            ~{(claim.documents.length * 0.3 + 0.6).toFixed(1)} MB · {claim.documents.length + 2} files
          </div>
        </div>
        <div style={{
          fontSize:11, color: ready ? PCDT2_t.c.success : PCDT2_t.c.textDim,
          fontFamily: PCDT2_t.f.mono, fontWeight:600, letterSpacing:'.06em', textTransform:'uppercase',
        }}>{ready ? 'Ready' : 'Locked'}</div>
      </div>

      <div style={{ marginTop:14, fontSize:11.5, color: PCDT2_t.c.textMuted, lineHeight:1.55 }}>
        <strong style={{ color: PCDT2_t.c.text }}>Next:</strong> Download the ZIP, log in to{' '}
        <span style={{ fontFamily: PCDT2_t.f.mono, color: PCDT2_t.c.accent }}>{insurer.portal.replace(/https?:\/\/(www\.)?/,'')}</span>,
        upload the package, note the claim reference and come back to mark it submitted.
        <span style={{ color: PCDT2_t.c.textDim, marginLeft:4 }}>(Phase 1: manual upload — Phase 2 will do this via NHCX.)</span>
      </div>
    </AppCard>
  );
}

// ── Sidebar ───────────────────────────────────────────────
function GateStrip({ gates }) {
  return (
    <div style={{
      display:'flex', alignItems:'center', gap:8,
      padding:'10px 14px',
      background: PCDT2_t.c.surface,
      border: `1px solid ${PCDT2_t.c.border}`,
      borderRadius:9,
    }}>
      {gates.map((g, i) => (
        <React.Fragment key={g.id}>
          <div style={{
            display:'flex', alignItems:'center', gap:7,
            padding:'5px 10px', borderRadius:6,
            background: g.ok ? PCDT2_t.c.successTint : PCDT2_t.c.surface2,
            color: g.ok ? PCDT2_t.c.success : PCDT2_t.c.textMuted,
            fontSize:12, fontWeight: g.ok ? 600 : 500,
          }}>
            <span style={{
              width:18, height:18, borderRadius:'50%',
              background: g.ok ? PCDT2_t.c.success : '#fff',
              border: g.ok ? '0' : `1.5px solid ${PCDT2_t.c.borderStrong}`,
              display:'grid', placeItems:'center',
              color:'#fff', fontSize:10, fontWeight:700,
              fontFamily: PCDT2_t.f.mono,
            }}>
              {g.ok ? <AppIcon name="check" size={10} color="#fff" stroke={2.8}/> : g.id}
            </span>
            {g.label}
            {g.count && g.count.total > 0 && (
              <span style={{ fontFamily: PCDT2_t.f.mono, fontSize:10, color: PCDT2_t.c.textMuted }}>
                {g.count.done}/{g.count.total}
              </span>
            )}
          </div>
          {i < gates.length - 1 && <AppIcon name="right" size={12} color={PCDT2_t.c.textDim}/>}
        </React.Fragment>
      ))}
    </div>
  );
}

function DischargeChecklistGuide({ insurer }) {
  return (
    <AppCard>
      <AppSectionLabel>What gets checked</AppSectionLabel>
      <ol style={{ paddingLeft:18, marginTop:10, marginBottom:0, fontSize:12, color: PCDT2_t.c.text, lineHeight:1.65 }}>
        <li><strong>Completeness</strong> — all mandatory fields on the discharge summary, cross-validated against EHR in HMS mode.</li>
        <li><strong>Tariff audit</strong> — each line item vs. {insurer.name}'s contracted rate. Overages must be acknowledged.</li>
        <li><strong>Implant gate</strong> — every implant charge must have a barcode. Missing → blocked.</li>
      </ol>
      <div style={{
        marginTop:12, padding:'10px 12px',
        background: PCDT2_t.c.warningTint, borderRadius:6,
        fontSize:11, color:'#92400E', lineHeight:1.55,
        display:'flex', gap:8, alignItems:'flex-start',
      }}>
        <AppIcon name="alert" size={13} color={PCDT2_t.c.warning}/>
        <span>Common Karnataka rejection causes: ICD-10 missing on D/S, ROHINI mismatch, room-rent upgrade not declared.</span>
      </div>
    </AppCard>
  );
}

function RohiniReminderCard() {
  return (
    <AppCard>
      <AppSectionLabel>ROHINI · stamped</AppSectionLabel>
      <div style={{
        marginTop:10, padding:'10px 12px',
        background: PCDT2_t.c.surface2, borderRadius:6,
        fontFamily: PCDT2_t.f.mono, fontSize:12, color: PCDT2_t.c.text,
        letterSpacing:'.04em',
      }}>{PCDT2_d.tenant.rohini}</div>
      <div style={{ fontSize:11, color: PCDT2_t.c.textMuted, marginTop:8, lineHeight:1.5 }}>
        Configured in <strong>Settings → Insurers</strong>. Auto-stamped on every claim PDF.
      </div>
    </AppCard>
  );
}

Object.assign(window, { DischargeTab });
